michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsGfxRadioControlFrame.h" michael@0: #include "nsRenderingContext.h" michael@0: #include "nsDisplayList.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: nsIFrame* michael@0: NS_NewGfxRadioControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) michael@0: { michael@0: return new (aPresShell) nsGfxRadioControlFrame(aContext); michael@0: } michael@0: michael@0: NS_IMPL_FRAMEARENA_HELPERS(nsGfxRadioControlFrame) michael@0: michael@0: nsGfxRadioControlFrame::nsGfxRadioControlFrame(nsStyleContext* aContext): michael@0: nsFormControlFrame(aContext) michael@0: { michael@0: } michael@0: michael@0: nsGfxRadioControlFrame::~nsGfxRadioControlFrame() michael@0: { michael@0: } michael@0: michael@0: #ifdef ACCESSIBILITY michael@0: a11y::AccType michael@0: nsGfxRadioControlFrame::AccessibleType() michael@0: { michael@0: return a11y::eHTMLRadioButtonType; michael@0: } michael@0: #endif michael@0: michael@0: //-------------------------------------------------------------- michael@0: // Draw the dot for a non-native radio button in the checked state. michael@0: static void michael@0: PaintCheckedRadioButton(nsIFrame* aFrame, michael@0: nsRenderingContext* aCtx, michael@0: const nsRect& aDirtyRect, michael@0: nsPoint aPt) michael@0: { michael@0: // The dot is an ellipse 2px on all sides smaller than the content-box, michael@0: // drawn in the foreground color. michael@0: nsRect rect(aPt, aFrame->GetSize()); michael@0: rect.Deflate(aFrame->GetUsedBorderAndPadding()); michael@0: rect.Deflate(nsPresContext::CSSPixelsToAppUnits(2), michael@0: nsPresContext::CSSPixelsToAppUnits(2)); michael@0: michael@0: aCtx->SetColor(aFrame->StyleColor()->mColor); michael@0: aCtx->FillEllipse(rect); michael@0: } michael@0: michael@0: void michael@0: nsGfxRadioControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists) michael@0: { michael@0: nsFormControlFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists); michael@0: michael@0: if (!IsVisibleForPainting(aBuilder)) michael@0: return; michael@0: michael@0: if (IsThemed()) michael@0: return; // The theme will paint the check, if any. michael@0: michael@0: bool checked = true; michael@0: GetCurrentCheckState(&checked); // Get check state from the content model michael@0: if (!checked) michael@0: return; michael@0: michael@0: aLists.Content()->AppendNewToTop(new (aBuilder) michael@0: nsDisplayGeneric(aBuilder, this, PaintCheckedRadioButton, michael@0: "CheckedRadioButton", michael@0: nsDisplayItem::TYPE_CHECKED_RADIOBUTTON)); michael@0: }