commit 1c62271c70f3cf3552ad0a190f61dcb27c0e5a08
parent 95039bc0c5e056fff625a2e340a418b88319d1f9
Author: Ting-Yu Lin <tlin@mozilla.com>
Date: Mon, 13 Oct 2025 21:36:14 +0000
Bug 1983345 Part 8 - Remove viewport ReflowInput adjustment in ReflowAbsoluteFrame(). r=layout-reviewers,emilio
When calculating hypothetical position with the viewport as absolute containing
block, we can use the containing block size passing into ReflowInput instead of
getting the computed size from viewport's ReflowInput. This makes the viewport
ReflowInput adjustment unnecessary (the code just before creating the abspos
child's Reflowinput), so we can remove it.
Differential Revision: https://phabricator.services.mozilla.com/D268304
Diffstat:
3 files changed, 16 insertions(+), 30 deletions(-)
diff --git a/layout/generic/AbsoluteContainingBlock.cpp b/layout/generic/AbsoluteContainingBlock.cpp
@@ -1036,30 +1036,10 @@ void AbsoluteContainingBlock::ReflowAbsoluteFrame(
border.ConvertTo(wm, outerWM).BStart(wm)
: NS_UNCONSTRAINEDSIZE;
- // If |aDelegatingFrame| is ViewportFrame, the parent reflow input is also
- // |mCBReflowInput| of |kidReflowInput|. When initializing |kidReflowInput|,
- // we use |logicalCBSize|, instead of the computed size of |mCBReflowInput|,
- // if the cb size is not NS_UNCONSTRAINEDSIZE. However, in
- // ReflowInput::CalculateHypotheticalPosition(), we may use the computed
- // size of |mCBReflowInput| to calculate the hypothetical position, so here,
- // we are trying to update the cb reflow input for kidReflowInput to match
- // the size of |logicalCBSize|.
- //
- // FIXME: Bug 1983345. We may not need this if all the init functions in
- // ReflowInput use the customized containing block rect (if any), instead of
- // using the size of |mCBReflowInput| to do calculation.
- Maybe<ReflowInput> parentReflowInput;
- if (const ViewportFrame* viewport = do_QueryFrame(aDelegatingFrame)) {
- parentReflowInput.emplace(aReflowInput);
- // This function tweaks the computed inline size, computed block size, and
- // available inline size of the input reflow input by scrollbars.
- Unused << viewport->AdjustReflowInputForScrollbars(
- parentReflowInput.ref());
- }
- ReflowInput kidReflowInput(
- aPresContext, parentReflowInput.refOr(aReflowInput), aKidFrame,
- LogicalSize(wm, availISize, availBSize), Some(logicalCBSize), initFlags,
- {}, {}, aAnchorPosReferenceData);
+ ReflowInput kidReflowInput(aPresContext, aReflowInput, aKidFrame,
+ LogicalSize(wm, availISize, availBSize),
+ Some(logicalCBSize), initFlags, {}, {},
+ aAnchorPosReferenceData);
if (nscoord kidAvailBSize = kidReflowInput.AvailableBSize();
kidAvailBSize != NS_UNCONSTRAINEDSIZE) {
diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp
@@ -1353,6 +1353,7 @@ static bool BlockPolarityFlipped(WritingMode aThisWm, WritingMode aOtherWm) {
// frame, which may be different from the absolute containing block.
void ReflowInput::CalculateHypotheticalPosition(
nsPlaceholderFrame* aPlaceholderFrame, const ReflowInput* aCBReflowInput,
+ const LogicalSize& aCBPaddingBoxSize,
nsHypotheticalPosition& aHypotheticalPos) const {
NS_ASSERTION(mStyleDisplay->mOriginalDisplay != StyleDisplay::None,
"mOriginalDisplay has not been properly initialized");
@@ -1547,6 +1548,7 @@ void ReflowInput::CalculateHypotheticalPosition(
// block.
const nsIFrame* cbFrame = aCBReflowInput->mFrame;
nsPoint cbOffset = blockContainer->GetOffsetToIgnoringScrolling(cbFrame);
+ nsSize cbSize;
if (cbFrame->IsViewportFrame()) {
// When the containing block is the ViewportFrame, i.e. we are calculating
// the static position for a fixed-positioned frame, we need to adjust the
@@ -1563,9 +1565,14 @@ void ReflowInput::CalculateHypotheticalPosition(
const nsMargin scrollbarSizes = sf->GetActualScrollbarSizes();
cbOffset.MoveBy(-scrollbarSizes.left, -scrollbarSizes.top);
}
+
+ // ViewportFrame has no border or padding, so the padding-box size is equal
+ // to the border-box size (cbSize) that we are computing.
+ cbSize = aCBPaddingBoxSize.GetPhysicalSize(cbwm);
+ } else {
+ cbSize = aCBReflowInput->ComputedSizeAsContainerIfConstrained();
}
- nsSize cbSize = aCBReflowInput->ComputedSizeAsContainerIfConstrained();
LogicalPoint logCBOffs(wm, cbOffset, cbSize - blockContainerSize);
aHypotheticalPos.mIStart += logCBOffs.I(wm);
aHypotheticalPos.mBStart += logCBOffs.B(wm);
@@ -1736,7 +1743,7 @@ void ReflowInput::InitAbsoluteConstraints(const ReflowInput* aCBReflowInput,
}
} else {
// XXXmats all this is broken for orthogonal writing-modes: bug 1521988.
- CalculateHypotheticalPosition(placeholderFrame, aCBReflowInput,
+ CalculateHypotheticalPosition(placeholderFrame, aCBReflowInput, aCBSize,
hypotheticalPos);
if (aCBReflowInput->mFrame->IsGridContainerFrame()) {
// 'hypotheticalPos' is relative to the padding rect of the CB *frame*.
diff --git a/layout/generic/ReflowInput.h b/layout/generic/ReflowInput.h
@@ -881,12 +881,11 @@ struct ReflowInput : public SizeComputationInput {
// hypothetical box will have the same block direction as the absolute
// containing block, but it may differ in the inline direction.
//
- // FIXME: Bug 1983345. We should update this function to use the customized
- // containing block rect (if any), instead of using |aCBReflowInput| to
- // calculate everything. Perhaps we could update
- // ReflowInput::mContainingBlockSize earlier and use it in this function.
+ // @param aCBPaddingBoxSize the padding-box size of the absolute containing
+ // block, in its own writing-mode.
void CalculateHypotheticalPosition(
nsPlaceholderFrame* aPlaceholderFrame, const ReflowInput* aCBReflowInput,
+ const LogicalSize& aCBPaddingBoxSize,
nsHypotheticalPosition& aHypotheticalPos) const;
void InitAbsoluteConstraints(const ReflowInput* aCBReflowInput,