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"
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/gfx/PathHelpers.h"
12 #include "nsLayoutUtils.h"
13 #include "nsRenderingContext.h"
14 #include "nsDisplayList.h"
16 using namespace mozilla
;
17 using namespace mozilla::gfx
;
20 NS_NewGfxRadioControlFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
)
22 return new (aPresShell
) nsGfxRadioControlFrame(aContext
);
25 NS_IMPL_FRAMEARENA_HELPERS(nsGfxRadioControlFrame
)
27 nsGfxRadioControlFrame::nsGfxRadioControlFrame(nsStyleContext
* aContext
):
28 nsFormControlFrame(aContext
)
32 nsGfxRadioControlFrame::~nsGfxRadioControlFrame()
38 nsGfxRadioControlFrame::AccessibleType()
40 return a11y::eHTMLRadioButtonType
;
44 //--------------------------------------------------------------
45 // Draw the dot for a non-native radio button in the checked state.
47 PaintCheckedRadioButton(nsIFrame
* aFrame
,
48 nsRenderingContext
* aCtx
,
49 const nsRect
& aDirtyRect
,
52 // The dot is an ellipse 2px on all sides smaller than the content-box,
53 // drawn in the foreground color.
54 nsRect
rect(aPt
, aFrame
->GetSize());
55 rect
.Deflate(aFrame
->GetUsedBorderAndPadding());
56 rect
.Deflate(nsPresContext::CSSPixelsToAppUnits(2),
57 nsPresContext::CSSPixelsToAppUnits(2));
60 ToRect(nsLayoutUtils::RectToGfxRect(rect
,
61 aFrame
->PresContext()->AppUnitsPerDevPixel()));
63 ColorPattern
color(ToDeviceColor(aFrame
->StyleColor()->mColor
));
65 DrawTarget
* drawTarget
= aCtx
->GetDrawTarget();
66 RefPtr
<PathBuilder
> builder
= drawTarget
->CreatePathBuilder();
67 AppendEllipseToPath(builder
, devPxRect
.Center(), devPxRect
.Size());
68 RefPtr
<Path
> ellipse
= builder
->Finish();
69 drawTarget
->Fill(ellipse
, color
);
73 nsGfxRadioControlFrame::BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
74 const nsRect
& aDirtyRect
,
75 const nsDisplayListSet
& aLists
)
77 nsFormControlFrame::BuildDisplayList(aBuilder
, aDirtyRect
, aLists
);
79 if (!IsVisibleForPainting(aBuilder
))
83 return; // The theme will paint the check, if any.
86 GetCurrentCheckState(&checked
); // Get check state from the content model
90 aLists
.Content()->AppendNewToTop(new (aBuilder
)
91 nsDisplayGeneric(aBuilder
, this, PaintCheckedRadioButton
,
93 nsDisplayItem::TYPE_CHECKED_RADIOBUTTON
));