Bug 1488080 Part 1 - Convert GetAllInFlowRects flags to EnumSet. r=dholbert

Differential Revision: https://phabricator.services.mozilla.com/D209096
This commit is contained in:
Ting-Yu Lin 2024-05-03 18:42:41 +00:00
parent 3e6016f346
commit b6efd1588f
9 changed files with 62 additions and 52 deletions

View File

@ -688,7 +688,8 @@ nsRect LocalAccessible::RelativeBounds(nsIFrame** aBoundingFrame) const {
if (frame && mContent) {
*aBoundingFrame = nsLayoutUtils::GetContainingBlockForClientRect(frame);
nsRect unionRect = nsLayoutUtils::GetAllInFlowRectsUnion(
frame, *aBoundingFrame, nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS);
frame, *aBoundingFrame,
nsLayoutUtils::GetAllInFlowRectsFlag::AccountForTransforms);
if (unionRect.IsEmpty()) {
// If we end up with a 0x0 rect from above (or one with negative

View File

@ -323,7 +323,8 @@ static Maybe<nsRect> ComputeTheIntersection(
//
// `intersectionRect` is kept relative to `target` during the loop.
auto inflowRect = nsLayoutUtils::GetAllInFlowRectsUnion(
target, target, nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS);
target, target,
nsLayoutUtils::GetAllInFlowRectsFlag::AccountForTransforms);
// For content-visibility, we need to observe the overflow clip edge,
// https://drafts.csswg.org/css-contain-2/#close-to-the-viewport
if (aIsForProximityToViewport ==

View File

@ -1088,7 +1088,7 @@ already_AddRefed<DOMRectList> Element::GetClientRects() {
nsLayoutUtils::RectListBuilder builder(rectList);
nsLayoutUtils::GetAllInFlowRects(
frame, nsLayoutUtils::GetContainingBlockForClientRect(frame), &builder,
nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS);
nsLayoutUtils::GetAllInFlowRectsFlag::AccountForTransforms);
return rectList.forget();
}

View File

@ -2039,7 +2039,7 @@ nsDOMWindowUtils::GetBoundsWithoutFlushing(Element* aElement,
if (frame) {
nsRect r = nsLayoutUtils::GetAllInFlowRectsUnion(
frame, nsLayoutUtils::GetContainingBlockForClientRect(frame),
nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS);
nsLayoutUtils::GetAllInFlowRectsFlag::AccountForTransforms);
rect->SetLayoutRect(r);
}

View File

@ -2891,7 +2891,8 @@ static void CollectClientRectsForSubtree(
if (!aTextOnly || isText) {
nsLayoutUtils::GetAllInFlowRectsAndTexts(
frame, nsLayoutUtils::GetContainingBlockForClientRect(frame),
aCollector, aTextList, nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS);
aCollector, aTextList,
nsLayoutUtils::GetAllInFlowRectsFlag::AccountForTransforms);
if (isText) {
return;
}

View File

@ -3498,7 +3498,7 @@ nsIFrame* nsLayoutUtils::GetFirstNonAnonymousFrame(nsIFrame* aFrame) {
struct BoxToRect : public nsLayoutUtils::BoxCallback {
const nsIFrame* mRelativeTo;
RectCallback* mCallback;
uint32_t mFlags;
nsLayoutUtils::GetAllInFlowRectsFlags mFlags;
// If the frame we're measuring relative to is the root, we know all frames
// are descendants of it, so we don't need to compute the common ancestor
// between a frame and mRelativeTo.
@ -3510,7 +3510,8 @@ struct BoxToRect : public nsLayoutUtils::BoxCallback {
bool mRelativeToIsTarget;
BoxToRect(const nsIFrame* aTargetFrame, const nsIFrame* aRelativeTo,
RectCallback* aCallback, uint32_t aFlags)
RectCallback* aCallback,
nsLayoutUtils::GetAllInFlowRectsFlags aFlags)
: mRelativeTo(aRelativeTo),
mCallback(aCallback),
mFlags(aFlags),
@ -3523,21 +3524,22 @@ struct BoxToRect : public nsLayoutUtils::BoxCallback {
const bool usingSVGOuterFrame = !!outer;
if (!outer) {
outer = aFrame;
switch (mFlags & nsLayoutUtils::RECTS_WHICH_BOX_MASK) {
case nsLayoutUtils::RECTS_USE_CONTENT_BOX:
r = aFrame->GetContentRectRelativeToSelf();
break;
case nsLayoutUtils::RECTS_USE_PADDING_BOX:
r = aFrame->GetPaddingRectRelativeToSelf();
break;
case nsLayoutUtils::RECTS_USE_MARGIN_BOX:
r = aFrame->GetMarginRectRelativeToSelf();
break;
default: // Use the border box
r = aFrame->GetRectRelativeToSelf();
if (mFlags.contains(
nsLayoutUtils::GetAllInFlowRectsFlag::UseContentBox)) {
r = aFrame->GetContentRectRelativeToSelf();
} else if (mFlags.contains(
nsLayoutUtils::GetAllInFlowRectsFlag::UsePaddingBox)) {
r = aFrame->GetPaddingRectRelativeToSelf();
} else if (mFlags.contains(
nsLayoutUtils::GetAllInFlowRectsFlag::UseMarginBox)) {
r = aFrame->GetMarginRectRelativeToSelf();
} else {
// Use the border-box.
r = aFrame->GetRectRelativeToSelf();
}
}
if (mFlags & nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS) {
if (mFlags.contains(
nsLayoutUtils::GetAllInFlowRectsFlag::AccountForTransforms)) {
const bool isAncestorKnown = [&] {
if (mRelativeToIsRoot) {
return true;
@ -3568,7 +3570,7 @@ struct MOZ_RAII BoxToRectAndText : public BoxToRect {
BoxToRectAndText(const nsIFrame* aTargetFrame, const nsIFrame* aRelativeTo,
RectCallback* aCallback, Sequence<nsString>* aTextList,
uint32_t aFlags)
nsLayoutUtils::GetAllInFlowRectsFlags aFlags)
: BoxToRect(aTargetFrame, aRelativeTo, aCallback, aFlags),
mTextList(aTextList) {}
@ -3609,7 +3611,7 @@ struct MOZ_RAII BoxToRectAndText : public BoxToRect {
void nsLayoutUtils::GetAllInFlowRects(nsIFrame* aFrame,
const nsIFrame* aRelativeTo,
RectCallback* aCallback,
uint32_t aFlags) {
GetAllInFlowRectsFlags aFlags) {
BoxToRect converter(aFrame, aRelativeTo, aCallback, aFlags);
GetAllInFlowBoxes(aFrame, &converter);
}
@ -3618,7 +3620,7 @@ void nsLayoutUtils::GetAllInFlowRectsAndTexts(nsIFrame* aFrame,
const nsIFrame* aRelativeTo,
RectCallback* aCallback,
Sequence<nsString>* aTextList,
uint32_t aFlags) {
GetAllInFlowRectsFlags aFlags) {
BoxToRectAndText converter(aFrame, aRelativeTo, aCallback, aTextList, aFlags);
GetAllInFlowBoxes(aFrame, &converter);
}
@ -3649,7 +3651,7 @@ nsIFrame* nsLayoutUtils::GetContainingBlockForClientRect(nsIFrame* aFrame) {
nsRect nsLayoutUtils::GetAllInFlowRectsUnion(nsIFrame* aFrame,
const nsIFrame* aRelativeTo,
uint32_t aFlags) {
GetAllInFlowRectsFlags aFlags) {
RectAccumulator accumulator;
GetAllInFlowRects(aFrame, aRelativeTo, &accumulator, aFlags);
return accumulator.mResultRect.IsEmpty() ? accumulator.mFirstRect
@ -9219,7 +9221,8 @@ CSSRect nsLayoutUtils::GetBoundingFrameRect(
CSSRect result;
nsIFrame* relativeTo = aRootScrollFrame->GetScrolledFrame();
result = CSSRect::FromAppUnits(nsLayoutUtils::GetAllInFlowRectsUnion(
aFrame, relativeTo, nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS));
aFrame, relativeTo,
nsLayoutUtils::GetAllInFlowRectsFlag::AccountForTransforms));
// If the element is contained in a scrollable frame that is not
// the root scroll frame, make sure to clip the result so that it is

View File

@ -1241,52 +1241,54 @@ class nsLayoutUtils {
static nsIFrame* GetContainingBlockForClientRect(nsIFrame* aFrame);
enum {
RECTS_ACCOUNT_FOR_TRANSFORMS = 0x01,
// Two bits for specifying which box type to use.
// With neither bit set (default), use the border box.
RECTS_USE_CONTENT_BOX = 0x02,
RECTS_USE_PADDING_BOX = 0x04,
RECTS_USE_MARGIN_BOX = 0x06, // both bits set
RECTS_WHICH_BOX_MASK = 0x06 // bitmask for these two bits
};
/**
* Collect all CSS boxes (content, padding, border, or margin) associated
* with aFrame and its continuations, "drilling down" through table wrapper
* frames and some anonymous blocks since they're not real CSS boxes.
*
* The boxes are positioned relative to aRelativeTo (taking scrolling
* into account) and passed to the callback in frame-tree order.
* If aFrame is null, no boxes are returned.
*
* For SVG frames, returns one rectangle, the bounding box.
* If aFlags includes RECTS_ACCOUNT_FOR_TRANSFORMS, then when converting
* the boxes into aRelativeTo coordinates, transforms (including CSS
* and SVG transforms) are taken into account.
* If aFlags includes one of RECTS_USE_CONTENT_BOX, RECTS_USE_PADDING_BOX,
* or RECTS_USE_MARGIN_BOX, the corresponding type of box is used.
* Otherwise (by default), the border box is used.
*
* If aFlags includes 'AccountForTransforms', then when converting the boxes
* into aRelativeTo coordinates, transforms (including CSS and SVG transforms)
* are taken into account.
*
* If aFlags includes one of 'UseContentBox', 'UsePaddingBox', 'UseMarginBox',
* the corresponding type of box is used. Otherwise (by default), the border
* box is used. Note that these "Box" flags are meant to be mutually
* exclusive, though we don't enforce that. If multiple "Box" flags are used,
* we'll gracefully just use the first one in the order of the enum.
*/
enum class GetAllInFlowRectsFlag : uint8_t {
AccountForTransforms,
UseContentBox,
UsePaddingBox,
UseMarginBox,
};
using GetAllInFlowRectsFlags = mozilla::EnumSet<GetAllInFlowRectsFlag>;
static void GetAllInFlowRects(nsIFrame* aFrame, const nsIFrame* aRelativeTo,
mozilla::RectCallback* aCallback,
uint32_t aFlags = 0);
GetAllInFlowRectsFlags aFlags = {});
static void GetAllInFlowRectsAndTexts(
nsIFrame* aFrame, const nsIFrame* aRelativeTo,
mozilla::RectCallback* aCallback,
mozilla::dom::Sequence<nsString>* aTextList, uint32_t aFlags = 0);
mozilla::dom::Sequence<nsString>* aTextList,
GetAllInFlowRectsFlags aFlags = {});
/**
* Computes the union of all rects returned by GetAllInFlowRects. If
* the union is empty, returns the first rect.
* If aFlags includes RECTS_ACCOUNT_FOR_TRANSFORMS, then when converting
* the boxes into aRelativeTo coordinates, transforms (including CSS
* and SVG transforms) are taken into account.
* If aFlags includes one of RECTS_USE_CONTENT_BOX, RECTS_USE_PADDING_BOX,
* or RECTS_USE_MARGIN_BOX, the corresponding type of box is used.
* Otherwise (by default), the border box is used.
*
* See GetAllInFlowRects() documentation for the meaning of aRelativeTo and
* aFlags.
*/
static nsRect GetAllInFlowRectsUnion(nsIFrame* aFrame,
const nsIFrame* aRelativeTo,
uint32_t aFlags = 0);
GetAllInFlowRectsFlags aFlags = {});
enum { EXCLUDE_BLUR_SHADOWS = 0x01 };
/**

View File

@ -200,11 +200,13 @@ void StickyScrollContainer::ComputeStickyLimits(nsIFrame* aFrame,
nsLayoutUtils::TransformRect(cbFrame, aFrame->GetParent(), *aContain);
} else {
*aContain = nsLayoutUtils::GetAllInFlowRectsUnion(
cbFrame, aFrame->GetParent(), nsLayoutUtils::RECTS_USE_CONTENT_BOX);
cbFrame, aFrame->GetParent(),
nsLayoutUtils::GetAllInFlowRectsFlag::UseContentBox);
}
nsRect marginRect = nsLayoutUtils::GetAllInFlowRectsUnion(
aFrame, aFrame->GetParent(), nsLayoutUtils::RECTS_USE_MARGIN_BOX);
aFrame, aFrame->GetParent(),
nsLayoutUtils::GetAllInFlowRectsFlag::UseMarginBox);
// Deflate aContain by the difference between the union of aFrame's
// continuations' margin boxes and the union of their border boxes, so that

View File

@ -7891,7 +7891,7 @@ nsRect nsIFrame::GetNormalRect() const {
nsRect nsIFrame::GetBoundingClientRect() {
return nsLayoutUtils::GetAllInFlowRectsUnion(
this, nsLayoutUtils::GetContainingBlockForClientRect(this),
nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS);
nsLayoutUtils::GetAllInFlowRectsFlag::AccountForTransforms);
}
nsPoint nsIFrame::GetPositionIgnoringScrolling() const {