Bumping manifests a=b2g-bump
[gecko.git] / layout / forms / nsGfxRadioControlFrame.cpp
blob7de80ba978b7dc7011613cb485318871e1d00e82
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"
8 #include "gfx2DGlue.h"
9 #include "gfxUtils.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;
19 nsIFrame*
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()
36 #ifdef ACCESSIBILITY
37 a11y::AccType
38 nsGfxRadioControlFrame::AccessibleType()
40 return a11y::eHTMLRadioButtonType;
42 #endif
44 //--------------------------------------------------------------
45 // Draw the dot for a non-native radio button in the checked state.
46 static void
47 PaintCheckedRadioButton(nsIFrame* aFrame,
48 nsRenderingContext* aCtx,
49 const nsRect& aDirtyRect,
50 nsPoint aPt)
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));
59 Rect devPxRect =
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);
72 void
73 nsGfxRadioControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
74 const nsRect& aDirtyRect,
75 const nsDisplayListSet& aLists)
77 nsFormControlFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
79 if (!IsVisibleForPainting(aBuilder))
80 return;
82 if (IsThemed())
83 return; // The theme will paint the check, if any.
85 bool checked = true;
86 GetCurrentCheckState(&checked); // Get check state from the content model
87 if (!checked)
88 return;
90 aLists.Content()->AppendNewToTop(new (aBuilder)
91 nsDisplayGeneric(aBuilder, this, PaintCheckedRadioButton,
92 "CheckedRadioButton",
93 nsDisplayItem::TYPE_CHECKED_RADIOBUTTON));