tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit a17f266b6587110181e1e6d1b549c7c8892cf3da
parent 1e37b32b03adc8225bccb1dc75b193370e1db22a
Author: Ting-Yu Lin <tlin@mozilla.com>
Date:   Mon,  6 Oct 2025 23:10:20 +0000

Bug 1992804 Part 3 - Improve paramaters and documentation for ResolveSizeDependentOffsets() and ResolveAutoMarginsAfterLayout(). r=layout-reviewers,dshin

For `ResolveSizeDependentOffsets` specifically:

- After the previous part, the `nsPresContext` parameter is no longer needed.
- `aLogicalCBSize` can be const-reference. Also, make it the second parameter to
  align `ResolveAutoMarginsAfterLayout`.

For both methods:
- Change parameter types from pointers to references.
- Improve the documentation.

Differential Revision: https://phabricator.services.mozilla.com/D267635

Diffstat:
Mlayout/generic/AbsoluteContainingBlock.cpp | 48++++++++++++++++++++++++------------------------
Mlayout/generic/AbsoluteContainingBlock.h | 24+++++++++++++++---------
2 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/layout/generic/AbsoluteContainingBlock.cpp b/layout/generic/AbsoluteContainingBlock.cpp @@ -694,9 +694,9 @@ static nscoord OffsetToAlignedStaticPos( } void AbsoluteContainingBlock::ResolveSizeDependentOffsets( - nsPresContext* aPresContext, ReflowInput& aKidReflowInput, + ReflowInput& aKidReflowInput, const LogicalSize& aLogicalCBSize, const LogicalSize& aKidSize, const LogicalMargin& aMargin, - LogicalMargin* aOffsets, LogicalSize* aLogicalCBSize) { + LogicalMargin& aOffsets) { WritingMode wm = aKidReflowInput.GetWritingMode(); WritingMode outerWM = aKidReflowInput.mParentReflowInput->GetWritingMode(); @@ -709,23 +709,23 @@ void AbsoluteContainingBlock::ResolveSizeDependentOffsets( // static position in that axis, *and* its static position is determined by // the axis-appropriate css-align property (which may require the child's // size, e.g. to center it within the parent). - if ((NS_AUTOOFFSET == aOffsets->IStart(outerWM)) || - (NS_AUTOOFFSET == aOffsets->BStart(outerWM)) || + if ((NS_AUTOOFFSET == aOffsets.IStart(outerWM)) || + (NS_AUTOOFFSET == aOffsets.BStart(outerWM)) || aKidReflowInput.mFlags.mIOffsetsNeedCSSAlign || aKidReflowInput.mFlags.mBOffsetsNeedCSSAlign) { const LogicalSize logicalCBSizeOuterWM = - aLogicalCBSize->ConvertTo(outerWM, wm); + aLogicalCBSize.ConvertTo(outerWM, wm); // placeholderContainer is used in each of the m{I,B}OffsetsNeedCSSAlign // clauses. We declare it at this scope so we can avoid having to look // it up twice (and only look it up if it's needed). nsContainerFrame* placeholderContainer = nullptr; - if (NS_AUTOOFFSET == aOffsets->IStart(outerWM)) { - NS_ASSERTION(NS_AUTOOFFSET != aOffsets->IEnd(outerWM), + if (NS_AUTOOFFSET == aOffsets.IStart(outerWM)) { + NS_ASSERTION(NS_AUTOOFFSET != aOffsets.IEnd(outerWM), "Can't solve for both start and end"); - aOffsets->IStart(outerWM) = - logicalCBSizeOuterWM.ISize(outerWM) - aOffsets->IEnd(outerWM) - + aOffsets.IStart(outerWM) = + logicalCBSizeOuterWM.ISize(outerWM) - aOffsets.IEnd(outerWM) - aMargin.IStartEnd(outerWM) - aKidSize.ISize(outerWM); } else if (aKidReflowInput.mFlags.mIOffsetsNeedCSSAlign) { placeholderContainer = GetPlaceholderContainer(aKidReflowInput.mFrame); @@ -735,15 +735,15 @@ void AbsoluteContainingBlock::ResolveSizeDependentOffsets( // Shift IStart from its current position (at start corner of the // alignment container) by the returned offset. And set IEnd to the // distance between the kid's end edge to containing block's end edge. - aOffsets->IStart(outerWM) += offset; - aOffsets->IEnd(outerWM) = + aOffsets.IStart(outerWM) += offset; + aOffsets.IEnd(outerWM) = logicalCBSizeOuterWM.ISize(outerWM) - - (aOffsets->IStart(outerWM) + aKidSize.ISize(outerWM)); + (aOffsets.IStart(outerWM) + aKidSize.ISize(outerWM)); } - if (NS_AUTOOFFSET == aOffsets->BStart(outerWM)) { - aOffsets->BStart(outerWM) = - logicalCBSizeOuterWM.BSize(outerWM) - aOffsets->BEnd(outerWM) - + if (NS_AUTOOFFSET == aOffsets.BStart(outerWM)) { + aOffsets.BStart(outerWM) = + logicalCBSizeOuterWM.BSize(outerWM) - aOffsets.BEnd(outerWM) - aMargin.BStartEnd(outerWM) - aKidSize.BSize(outerWM); } else if (aKidReflowInput.mFlags.mBOffsetsNeedCSSAlign) { if (!placeholderContainer) { @@ -755,17 +755,17 @@ void AbsoluteContainingBlock::ResolveSizeDependentOffsets( // Shift BStart from its current position (at start corner of the // alignment container) by the returned offset. And set BEnd to the // distance between the kid's end edge to containing block's end edge. - aOffsets->BStart(outerWM) += offset; - aOffsets->BEnd(outerWM) = + aOffsets.BStart(outerWM) += offset; + aOffsets.BEnd(outerWM) = logicalCBSizeOuterWM.BSize(outerWM) - - (aOffsets->BStart(outerWM) + aKidSize.BSize(outerWM)); + (aOffsets.BStart(outerWM) + aKidSize.BSize(outerWM)); } - aKidReflowInput.SetComputedLogicalOffsets(outerWM, *aOffsets); + aKidReflowInput.SetComputedLogicalOffsets(outerWM, aOffsets); } } void AbsoluteContainingBlock::ResolveAutoMarginsAfterLayout( - ReflowInput& aKidReflowInput, const LogicalSize* aLogicalCBSize, + ReflowInput& aKidReflowInput, const LogicalSize& aLogicalCBSize, const LogicalSize& aKidSize, LogicalMargin& aMargin, LogicalMargin& aOffsets) { MOZ_ASSERT(aKidReflowInput.mFlags.mDeferAutoMarginComputation); @@ -784,7 +784,7 @@ void AbsoluteContainingBlock::ResolveAutoMarginsAfterLayout( offsetsInWM.BStart(wm) == NS_AUTOOFFSET; nscoord availMarginSpace = autoOffset ? 0 - : aLogicalCBSize->BSize(wm) - kidSizeInWM.BSize(wm) - + : aLogicalCBSize.BSize(wm) - kidSizeInWM.BSize(wm) - offsetsInWM.BStartEnd(wm) - marginInWM.BStartEnd(wm); const auto& styleMargin = aKidReflowInput.mStyleMargin; @@ -1106,11 +1106,11 @@ void AbsoluteContainingBlock::ReflowAbsoluteFrame( // If we're solving for start in either inline or block direction, // then compute it now that we know the dimensions. - ResolveSizeDependentOffsets(aPresContext, kidReflowInput, kidSize, margin, - &offsets, &logicalCBSize); + ResolveSizeDependentOffsets(kidReflowInput, logicalCBSize, kidSize, + margin, offsets); if (kidReflowInput.mFlags.mDeferAutoMarginComputation) { - ResolveAutoMarginsAfterLayout(kidReflowInput, &logicalCBSize, kidSize, + ResolveAutoMarginsAfterLayout(kidReflowInput, logicalCBSize, kidSize, margin, offsets); } diff --git a/layout/generic/AbsoluteContainingBlock.h b/layout/generic/AbsoluteContainingBlock.h @@ -120,29 +120,35 @@ class AbsoluteContainingBlock { /** * After an abspos child's size is known, this method can be used to * resolve size-dependent values in the ComputedLogicalOffsets on its - * reflow input. (This may involve resolving the inline dimension of - * aLogicalCBSize, too; hence, that variable is an in/outparam.) + * reflow input. * - * aKidSize, aMargin, aOffsets, and aLogicalCBSize are all expected to be - * represented in terms of the absolute containing block's writing-mode. + * aLogicalCBSize is expected in the abspos child's writing-mode. aKidSize, + * aMargin, aOffsets, are all expected in the absolute containing block's + * writing-mode. + * + * aOffset is an outparam. */ - void ResolveSizeDependentOffsets(nsPresContext* aPresContext, - ReflowInput& aKidReflowInput, + void ResolveSizeDependentOffsets(ReflowInput& aKidReflowInput, + const LogicalSize& aLogicalCBSize, const LogicalSize& aKidSize, const LogicalMargin& aMargin, - LogicalMargin* aOffsets, - LogicalSize* aLogicalCBSize); + LogicalMargin& aOffsets); /** * For frames that have intrinsic block sizes, since we want to use the * frame's actual instrinsic block-size, we don't compute margins in * InitAbsoluteConstraints because the block-size isn't computed yet. This * method computes the margins for them after layout. + * + * aLogicalCBSize is expected in the abspos child's writing-mode. aKidSize, + * aMargin, aOffsets, are all expected in the absolute containing block's + * writing-mode. + * * aMargin and aOffsets are both outparams (though we only touch aOffsets if * the position is overconstrained) */ void ResolveAutoMarginsAfterLayout(ReflowInput& aKidReflowInput, - const LogicalSize* aLogicalCBSize, + const LogicalSize& aLogicalCBSize, const LogicalSize& aKidSize, LogicalMargin& aMargin, LogicalMargin& aOffsets);