Skip to content

Commit

Permalink
Bug 1143218 - Part 3: A better fix for bug 1105137 using line-left an…
Browse files Browse the repository at this point in the history
…d line-right to place floats. r=jfkthame, a=sledru
  • Loading branch information
smontagu committed Mar 22, 2015
1 parent c3bbd05 commit 09de2de
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 196 deletions.
20 changes: 8 additions & 12 deletions layout/generic/nsBlockFrame.cpp
Expand Up @@ -1940,15 +1940,10 @@ nsBlockFrame::PropagateFloatDamage(nsBlockReflowState& aState,
nscoord lineBCoordCombinedAfter = lineBCoordCombinedBefore +
overflow.BSize(wm);

// "Translate" the float manager with an offset of (0, 0) in order to
// set the origin to our writing mode
LogicalPoint oPt(wm);
WritingMode oldWM = floatManager->Translate(wm, oPt, containerWidth);
bool isDirty = floatManager->IntersectsDamage(wm, lineBCoordBefore,
lineBCoordAfter) ||
floatManager->IntersectsDamage(wm, lineBCoordCombinedBefore,
lineBCoordCombinedAfter);
floatManager->Untranslate(oldWM, oPt, containerWidth);
if (isDirty) {
aLine->MarkDirty();
return;
Expand Down Expand Up @@ -3345,8 +3340,7 @@ nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState,
availSpace.Size(wm).ConvertTo(frame->GetWritingMode(), wm));
blockHtmlRS.mFlags.mHasClearance = aLine->HasClearance();

nsFloatManager::SavedState
floatManagerState(aState.mReflowState.GetWritingMode());
nsFloatManager::SavedState floatManagerState;
if (mayNeedRetry) {
blockHtmlRS.mDiscoveredClearance = &clearanceFrame;
aState.mFloatManager->PushState(&floatManagerState);
Expand Down Expand Up @@ -3611,8 +3605,7 @@ nsBlockFrame::ReflowInlineFrames(nsBlockReflowState& aState,
int32_t forceBreakOffset = -1;
gfxBreakPriority forceBreakPriority = gfxBreakPriority::eNoBreak;
do {
nsFloatManager::SavedState
floatManagerState(aState.mReflowState.GetWritingMode());
nsFloatManager::SavedState floatManagerState;
aState.mReflowState.mFloatManager->PushState(&floatManagerState);

// Once upon a time we allocated the first 30 nsLineLayout objects
Expand Down Expand Up @@ -6213,10 +6206,13 @@ nsBlockFrame::RecoverFloatsFor(nsIFrame* aFrame,
// If the element is relatively positioned, then adjust x and y
// accordingly so that we consider relatively positioned frames
// at their original position.
LogicalPoint pos = block->GetLogicalNormalPosition(aWM, aContainerWidth);
WritingMode oldWM = aFloatManager.Translate(aWM, pos, aContainerWidth);

LogicalRect rect(aWM, block->GetNormalRect(), aContainerWidth);
nscoord lineLeft = rect.LineLeft(aWM, aContainerWidth);
nscoord blockStart = rect.BStart(aWM);
aFloatManager.Translate(lineLeft, blockStart);
block->RecoverFloats(aFloatManager, aWM, aContainerWidth);
aFloatManager.Untranslate(oldWM, pos, aContainerWidth);
aFloatManager.Translate(-lineLeft, -blockStart);
}
}

Expand Down
26 changes: 15 additions & 11 deletions layout/generic/nsBlockReflowContext.cpp
Expand Up @@ -252,7 +252,7 @@ nsBlockReflowContext::ReflowBlock(const LogicalRect& aSpace,
}
}

LogicalPoint tPt(mWritingMode);
nscoord tI = 0, tB = 0;
// The values of x and y do not matter for floats, so don't bother
// calculating them. Floats are guaranteed to have their own float
// manager, so tI and tB don't matter. mICoord and mBCoord don't
Expand All @@ -264,12 +264,18 @@ nsBlockReflowContext::ReflowBlock(const LogicalRect& aSpace,
// reflow auto inline-start/end margins will have a zero value.

WritingMode frameWM = aFrameRS.GetWritingMode();
mICoord = tPt.I(mWritingMode) =
mSpace.IStart(mWritingMode) +
aFrameRS.ComputedLogicalMargin().ConvertTo(mWritingMode,
frameWM).IStart(mWritingMode);
mBCoord = tPt.B(mWritingMode) = mSpace.BStart(mWritingMode) +
mBStartMargin.get() + aClearance;
LogicalMargin usedMargin =
aFrameRS.ComputedLogicalMargin().ConvertTo(mWritingMode, frameWM);
mICoord = mSpace.IStart(mWritingMode) + usedMargin.IStart(mWritingMode);
mBCoord = mSpace.BStart(mWritingMode) + mBStartMargin.get() + aClearance;

LogicalRect space(mWritingMode, mICoord, mBCoord,
mSpace.ISize(mWritingMode) -
usedMargin.IStartEnd(mWritingMode),
mSpace.BSize(mWritingMode) -
usedMargin.BStartEnd(mWritingMode));
tI = space.LineLeft(mWritingMode, mContainerWidth);
tB = mBCoord;

if ((mFrame->GetStateBits() & NS_BLOCK_FLOAT_MGR) == 0)
aFrameRS.mBlockDelta =
Expand All @@ -284,11 +290,9 @@ nsBlockReflowContext::ReflowBlock(const LogicalRect& aSpace,
mMetrics.BSize(mWritingMode) = nscoord(0xdeadbeef);
#endif

WritingMode oldWM =
mOuterReflowState.mFloatManager->Translate(mWritingMode, tPt,
mContainerWidth);
mOuterReflowState.mFloatManager->Translate(tI, tB);
mFrame->Reflow(mPresContext, mMetrics, aFrameRS, aFrameReflowStatus);
mOuterReflowState.mFloatManager->Untranslate(oldWM, tPt, mContainerWidth);
mOuterReflowState.mFloatManager->Translate(-tI, -tB);

#ifdef DEBUG
if (!NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus)) {
Expand Down
87 changes: 30 additions & 57 deletions layout/generic/nsBlockReflowState.cpp
Expand Up @@ -38,8 +38,6 @@ nsBlockReflowState::nsBlockReflowState(const nsHTMLReflowState& aReflowState,
: mBlock(aFrame),
mPresContext(aPresContext),
mReflowState(aReflowState),
mFloatManagerOrigin(aReflowState.GetWritingMode()),
mFloatManagerStateBefore(aReflowState.GetWritingMode()),
mContentArea(aReflowState.GetWritingMode()),
mPushedFloats(nullptr),
mOverflowTracker(nullptr),
Expand Down Expand Up @@ -106,7 +104,7 @@ nsBlockReflowState::nsBlockReflowState(const nsHTMLReflowState& aReflowState,
"FloatManager should be set in nsBlockReflowState" );
if (mFloatManager) {
// Save the coordinate system origin for later.
mFloatManager->GetTranslation(mFloatManagerWM, mFloatManagerOrigin);
mFloatManager->GetTranslation(mFloatManagerI, mFloatManagerB);
mFloatManager->PushState(&mFloatManagerStateBefore); // never popped
}

Expand Down Expand Up @@ -311,16 +309,11 @@ nsBlockReflowState::GetFloatAvailableSpaceWithState(
WritingMode wm = mReflowState.GetWritingMode();
#ifdef DEBUG
// Verify that the caller setup the coordinate system properly
WritingMode wWM;
LogicalPoint wPt(wWM);
mFloatManager->GetTranslation(wWM, wPt);
nscoord wI, wB;
mFloatManager->GetTranslation(wI, wB);
if (wWM == mFloatManagerWM) {
NS_ASSERTION(wPt == mFloatManagerOrigin, "bad coord system");
} else {
//XXX if the writing modes are different we can't easily assert that
// the origin is the same.
}
NS_ASSERTION((wI == mFloatManagerI) && (wB == mFloatManagerB),
"bad coord system");
#endif
nscoord blockSize = (mContentArea.BSize(wm) == nscoord_MAX)
Expand Down Expand Up @@ -353,15 +346,11 @@ nsBlockReflowState::GetFloatAvailableSpaceForBSize(
WritingMode wm = mReflowState.GetWritingMode();
#ifdef DEBUG
// Verify that the caller setup the coordinate system properly
WritingMode wWM;
LogicalPoint wPt(wWM);
mFloatManager->GetTranslation(wWM, wPt);
if (wWM == mFloatManagerWM) {
NS_ASSERTION(wPt == mFloatManagerOrigin, "bad coord system");
} else {
//XXX if the writing modes are different we can't easily assert that
// the origin is the same.
}
nscoord wI, wB;
mFloatManager->GetTranslation(wI, wB);
NS_ASSERTION((wI == mFloatManagerI) && (wB == mFloatManagerB),
"bad coord system");
#endif
nsFlowAreaRect result =
mFloatManager->GetFlowArea(wm, aBCoord, nsFloatManager::WIDTH_WITHIN_HEIGHT,
Expand Down Expand Up @@ -469,10 +458,6 @@ nsBlockReflowState::RecoverFloats(nsLineList::iterator aLine,
nscoord aDeltaBCoord)
{
WritingMode wm = mReflowState.GetWritingMode();
// "Translate" the float manager with an offset of (0, 0) in order to
// set the origin to our writing mode
LogicalPoint oPt(wm);
WritingMode oldWM = mFloatManager->Translate(wm, oPt, ContainerWidth());
if (aLine->HasFloats()) {
// Place the floats into the space-manager again. Also slide
// them, just like the regular frames on the line.
Expand All @@ -486,14 +471,11 @@ nsBlockReflowState::RecoverFloats(nsLineList::iterator aLine,
}
#ifdef DEBUG
if (nsBlockFrame::gNoisyReflow || nsBlockFrame::gNoisyFloatManager) {
WritingMode tWM;
LogicalPoint tPt(tWM);
mFloatManager->GetTranslation(tWM, tPt);
nscoord tI, tB;
mFloatManager->GetTranslation(tI, tB);
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
printf("RecoverFloats: txy=%d,%d (%d,%d) ",
tPt.I(tWM), tPt.B(tWM),
mFloatManagerOrigin.I(mFloatManagerWM),
mFloatManagerOrigin.B(mFloatManagerWM));
printf("RecoverFloats: tIB=%d,%d (%d,%d) ",
tI, tB, mFloatManagerI, mFloatManagerB);
nsFrame::ListTag(stdout, floatFrame);
LogicalRect region = nsFloatManager::GetRegionFor(wm, floatFrame,
ContainerWidth());
Expand All @@ -512,7 +494,6 @@ nsBlockReflowState::RecoverFloats(nsLineList::iterator aLine,
nsBlockFrame::RecoverFloatsFor(aLine->mFirstChild, *mFloatManager, wm,
ContainerWidth());
}
mFloatManager->Untranslate(oldWM, oPt, ContainerWidth());
}
/**
Expand Down Expand Up @@ -598,10 +579,11 @@ nsBlockReflowState::AddFloat(nsLineLayout* aLineLayout,
// that's a child of our block) we need to restore the space
// manager's translation to the space that the block resides in
// before placing the float.
WritingMode oldWM;
LogicalPoint oPt(oldWM);
mFloatManager->GetTranslation(oldWM, oPt);
mFloatManager->SetTranslation(mFloatManagerWM, mFloatManagerOrigin);
nscoord oI, oB;
mFloatManager->GetTranslation(oI, oB);
nscoord dI = oI - mFloatManagerI;
nscoord dB = oB - mFloatManagerB;
mFloatManager->Translate(-dI, -dB);

bool placed;

Expand Down Expand Up @@ -641,7 +623,7 @@ nsBlockReflowState::AddFloat(nsLineLayout* aLineLayout,
}

// Restore coordinate system
mFloatManager->SetTranslation(oldWM, oPt);
mFloatManager->Translate(dI, dB);

return placed;
}
Expand Down Expand Up @@ -708,12 +690,7 @@ nsBlockReflowState::FlowAndPlaceFloat(nsIFrame* aFloat)

// Enforce CSS2 9.5.1 rule [2], i.e., make sure that a float isn't
// ``above'' another float that preceded it in the flow.
// "Translate" the float manager with an offset of (0, 0) in order to
// set the origin to our writing mode
LogicalPoint oPt(wm);
WritingMode oldWM = mFloatManager->Translate(wm, oPt, ContainerWidth());
mBCoord = std::max(mFloatManager->GetLowestFloatTop(wm, ContainerWidth()),
mBCoord);
mBCoord = std::max(mFloatManager->GetLowestFloatTop(), mBCoord);

// See if the float should clear any preceding floats...
// XXX We need to mark this float somehow so that it gets reflowed
Expand Down Expand Up @@ -849,7 +826,9 @@ nsBlockReflowState::FlowAndPlaceFloat(nsIFrame* aFloat)
// We don't worry about the geometry of the prev in flow, let the continuation
// place and size itself as required.

// Assign inline and block dir coordinates to the float.
// Assign inline and block dir coordinates to the float. We don't use
// LineLeft() and LineRight() here, because we would only have to
// convert the result back into this block's writing mode.
LogicalPoint floatPos(wm);
if ((NS_STYLE_FLOAT_LEFT == floatDisplay->mFloats) == wm.IsBidiLTR()) {
floatPos.I(wm) = floatAvailableSpace.mRect.IStart(wm);
Expand Down Expand Up @@ -979,14 +958,11 @@ nsBlockReflowState::FlowAndPlaceFloat(nsIFrame* aFloat)
}

#ifdef NOISY_FLOATMANAGER
WritingMode tWM;
LogicalPoint tPt(wm);
mFloatManager->GetTranslation(tWM, tPt);
nsFrame::ListTag(stdout, mBlock);
printf(": FlowAndPlaceFloat: AddFloat: txy=%d,%d (%d,%d) {%d,%d,%d,%d}\n",
tPt.I(tWM), tPt.B(tWM),
mFloatManagerOrigin.I(mFloatManagerWM),
mFloatManagerOrigin.B(mFloatManagerWM),
nscoord tI, tB;
mFloatManager->GetTranslation(tI, tB);
nsIFrame::ListTag(stdout, mBlock);
printf(": FlowAndPlaceFloat: AddFloat: tIB=%d,%d (%d,%d) {%d,%d,%d,%d}\n",
tI, tB, mFloatManagerI, mFloatManagerB,
region.IStart(wm), region.BStart(wm),
region.ISize(wm), region.BSize(wm));
#endif
Expand All @@ -1001,8 +977,6 @@ nsBlockReflowState::FlowAndPlaceFloat(nsIFrame* aFloat)
}
#endif

mFloatManager->Untranslate(oldWM, oPt, ContainerWidth());

return true;
}

Expand Down Expand Up @@ -1085,8 +1059,7 @@ nsBlockReflowState::ClearFloats(nscoord aBCoord, uint8_t aBreakType,
WritingMode wm = mReflowState.GetWritingMode();

if (aBreakType != NS_STYLE_CLEAR_NONE) {
newBCoord = mFloatManager->ClearFloats(wm, newBCoord, aBreakType,
ContainerWidth(), aFlags);
newBCoord = mFloatManager->ClearFloats(newBCoord, aBreakType, aFlags);
}

if (aReplacedBlock) {
Expand Down
3 changes: 1 addition & 2 deletions layout/generic/nsBlockReflowState.h
Expand Up @@ -159,8 +159,7 @@ class nsBlockReflowState {
// padding. This, therefore, represents the inner "content area" (in
// spacemanager coordinates) where child frames will be placed,
// including child blocks and floats.
mozilla::WritingMode mFloatManagerWM;
mozilla::LogicalPoint mFloatManagerOrigin;
nscoord mFloatManagerI, mFloatManagerB;

// XXX get rid of this
nsReflowStatus mReflowStatus;
Expand Down

0 comments on commit 09de2de

Please sign in to comment.