mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 21:28:55 +00:00
Bug 789096 patch 7: Use logical coordinates in nsBlockReflowContext. r=jfkthame
This commit is contained in:
parent
caa93255c4
commit
f3e261c3a0
@ -1257,6 +1257,19 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
nsPoint GetPhysicalPosition(WritingMode aWritingMode,
|
||||
nscoord aContainerWidth) const
|
||||
{
|
||||
CHECK_WRITING_MODE(aWritingMode);
|
||||
if (aWritingMode.IsVertical()) {
|
||||
return nsPoint(aWritingMode.IsVerticalLR() ? BStart() : aContainerWidth - BEnd(),
|
||||
IStart());
|
||||
} else {
|
||||
return nsPoint(aWritingMode.IsBidiLTR() ? IStart() : aContainerWidth - IEnd(),
|
||||
BStart());
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 // XXX this would require aContainerWidth as well
|
||||
/**
|
||||
* Return a LogicalRect representing this rect in a different writing mode
|
||||
|
@ -16,7 +16,7 @@
|
||||
#undef NOISY_FINAL_SIZE // enables debug output for desired width/height computation, once all children have been reflowed
|
||||
#undef NOISY_REMOVE_FRAME
|
||||
#undef NOISY_COMBINED_AREA // enables debug output for combined area computation
|
||||
#undef NOISY_VERTICAL_MARGINS
|
||||
#undef NOISY_BLOCK_DIR_MARGINS
|
||||
#undef NOISY_REFLOW_REASON // gives a little info about why each reflow was requested
|
||||
#undef REFLOW_STATUS_COVERAGE // I think this is most useful for printing, to see which frames return "incomplete"
|
||||
#undef NOISY_FLOATMANAGER // enables debug output for float manager use, useful for analysing reflow of floats
|
||||
|
@ -3019,8 +3019,10 @@ nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState,
|
||||
|
||||
// Now compute the collapsed margin-top value into aState.mPrevBottomMargin, assuming
|
||||
// that all child margins collapse down to clearanceFrame.
|
||||
nsBlockReflowContext::ComputeCollapsedTopMargin(reflowState,
|
||||
&aState.mPrevBottomMargin, clearanceFrame, &mayNeedRetry);
|
||||
nsBlockReflowContext::ComputeCollapsedBStartMargin(reflowState,
|
||||
&aState.mPrevBottomMargin,
|
||||
clearanceFrame,
|
||||
&mayNeedRetry);
|
||||
|
||||
// XXX optimization; we could check the collapsing children to see if they are sure
|
||||
// to require clearance, and so avoid retrying them
|
||||
@ -3053,8 +3055,10 @@ nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState,
|
||||
|
||||
// Compute the collapsed margin again, ignoring the incoming margin this time
|
||||
mayNeedRetry = false;
|
||||
nsBlockReflowContext::ComputeCollapsedTopMargin(reflowState,
|
||||
&aState.mPrevBottomMargin, clearanceFrame, &mayNeedRetry);
|
||||
nsBlockReflowContext::ComputeCollapsedBStartMargin(reflowState,
|
||||
&aState.mPrevBottomMargin,
|
||||
clearanceFrame,
|
||||
&mayNeedRetry);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3210,8 +3214,7 @@ nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState,
|
||||
*aKeepReflowGoing = brc.PlaceBlock(blockHtmlRS, forceFit, aLine.get(),
|
||||
collapsedBottomMargin,
|
||||
overflowAreas,
|
||||
frameReflowStatus,
|
||||
aState.mContainerWidth);
|
||||
frameReflowStatus);
|
||||
if (!NS_FRAME_IS_FULLY_COMPLETE(frameReflowStatus) &&
|
||||
ShouldAvoidBreakInside(aState.mReflowState)) {
|
||||
*aKeepReflowGoing = false;
|
||||
@ -3300,7 +3303,7 @@ nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState,
|
||||
// flow block. Since we just continued the child block frame,
|
||||
// we know that line->mFirstChild is not the last flow block
|
||||
// therefore zero out the running margin value.
|
||||
#ifdef NOISY_VERTICAL_MARGINS
|
||||
#ifdef NOISY_BLOCK_DIR_MARGINS
|
||||
ListTag(stdout);
|
||||
printf(": reflow incomplete, frame=");
|
||||
nsFrame::ListTag(stdout, frame);
|
||||
@ -3328,7 +3331,7 @@ nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState,
|
||||
aState.mOverflowTracker->Insert(nextFrame, frameReflowStatus);
|
||||
NS_MergeReflowStatusInto(&aState.mReflowStatus, frameReflowStatus);
|
||||
|
||||
#ifdef NOISY_VERTICAL_MARGINS
|
||||
#ifdef NOISY_BLOCK_DIR_MARGINS
|
||||
ListTag(stdout);
|
||||
printf(": reflow complete but overflow incomplete for ");
|
||||
nsFrame::ListTag(stdout, frame);
|
||||
@ -3339,7 +3342,7 @@ nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState,
|
||||
}
|
||||
}
|
||||
else { // frame is fully complete
|
||||
#ifdef NOISY_VERTICAL_MARGINS
|
||||
#ifdef NOISY_BLOCK_DIR_MARGINS
|
||||
ListTag(stdout);
|
||||
printf(": reflow complete for ");
|
||||
nsFrame::ListTag(stdout, frame);
|
||||
@ -3348,12 +3351,12 @@ nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState,
|
||||
#endif
|
||||
aState.mPrevBottomMargin = collapsedBottomMargin;
|
||||
}
|
||||
#ifdef NOISY_VERTICAL_MARGINS
|
||||
#ifdef NOISY_BLOCK_DIR_MARGINS
|
||||
ListTag(stdout);
|
||||
printf(": frame=");
|
||||
nsFrame::ListTag(stdout, frame);
|
||||
printf(" carriedOutBottomMargin=%d collapsedBottomMargin=%d => %d\n",
|
||||
brc.GetCarriedOutBottomMargin(), collapsedBottomMargin.get(),
|
||||
printf(" carriedOutBEndMargin=%d collapsedBottomMargin=%d => %d\n",
|
||||
brc.GetCarriedOutBEndMargin(), collapsedBottomMargin.get(),
|
||||
aState.mPrevBottomMargin);
|
||||
#endif
|
||||
} else {
|
||||
@ -5788,8 +5791,9 @@ nsBlockFrame::ReflowFloat(nsBlockReflowState& aState,
|
||||
floatRS.mDiscoveredClearance = nullptr;
|
||||
// Only first in flow gets a top margin.
|
||||
if (!aFloat->GetPrevInFlow()) {
|
||||
nsBlockReflowContext::ComputeCollapsedTopMargin(floatRS, &margin,
|
||||
clearanceFrame, &mayNeedRetry);
|
||||
nsBlockReflowContext::ComputeCollapsedBStartMargin(floatRS, &margin,
|
||||
clearanceFrame,
|
||||
&mayNeedRetry);
|
||||
|
||||
if (mayNeedRetry && !clearanceFrame) {
|
||||
floatRS.mDiscoveredClearance = &clearanceFrame;
|
||||
|
@ -14,21 +14,24 @@
|
||||
#include "nsLineBox.h"
|
||||
#include "nsLayoutUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
#ifdef DEBUG
|
||||
#undef NOISY_MAX_ELEMENT_SIZE
|
||||
#undef REALLY_NOISY_MAX_ELEMENT_SIZE
|
||||
#undef NOISY_VERTICAL_MARGINS
|
||||
#undef NOISY_BLOCK_DIR_MARGINS
|
||||
#else
|
||||
#undef NOISY_MAX_ELEMENT_SIZE
|
||||
#undef REALLY_NOISY_MAX_ELEMENT_SIZE
|
||||
#undef NOISY_VERTICAL_MARGINS
|
||||
#undef NOISY_BLOCK_DIR_MARGINS
|
||||
#endif
|
||||
|
||||
nsBlockReflowContext::nsBlockReflowContext(nsPresContext* aPresContext,
|
||||
const nsHTMLReflowState& aParentRS)
|
||||
: mPresContext(aPresContext),
|
||||
mOuterReflowState(aParentRS),
|
||||
mMetrics(aParentRS.GetWritingMode())
|
||||
mSpace(aParentRS.GetWritingMode()),
|
||||
mMetrics(aParentRS)
|
||||
{
|
||||
}
|
||||
|
||||
@ -41,39 +44,42 @@ static nsIFrame* DescendIntoBlockLevelFrame(nsIFrame* aFrame)
|
||||
}
|
||||
|
||||
bool
|
||||
nsBlockReflowContext::ComputeCollapsedTopMargin(const nsHTMLReflowState& aRS,
|
||||
nsCollapsingMargin* aMargin, nsIFrame* aClearanceFrame,
|
||||
bool* aMayNeedRetry, bool* aBlockIsEmpty)
|
||||
nsBlockReflowContext::ComputeCollapsedBStartMargin(const nsHTMLReflowState& aRS,
|
||||
nsCollapsingMargin* aMargin,
|
||||
nsIFrame* aClearanceFrame,
|
||||
bool* aMayNeedRetry,
|
||||
bool* aBlockIsEmpty)
|
||||
{
|
||||
// Include frame's top margin
|
||||
aMargin->Include(aRS.ComputedPhysicalMargin().top);
|
||||
WritingMode wm = aRS.GetWritingMode();
|
||||
// Include frame's block-start margin
|
||||
aMargin->Include(aRS.ComputedLogicalMargin().BStart(wm));
|
||||
|
||||
// The inclusion of the bottom margin when empty is done by the caller
|
||||
// The inclusion of the block-end margin when empty is done by the caller
|
||||
// since it doesn't need to be done by the top-level (non-recursive)
|
||||
// caller.
|
||||
|
||||
#ifdef NOISY_VERTICAL_MARGINS
|
||||
#ifdef NOISY_BLOCKDIR_MARGINS
|
||||
nsFrame::ListTag(stdout, aRS.frame);
|
||||
printf(": %d => %d\n", aRS.ComputedPhysicalMargin().top, aMargin->get());
|
||||
printf(": %d => %d\n", aRS.ComputedLogicalMargin().BStart(wm), aMargin->get());
|
||||
#endif
|
||||
|
||||
bool dirtiedLine = false;
|
||||
bool setBlockIsEmpty = false;
|
||||
|
||||
// Calculate the frame's generational top-margin from its child
|
||||
// blocks. Note that if the frame has a non-zero top-border or
|
||||
// top-padding then this step is skipped because it will be a margin
|
||||
// Calculate the frame's generational block-start-margin from its child
|
||||
// blocks. Note that if the frame has a non-zero block-start-border or
|
||||
// block-start-padding then this step is skipped because it will be a margin
|
||||
// root. It is also skipped if the frame is a margin root for other
|
||||
// reasons.
|
||||
nsIFrame* frame = DescendIntoBlockLevelFrame(aRS.frame);
|
||||
nsPresContext* prescontext = frame->PresContext();
|
||||
nsBlockFrame* block = nullptr;
|
||||
if (0 == aRS.ComputedPhysicalBorderPadding().top) {
|
||||
if (0 == aRS.ComputedLogicalBorderPadding().BStart(wm)) {
|
||||
block = nsLayoutUtils::GetAsBlock(frame);
|
||||
if (block) {
|
||||
bool topMarginRoot, unused;
|
||||
block->IsMarginRoot(&topMarginRoot, &unused);
|
||||
if (topMarginRoot) {
|
||||
bool bStartMarginRoot, unused;
|
||||
block->IsMarginRoot(&bStartMarginRoot, &unused);
|
||||
if (bStartMarginRoot) {
|
||||
block = nullptr;
|
||||
}
|
||||
}
|
||||
@ -112,7 +118,7 @@ nsBlockReflowContext::ComputeCollapsedTopMargin(const nsHTMLReflowState& aRS,
|
||||
line->MarkDirty();
|
||||
dirtiedLine = true;
|
||||
}
|
||||
|
||||
|
||||
bool isEmpty;
|
||||
if (line->IsInline()) {
|
||||
isEmpty = line->IsEmpty();
|
||||
@ -129,7 +135,7 @@ nsBlockReflowContext::ComputeCollapsedTopMargin(const nsHTMLReflowState& aRS,
|
||||
// child blocks margin and so in so that we can look into
|
||||
// it. For its margins to be computed we need to have a reflow
|
||||
// state for it.
|
||||
|
||||
|
||||
// We may have to construct an extra reflow state here if
|
||||
// we drilled down through a block wrapper. At the moment
|
||||
// we can only drill down one level so we only have to support
|
||||
@ -153,12 +159,18 @@ nsBlockReflowContext::ComputeCollapsedTopMargin(const nsHTMLReflowState& aRS,
|
||||
if (kid->StyleDisplay()->mBreakType != NS_STYLE_CLEAR_NONE) {
|
||||
*aMayNeedRetry = true;
|
||||
}
|
||||
if (ComputeCollapsedTopMargin(innerReflowState, aMargin, aClearanceFrame, aMayNeedRetry, &isEmpty)) {
|
||||
if (ComputeCollapsedBStartMargin(innerReflowState, aMargin,
|
||||
aClearanceFrame, aMayNeedRetry,
|
||||
&isEmpty)) {
|
||||
line->MarkDirty();
|
||||
dirtiedLine = true;
|
||||
}
|
||||
if (isEmpty)
|
||||
aMargin->Include(innerReflowState.ComputedPhysicalMargin().bottom);
|
||||
if (isEmpty) {
|
||||
WritingMode innerWM = innerReflowState.GetWritingMode();
|
||||
LogicalMargin innerMargin =
|
||||
innerReflowState.ComputedLogicalMargin().ConvertTo(wm, innerWM);
|
||||
aMargin->Include(innerMargin.BEnd(wm));
|
||||
}
|
||||
}
|
||||
if (outerReflowState != &aRS) {
|
||||
delete const_cast<nsHTMLReflowState*>(outerReflowState);
|
||||
@ -187,7 +199,7 @@ nsBlockReflowContext::ComputeCollapsedTopMargin(const nsHTMLReflowState& aRS,
|
||||
*aBlockIsEmpty = aRS.frame->IsEmpty();
|
||||
}
|
||||
|
||||
#ifdef NOISY_VERTICAL_MARGINS
|
||||
#ifdef NOISY_BLOCKDIR_MARGINS
|
||||
nsFrame::ListTag(stdout, aRS.frame);
|
||||
printf(": => %d\n", aMargin->get());
|
||||
#endif
|
||||
@ -197,55 +209,67 @@ nsBlockReflowContext::ComputeCollapsedTopMargin(const nsHTMLReflowState& aRS,
|
||||
|
||||
void
|
||||
nsBlockReflowContext::ReflowBlock(const nsRect& aSpace,
|
||||
bool aApplyTopMargin,
|
||||
bool aApplyBStartMargin,
|
||||
nsCollapsingMargin& aPrevMargin,
|
||||
nscoord aClearance,
|
||||
bool aIsAdjacentWithTop,
|
||||
bool aIsAdjacentWithBStart,
|
||||
nsLineBox* aLine,
|
||||
nsHTMLReflowState& aFrameRS,
|
||||
nsReflowStatus& aFrameReflowStatus,
|
||||
nsBlockReflowState& aState)
|
||||
{
|
||||
mFrame = aFrameRS.frame;
|
||||
mSpace = aSpace;
|
||||
mWritingMode = aState.mReflowState.GetWritingMode();
|
||||
mContainerWidth = aState.mContainerWidth;
|
||||
mSpace = LogicalRect(mWritingMode, aSpace, mContainerWidth);
|
||||
|
||||
if (!aIsAdjacentWithTop) {
|
||||
if (!aIsAdjacentWithBStart) {
|
||||
aFrameRS.mFlags.mIsTopOfPage = false; // make sure this is cleared
|
||||
}
|
||||
|
||||
if (aApplyTopMargin) {
|
||||
mTopMargin = aPrevMargin;
|
||||
if (aApplyBStartMargin) {
|
||||
mBStartMargin = aPrevMargin;
|
||||
|
||||
#ifdef NOISY_VERTICAL_MARGINS
|
||||
#ifdef NOISY_BLOCKDIR_MARGINS
|
||||
nsFrame::ListTag(stdout, mOuterReflowState.frame);
|
||||
printf(": reflowing ");
|
||||
nsFrame::ListTag(stdout, mFrame);
|
||||
printf(" margin => %d, clearance => %d\n", mTopMargin.get(), aClearance);
|
||||
printf(" margin => %d, clearance => %d\n", mBStartMargin.get(), aClearance);
|
||||
#endif
|
||||
|
||||
// Adjust the available height if its constrained so that the
|
||||
// Adjust the available block size if it's constrained so that the
|
||||
// child frame doesn't think it can reflow into its margin area.
|
||||
if (NS_UNCONSTRAINEDSIZE != aFrameRS.AvailableHeight()) {
|
||||
aFrameRS.AvailableHeight() -= mTopMargin.get() + aClearance;
|
||||
if (NS_UNCONSTRAINEDSIZE != aFrameRS.AvailableBSize()) {
|
||||
aFrameRS.AvailableBSize() -= mBStartMargin.get() + aClearance;
|
||||
}
|
||||
}
|
||||
|
||||
nscoord tx = 0, ty = 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 tx and ty
|
||||
// don't matter. mX and mY don't matter becacuse they are only used in
|
||||
// PlaceBlock, which is not used for floats.
|
||||
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
|
||||
// matter becacuse they are only used in PlaceBlock, which is not used
|
||||
// for floats.
|
||||
if (aLine) {
|
||||
// Compute x/y coordinate where reflow will begin. Use the rules
|
||||
// from 10.3.3 to determine what to apply. At this point in the
|
||||
// reflow auto left/right margins will have a zero value.
|
||||
// Compute inline/block coordinate where reflow will begin. Use the
|
||||
// rules from 10.3.3 to determine what to apply. At this point in the
|
||||
// reflow auto inline-start/end margins will have a zero value.
|
||||
|
||||
mX = tx = mSpace.x + aFrameRS.ComputedPhysicalMargin().left;
|
||||
mY = ty = mSpace.y + mTopMargin.get() + aClearance;
|
||||
WritingMode frameWM = aFrameRS.GetWritingMode();
|
||||
mICoord = tI =
|
||||
mSpace.IStart(mWritingMode) +
|
||||
aFrameRS.ComputedLogicalMargin().ConvertTo(mWritingMode,
|
||||
frameWM).IStart(mWritingMode);
|
||||
mBCoord = tB = mSpace.BStart(mWritingMode) +
|
||||
mBStartMargin.get() + aClearance;
|
||||
|
||||
//XXX temporary until nsFloatManager is logicalized
|
||||
tI = aSpace.x + aFrameRS.ComputedPhysicalMargin().left;
|
||||
tB = aSpace.y + mBStartMargin.get() + aClearance;
|
||||
|
||||
if ((mFrame->GetStateBits() & NS_BLOCK_FLOAT_MGR) == 0)
|
||||
aFrameRS.mBlockDelta =
|
||||
mOuterReflowState.mBlockDelta + ty - aLine->BStart();
|
||||
mOuterReflowState.mBlockDelta + mBCoord - aLine->BStart();
|
||||
}
|
||||
|
||||
// Let frame know that we are reflowing it
|
||||
@ -256,9 +280,9 @@ nsBlockReflowContext::ReflowBlock(const nsRect& aSpace,
|
||||
mMetrics.Height() = nscoord(0xdeadbeef);
|
||||
#endif
|
||||
|
||||
mOuterReflowState.mFloatManager->Translate(tx, ty);
|
||||
mOuterReflowState.mFloatManager->Translate(tI, tB);
|
||||
mFrame->Reflow(mPresContext, mMetrics, aFrameRS, aFrameReflowStatus);
|
||||
mOuterReflowState.mFloatManager->Translate(-tx, -ty);
|
||||
mOuterReflowState.mFloatManager->Translate(-tI, -tB);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (!NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus)) {
|
||||
@ -303,92 +327,100 @@ nsBlockReflowContext::ReflowBlock(const nsRect& aSpace,
|
||||
|
||||
/**
|
||||
* Attempt to place the block frame within the available space. If
|
||||
* it fits, apply horizontal positioning (CSS 10.3.3), collapse
|
||||
* margins (CSS2 8.3.1). Also apply relative positioning.
|
||||
* it fits, apply inline-dir ("horizontal") positioning (CSS 10.3.3),
|
||||
* collapse margins (CSS2 8.3.1). Also apply relative positioning.
|
||||
*/
|
||||
bool
|
||||
nsBlockReflowContext::PlaceBlock(const nsHTMLReflowState& aReflowState,
|
||||
bool aForceFit,
|
||||
nsLineBox* aLine,
|
||||
nsCollapsingMargin& aBottomMarginResult,
|
||||
nsCollapsingMargin& aBEndMarginResult,
|
||||
nsOverflowAreas& aOverflowAreas,
|
||||
nsReflowStatus aReflowStatus,
|
||||
nscoord aContainerWidth)
|
||||
nsReflowStatus aReflowStatus)
|
||||
{
|
||||
// Compute collapsed bottom margin value.
|
||||
// Compute collapsed block-end margin value.
|
||||
WritingMode wm = aReflowState.GetWritingMode();
|
||||
WritingMode parentWM = mMetrics.GetWritingMode();
|
||||
if (NS_FRAME_IS_COMPLETE(aReflowStatus)) {
|
||||
aBottomMarginResult = mMetrics.mCarriedOutBottomMargin;
|
||||
aBottomMarginResult.Include(aReflowState.ComputedPhysicalMargin().bottom);
|
||||
aBEndMarginResult = mMetrics.mCarriedOutBottomMargin;
|
||||
aBEndMarginResult.Include(aReflowState.ComputedLogicalMargin().BEnd(wm));
|
||||
} else {
|
||||
// The used bottom-margin is set to zero above a break.
|
||||
aBottomMarginResult.Zero();
|
||||
aBEndMarginResult.Zero();
|
||||
}
|
||||
|
||||
nsPoint position(mX, mY);
|
||||
nscoord backupContainingBlockAdvance = 0;
|
||||
|
||||
// Check whether the block's bottom margin collapses with its top
|
||||
// Check whether the block's block-end margin collapses with its block-start
|
||||
// margin. See CSS 2.1 section 8.3.1; those rules seem to match
|
||||
// nsBlockFrame::IsEmpty(). Any such block must have zero height so
|
||||
// nsBlockFrame::IsEmpty(). Any such block must have zero block-size so
|
||||
// check that first. Note that a block can have clearance and still
|
||||
// have adjoining top/bottom margins, because the clearance goes
|
||||
// above the top margin.
|
||||
// have adjoining block-start/end margins, because the clearance goes
|
||||
// above the block-start margin.
|
||||
// Mark the frame as non-dirty; it has been reflowed (or we wouldn't
|
||||
// be here), and we don't want to assert in CachedIsEmpty()
|
||||
mFrame->RemoveStateBits(NS_FRAME_IS_DIRTY);
|
||||
bool empty = 0 == mMetrics.Height() && aLine->CachedIsEmpty();
|
||||
bool empty = 0 == mMetrics.BSize(parentWM) && aLine->CachedIsEmpty();
|
||||
if (empty) {
|
||||
// Collapse the bottom margin with the top margin that was already
|
||||
// applied.
|
||||
aBottomMarginResult.Include(mTopMargin);
|
||||
// Collapse the block-end margin with the block-start margin that was
|
||||
// already applied.
|
||||
aBEndMarginResult.Include(mBStartMargin);
|
||||
|
||||
#ifdef NOISY_VERTICAL_MARGINS
|
||||
#ifdef NOISY_BLOCKDIR_MARGINS
|
||||
printf(" ");
|
||||
nsFrame::ListTag(stdout, mOuterReflowState.frame);
|
||||
printf(": ");
|
||||
nsFrame::ListTag(stdout, mFrame);
|
||||
printf(" -- collapsing top & bottom margin together; y=%d spaceY=%d\n",
|
||||
position.y, mSpace.y);
|
||||
printf(" -- collapsing block start & end margin together; BStart=%d spaceBStart=%d\n",
|
||||
mBCoord, mSpace.BStart(mWritingMode));
|
||||
#endif
|
||||
// Section 8.3.1 of CSS 2.1 says that blocks with adjoining
|
||||
// top/bottom margins whose top margin collapses with their
|
||||
// parent's top margin should have their top border-edge at the
|
||||
// "top/bottom" (i.e. block-start/end) margins whose top margin collapses
|
||||
// with their parent's top margin should have their top border-edge at the
|
||||
// top border-edge of their parent. We actually don't have to do
|
||||
// anything special to make this happen. In that situation,
|
||||
// nsBlockFrame::ShouldApplyTopMargin will have returned false,
|
||||
// and mTopMargin and aClearance will have been zero in
|
||||
// nsBlockFrame::ShouldApplyBStartMargin will have returned false,
|
||||
// and mBStartMargin and aClearance will have been zero in
|
||||
// ReflowBlock.
|
||||
|
||||
// If we did apply our top margin, but now we're collapsing it
|
||||
// into the bottom margin, we need to back up the containing
|
||||
// block's y-advance by our top margin so that it doesn't get
|
||||
// If we did apply our block-start margin, but now we're collapsing it
|
||||
// into the block-end margin, we need to back up the containing
|
||||
// block's bCoord-advance by our block-start margin so that it doesn't get
|
||||
// counted twice. Note that here we're allowing the line's bounds
|
||||
// to become different from the block's position; we do this
|
||||
// because the containing block will place the next line at the
|
||||
// line's YMost, and it must place the next line at a different
|
||||
// line's BEnd, and it must place the next line at a different
|
||||
// point from where this empty block will be.
|
||||
backupContainingBlockAdvance = mTopMargin.get();
|
||||
backupContainingBlockAdvance = mBStartMargin.get();
|
||||
}
|
||||
|
||||
// See if the frame fit. If it's the first frame or empty then it
|
||||
// always fits. If the height is unconstrained then it always fits,
|
||||
// even if there's some sort of integer overflow that makes y +
|
||||
// mMetrics.Height() appear to go beyond the available height.
|
||||
if (!empty && !aForceFit && mSpace.height != NS_UNCONSTRAINEDSIZE) {
|
||||
nscoord yMost = position.y - backupContainingBlockAdvance + mMetrics.Height();
|
||||
if (yMost > mSpace.YMost()) {
|
||||
// always fits. If the block-size is unconstrained then it always fits,
|
||||
// even if there's some sort of integer overflow that makes bCoord +
|
||||
// mMetrics.BSize() appear to go beyond the available height.
|
||||
if (!empty && !aForceFit &&
|
||||
mSpace.BSize(mWritingMode) != NS_UNCONSTRAINEDSIZE) {
|
||||
nscoord bEnd = mBCoord -
|
||||
backupContainingBlockAdvance + mMetrics.BSize(mWritingMode);
|
||||
if (bEnd > mSpace.BEnd(mWritingMode)) {
|
||||
// didn't fit, we must acquit.
|
||||
mFrame->DidReflow(mPresContext, &aReflowState, nsDidReflowStatus::FINISHED);
|
||||
mFrame->DidReflow(mPresContext, &aReflowState,
|
||||
nsDidReflowStatus::FINISHED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
aLine->SetBounds(aReflowState.GetWritingMode(),
|
||||
nsRect(position.x,
|
||||
position.y - backupContainingBlockAdvance,
|
||||
mMetrics.Width(),
|
||||
mMetrics.Height()),
|
||||
aContainerWidth);
|
||||
aLine->SetBounds(mWritingMode,
|
||||
mICoord, mBCoord - backupContainingBlockAdvance,
|
||||
mMetrics.ISize(mWritingMode), mMetrics.BSize(mWritingMode),
|
||||
mContainerWidth);
|
||||
|
||||
// XXX temporary until other classes are logicalized
|
||||
nsPoint position = LogicalRect(mWritingMode,
|
||||
mICoord, mBCoord,
|
||||
mMetrics.ISize(mWritingMode),
|
||||
mMetrics.BSize(mWritingMode)).
|
||||
GetPhysicalPosition(mWritingMode, mContainerWidth);
|
||||
|
||||
aReflowState.ApplyRelativePositioning(&position);
|
||||
|
||||
|
@ -29,10 +29,10 @@ public:
|
||||
~nsBlockReflowContext() { }
|
||||
|
||||
void ReflowBlock(const nsRect& aSpace,
|
||||
bool aApplyTopMargin,
|
||||
bool aApplyBStartMargin,
|
||||
nsCollapsingMargin& aPrevMargin,
|
||||
nscoord aClearance,
|
||||
bool aIsAdjacentWithTop,
|
||||
bool aIsAdjacentWithBStart,
|
||||
nsLineBox* aLine,
|
||||
nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aReflowStatus,
|
||||
@ -41,51 +41,52 @@ public:
|
||||
bool PlaceBlock(const nsHTMLReflowState& aReflowState,
|
||||
bool aForceFit,
|
||||
nsLineBox* aLine,
|
||||
nsCollapsingMargin& aBottomMarginResult /* out */,
|
||||
nsCollapsingMargin& aBEndMarginResult /* out */,
|
||||
nsOverflowAreas& aOverflowAreas,
|
||||
nsReflowStatus aReflowStatus,
|
||||
nscoord aContainerWidth);
|
||||
nsReflowStatus aReflowStatus);
|
||||
|
||||
nsCollapsingMargin& GetCarriedOutBottomMargin() {
|
||||
nsCollapsingMargin& GetCarriedOutBEndMargin() {
|
||||
return mMetrics.mCarriedOutBottomMargin;
|
||||
}
|
||||
|
||||
nscoord GetTopMargin() const {
|
||||
return mTopMargin.get();
|
||||
}
|
||||
|
||||
const nsHTMLReflowMetrics& GetMetrics() const {
|
||||
return mMetrics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the collapsed top margin for a block whose reflow state is in aRS.
|
||||
* Computes the collapsed block-start margin for a block whose reflow state
|
||||
* is in aRS.
|
||||
* The computed margin is added into aMargin.
|
||||
* If aClearanceFrame is null then this is the first optimistic pass which shall assume
|
||||
* that no frames have clearance, and we clear the HasClearance on all frames encountered.
|
||||
* If non-null, this is the second pass and
|
||||
* the caller has decided aClearanceFrame needs clearance (and we will
|
||||
* therefore stop collapsing there); also, this function is responsible for marking
|
||||
* it with SetHasClearance.
|
||||
* If in the optimistic pass any frame is encountered that might possibly need
|
||||
* clearance (i.e., if we really needed the optimism assumption) then we set aMayNeedRetry
|
||||
* to true.
|
||||
* We return true if we changed the clearance state of any line and marked it dirty.
|
||||
* If aClearanceFrame is null then this is the first optimistic pass which
|
||||
* shall assume that no frames have clearance, and we clear the HasClearance
|
||||
* on all frames encountered.
|
||||
* If non-null, this is the second pass and the caller has decided
|
||||
* aClearanceFrame needs clearance (and we will therefore stop collapsing
|
||||
* there); also, this function is responsible for marking it with
|
||||
* SetHasClearance.
|
||||
* If in the optimistic pass any frame is encountered that might possibly
|
||||
* need clearance (i.e., if we really needed the optimism assumption) then
|
||||
* we set aMayNeedRetry to true.
|
||||
* We return true if we changed the clearance state of any line and marked it
|
||||
* dirty.
|
||||
*/
|
||||
static bool ComputeCollapsedTopMargin(const nsHTMLReflowState& aRS,
|
||||
nsCollapsingMargin* aMargin, nsIFrame* aClearanceFrame,
|
||||
bool* aMayNeedRetry, bool* aIsEmpty = nullptr);
|
||||
static bool ComputeCollapsedBStartMargin(const nsHTMLReflowState& aRS,
|
||||
nsCollapsingMargin* aMargin,
|
||||
nsIFrame* aClearanceFrame,
|
||||
bool* aMayNeedRetry,
|
||||
bool* aIsEmpty = nullptr);
|
||||
|
||||
protected:
|
||||
nsPresContext* mPresContext;
|
||||
const nsHTMLReflowState& mOuterReflowState;
|
||||
|
||||
nsIFrame* mFrame;
|
||||
nsRect mSpace;
|
||||
mozilla::LogicalRect mSpace;
|
||||
|
||||
nscoord mX, mY;
|
||||
nscoord mICoord, mBCoord, mContainerWidth;
|
||||
mozilla::WritingMode mWritingMode;
|
||||
nsHTMLReflowMetrics mMetrics;
|
||||
nsCollapsingMargin mTopMargin;
|
||||
nsCollapsingMargin mBStartMargin;
|
||||
};
|
||||
|
||||
#endif /* nsBlockReflowContext_h___ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user