Index: third_party/WebKit/Source/core/layout/LayoutBox.cpp |
diff --git a/third_party/WebKit/Source/core/layout/LayoutBox.cpp b/third_party/WebKit/Source/core/layout/LayoutBox.cpp |
index ffbe2f18715c4a113784f356381cfaaaeb5d4743..6db2cea6a4f3996d9bc4011380f32718ad99a124 100644 |
--- a/third_party/WebKit/Source/core/layout/LayoutBox.cpp |
+++ b/third_party/WebKit/Source/core/layout/LayoutBox.cpp |
@@ -4736,4 +4736,55 @@ void LayoutBox::clearPercentHeightDescendants() |
} |
} |
+LayoutUnit LayoutBox::pageLogicalHeightForOffset(LayoutUnit offset) const |
+{ |
+ LayoutView* layoutView = view(); |
+ LayoutFlowThread* flowThread = flowThreadContainingBlock(); |
+ if (!flowThread) |
+ return layoutView->layoutState()->pageLogicalHeight(); |
+ return flowThread->pageLogicalHeightForOffset(offset + offsetFromLogicalTopOfFirstPage()); |
+} |
+ |
+LayoutUnit LayoutBox::pageRemainingLogicalHeightForOffset(LayoutUnit offset, PageBoundaryRule pageBoundaryRule) const |
+{ |
+ LayoutView* layoutView = view(); |
+ offset += offsetFromLogicalTopOfFirstPage(); |
+ |
+ LayoutFlowThread* flowThread = flowThreadContainingBlock(); |
+ if (!flowThread) { |
+ LayoutUnit pageLogicalHeight = layoutView->layoutState()->pageLogicalHeight(); |
+ LayoutUnit remainingHeight = pageLogicalHeight - intMod(offset, pageLogicalHeight); |
+ if (pageBoundaryRule == AssociateWithFormerPage) { |
+ // An offset exactly at a page boundary will act as being part of the former page in |
+ // question (i.e. no remaining space), rather than being part of the latter (i.e. one |
+ // whole page length of remaining space). |
+ remainingHeight = intMod(remainingHeight, pageLogicalHeight); |
+ } |
+ return remainingHeight; |
+ } |
+ |
+ return flowThread->pageRemainingLogicalHeightForOffset(offset, pageBoundaryRule); |
+} |
+ |
+LayoutUnit LayoutBox::calculatePaginationStrutToFitContent(LayoutUnit offset, LayoutUnit strutToNextPage, LayoutUnit contentLogicalHeight) const |
+{ |
+ ASSERT(strutToNextPage == pageRemainingLogicalHeightForOffset(offset, AssociateWithLatterPage)); |
+ LayoutUnit nextPageLogicalTop = offset + strutToNextPage; |
+ if (pageLogicalHeightForOffset(nextPageLogicalTop) >= contentLogicalHeight) |
+ return strutToNextPage; // Content fits just fine in the next page or column. |
+ |
+ // Moving to the top of the next page or column doesn't result in enough space for the content |
+ // that we're trying to fit. If we're in a nested fragmentation context, we may find enough |
+ // space if we move to a column further ahead, by effectively breaking to the next outer |
+ // fragmentainer. |
+ LayoutFlowThread* flowThread = flowThreadContainingBlock(); |
+ if (!flowThread) { |
+ // If there's no flow thread, we're not nested. All pages have the same height. Give up. |
+ return strutToNextPage; |
+ } |
+ // Start searching for a suitable offset at the top of the next page or column. |
+ LayoutUnit flowThreadOffset = offsetFromLogicalTopOfFirstPage() + nextPageLogicalTop; |
+ return strutToNextPage + flowThread->nextLogicalTopForUnbreakableContent(flowThreadOffset, contentLogicalHeight) - flowThreadOffset; |
+} |
+ |
} // namespace blink |