2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-08-06 09:13:07 +04:00
|
|
|
|
|
|
|
#include "nsGfxRadioControlFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCSSRendering.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2011-01-28 07:38:14 +03:00
|
|
|
#include "nsAccessibilityService.h"
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-04-01 05:01:33 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2002-09-21 05:03:38 +04:00
|
|
|
#include "nsITheme.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2009-01-19 21:31:32 +03:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
1999-08-06 09:13:07 +04:00
|
|
|
|
2005-11-04 05:38:33 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewGfxRadioControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsGfxRadioControlFrame(aContext);
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsGfxRadioControlFrame)
|
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
nsGfxRadioControlFrame::nsGfxRadioControlFrame(nsStyleContext* aContext):
|
|
|
|
nsFormControlFrame(aContext)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGfxRadioControlFrame::~nsGfxRadioControlFrame()
|
|
|
|
{
|
2000-02-09 22:34:39 +03:00
|
|
|
}
|
|
|
|
|
2009-04-02 14:03:52 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2012-05-29 05:18:45 +04:00
|
|
|
already_AddRefed<Accessible>
|
2010-06-28 16:02:03 +04:00
|
|
|
nsGfxRadioControlFrame::CreateAccessible()
|
2001-05-18 03:52:32 +04:00
|
|
|
{
|
2011-01-28 07:38:14 +03:00
|
|
|
nsAccessibilityService* accService = nsIPresShell::AccService();
|
2001-05-18 03:52:32 +04:00
|
|
|
if (accService) {
|
2010-06-28 16:02:03 +04:00
|
|
|
return accService->CreateHTMLRadioButtonAccessible(mContent,
|
|
|
|
PresContext()->PresShell());
|
2001-05-18 03:52:32 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2001-05-18 03:52:32 +04:00
|
|
|
}
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
1999-08-06 09:13:07 +04:00
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//--------------------------------------------------------------
|
2009-04-03 12:45:17 +04:00
|
|
|
// Draw the dot for a non-native radio button in the checked state.
|
|
|
|
static void
|
|
|
|
PaintCheckedRadioButton(nsIFrame* aFrame,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx,
|
2009-04-03 12:45:17 +04:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsPoint aPt)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
2009-04-03 12:45:17 +04:00
|
|
|
// The dot is an ellipse 2px on all sides smaller than the content-box,
|
|
|
|
// drawn in the foreground color.
|
|
|
|
nsRect rect(aPt, aFrame->GetSize());
|
|
|
|
rect.Deflate(aFrame->GetUsedBorderAndPadding());
|
|
|
|
rect.Deflate(nsPresContext::CSSPixelsToAppUnits(2),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(2));
|
|
|
|
|
|
|
|
aCtx->SetColor(aFrame->GetStyleColor()->mColor);
|
|
|
|
aCtx->FillEllipse(rect);
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxRadioControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
2009-04-03 12:45:17 +04:00
|
|
|
nsresult rv = nsFormControlFrame::BuildDisplayList(aBuilder, aDirtyRect,
|
|
|
|
aLists);
|
2006-01-26 05:29:17 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!IsVisibleForPainting(aBuilder))
|
2001-01-27 17:09:34 +03:00
|
|
|
return NS_OK;
|
2006-01-26 05:29:17 +03:00
|
|
|
|
|
|
|
if (IsThemed())
|
2009-04-03 12:45:17 +04:00
|
|
|
return NS_OK; // The theme will paint the check, if any.
|
1999-08-06 09:13:07 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool checked = true;
|
2006-01-26 05:29:17 +03:00
|
|
|
GetCurrentCheckState(&checked); // Get check state from the content model
|
|
|
|
if (!checked)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return aLists.Content()->AppendNewToTop(new (aBuilder)
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayGeneric(aBuilder, this, PaintCheckedRadioButton,
|
|
|
|
"CheckedRadioButton",
|
2010-07-16 01:07:49 +04:00
|
|
|
nsDisplayItem::TYPE_CHECKED_RADIOBUTTON));
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|