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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBox.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc.
7 * All rights reserved. 7 * All rights reserved.
8 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 4701 matching lines...) Expand 10 before | Expand all | Expand 10 after
4712 return; 4712 return;
4713 4713
4714 LayoutUnit logicalTop = child.logicalTop(); 4714 LayoutUnit logicalTop = child.logicalTop();
4715 LayoutUnit logicalHeight = child.logicalHeightIncludingOverflow(); 4715 LayoutUnit logicalHeight = child.logicalHeightIncludingOverflow();
4716 LayoutUnit spaceLeft = 4716 LayoutUnit spaceLeft =
4717 pageRemainingLogicalHeightForOffset(logicalTop, AssociateWithLatterPage); 4717 pageRemainingLogicalHeightForOffset(logicalTop, AssociateWithLatterPage);
4718 if (spaceLeft < logicalHeight) 4718 if (spaceLeft < logicalHeight)
4719 child.setOffsetToNextPage(spaceLeft); 4719 child.setOffsetToNextPage(spaceLeft);
4720 } 4720 }
4721 4721
4722 bool LayoutBox::childNeedsRelayoutForPagination(const LayoutBox& child) const {
4723 // TODO(mstensho): Should try to get this to work for floats too, instead of
4724 // just marking and bailing here.
4725 if (child.isFloating())
4726 return true;
4727 LayoutUnit logicalTop = child.logicalTop();
4728 // Figure out if we really need to force re-layout of the child. We only need
4729 // to do this if there's a chance that we need to recalculate pagination
4730 // struts inside.
4731 if (LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalTop)) {
4732 LayoutUnit logicalHeight = child.logicalHeightIncludingOverflow();
4733 LayoutUnit remainingSpace = pageRemainingLogicalHeightForOffset(
4734 logicalTop, AssociateWithLatterPage);
4735 if (child.offsetToNextPage()) {
4736 // We need to relayout unless we're going to break at the exact same
4737 // location as before.
4738 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:/
4739 return true;
4740 } else if (logicalHeight > remainingSpace) {
4741 // Last time we laid out this child, we didn't need to break, but now we
4742 // have to. So we need to relayout.
4743 return true;
4744 }
4745 } else {
4746 return true;
4747 }
4748
4749 // It seems that we can skip layout of this child, but we need to ask the flow
4750 // thread for permission first. We currently cannot skip over objects
4751 // containing column spanners.
4752 LayoutFlowThread* flowThread = child.flowThreadContainingBlock();
4753 return flowThread && !flowThread->canSkipLayout(child);
4754 }
4755
4722 void LayoutBox::markChildForPaginationRelayoutIfNeeded( 4756 void LayoutBox::markChildForPaginationRelayoutIfNeeded(
4723 LayoutBox& child, 4757 LayoutBox& child,
4724 SubtreeLayoutScope& layoutScope) { 4758 SubtreeLayoutScope& layoutScope) {
4725 DCHECK(!child.needsLayout()); 4759 DCHECK(!child.needsLayout());
4726 LayoutState* layoutState = view()->layoutState(); 4760 LayoutState* layoutState = view()->layoutState();
4727 // TODO(mstensho): Should try to get this to work for floats too, instead of 4761
4728 // just marking and bailing here. 4762 if (layoutState->paginationStateChanged() ||
4729 if (layoutState->paginationStateChanged() || child.isFloating()) { 4763 (layoutState->isPaginated() && childNeedsRelayoutForPagination(child)))
4730 layoutScope.setChildNeedsLayout(&child); 4764 layoutScope.setChildNeedsLayout(&child);
4731 return;
4732 }
4733 if (!layoutState->isPaginated())
4734 return;
4735
4736 LayoutUnit logicalTop = child.logicalTop();
4737 if (LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalTop)) {
4738 // Figure out if we really need to force re-layout of the child. We only
4739 // need to do this if there's a chance that we need to recalculate
4740 // pagination struts inside.
4741 LayoutUnit remainingSpace = pageRemainingLogicalHeightForOffset(
4742 logicalTop, AssociateWithLatterPage);
4743 LayoutUnit logicalHeight = child.logicalHeightIncludingOverflow();
4744 if ((!child.offsetToNextPage() && logicalHeight <= remainingSpace) ||
4745 child.offsetToNextPage() == remainingSpace) {
4746 // We don't need to relayout this child, either because the child wasn't
4747 // previously fragmented, and won't be fragmented now either, or because
4748 // it would fragment at the exact same position as before.
4749 //
4750 // We want to skip layout of this child, but we need to ask the flow
4751 // thread for permission first. We currently cannot skip over objects
4752 // containing column spanners.
4753 LayoutFlowThread* flowThread = child.flowThreadContainingBlock();
4754 if (!flowThread || flowThread->canSkipLayout(child))
4755 return;
4756 }
4757 }
4758
4759 layoutScope.setChildNeedsLayout(&child);
4760 } 4765 }
4761 4766
4762 void LayoutBox::markOrthogonalWritingModeRoot() { 4767 void LayoutBox::markOrthogonalWritingModeRoot() {
4763 ASSERT(frameView()); 4768 ASSERT(frameView());
4764 frameView()->addOrthogonalWritingModeRoot(*this); 4769 frameView()->addOrthogonalWritingModeRoot(*this);
4765 } 4770 }
4766 4771
4767 void LayoutBox::unmarkOrthogonalWritingModeRoot() { 4772 void LayoutBox::unmarkOrthogonalWritingModeRoot() {
4768 ASSERT(frameView()); 4773 ASSERT(frameView());
4769 frameView()->removeOrthogonalWritingModeRoot(*this); 4774 frameView()->removeOrthogonalWritingModeRoot(*this);
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
5633 LayoutRect rect = frameRect(); 5638 LayoutRect rect = frameRect();
5634 5639
5635 LayoutBlock* block = containingBlock(); 5640 LayoutBlock* block = containingBlock();
5636 if (block) 5641 if (block)
5637 block->adjustChildDebugRect(rect); 5642 block->adjustChildDebugRect(rect);
5638 5643
5639 return rect; 5644 return rect;
5640 } 5645 }
5641 5646
5642 } // namespace blink 5647 } // namespace blink
OLDNEW
« 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