commit 4c56aa50ce983cb102bff3e84acb302222397ee7
parent a17f266b6587110181e1e6d1b549c7c8892cf3da
Author: Ting-Yu Lin <tlin@mozilla.com>
Date: Mon, 6 Oct 2025 23:10:21 +0000
Bug 1992804 Part 4 - Delete unused logic that computes CB size for abspos in ReflowInput::ComputeContainingBlockRectangle(). r=layout-reviewers,dshin
The logic is intended to compute the containing-block size for two types of
frames: first-in-flow abspos frames, and table inner frames that have abspos
style.
However, the code is unused because `AbsoluteContainingBlock` always provides a
cb size [1], as does `CreateReflowInputForInnerTable()` [2].
[1] https://searchfox.org/firefox-main/rev/c264672892dc13242a131017ea95d736f6fed69e/layout/generic/AbsoluteContainingBlock.cpp#1076
[2] https://searchfox.org/firefox-main/rev/c264672892dc13242a131017ea95d736f6fed69e/layout/tables/nsTableWrapperFrame.cpp#520,541,570
Differential Revision: https://phabricator.services.mozilla.com/D267636
Diffstat:
2 files changed, 36 insertions(+), 59 deletions(-)
diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp
@@ -2138,14 +2138,18 @@ static nscoord CalcQuirkContainingBlockHeight(
return std::max(result, 0);
}
-// Called by InitConstraints() to compute the containing block rectangle for
-// the element. Handles the special logic for absolutely positioned elements
LogicalSize ReflowInput::ComputeContainingBlockRectangle(
nsPresContext* aPresContext, const ReflowInput* aContainingBlockRI) const {
- // Unless the element is absolutely positioned, the containing block is
- // formed by the content edge of the nearest block-level ancestor
- LogicalSize cbSize = aContainingBlockRI->ComputedSize();
+ MOZ_ASSERT(!mFrame->IsAbsolutelyPositioned(mStyleDisplay) ||
+ // XXX: We have a hack putting abspos continuations in overflow
+ // container lists (bug 154892), so they are not reflowed by
+ // AbsoluteContainingBlock until we revisit the abspos
+ // continuations handling.
+ mFrame->GetPrevInFlow(),
+ "AbsoluteContainingBlock always provides a containing-block size "
+ "when creating ReflowInput for its children!");
+ LogicalSize cbSize = aContainingBlockRI->ComputedSize();
WritingMode wm = aContainingBlockRI->GetWritingMode();
if (aContainingBlockRI->mFlags.mTreatBSizeAsIndefinite) {
@@ -2157,57 +2161,24 @@ LogicalSize ReflowInput::ComputeContainingBlockRectangle(
cbSize.BSize(wm) = *aContainingBlockRI->mPercentageBasisInBlockAxis;
}
- if (((mFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW) &&
- // XXXfr hack for making frames behave properly when in overflow
- // container lists, see bug 154892; need to revisit later
- !mFrame->GetPrevInFlow()) ||
- (mFrame->IsTableFrame() &&
- mFrame->GetParent()->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW))) &&
- mStyleDisplay->IsAbsolutelyPositioned(mFrame)) {
- // See if the ancestor is block-level or inline-level
- const auto computedPadding = aContainingBlockRI->ComputedLogicalPadding(wm);
- if (aContainingBlockRI->mStyleDisplay->IsInlineOutsideStyle()) {
- // Base our size on the actual size of the frame. In cases when this is
- // completely bogus (eg initial reflow), this code shouldn't even be
- // called, since the code in nsInlineFrame::Reflow will pass in
- // the containing block dimensions to our constructor.
- // XXXbz we should be taking the in-flows into account too, but
- // that's very hard.
-
- LogicalMargin computedBorder =
- aContainingBlockRI->ComputedLogicalBorderPadding(wm) -
- computedPadding;
- cbSize.ISize(wm) =
- aContainingBlockRI->mFrame->ISize(wm) - computedBorder.IStartEnd(wm);
- NS_ASSERTION(cbSize.ISize(wm) >= 0, "Negative containing block isize!");
- cbSize.BSize(wm) =
- aContainingBlockRI->mFrame->BSize(wm) - computedBorder.BStartEnd(wm);
- NS_ASSERTION(cbSize.BSize(wm) >= 0, "Negative containing block bsize!");
- } else {
- // If the ancestor is block-level, the containing block is formed by the
- // padding edge of the ancestor
- cbSize += computedPadding.Size(wm);
- }
- } else {
- auto IsQuirky = [](const StyleSize& aSize) -> bool {
- return aSize.ConvertsToPercentage();
- };
- const auto anchorResolutionParams = AnchorPosResolutionParams::From(this);
- // an element in quirks mode gets a containing block based on looking for a
- // parent with a non-auto height if the element has a percent height.
- // Note: We don't emulate this quirk for percents in calc(), or in vertical
- // writing modes, or if the containing block is a flex or grid item.
- if (!wm.IsVertical() && NS_UNCONSTRAINEDSIZE == cbSize.BSize(wm)) {
- if (eCompatibility_NavQuirks == aPresContext->CompatibilityMode() &&
- !aContainingBlockRI->mFrame->IsFlexOrGridItem() &&
- (IsQuirky(*mStylePosition->GetHeight(anchorResolutionParams)) ||
- (mFrame->IsTableWrapperFrame() &&
- IsQuirky(*mFrame->PrincipalChildList()
- .FirstChild()
- ->StylePosition()
- ->GetHeight(anchorResolutionParams))))) {
- cbSize.BSize(wm) = CalcQuirkContainingBlockHeight(aContainingBlockRI);
- }
+ auto IsQuirky = [](const StyleSize& aSize) -> bool {
+ return aSize.ConvertsToPercentage();
+ };
+ const auto anchorResolutionParams = AnchorPosResolutionParams::From(this);
+ // an element in quirks mode gets a containing block based on looking for a
+ // parent with a non-auto height if the element has a percent height.
+ // Note: We don't emulate this quirk for percents in calc(), or in vertical
+ // writing modes, or if the containing block is a flex or grid item.
+ if (!wm.IsVertical() && NS_UNCONSTRAINEDSIZE == cbSize.BSize(wm)) {
+ if (eCompatibility_NavQuirks == aPresContext->CompatibilityMode() &&
+ !aContainingBlockRI->mFrame->IsFlexOrGridItem() &&
+ (IsQuirky(*mStylePosition->GetHeight(anchorResolutionParams)) ||
+ (mFrame->IsTableWrapperFrame() &&
+ IsQuirky(*mFrame->PrincipalChildList()
+ .FirstChild()
+ ->StylePosition()
+ ->GetHeight(anchorResolutionParams))))) {
+ cbSize.BSize(wm) = CalcQuirkContainingBlockHeight(aContainingBlockRI);
}
}
diff --git a/layout/generic/ReflowInput.h b/layout/generic/ReflowInput.h
@@ -701,9 +701,6 @@ struct ReflowInput : public SizeComputationInput {
static constexpr float kNormalLineHeightFactor = 1.2f;
- LogicalSize ComputeContainingBlockRectangle(
- nsPresContext* aPresContext, const ReflowInput* aContainingBlockRI) const;
-
/**
* Apply the mComputed(Min/Max)ISize constraints to the content
* size computed so far.
@@ -855,6 +852,15 @@ struct ReflowInput : public SizeComputationInput {
const Maybe<LogicalMargin>& aPadding,
LayoutFrameType aFrameType);
+ /**
+ * Compute the content-box rect of the containing block frame in mFrame's
+ * writing-mode (mWritingMode).
+ *
+ * Note: the block-size in the return value may be unconstrained.
+ */
+ LogicalSize ComputeContainingBlockRectangle(
+ nsPresContext* aPresContext, const ReflowInput* aContainingBlockRI) const;
+
// Returns the nearest containing block or block frame (whether or not
// it is a containing block) for the specified frame. Also returns
// the inline-start edge and logical size of the containing block's