Files
palemoon27/layout/forms/nsGfxCheckboxControlFrame.cpp
roytam1 7c9b1cc625 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1230034 part 1 - Remove NS_PROPERTY_DESCRIPTOR_CONST macro. r=dbaron (7251a79067)
- Bug 1230034 part 2 - Constify aFrame parameters of frame property functions. r=dbaron (da8f373594)
- Bug 1230034 part 3 - Move some frame property declaration around. r=dbaron (d081d6b103)
- Bug 1235467. If the root reference frame is transformed don't use an ancestor of the root reference frame as the local reference frame. r=mattwoodrow (05fd8ae29c)
- Bug 1163583 - Crashtest. (cc20379288)
- Bug 1235489 - Remove assertion which is breakable when reflow is interrupted. r=jfkthame (f6a4001b55)
- Bug 1224669 - Reftest with extreme negative letter-spacing affecting intrinsic width. r=dholbert (b7dc81eb9a)
- Bug 1224669 - Clamp width to be non-negative during intrinsic width calculation. r=dholbert (9fa8d6cab7)
- Bug 1239251 - Initialize mCommonAncestorWithLastFrame with nullptr in constructor BuildTextRunsScanner. r=roc (2178f72ee3)
- Bug 1231175 - Reftest for failure to recognize mixed directionality in RTL para beginning with number within embed/isolate controls. r=smontagu (f3b0755b4c)
- Bug 1231175 - Missed change from Unicode 6.3 bidi algorithm update (ported from ICU's ubidi): include new ENL and ENR bidi pseudo-types in MASK_LTR. r=smontagu (f9c2cb657c)
- Bug 1233135 - Do not touch display value of anonymous box for ruby. r=dbaron (efe08e7e4a)
- Bug 1228716 - Give different frame keys for nsDisplayBlendContainer. r=roc (d7dfe4af0f)
- Bug 1235696. The animated geometry root of a transfromed and sticky pos frame should be the frame itself. r=mattwoodrow (d94a1284c5)
- Bug 1240073 - Use the transformed frame as the AGR for active transform so that FrameLayerBuilder knows that they can move independently. r=tnikkel (67b1ea8173)
- Bug 1237982 - Force perspective layers to always be active. r=thinker (591f169a91)
- Bug 1230774 - Use correct Z order to sort perspective items. r=roc (1be759c298)
- Bug 1230693 - Rebase transforms to the origin for callers than don't want them offset. r=mstange (cabb21c6e7)
- Bug 1230780 - Propagate preserve-3d handling through nsDisplayPerspective. r=thinker (8f82183587)
- Bug 1237457 - Partially Moz2Dify nsDisplayGeneric. r=roc. (e2221425d5)
- Bug 1226796 - Remove redundant preprocessor flags in nsContainerFrame.cpp. r=jfkthame (1853453cd4)
- Bug 1211635 - Popups should be treated as top-level windows, allowing XUL alerts translucency. r=MattN r=roc (07bd00b85a)
2023-08-22 11:29:06 +08:00

148 lines
4.9 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsGfxCheckboxControlFrame.h"
#include "gfxUtils.h"
#include "mozilla/gfx/2D.h"
#include "nsIContent.h"
#include "nsCOMPtr.h"
#include "nsLayoutUtils.h"
#include "nsRenderingContext.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsDisplayList.h"
#include <algorithm>
using namespace mozilla;
using namespace mozilla::gfx;
static void
PaintCheckMark(nsIFrame* aFrame,
DrawTarget* aDrawTarget,
const nsRect& aDirtyRect,
nsPoint aPt)
{
nsRect rect(aPt, aFrame->GetSize());
rect.Deflate(aFrame->GetUsedBorderAndPadding());
// Points come from the coordinates on a 7X7 unit box centered at 0,0
const int32_t checkPolygonX[] = { -3, -1, 3, 3, -1, -3 };
const int32_t checkPolygonY[] = { -1, 1, -3, -1, 3, 1 };
const int32_t checkNumPoints = sizeof(checkPolygonX) / sizeof(int32_t);
const int32_t checkSize = 9; // 2 units of padding on either side
// of the 7x7 unit checkmark
// Scale the checkmark based on the smallest dimension
nscoord paintScale = std::min(rect.width, rect.height) / checkSize;
nsPoint paintCenter(rect.x + rect.width / 2,
rect.y + rect.height / 2);
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
nsPoint p = paintCenter + nsPoint(checkPolygonX[0] * paintScale,
checkPolygonY[0] * paintScale);
int32_t appUnitsPerDevPixel = aFrame->PresContext()->AppUnitsPerDevPixel();
builder->MoveTo(NSPointToPoint(p, appUnitsPerDevPixel));
for (int32_t polyIndex = 1; polyIndex < checkNumPoints; polyIndex++) {
p = paintCenter + nsPoint(checkPolygonX[polyIndex] * paintScale,
checkPolygonY[polyIndex] * paintScale);
builder->LineTo(NSPointToPoint(p, appUnitsPerDevPixel));
}
RefPtr<Path> path = builder->Finish();
aDrawTarget->Fill(path,
ColorPattern(ToDeviceColor(aFrame->StyleColor()->mColor)));
}
static void
PaintIndeterminateMark(nsIFrame* aFrame,
DrawTarget* aDrawTarget,
const nsRect& aDirtyRect,
nsPoint aPt)
{
int32_t appUnitsPerDevPixel = aFrame->PresContext()->AppUnitsPerDevPixel();
nsRect rect(aPt, aFrame->GetSize());
rect.Deflate(aFrame->GetUsedBorderAndPadding());
rect.y += (rect.height - rect.height/4) / 2;
rect.height /= 4;
Rect devPxRect = NSRectToSnappedRect(rect, appUnitsPerDevPixel, *aDrawTarget);
aDrawTarget->FillRect(
devPxRect, ColorPattern(ToDeviceColor(aFrame->StyleColor()->mColor)));
}
//------------------------------------------------------------
nsIFrame*
NS_NewGfxCheckboxControlFrame(nsIPresShell* aPresShell,
nsStyleContext* aContext)
{
return new (aPresShell) nsGfxCheckboxControlFrame(aContext);
}
NS_IMPL_FRAMEARENA_HELPERS(nsGfxCheckboxControlFrame)
//------------------------------------------------------------
// Initialize GFX-rendered state
nsGfxCheckboxControlFrame::nsGfxCheckboxControlFrame(nsStyleContext* aContext)
: nsFormControlFrame(aContext)
{
}
nsGfxCheckboxControlFrame::~nsGfxCheckboxControlFrame()
{
}
#ifdef ACCESSIBILITY
a11y::AccType
nsGfxCheckboxControlFrame::AccessibleType()
{
return a11y::eHTMLCheckboxType;
}
#endif
//------------------------------------------------------------
void
nsGfxCheckboxControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists)
{
nsFormControlFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
// Get current checked state through content model.
if ((!IsChecked() && !IsIndeterminate()) || !IsVisibleForPainting(aBuilder))
return; // we're not checked or not visible, nothing to paint.
if (IsThemed())
return; // No need to paint the checkmark. The theme will do it.
aLists.Content()->AppendNewToTop(new (aBuilder)
nsDisplayGeneric(aBuilder, this,
IsIndeterminate()
? PaintIndeterminateMark : PaintCheckMark,
"CheckedCheckbox",
nsDisplayItem::TYPE_CHECKED_CHECKBOX));
}
//------------------------------------------------------------
bool
nsGfxCheckboxControlFrame::IsChecked()
{
nsCOMPtr<nsIDOMHTMLInputElement> elem(do_QueryInterface(mContent));
bool retval = false;
elem->GetChecked(&retval);
return retval;
}
bool
nsGfxCheckboxControlFrame::IsIndeterminate()
{
nsCOMPtr<nsIDOMHTMLInputElement> elem(do_QueryInterface(mContent));
bool retval = false;
elem->GetIndeterminate(&retval);
return retval;
}