Line data Source code
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/. */
5 :
6 : #include "nsGfxRadioControlFrame.h"
7 :
8 : #include "gfx2DGlue.h"
9 : #include "gfxContext.h"
10 : #include "gfxUtils.h"
11 : #include "mozilla/gfx/2D.h"
12 : #include "mozilla/gfx/PathHelpers.h"
13 : #include "nsLayoutUtils.h"
14 : #include "nsDisplayList.h"
15 :
16 : using namespace mozilla;
17 : using namespace mozilla::gfx;
18 :
19 : nsIFrame*
20 0 : NS_NewGfxRadioControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
21 : {
22 0 : return new (aPresShell) nsGfxRadioControlFrame(aContext);
23 : }
24 :
25 0 : NS_IMPL_FRAMEARENA_HELPERS(nsGfxRadioControlFrame)
26 :
27 0 : nsGfxRadioControlFrame::nsGfxRadioControlFrame(nsStyleContext* aContext):
28 0 : nsFormControlFrame(aContext, kClassID)
29 : {
30 0 : }
31 :
32 0 : nsGfxRadioControlFrame::~nsGfxRadioControlFrame()
33 : {
34 0 : }
35 :
36 : #ifdef ACCESSIBILITY
37 : a11y::AccType
38 0 : nsGfxRadioControlFrame::AccessibleType()
39 : {
40 0 : return a11y::eHTMLRadioButtonType;
41 : }
42 : #endif
43 :
44 : #ifdef MOZ_WIDGET_ANDROID
45 :
46 : //--------------------------------------------------------------
47 : // Draw the dot for a non-native radio button in the checked state.
48 : static void
49 : PaintCheckedRadioButton(nsIFrame* aFrame,
50 : DrawTarget* aDrawTarget,
51 : const nsRect& aDirtyRect,
52 : nsPoint aPt)
53 : {
54 : // The dot is an ellipse 2px on all sides smaller than the content-box,
55 : // drawn in the foreground color.
56 : nsRect rect(aPt, aFrame->GetSize());
57 : rect.Deflate(aFrame->GetUsedBorderAndPadding());
58 : rect.Deflate(nsPresContext::CSSPixelsToAppUnits(2),
59 : nsPresContext::CSSPixelsToAppUnits(2));
60 :
61 : Rect devPxRect =
62 : ToRect(nsLayoutUtils::RectToGfxRect(rect,
63 : aFrame->PresContext()->AppUnitsPerDevPixel()));
64 :
65 : ColorPattern color(ToDeviceColor(aFrame->StyleColor()->mColor));
66 :
67 : RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
68 : AppendEllipseToPath(builder, devPxRect.Center(), devPxRect.Size());
69 : RefPtr<Path> ellipse = builder->Finish();
70 : aDrawTarget->Fill(ellipse, color);
71 : }
72 :
73 : void
74 : nsGfxRadioControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
75 : const nsRect& aDirtyRect,
76 : const nsDisplayListSet& aLists)
77 : {
78 : nsFormControlFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
79 :
80 : if (!IsVisibleForPainting(aBuilder))
81 : return;
82 :
83 : if (IsThemed())
84 : return; // The theme will paint the check, if any.
85 :
86 : bool checked = true;
87 : GetCurrentCheckState(&checked); // Get check state from the content model
88 : if (!checked)
89 : return;
90 :
91 : aLists.Content()->AppendNewToTop(new (aBuilder)
92 : nsDisplayGeneric(aBuilder, this, PaintCheckedRadioButton,
93 : "CheckedRadioButton",
94 : nsDisplayItem::TYPE_CHECKED_RADIOBUTTON));
95 : }
96 :
97 : #endif
|