layout/forms/nsGfxRadioControlFrame.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/forms/nsGfxRadioControlFrame.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,78 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsGfxRadioControlFrame.h"
    1.10 +#include "nsRenderingContext.h"
    1.11 +#include "nsDisplayList.h"
    1.12 +
    1.13 +using namespace mozilla;
    1.14 +
    1.15 +nsIFrame*
    1.16 +NS_NewGfxRadioControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
    1.17 +{
    1.18 +  return new (aPresShell) nsGfxRadioControlFrame(aContext);
    1.19 +}
    1.20 +
    1.21 +NS_IMPL_FRAMEARENA_HELPERS(nsGfxRadioControlFrame)
    1.22 +
    1.23 +nsGfxRadioControlFrame::nsGfxRadioControlFrame(nsStyleContext* aContext):
    1.24 +  nsFormControlFrame(aContext)
    1.25 +{
    1.26 +}
    1.27 +
    1.28 +nsGfxRadioControlFrame::~nsGfxRadioControlFrame()
    1.29 +{
    1.30 +}
    1.31 +
    1.32 +#ifdef ACCESSIBILITY
    1.33 +a11y::AccType
    1.34 +nsGfxRadioControlFrame::AccessibleType()
    1.35 +{
    1.36 +  return a11y::eHTMLRadioButtonType;
    1.37 +}
    1.38 +#endif
    1.39 +
    1.40 +//--------------------------------------------------------------
    1.41 +// Draw the dot for a non-native radio button in the checked state.
    1.42 +static void
    1.43 +PaintCheckedRadioButton(nsIFrame* aFrame,
    1.44 +                        nsRenderingContext* aCtx,
    1.45 +                        const nsRect& aDirtyRect,
    1.46 +                        nsPoint aPt)
    1.47 +{
    1.48 +  // The dot is an ellipse 2px on all sides smaller than the content-box,
    1.49 +  // drawn in the foreground color.
    1.50 +  nsRect rect(aPt, aFrame->GetSize());
    1.51 +  rect.Deflate(aFrame->GetUsedBorderAndPadding());
    1.52 +  rect.Deflate(nsPresContext::CSSPixelsToAppUnits(2),
    1.53 +               nsPresContext::CSSPixelsToAppUnits(2));
    1.54 +
    1.55 +  aCtx->SetColor(aFrame->StyleColor()->mColor);
    1.56 +  aCtx->FillEllipse(rect);
    1.57 +}
    1.58 +
    1.59 +void
    1.60 +nsGfxRadioControlFrame::BuildDisplayList(nsDisplayListBuilder*   aBuilder,
    1.61 +                                         const nsRect&           aDirtyRect,
    1.62 +                                         const nsDisplayListSet& aLists)
    1.63 +{
    1.64 +  nsFormControlFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
    1.65 +
    1.66 +  if (!IsVisibleForPainting(aBuilder))
    1.67 +    return;
    1.68 +  
    1.69 +  if (IsThemed())
    1.70 +    return; // The theme will paint the check, if any.
    1.71 +
    1.72 +  bool checked = true;
    1.73 +  GetCurrentCheckState(&checked); // Get check state from the content model
    1.74 +  if (!checked)
    1.75 +    return;
    1.76 +    
    1.77 +  aLists.Content()->AppendNewToTop(new (aBuilder)
    1.78 +    nsDisplayGeneric(aBuilder, this, PaintCheckedRadioButton,
    1.79 +                     "CheckedRadioButton",
    1.80 +                     nsDisplayItem::TYPE_CHECKED_RADIOBUTTON));
    1.81 +}

mercurial