Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(831)

Unified Diff: third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp

Issue 1462913002: A line that ends up naturally in the next column may need to propagate a strut. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Prepositionize responsibly. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/multicol/orphaned-line-at-exact-top-of-column-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp b/third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp
index 32c4ec825b50ed29f87cfa3b9aa4278e39891c2c..c115299d3723ac3e6b5eea4eebd0e784799e0867 100644
--- a/third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutBlockFlow.cpp
@@ -737,7 +737,7 @@ LayoutUnit LayoutBlockFlow::adjustBlockChildForPagination(LayoutUnit logicalTop,
return newLogicalTop;
}
-static inline bool shouldSetStrutOnBlock(const LayoutBlockFlow& block, const RootInlineBox& lineBox, LayoutUnit lineLogicalOffset, int lineIndex, LayoutUnit remainingLogicalHeight)
+static bool shouldSetStrutOnBlock(const LayoutBlockFlow& block, const RootInlineBox& lineBox, LayoutUnit lineLogicalOffset, int lineIndex, LayoutUnit remainingLogicalHeight)
{
bool wantsStrutOnBlock = false;
if (!block.style()->hasAutoOrphans() && block.style()->orphans() >= lineIndex) {
@@ -762,6 +762,14 @@ static inline bool shouldSetStrutOnBlock(const LayoutBlockFlow& block, const Roo
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
@@ -805,10 +813,7 @@ 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.
- LayoutUnit paginationStrut = remainingLogicalHeight + std::max<LayoutUnit>(0, logicalOffset);
- if (isFloating())
- paginationStrut += marginBefore(); // Floats' margins do not collapse with page or column boundaries.
- setPaginationStrutPropagatedFromChild(paginationStrut);
+ setPaginationStrutPropagatedFromChild(calculateStrutForPropagation(*this, remainingLogicalHeight + logicalOffset));
} else {
logicalOffset += remainingLogicalHeight;
delta += remainingLogicalHeight;
@@ -819,6 +824,27 @@ void LayoutBlockFlow::adjustLinePositionForPagination(RootInlineBox& lineBox, La
// We're at the very top of a page or column.
if (lineBox != firstRootBox())
lineBox.setIsFirstAfterPageBreak(true);
+ // If this is the first line in the block, and the block has a top border, padding, or (in
+ // 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));
+ } 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 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
+ // room for the top border, padding and (if it's a float) margin and the line in one
+ // column or page.
+ if (totalLogicalOffset + lineHeight <= pageLogicalHeight)
+ setPaginationStrutPropagatedFromChild(strut);
+ }
}
paginatedContentWasLaidOut(logicalOffset);
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/multicol/orphaned-line-at-exact-top-of-column-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698