Backout a74bd5095902, Bug 959405 - Please update the Buri Moz-central, 1.3, 1.2 with...
[gecko.git] / layout / forms / nsGfxRadioControlFrame.cpp
blob909ea5c6cdcc470236df3f3c5f23c09c65779534
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsGfxRadioControlFrame.h"
7 #include "nsRenderingContext.h"
8 #include "nsDisplayList.h"
10 using namespace mozilla;
12 nsIFrame*
13 NS_NewGfxRadioControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
15 return new (aPresShell) nsGfxRadioControlFrame(aContext);
18 NS_IMPL_FRAMEARENA_HELPERS(nsGfxRadioControlFrame)
20 nsGfxRadioControlFrame::nsGfxRadioControlFrame(nsStyleContext* aContext):
21 nsFormControlFrame(aContext)
25 nsGfxRadioControlFrame::~nsGfxRadioControlFrame()
29 #ifdef ACCESSIBILITY
30 a11y::AccType
31 nsGfxRadioControlFrame::AccessibleType()
33 return a11y::eHTMLRadioButtonType;
35 #endif
37 //--------------------------------------------------------------
38 // Draw the dot for a non-native radio button in the checked state.
39 static void
40 PaintCheckedRadioButton(nsIFrame* aFrame,
41 nsRenderingContext* aCtx,
42 const nsRect& aDirtyRect,
43 nsPoint aPt)
45 // The dot is an ellipse 2px on all sides smaller than the content-box,
46 // drawn in the foreground color.
47 nsRect rect(aPt, aFrame->GetSize());
48 rect.Deflate(aFrame->GetUsedBorderAndPadding());
49 rect.Deflate(nsPresContext::CSSPixelsToAppUnits(2),
50 nsPresContext::CSSPixelsToAppUnits(2));
52 aCtx->SetColor(aFrame->StyleColor()->mColor);
53 aCtx->FillEllipse(rect);
56 void
57 nsGfxRadioControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
58 const nsRect& aDirtyRect,
59 const nsDisplayListSet& aLists)
61 nsFormControlFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
63 if (!IsVisibleForPainting(aBuilder))
64 return;
66 if (IsThemed())
67 return; // The theme will paint the check, if any.
69 bool checked = true;
70 GetCurrentCheckState(&checked); // Get check state from the content model
71 if (!checked)
72 return;
74 aLists.Content()->AppendNewToTop(new (aBuilder)
75 nsDisplayGeneric(aBuilder, this, PaintCheckedRadioButton,
76 "CheckedRadioButton",
77 nsDisplayItem::TYPE_CHECKED_RADIOBUTTON));