Bug 1778931 Part 3 - Tweak floatRI's mIsTopOfPage bit in FlowAndPlaceFloat(). r=dholbert

The old code tweaks mIsTopOfPage in ReflowFloat(). However
`aAvailableSize.ISize()` (in containing block's writing-mode) always equals to
ContentISize() because it is computed via ComputeAvailableSizeForFloat().
Therefore, the only reason the floatRI's mIsTopOfPage can be `false` is when
some floats are already being placed, and we only check this in the
`!earlyFloatReflow` branch.

By tweaking mIsTopOfPage bit in FlowAndPlaceFloat(), we can also remove two
unused parameters in ReflowFloat().

This patch shouldn't change the behavior.

Differential Revision: https://phabricator.services.mozilla.com/D151457
This commit is contained in:
Ting-Yu Lin
2022-07-26 04:54:37 +00:00
parent ec5a3f5850
commit 7c8f078be7
3 changed files with 26 additions and 27 deletions

View File

@@ -709,6 +709,12 @@ BlockReflowState::PlaceFloatResult BlockReflowState::FlowAndPlaceFloat(
// content.
AutoRestore<nscoord> restoreBCoord(mBCoord);
// Whether the block-direction position available to place a float has been
// pushed down due to the presence of other floats.
auto HasFloatPushedDown = [this, &restoreBCoord]() {
return mBCoord != restoreBCoord.SavedValue();
};
// Grab the float's display information
const nsStyleDisplay* floatDisplay = aFloat->StyleDisplay();
@@ -754,8 +760,7 @@ BlockReflowState::PlaceFloatResult BlockReflowState::FlowAndPlaceFloat(
bool earlyFloatReflow =
aFloat->IsLetterFrame() || floatMarginISize == NS_UNCONSTRAINEDSIZE;
if (earlyFloatReflow) {
mBlock->ReflowFloat(*this, *floatRI, availSize, aFloat, false,
reflowStatus);
mBlock->ReflowFloat(*this, *floatRI, aFloat, reflowStatus);
floatMarginISize = aFloat->ISize(wm) + floatMargin.IStartEnd(wm);
NS_ASSERTION(reflowStatus.IsComplete(),
"letter frames and orthogonal floats with auto block-size "
@@ -764,11 +769,12 @@ BlockReflowState::PlaceFloatResult BlockReflowState::FlowAndPlaceFloat(
}
// Now we've computed the float's margin inline-size.
if (mBCoord == restoreBCoord.SavedValue() && aAvailableISizeInCurrentLine &&
if (!HasFloatPushedDown() && aAvailableISizeInCurrentLine &&
floatMarginISize > *aAvailableISizeInCurrentLine) {
// The block-dir coordinate stays the same, e.g. it doesn't increase due to
// clearance, but the float cannot fit in the available inline-size of the
// current line. Let's notify our caller to place it later.
// We haven't needed to push down the float-placement block-dir coordinate
// (for float clearance), but the float cannot fit in the available
// inline-size of the current line. Let's notify our caller to place it
// later.
return PlaceFloatResult::ShouldPlaceBelowCurrentLine;
}
@@ -842,9 +848,18 @@ BlockReflowState::PlaceFloatResult BlockReflowState::FlowAndPlaceFloat(
floatRI.emplace(mPresContext, mReflowInput, aFloat,
availSize.ConvertTo(floatWM, wm));
}
bool pushedDown = mBCoord != restoreBCoord.SavedValue();
mBlock->ReflowFloat(*this, *floatRI, availSize, aFloat, pushedDown,
reflowStatus);
// Normally the mIsTopOfPage state is copied from the parent reflow input.
// However, when reflowing a float, if we've placed other floats that force
// this float being pushed down, we should unset the mIsTopOfPage bit.
if (floatRI->mFlags.mIsTopOfPage && HasFloatPushedDown()) {
// HasFloatPushedDown() implies that we increased mBCoord, and we
// should've turned off mustPlaceFloat when we did that.
NS_ASSERTION(!mustPlaceFloat,
"mustPlaceFloat shouldn't be set if we're not at the "
"top-of-page!");
floatRI->mFlags.mIsTopOfPage = false;
}
mBlock->ReflowFloat(*this, *floatRI, aFloat, reflowStatus);
}
if (aFloat->GetPrevInFlow()) {
floatMargin.BStart(wm) = 0;

View File

@@ -6618,8 +6618,7 @@ const nsStyleText* nsBlockFrame::StyleTextForLineLayout() {
}
void nsBlockFrame::ReflowFloat(BlockReflowState& aState, ReflowInput& aFloatRI,
const LogicalSize& aAvailableSize,
nsIFrame* aFloat, bool aFloatPushedDown,
nsIFrame* aFloat,
nsReflowStatus& aReflowStatus) {
MOZ_ASSERT(aReflowStatus.IsEmpty(),
"Caller should pass a fresh reflow status!");
@@ -6628,15 +6627,6 @@ void nsBlockFrame::ReflowFloat(BlockReflowState& aState, ReflowInput& aFloatRI,
WritingMode wm = aState.mReflowInput.GetWritingMode();
// Normally the mIsTopOfPage state is copied from the parent reflow
// input. However, when reflowing a float, if we've placed other
// floats that force this float *down* or *narrower*, we should unset
// the mIsTopOfPage state.
if (aFloatRI.mFlags.mIsTopOfPage &&
(aFloatPushedDown || aAvailableSize.ISize(wm) != aState.ContentISize())) {
aFloatRI.mFlags.mIsTopOfPage = false;
}
// Setup a block reflow context to reflow the float.
nsBlockReflowContext brc(aState.mPresContext, aState.mReflowInput);

View File

@@ -778,16 +778,10 @@ class nsBlockFrame : public nsContainerFrame {
LineIterator aLine, nsIFrame* aFrame,
LineReflowStatus* aLineReflowStatus);
// @param aAvailableSize the result of
// BlockReflowState::ComputeAvailableSizeForFloat().
// @param aFloatPushedDown whether the block-direction position available to
// place a float has been pushed down due to the presence of other
// floats.
// @param aReflowStatus an incomplete status indicates the float should be
// split but only if the available block-size is constrained.
void ReflowFloat(BlockReflowState& aState, ReflowInput& aFloatRI,
const mozilla::LogicalSize& aAvailableSize, nsIFrame* aFloat,
bool aFloatPushedDown, nsReflowStatus& aReflowStatus);
nsIFrame* aFloat, nsReflowStatus& aReflowStatus);
//----------------------------------------
// Methods for pushing/pulling lines/frames