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

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

Issue 2459293004: Avoid unnecessary relayout of floats when not paginated. (Closed)
Patch Set: Created 4 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/Source/core/layout/LayoutBox.h ('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/LayoutBox.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutBox.cpp b/third_party/WebKit/Source/core/layout/LayoutBox.cpp
index 8d203b08651e60bbcb9308cb84aa526d1e0aae02..5aad7f755841285c46b4aeb9ace8980f0c7075c0 100644
--- a/third_party/WebKit/Source/core/layout/LayoutBox.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutBox.cpp
@@ -4719,44 +4719,49 @@ void LayoutBox::updateFragmentationInfoForChild(LayoutBox& child) {
child.setOffsetToNextPage(spaceLeft);
}
-void LayoutBox::markChildForPaginationRelayoutIfNeeded(
- LayoutBox& child,
- SubtreeLayoutScope& layoutScope) {
- DCHECK(!child.needsLayout());
- LayoutState* layoutState = view()->layoutState();
+bool LayoutBox::childNeedsRelayoutForPagination(const LayoutBox& child) const {
// TODO(mstensho): Should try to get this to work for floats too, instead of
// just marking and bailing here.
- if (layoutState->paginationStateChanged() || child.isFloating()) {
- layoutScope.setChildNeedsLayout(&child);
- return;
- }
- if (!layoutState->isPaginated())
- return;
-
+ if (child.isFloating())
+ return true;
LayoutUnit logicalTop = child.logicalTop();
+ // Figure out if we really need to force re-layout of the child. We only need
+ // to do this if there's a chance that we need to recalculate pagination
+ // struts inside.
if (LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalTop)) {
- // Figure out if we really need to force re-layout of the child. We only
- // need to do this if there's a chance that we need to recalculate
- // pagination struts inside.
+ LayoutUnit logicalHeight = child.logicalHeightIncludingOverflow();
LayoutUnit remainingSpace = pageRemainingLogicalHeightForOffset(
logicalTop, AssociateWithLatterPage);
- LayoutUnit logicalHeight = child.logicalHeightIncludingOverflow();
- if ((!child.offsetToNextPage() && logicalHeight <= remainingSpace) ||
- child.offsetToNextPage() == remainingSpace) {
- // We don't need to relayout this child, either because the child wasn't
- // previously fragmented, and won't be fragmented now either, or because
- // it would fragment at the exact same position as before.
- //
- // We want to skip layout of this child, but we need to ask the flow
- // thread for permission first. We currently cannot skip over objects
- // containing column spanners.
- LayoutFlowThread* flowThread = child.flowThreadContainingBlock();
- if (!flowThread || flowThread->canSkipLayout(child))
- return;
+ if (child.offsetToNextPage()) {
+ // We need to relayout unless we're going to break at the exact same
+ // location as before.
+ if (child.offsetToNextPage() != remainingSpace)
eae 2016/11/01 16:55:10 Is checking the break offset sufficient here? Don'
mstensho (USE GERRIT) 2016/11/01 17:54:26 We no longer store the start offset, as of https:/
+ return true;
+ } else if (logicalHeight > remainingSpace) {
+ // Last time we laid out this child, we didn't need to break, but now we
+ // have to. So we need to relayout.
+ return true;
}
+ } else {
+ return true;
}
- layoutScope.setChildNeedsLayout(&child);
+ // It seems that we can skip layout of this child, but we need to ask the flow
+ // thread for permission first. We currently cannot skip over objects
+ // containing column spanners.
+ LayoutFlowThread* flowThread = child.flowThreadContainingBlock();
+ return flowThread && !flowThread->canSkipLayout(child);
+}
+
+void LayoutBox::markChildForPaginationRelayoutIfNeeded(
+ LayoutBox& child,
+ SubtreeLayoutScope& layoutScope) {
+ DCHECK(!child.needsLayout());
+ LayoutState* layoutState = view()->layoutState();
+
+ if (layoutState->paginationStateChanged() ||
+ (layoutState->isPaginated() && childNeedsRelayoutForPagination(child)))
+ layoutScope.setChildNeedsLayout(&child);
}
void LayoutBox::markOrthogonalWritingModeRoot() {
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBox.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698