Bug 1795196 Part 1 - Remove ComputedISize() and ComputedBSize() that return writable references. r=emilio

Users of these two getters should use setters such as SetComputedISize() instead.

Differential Revision: https://phabricator.services.mozilla.com/D159352
This commit is contained in:
Ting-Yu Lin 2022-10-18 00:26:19 +00:00
parent 968de3c515
commit 261c24ebe5
4 changed files with 56 additions and 56 deletions

View file

@ -210,10 +210,10 @@ void nsHTMLButtonControlFrame::ReflowButtonContents(
childPos.B(wm) = 0; // This will be set properly later, after reflowing the childPos.B(wm) = 0; // This will be set properly later, after reflowing the
// child to determine its size. // child to determine its size.
const LayoutFrameType frameType = aFirstKid->Type(); if (aFirstKid->IsFlexOrGridContainer()) {
if (frameType == LayoutFrameType::FlexContainer || // XXX: Should we use ResetResizeFlags::Yes?
frameType == LayoutFrameType::GridContainer) { contentsReflowInput.SetComputedBSize(aButtonReflowInput.ComputedBSize(),
contentsReflowInput.ComputedBSize() = aButtonReflowInput.ComputedBSize(); ReflowInput::ResetResizeFlags::No);
contentsReflowInput.ComputedMinBSize() = contentsReflowInput.ComputedMinBSize() =
aButtonReflowInput.ComputedMinBSize(); aButtonReflowInput.ComputedMinBSize();
contentsReflowInput.ComputedMaxBSize() = contentsReflowInput.ComputedMaxBSize() =

View file

@ -271,7 +271,8 @@ bool ReflowInput::ShouldReflowAllKids() const {
mFrame->HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE)); mFrame->HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE));
} }
void ReflowInput::SetComputedISize(nscoord aComputedISize) { void ReflowInput::SetComputedISize(nscoord aComputedISize,
ResetResizeFlags aFlags) {
// It'd be nice to assert that |frame| is not in reflow, but this fails for // It'd be nice to assert that |frame| is not in reflow, but this fails for
// two reasons: // two reasons:
// //
@ -287,40 +288,37 @@ void ReflowInput::SetComputedISize(nscoord aComputedISize) {
NS_WARNING_ASSERTION(aComputedISize >= 0, "Invalid computed inline-size!"); NS_WARNING_ASSERTION(aComputedISize >= 0, "Invalid computed inline-size!");
if (ComputedISize() != aComputedISize) { if (ComputedISize() != aComputedISize) {
ComputedISize() = std::max(0, aComputedISize); mComputedSize.ISize(mWritingMode) = std::max(0, aComputedISize);
const LayoutFrameType frameType = mFrame->Type(); const LayoutFrameType frameType = mFrame->Type();
if (frameType != LayoutFrameType::Viewport) { if (aFlags == ResetResizeFlags::Yes &&
frameType != LayoutFrameType::Viewport) {
InitResizeFlags(mFrame->PresContext(), frameType); InitResizeFlags(mFrame->PresContext(), frameType);
} }
} }
} }
void ReflowInput::SetComputedBSize(nscoord aComputedBSize) { void ReflowInput::SetComputedBSize(nscoord aComputedBSize,
ResetResizeFlags aFlags) {
// It'd be nice to assert that |frame| is not in reflow, but this fails // It'd be nice to assert that |frame| is not in reflow, but this fails
// because: // for two reasons:
// //
// nsIFrame::BoxReflow creates a reflow input for its parent. This reflow // 1) Viewport frames reset the computed block size on a copy of their reflow
// input when reflowing fixed-pos kids. In that case we actually don't want
// to mess with the resize flags, because comparing the frame's rect to the
// munged computed bsize is pointless.
// 2) nsIFrame::BoxReflow creates a reflow input for its parent. This reflow
// input is not used to reflow the parent, but just as a parent for the // input is not used to reflow the parent, but just as a parent for the
// frame's own reflow input. So given a nsBoxFrame inside some non-XUL // frame's own reflow input. So given a nsBoxFrame inside some non-XUL
// (like a text control, for example), we'll end up creating a reflow // (like a text control, for example), we'll end up creating a reflow
// input for the parent while the parent is reflowing. // input for the parent while the parent is reflowing.
NS_WARNING_ASSERTION(aComputedBSize >= 0, "Invalid computed block-size!");
if (ComputedBSize() != aComputedBSize) { if (ComputedBSize() != aComputedBSize) {
SetComputedBSizeWithoutResettingResizeFlags(aComputedBSize); mComputedSize.BSize(mWritingMode) = std::max(0, aComputedBSize);
InitResizeFlags(mFrame->PresContext(), mFrame->Type()); InitResizeFlags(mFrame->PresContext(), mFrame->Type());
} }
} }
void ReflowInput::SetComputedBSizeWithoutResettingResizeFlags(
nscoord aComputedBSize) {
// Viewport frames reset the computed block size on a copy of their reflow
// input when reflowing fixed-pos kids. In that case we actually don't
// want to mess with the resize flags, because comparing the frame's rect
// to the munged computed isize is pointless.
NS_WARNING_ASSERTION(aComputedBSize >= 0, "Invalid computed block-size!");
ComputedBSize() = std::max(0, aComputedBSize);
}
void ReflowInput::Init(nsPresContext* aPresContext, void ReflowInput::Init(nsPresContext* aPresContext,
const Maybe<LogicalSize>& aContainingBlockSize, const Maybe<LogicalSize>& aContainingBlockSize,
const Maybe<LogicalMargin>& aBorder, const Maybe<LogicalMargin>& aBorder,
@ -354,7 +352,7 @@ void ReflowInput::Init(nsPresContext* aPresContext,
if (type == mozilla::LayoutFrameType::Placeholder) { if (type == mozilla::LayoutFrameType::Placeholder) {
// Placeholders have a no-op Reflow method that doesn't need the rest of // Placeholders have a no-op Reflow method that doesn't need the rest of
// this initialization, so we bail out early. // this initialization, so we bail out early.
ComputedBSize() = ComputedISize() = 0; mComputedSize.SizeTo(mWritingMode, 0, 0);
return; return;
} }
@ -423,7 +421,7 @@ void ReflowInput::Init(nsPresContext* aPresContext,
// columns in the container's block direction // columns in the container's block direction
if (type == LayoutFrameType::ColumnSet && if (type == LayoutFrameType::ColumnSet &&
mStylePosition->ISize(mWritingMode).IsAuto()) { mStylePosition->ISize(mWritingMode).IsAuto()) {
ComputedISize() = NS_UNCONSTRAINEDSIZE; SetComputedISize(NS_UNCONSTRAINEDSIZE, ResetResizeFlags::No);
} else { } else {
SetAvailableBSize(NS_UNCONSTRAINEDSIZE); SetAvailableBSize(NS_UNCONSTRAINEDSIZE);
} }
@ -1766,8 +1764,7 @@ void ReflowInput::InitAbsoluteConstraints(nsPresContext* aPresContext,
ComputedLogicalMargin(wm).Size(wm) + ComputedLogicalMargin(wm).Size(wm) +
ComputedLogicalOffsets(wm).Size(wm), ComputedLogicalOffsets(wm).Size(wm),
ComputedLogicalBorderPadding(wm).Size(wm), {}, mComputeSizeFlags); ComputedLogicalBorderPadding(wm).Size(wm), {}, mComputeSizeFlags);
ComputedISize() = sizeResult.mLogicalSize.ISize(wm); mComputedSize = sizeResult.mLogicalSize;
ComputedBSize() = sizeResult.mLogicalSize.BSize(wm);
NS_ASSERTION(ComputedISize() >= 0, "Bogus inline-size"); NS_ASSERTION(ComputedISize() >= 0, "Bogus inline-size");
NS_ASSERTION( NS_ASSERTION(
ComputedBSize() == NS_UNCONSTRAINEDSIZE || ComputedBSize() >= 0, ComputedBSize() == NS_UNCONSTRAINEDSIZE || ComputedBSize() >= 0,
@ -1915,8 +1912,7 @@ void ReflowInput::InitAbsoluteConstraints(nsPresContext* aPresContext,
ComputeAbsPosBlockAutoMargin(availMarginSpace, cbwm, marginBStartIsAuto, ComputeAbsPosBlockAutoMargin(availMarginSpace, cbwm, marginBStartIsAuto,
marginBEndIsAuto, margin, offsets); marginBEndIsAuto, margin, offsets);
} }
ComputedBSize() = computedSize.ConvertTo(wm, cbwm).BSize(wm); mComputedSize = computedSize.ConvertTo(wm, cbwm);
ComputedISize() = computedSize.ConvertTo(wm, cbwm).ISize(wm);
SetComputedLogicalOffsets(cbwm, offsets); SetComputedLogicalOffsets(cbwm, offsets);
SetComputedLogicalMargin(cbwm, margin); SetComputedLogicalMargin(cbwm, margin);
@ -2174,18 +2170,14 @@ void ReflowInput::InitConstraints(
SetComputedLogicalOffsets(wm, LogicalMargin(wm)); SetComputedLogicalOffsets(wm, LogicalMargin(wm));
const auto borderPadding = ComputedLogicalBorderPadding(wm); const auto borderPadding = ComputedLogicalBorderPadding(wm);
ComputedISize() = AvailableISize() - borderPadding.IStartEnd(wm); SetComputedISize(
if (ComputedISize() < 0) { std::max(0, AvailableISize() - borderPadding.IStartEnd(wm)),
ComputedISize() = 0; ResetResizeFlags::No);
} SetComputedBSize(
if (AvailableBSize() != NS_UNCONSTRAINEDSIZE) { AvailableBSize() != NS_UNCONSTRAINEDSIZE
ComputedBSize() = AvailableBSize() - borderPadding.BStartEnd(wm); ? std::max(0, AvailableBSize() - borderPadding.BStartEnd(wm))
if (ComputedBSize() < 0) { : NS_UNCONSTRAINEDSIZE,
ComputedBSize() = 0; ResetResizeFlags::No);
}
} else {
ComputedBSize() = NS_UNCONSTRAINEDSIZE;
}
ComputedMinISize() = ComputedMinBSize() = 0; ComputedMinISize() = ComputedMinBSize() = 0;
ComputedMaxBSize() = ComputedMaxBSize() = NS_UNCONSTRAINEDSIZE; ComputedMaxBSize() = ComputedMaxBSize() = NS_UNCONSTRAINEDSIZE;
@ -2304,19 +2296,22 @@ void ReflowInput::InitConstraints(
// calc() with both percentages and lengths act like auto on internal // calc() with both percentages and lengths act like auto on internal
// table elements // table elements
if (isAutoISize || inlineSize.HasLengthAndPercentage()) { if (isAutoISize || inlineSize.HasLengthAndPercentage()) {
ComputedISize() = AvailableISize(); if (AvailableISize() != NS_UNCONSTRAINEDSIZE && !rowOrRowGroup) {
if ((ComputedISize() != NS_UNCONSTRAINEDSIZE) && !rowOrRowGroup) {
// Internal table elements don't have margins. Only tables and // Internal table elements don't have margins. Only tables and
// cells have border and padding // cells have border and padding
ComputedISize() -= ComputedLogicalBorderPadding(wm).IStartEnd(wm); SetComputedISize(
if (ComputedISize() < 0) ComputedISize() = 0; std::max(0, AvailableISize() -
ComputedLogicalBorderPadding(wm).IStartEnd(wm)),
ResetResizeFlags::No);
} else {
SetComputedISize(AvailableISize(), ResetResizeFlags::No);
} }
NS_ASSERTION(ComputedISize() >= 0, "Bogus computed isize"); NS_ASSERTION(ComputedISize() >= 0, "Bogus computed isize");
} else { } else {
ComputedISize() = SetComputedISize(
ComputeISizeValue(cbSize, mStylePosition->mBoxSizing, inlineSize); ComputeISizeValue(cbSize, mStylePosition->mBoxSizing, inlineSize),
ResetResizeFlags::No);
} }
// Calculate the computed block size // Calculate the computed block size
@ -2328,11 +2323,12 @@ void ReflowInput::InitConstraints(
// calc() with both percentages and lengths acts like 'auto' on internal // calc() with both percentages and lengths acts like 'auto' on internal
// table elements // table elements
if (isAutoBSize || blockSize.HasLengthAndPercentage()) { if (isAutoBSize || blockSize.HasLengthAndPercentage()) {
ComputedBSize() = NS_UNCONSTRAINEDSIZE; SetComputedBSize(NS_UNCONSTRAINEDSIZE, ResetResizeFlags::No);
} else { } else {
ComputedBSize() = SetComputedBSize(
ComputeBSizeValue(cbSize.BSize(wm), mStylePosition->mBoxSizing, ComputeBSizeValue(cbSize.BSize(wm), mStylePosition->mBoxSizing,
blockSize.AsLengthPercentage()); blockSize.AsLengthPercentage()),
ResetResizeFlags::No);
} }
// Doesn't apply to internal table elements // Doesn't apply to internal table elements

View file

@ -341,8 +341,6 @@ struct ReflowInput : public SizeComputationInput {
mAvailableSize.BSize(mWritingMode) = aAvailableBSize; mAvailableSize.BSize(mWritingMode) = aAvailableBSize;
} }
nscoord& ComputedISize() { return mComputedSize.ISize(mWritingMode); }
nscoord& ComputedBSize() { return mComputedSize.BSize(mWritingMode); }
nscoord& ComputedMinISize() { return mComputedMinSize.ISize(mWritingMode); } nscoord& ComputedMinISize() { return mComputedMinSize.ISize(mWritingMode); }
nscoord& ComputedMaxISize() { return mComputedMaxSize.ISize(mWritingMode); } nscoord& ComputedMaxISize() { return mComputedMaxSize.ISize(mWritingMode); }
nscoord& ComputedMinBSize() { return mComputedMinSize.BSize(mWritingMode); } nscoord& ComputedMinBSize() { return mComputedMinSize.BSize(mWritingMode); }
@ -814,14 +812,19 @@ struct ReflowInput : public SizeComputationInput {
} }
} }
// Use "No" to request SetComputedISize/SetComputedBSize not to reset resize
// flags.
enum class ResetResizeFlags : bool { No, Yes };
// This method doesn't apply min/max computed inline-sizes to the value passed // This method doesn't apply min/max computed inline-sizes to the value passed
// in. // in.
void SetComputedISize(nscoord aComputedISize); void SetComputedISize(nscoord aComputedISize,
ResetResizeFlags aFlags = ResetResizeFlags::Yes);
// These methods don't apply min/max computed block-sizes to the value passed // These methods don't apply min/max computed block-sizes to the value passed
// in. // in.
void SetComputedBSize(nscoord aComputedBSize); void SetComputedBSize(nscoord aComputedBSize,
void SetComputedBSizeWithoutResettingResizeFlags(nscoord aComputedBSize); ResetResizeFlags aFlags = ResetResizeFlags::Yes);
bool WillReflowAgainForClearance() const { bool WillReflowAgainForClearance() const {
return mDiscoveredClearance && *mDiscoveredClearance; return mDiscoveredClearance && *mDiscoveredClearance;

View file

@ -310,8 +310,9 @@ nsPoint ViewportFrame::AdjustReflowInputForScrollbars(
scrollbars.IStartEnd(wm)); scrollbars.IStartEnd(wm));
aReflowInput->SetAvailableISize(aReflowInput->AvailableISize() - aReflowInput->SetAvailableISize(aReflowInput->AvailableISize() -
scrollbars.IStartEnd(wm)); scrollbars.IStartEnd(wm));
aReflowInput->SetComputedBSizeWithoutResettingResizeFlags( aReflowInput->SetComputedBSize(
aReflowInput->ComputedBSize() - scrollbars.BStartEnd(wm)); aReflowInput->ComputedBSize() - scrollbars.BStartEnd(wm),
ReflowInput::ResetResizeFlags::No);
return nsPoint(scrollbars.Left(wm), scrollbars.Top(wm)); return nsPoint(scrollbars.Left(wm), scrollbars.Top(wm));
} }
return nsPoint(0, 0); return nsPoint(0, 0);