2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 05:13:07 +00:00
|
|
|
|
|
|
|
#include "nsGfxRadioControlFrame.h"
|
2014-10-16 11:03:44 +00:00
|
|
|
|
|
|
|
#include "gfx2DGlue.h"
|
2014-10-17 11:53:16 +00:00
|
|
|
#include "gfxUtils.h"
|
2014-10-16 11:03:44 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/gfx/PathHelpers.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2011-04-08 01:04:40 +00:00
|
|
|
#include "nsRenderingContext.h"
|
2006-01-26 02:29:17 +00:00
|
|
|
#include "nsDisplayList.h"
|
1999-08-06 05:13:07 +00:00
|
|
|
|
2012-09-28 21:53:44 +00:00
|
|
|
using namespace mozilla;
|
2014-10-16 11:03:44 +00:00
|
|
|
using namespace mozilla::gfx;
|
2012-09-28 21:53:44 +00:00
|
|
|
|
2005-11-04 02:38:33 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewGfxRadioControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-08-06 05:13:07 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsGfxRadioControlFrame(aContext);
|
1999-08-06 05:13:07 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsGfxRadioControlFrame)
|
|
|
|
|
2006-03-26 21:30:36 +00:00
|
|
|
nsGfxRadioControlFrame::nsGfxRadioControlFrame(nsStyleContext* aContext):
|
|
|
|
nsFormControlFrame(aContext)
|
1999-08-06 05:13:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGfxRadioControlFrame::~nsGfxRadioControlFrame()
|
|
|
|
{
|
2000-02-09 19:34:39 +00:00
|
|
|
}
|
|
|
|
|
2009-04-02 10:03:52 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-28 21:53:44 +00:00
|
|
|
a11y::AccType
|
|
|
|
nsGfxRadioControlFrame::AccessibleType()
|
2001-05-17 23:52:32 +00:00
|
|
|
{
|
2012-12-18 01:25:52 +00:00
|
|
|
return a11y::eHTMLRadioButtonType;
|
2001-05-17 23:52:32 +00:00
|
|
|
}
|
2001-08-17 03:13:07 +00:00
|
|
|
#endif
|
1999-08-06 05:13:07 +00:00
|
|
|
|
2000-02-09 19:34:39 +00:00
|
|
|
//--------------------------------------------------------------
|
2009-04-03 08:45:17 +00:00
|
|
|
// Draw the dot for a non-native radio button in the checked state.
|
|
|
|
static void
|
|
|
|
PaintCheckedRadioButton(nsIFrame* aFrame,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext* aCtx,
|
2009-04-03 08:45:17 +00:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsPoint aPt)
|
1999-08-06 05:13:07 +00:00
|
|
|
{
|
2009-04-03 08:45:17 +00: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));
|
|
|
|
|
2014-10-16 11:03:44 +00:00
|
|
|
Rect devPxRect =
|
|
|
|
ToRect(nsLayoutUtils::RectToGfxRect(rect,
|
|
|
|
aFrame->PresContext()->AppUnitsPerDevPixel()));
|
|
|
|
|
2014-10-17 11:53:16 +00:00
|
|
|
ColorPattern color(ToDeviceColor(aFrame->StyleColor()->mColor));
|
2014-10-16 11:03:44 +00:00
|
|
|
|
|
|
|
DrawTarget* drawTarget = aCtx->GetDrawTarget();
|
|
|
|
RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
|
|
|
|
AppendEllipseToPath(builder, devPxRect.Center(), devPxRect.Size());
|
|
|
|
RefPtr<Path> ellipse = builder->Finish();
|
|
|
|
drawTarget->Fill(ellipse, color);
|
1999-08-06 05:13:07 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
void
|
2006-01-26 02:29:17 +00:00
|
|
|
nsGfxRadioControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
1999-08-06 05:13:07 +00:00
|
|
|
{
|
2013-02-14 11:08:08 +00:00
|
|
|
nsFormControlFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
if (!IsVisibleForPainting(aBuilder))
|
2013-02-14 11:12:27 +00:00
|
|
|
return;
|
2006-01-26 02:29:17 +00:00
|
|
|
|
|
|
|
if (IsThemed())
|
2013-02-14 11:12:27 +00:00
|
|
|
return; // The theme will paint the check, if any.
|
1999-08-06 05:13:07 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool checked = true;
|
2006-01-26 02:29:17 +00:00
|
|
|
GetCurrentCheckState(&checked); // Get check state from the content model
|
|
|
|
if (!checked)
|
2013-02-14 11:12:27 +00:00
|
|
|
return;
|
2006-01-26 02:29:17 +00:00
|
|
|
|
2013-02-14 11:08:08 +00:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
2010-08-13 10:01:13 +00:00
|
|
|
nsDisplayGeneric(aBuilder, this, PaintCheckedRadioButton,
|
|
|
|
"CheckedRadioButton",
|
2010-07-15 21:07:49 +00:00
|
|
|
nsDisplayItem::TYPE_CHECKED_RADIOBUTTON));
|
1999-08-06 05:13:07 +00:00
|
|
|
}
|