commit e44da5448463e8b1db7c9c9ec19a8f888a20f1eb
parent 2fe4a381eb1d70e17c1d0d034051cd02be7ff0ca
Author: Ting-Yu Lin <tlin@mozilla.com>
Date: Fri, 24 Oct 2025 16:19:48 +0000
Bug 1996146 Part 5 - Move two abspos reflow methods from nsIFrame to nsContainerFrame. r=layout-reviewers,dshin
After changing the table parts to use `nsContainerFrame`, we can move these two
methods into `nsContainerFrame`, and get rid of the type-casting from
`nsIFrame*` to `nsContainerFrame*` in `ReflowAbsoluteFrames`.
Also, revise the documentation for both methods. Note that `nsReflowStatus`
turned into a C++ class that initializes itself, so I delete the description "is
assume to be already-initialized".
Differential Revision: https://phabricator.services.mozilla.com/D269903
Diffstat:
5 files changed, 55 insertions(+), 59 deletions(-)
diff --git a/layout/generic/AbsoluteContainingBlock.h b/layout/generic/AbsoluteContainingBlock.h
@@ -75,9 +75,8 @@ class AbsoluteContainingBlock {
* coordinate space) the overflow areas of the absolutely positioned
* children.
*
- * @param aReflowStatus is assumed to be already-initialized, e.g. with the
- * status of the delegating frame's main reflow. This function merges in the
- * statuses of the absolutely positioned children's reflows.
+ * @param aReflowStatus This function merges in the statuses of the absolutely
+ * positioned children's reflows.
*
* @param aFlags zero or more AbsPosReflowFlags
*/
diff --git a/layout/generic/nsContainerFrame.cpp b/layout/generic/nsContainerFrame.cpp
@@ -964,6 +964,38 @@ void nsContainerFrame::FinishReflowChild(nsIFrame* aKidFrame,
aKidFrame->DidReflow(aPresContext, aReflowInput);
}
+void nsContainerFrame::FinishReflowWithAbsoluteFrames(
+ nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
+ const ReflowInput& aReflowInput, nsReflowStatus& aStatus) {
+ ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowInput, aStatus);
+ FinishAndStoreOverflow(&aDesiredSize, aReflowInput.mStyleDisplay);
+}
+
+void nsContainerFrame::ReflowAbsoluteFrames(nsPresContext* aPresContext,
+ ReflowOutput& aDesiredSize,
+ const ReflowInput& aReflowInput,
+ nsReflowStatus& aStatus) {
+ if (HasAbsolutelyPositionedChildren()) {
+ AbsoluteContainingBlock* absoluteContainer = GetAbsoluteContainingBlock();
+
+ // The containing block for the abs pos kids is formed by our padding edge.
+ nsMargin usedBorder = GetUsedBorder();
+ nscoord containingBlockWidth =
+ std::max(0, aDesiredSize.Width() - usedBorder.LeftRight());
+ nscoord containingBlockHeight =
+ std::max(0, aDesiredSize.Height() - usedBorder.TopBottom());
+ nsRect containingBlock(0, 0, containingBlockWidth, containingBlockHeight);
+ // XXX: To optimize the performance, set the flags only when the CB width or
+ // height actually changes.
+ AbsPosReflowFlags flags{AbsPosReflowFlag::AllowFragmentation,
+ AbsPosReflowFlag::CBWidthChanged,
+ AbsPosReflowFlag::CBHeightChanged};
+ absoluteContainer->Reflow(this, aPresContext, aReflowInput, aStatus,
+ containingBlock, flags,
+ &aDesiredSize.mOverflowAreas);
+ }
+}
+
void nsContainerFrame::ReflowOverflowContainerChildren(
nsPresContext* aPresContext, const ReflowInput& aReflowInput,
OverflowAreas& aOverflowRects, ReflowChildFlags aFlags,
diff --git a/layout/generic/nsContainerFrame.h b/layout/generic/nsContainerFrame.h
@@ -283,6 +283,27 @@ class nsContainerFrame : public nsSplittableFrame {
static void PositionChildViews(nsIFrame* aFrame);
+ /**
+ * Let the absolutely positioned containing block reflow any absolutely
+ * positioned child frames that need to be reflowed.
+ *
+ * @param aStatus The reflow statuses of any reflowed absolute children will
+ * be merged into aStatus; aside from that, this method won't modify aStatus.
+ */
+ void ReflowAbsoluteFrames(nsPresContext* aPresContext,
+ ReflowOutput& aDesiredSize,
+ const ReflowInput& aReflowInput,
+ nsReflowStatus& aStatus);
+
+ /**
+ * A convenience method to call ReflowAbsoluteFrames() and
+ * FinishAndStoreOverflow().
+ */
+ void FinishReflowWithAbsoluteFrames(nsPresContext* aPresContext,
+ ReflowOutput& aDesiredSize,
+ const ReflowInput& aReflowInput,
+ nsReflowStatus& aStatus);
+
// ==========================================================================
/* Overflow containers are continuation frames that hold overflow. They
* are created when the frame runs out of computed block-size, but still has
diff --git a/layout/generic/nsIFrame.cpp b/layout/generic/nsIFrame.cpp
@@ -7455,47 +7455,6 @@ void nsIFrame::DidReflow(nsPresContext* aPresContext,
aPresContext->ReflowedFrame();
}
-void nsIFrame::FinishReflowWithAbsoluteFrames(nsPresContext* aPresContext,
- ReflowOutput& aDesiredSize,
- const ReflowInput& aReflowInput,
- nsReflowStatus& aStatus) {
- ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowInput, aStatus);
-
- FinishAndStoreOverflow(&aDesiredSize, aReflowInput.mStyleDisplay);
-}
-
-void nsIFrame::ReflowAbsoluteFrames(nsPresContext* aPresContext,
- ReflowOutput& aDesiredSize,
- const ReflowInput& aReflowInput,
- nsReflowStatus& aStatus) {
- if (HasAbsolutelyPositionedChildren()) {
- AbsoluteContainingBlock* absoluteContainer = GetAbsoluteContainingBlock();
-
- // Let the absolutely positioned container reflow any absolutely positioned
- // child frames that need to be reflowed
-
- // The containing block for the abs pos kids is formed by our padding edge.
- nsMargin usedBorder = GetUsedBorder();
- nscoord containingBlockWidth =
- std::max(0, aDesiredSize.Width() - usedBorder.LeftRight());
- nscoord containingBlockHeight =
- std::max(0, aDesiredSize.Height() - usedBorder.TopBottom());
- nsContainerFrame* container = do_QueryFrame(this);
- NS_ASSERTION(container,
- "Abs-pos children only supported on container frames for now");
-
- nsRect containingBlock(0, 0, containingBlockWidth, containingBlockHeight);
- // XXX: To optimize the performance, set the flags only when the CB width or
- // height actually changes.
- AbsPosReflowFlags flags{AbsPosReflowFlag::AllowFragmentation,
- AbsPosReflowFlag::CBWidthChanged,
- AbsPosReflowFlag::CBHeightChanged};
- absoluteContainer->Reflow(container, aPresContext, aReflowInput, aStatus,
- containingBlock, flags,
- &aDesiredSize.mOverflowAreas);
- }
-}
-
/* virtual */
bool nsIFrame::CanContinueTextRun() const {
// By default, a frame will *not* allow a text run to be continued
diff --git a/layout/generic/nsIFrame.h b/layout/generic/nsIFrame.h
@@ -3196,11 +3196,6 @@ class nsIFrame : public nsQueryFrame {
virtual void DidReflow(nsPresContext* aPresContext,
const ReflowInput* aReflowInput);
- void FinishReflowWithAbsoluteFrames(nsPresContext* aPresContext,
- ReflowOutput& aDesiredSize,
- const ReflowInput& aReflowInput,
- nsReflowStatus& aStatus);
-
/**
* Updates the overflow areas of the frame. This can be called if an
* overflow area of the frame's children has changed without reflowing.
@@ -4613,16 +4608,6 @@ class nsIFrame : public nsQueryFrame {
*/
bool DoesClipChildrenInBothAxes() const;
- /**
- * NOTE: aStatus is assumed to be already-initialized. The reflow statuses of
- * any reflowed absolute children will be merged into aStatus; aside from
- * that, this method won't modify aStatus.
- */
- void ReflowAbsoluteFrames(nsPresContext* aPresContext,
- ReflowOutput& aDesiredSize,
- const ReflowInput& aReflowInput,
- nsReflowStatus& aStatus);
-
private:
nscoord ComputeISizeValueFromAspectRatio(
mozilla::WritingMode aWM, const mozilla::LogicalSize& aCBSize,