layout/forms/nsGfxRadioControlFrame.cpp

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:585110a54e9c
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 #include "nsRenderingContext.h"
8 #include "nsDisplayList.h"
9
10 using namespace mozilla;
11
12 nsIFrame*
13 NS_NewGfxRadioControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
14 {
15 return new (aPresShell) nsGfxRadioControlFrame(aContext);
16 }
17
18 NS_IMPL_FRAMEARENA_HELPERS(nsGfxRadioControlFrame)
19
20 nsGfxRadioControlFrame::nsGfxRadioControlFrame(nsStyleContext* aContext):
21 nsFormControlFrame(aContext)
22 {
23 }
24
25 nsGfxRadioControlFrame::~nsGfxRadioControlFrame()
26 {
27 }
28
29 #ifdef ACCESSIBILITY
30 a11y::AccType
31 nsGfxRadioControlFrame::AccessibleType()
32 {
33 return a11y::eHTMLRadioButtonType;
34 }
35 #endif
36
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)
44 {
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));
51
52 aCtx->SetColor(aFrame->StyleColor()->mColor);
53 aCtx->FillEllipse(rect);
54 }
55
56 void
57 nsGfxRadioControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
58 const nsRect& aDirtyRect,
59 const nsDisplayListSet& aLists)
60 {
61 nsFormControlFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
62
63 if (!IsVisibleForPainting(aBuilder))
64 return;
65
66 if (IsThemed())
67 return; // The theme will paint the check, if any.
68
69 bool checked = true;
70 GetCurrentCheckState(&checked); // Get check state from the content model
71 if (!checked)
72 return;
73
74 aLists.Content()->AppendNewToTop(new (aBuilder)
75 nsDisplayGeneric(aBuilder, this, PaintCheckedRadioButton,
76 "CheckedRadioButton",
77 nsDisplayItem::TYPE_CHECKED_RADIOBUTTON));
78 }

mercurial