Commit d27423b8 authored by mstensho's avatar mstensho Committed by Commit bot

Add marginBeforeIfFloating() to LayoutBlockFlow.

Floats' margins need special attention for pagination, because they are not to
be eaten by page or column boundaries.

Clamp strut to >= 0 in LayoutBlockFlow::setPaginationStrutPropagatedFromChild()
instead of doing it (poorly) in calculateStrutForPropagation().

Removed calculateStrutForPropagation(), because there was hardly anything left
there now (and this lets us make marginBeforeIfFloating() private). This
function also turned out not to be universally usable, since we were already
calculating the strut on our own in adjustLinePositionForPagination() in one
case.

R=leviw@chromium.org

Review URL: https://codereview.chromium.org/1460203003

Cr-Commit-Position: refs/heads/master@{#361084}
parent 8948e325
......@@ -716,9 +716,7 @@ LayoutUnit LayoutBlockFlow::adjustBlockChildForPagination(LayoutUnit logicalTop,
// FIXME: Should really check if we're exceeding the page height before propagating the strut, but we don't
// have all the information to do so (the strut only has the remaining amount to push). Gecko gets this wrong too
// and pushes to the next page anyway, so not too concerned about it.
paginationStrut += logicalTop;
if (isFloating())
paginationStrut += marginBefore(); // Floats' margins do not collapse with page or column boundaries.
paginationStrut += logicalTop + marginBeforeIfFloating();
setPaginationStrutPropagatedFromChild(paginationStrut);
if (childBlockFlow)
childBlockFlow->setPaginationStrutPropagatedFromChild(LayoutUnit());
......@@ -762,14 +760,6 @@ static bool shouldSetStrutOnBlock(const LayoutBlockFlow& block, const RootInline
return wantsStrutOnBlock && block.allowsPaginationStrut();
}
static LayoutUnit calculateStrutForPropagation(const LayoutBlockFlow& blockFlow, LayoutUnit lineLogicalOffset)
{
LayoutUnit paginationStrut = std::max<LayoutUnit>(LayoutUnit(), lineLogicalOffset);
if (blockFlow.isFloating())
paginationStrut += blockFlow.marginBefore(); // Floats' margins do not collapse with page or column boundaries.
return paginationStrut;
}
void LayoutBlockFlow::adjustLinePositionForPagination(RootInlineBox& lineBox, LayoutUnit& delta)
{
// TODO(mstensho): Pay attention to line overflow. It should be painted in the same column as
......@@ -813,7 +803,8 @@ void LayoutBlockFlow::adjustLinePositionForPagination(RootInlineBox& lineBox, La
// content-less portions (struts) at the beginning of a block before a break, if it can
// be avoided. After all, that's the reason for setting struts on blocks and not lines
// in the first place.
setPaginationStrutPropagatedFromChild(calculateStrutForPropagation(*this, remainingLogicalHeight + logicalOffset));
LayoutUnit strut = remainingLogicalHeight + logicalOffset + marginBeforeIfFloating();
setPaginationStrutPropagatedFromChild(strut);
} else {
logicalOffset += remainingLogicalHeight;
delta += remainingLogicalHeight;
......@@ -828,15 +819,15 @@ void LayoutBlockFlow::adjustLinePositionForPagination(RootInlineBox& lineBox, La
// case it's a float) margin, we may want to set a strut on the block, so that everything
// ends up in the next column or page. Setting a strut on the block is also important when
// it comes to satisfying orphan requirements.
if (shouldSetStrutOnBlock(*this, lineBox, logicalOffset, lineIndex, remainingLogicalHeight))
setPaginationStrutPropagatedFromChild(calculateStrutForPropagation(*this, logicalOffset));
if (shouldSetStrutOnBlock(*this, lineBox, logicalOffset, lineIndex, remainingLogicalHeight)) {
LayoutUnit strut = logicalOffset + marginBeforeIfFloating();
setPaginationStrutPropagatedFromChild(strut);
}
} else if (lineBox == firstRootBox() && allowsPaginationStrut()) {
// This is the first line in the block. The block may still start in the previous column or
// page, and if that's the case, attempt to pull it over to where this line is, so that we
// don't split the top border, padding, or (in case it's a float) margin.
LayoutUnit totalLogicalOffset = logicalOffset;
if (isFloating())
totalLogicalOffset += marginBefore(); // Floats' margins do not collapse with page or column boundaries.
LayoutUnit totalLogicalOffset = logicalOffset + marginBeforeIfFloating();
LayoutUnit strut = remainingLogicalHeight + totalLogicalOffset - pageLogicalHeight;
if (strut > 0) {
// The block starts in a previous column or page. Set a strut on the block if there's
......@@ -2932,6 +2923,7 @@ bool LayoutBlockFlow::allowsPaginationStrut() const
void LayoutBlockFlow::setPaginationStrutPropagatedFromChild(LayoutUnit strut)
{
strut = std::max(strut, LayoutUnit());
if (!m_rareData) {
if (!strut)
return;
......
......@@ -516,6 +516,10 @@ private:
LayoutUnit collapsedMarginBefore() const final { return maxPositiveMarginBefore() - maxNegativeMarginBefore(); }
LayoutUnit collapsedMarginAfter() const final { return maxPositiveMarginAfter() - maxNegativeMarginAfter(); }
// Floats' margins do not collapse with page or column boundaries, and we therefore need to
// treat them specially in some cases.
LayoutUnit marginBeforeIfFloating() const { return isFloating() ? marginBefore() : LayoutUnit(); }
LayoutUnit collapseMargins(LayoutBox& child, MarginInfo&, bool childIsSelfCollapsing, bool childDiscardMarginBefore, bool childDiscardMarginAfter);
LayoutUnit clearFloatsIfNeeded(LayoutBox& child, MarginInfo&, LayoutUnit oldTopPosMargin, LayoutUnit oldTopNegMargin, LayoutUnit yPos, bool childIsSelfCollapsing, bool childDiscardMargin);
LayoutUnit estimateLogicalTopPosition(LayoutBox& child, const MarginInfo&, LayoutUnit& estimateWithoutPagination);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment