Skip to content

Commit

Permalink
Bug 1877850 Part 2 - Rewrite ComputedSizeAsContainerIfConstrained() u…
Browse files Browse the repository at this point in the history
…sing logical coordinates, and use it in BlockReflowState. r=dholbert

This patch doesn't change behavior.

Differential Revision: https://phabricator.services.mozilla.com/D200238
  • Loading branch information
aethanyc committed Feb 1, 2024
1 parent 5432f83 commit ba5c674
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 32 deletions.
23 changes: 1 addition & 22 deletions layout/generic/BlockReflowState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ BlockReflowState::BlockReflowState(
mReflowInput(aReflowInput),
mContentArea(aReflowInput.GetWritingMode()),
mInsetForBalance(aInset),
mContainerSize(aReflowInput.ComputedSizeAsContainerIfConstrained()),
mPushedFloats(nullptr),
mOverflowTracker(nullptr),
mBorderPadding(
Expand All @@ -52,28 +53,6 @@ BlockReflowState::BlockReflowState(

WritingMode wm = aReflowInput.GetWritingMode();

// Note that mContainerSize is the physical size, needed to
// convert logical block-coordinates in vertical-rl writing mode
// (measured from a RHS origin) to physical coordinates within the
// containing block.
// If aReflowInput doesn't have a constrained ComputedWidth(), we set
// mContainerSize.width to zero, which means lines will be positioned
// (physically) incorrectly; we will fix them up at the end of
// nsBlockFrame::Reflow, after we know the total block-size of the
// frame.
mContainerSize.width = aReflowInput.ComputedWidth();
if (mContainerSize.width == NS_UNCONSTRAINEDSIZE) {
mContainerSize.width = 0;
}

mContainerSize.width += mBorderPadding.LeftRight(wm);

// For now at least, we don't do that fix-up for mContainerHeight.
// It's only used in nsBidiUtils::ReorderFrames for vertical rtl
// writing modes, which aren't fully supported for the time being.
mContainerSize.height =
aReflowInput.ComputedHeight() + mBorderPadding.TopBottom(wm);

if (aBStartMarginRoot || 0 != mBorderPadding.BStart(wm)) {
mFlags.mIsBStartMarginRoot = true;
mFlags.mShouldApplyBStartMargin = true;
Expand Down
5 changes: 5 additions & 0 deletions layout/generic/BlockReflowState.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ class BlockReflowState {
nscoord mInsetForBalance;

// Physical size. Use only for physical <-> logical coordinate conversion.
//
// Note: for vertical-rl writing-mode, if mContainerSize's width is
// initialized to zero due to unconstrained block-size, lines will be
// positioned (physically) incorrectly. We will fix them up at the end of
// nsBlockFrame::Reflow() after we know the total block-size of the frame.
nsSize mContainerSize;
const nsSize& ContainerSize() const { return mContainerSize; }

Expand Down
15 changes: 15 additions & 0 deletions layout/generic/ReflowInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,21 @@ nscoord SizeComputationInput::ComputeBSizeValue(
return nsLayoutUtils::ComputeBSizeValue(aContainingBlockBSize, inside, aSize);
}

nsSize ReflowInput::ComputedSizeAsContainerIfConstrained() const {
LogicalSize size = ComputedSize();
if (size.ISize(mWritingMode) == NS_UNCONSTRAINEDSIZE) {
size.ISize(mWritingMode) = 0;
} else {
size.ISize(mWritingMode) += mComputedBorderPadding.IStartEnd(mWritingMode);
}
if (size.BSize(mWritingMode) == NS_UNCONSTRAINEDSIZE) {
size.BSize(mWritingMode) = 0;
} else {
size.BSize(mWritingMode) += mComputedBorderPadding.BStartEnd(mWritingMode);
}
return size.GetPhysicalSize(mWritingMode);
}

bool ReflowInput::ShouldReflowAllKids() const {
// Note that we could make a stronger optimization for IsBResize if
// we use it in a ShouldReflowChild test that replaces the current
Expand Down
11 changes: 1 addition & 10 deletions layout/generic/ReflowInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,16 +417,7 @@ struct ReflowInput : public SizeComputationInput {

// Return ReflowInput's computed size including border-padding, with
// unconstrained dimensions replaced by zero.
nsSize ComputedSizeAsContainerIfConstrained() const {
const nscoord wd = ComputedWidth();
const nscoord ht = ComputedHeight();
return nsSize(wd == NS_UNCONSTRAINEDSIZE
? 0
: wd + ComputedPhysicalBorderPadding().LeftRight(),
ht == NS_UNCONSTRAINEDSIZE
? 0
: ht + ComputedPhysicalBorderPadding().TopBottom());
}
nsSize ComputedSizeAsContainerIfConstrained() const;

// Our saved containing block dimensions.
LogicalSize mContainingBlockSize{mWritingMode};
Expand Down

0 comments on commit ba5c674

Please sign in to comment.