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

Side by Side Diff: Source/core/layout/LayoutBlock.cpp

Issue 1128713004: Don't mark a positioned object for layout when we've just laid it out. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 7 months 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 | Annotate | Revision Log
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) 2007 David Smith (catfish.man@gmail.com) 4 * (C) 2007 David Smith (catfish.man@gmail.com)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 1662 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 Length marginLeft = child.style()->marginStartUsing(style()); 1673 Length marginLeft = child.style()->marginStartUsing(style());
1674 Length marginRight = child.style()->marginEndUsing(style()); 1674 Length marginRight = child.style()->marginEndUsing(style());
1675 LayoutUnit margin = 0; 1675 LayoutUnit margin = 0;
1676 if (marginLeft.isFixed()) 1676 if (marginLeft.isFixed())
1677 margin += marginLeft.value(); 1677 margin += marginLeft.value();
1678 if (marginRight.isFixed()) 1678 if (marginRight.isFixed())
1679 margin += marginRight.value(); 1679 margin += marginRight.value();
1680 return margin; 1680 return margin;
1681 } 1681 }
1682 1682
1683 static bool needsLayoutDueToStaticPosition(LayoutObject* child, LayoutObject* co ntainingBlock)
1684 {
1685 // When a non-positioned block element moves, it may have positioned childre n that are implicitly positioned relative to the
1686 // non-positioned block. In block flow we can detect these when we layout th e non-positioned block, in line layout we always
1687 // need to mark the positioned child for layout if its statically positioned in the direction in which the object lays out.
1688 // TODO(rhogan): We may need to move the block layout case in here too, as m arking a positioned object for layout while laying out an object's children
1689 // invalidly assumes that our positionedObjects list is in DOM order and tha t we could never mark a positioned object for layout
1690 // *after* we've laid it out in layoutPositionedObjects.
leviw_travelin_and_unemployed 2015/05/19 18:32:12 We should assert this. Can you file a bug and link
rhogan 2015/05/20 20:15:06 Added the bug, but couldn't think of a way of asse
1691 if (!child->parent()->childrenInline())
1692 return false;
1693 const ComputedStyle* style = child->style();
1694 bool isHorizontal = style->isHorizontalWritingMode();
1695 return style->isDisplayInlineType() ? style->hasStaticInlinePosition(isHoriz ontal) : style->hasStaticBlockPosition(isHorizontal);
1696 }
1697
1683 void LayoutBlock::layoutPositionedObjects(bool relayoutChildren, PositionedLayou tBehavior info) 1698 void LayoutBlock::layoutPositionedObjects(bool relayoutChildren, PositionedLayou tBehavior info)
1684 { 1699 {
1685 TrackedLayoutBoxListHashSet* positionedDescendants = positionedObjects(); 1700 TrackedLayoutBoxListHashSet* positionedDescendants = positionedObjects();
1686 if (!positionedDescendants) 1701 if (!positionedDescendants)
1687 return; 1702 return;
1688 1703
1689 if (hasColumns()) 1704 if (hasColumns())
1690 view()->layoutState()->clearPaginationInformation(); // Positioned objec ts are not part of the column flow, so they don't paginate with the columns. 1705 view()->layoutState()->clearPaginationInformation(); // Positioned objec ts are not part of the column flow, so they don't paginate with the columns.
1691 1706
1692 for (auto* positionedObject : *positionedDescendants) { 1707 for (auto* positionedObject : *positionedDescendants) {
1693 positionedObject->setMayNeedPaintInvalidation(); 1708 positionedObject->setMayNeedPaintInvalidation();
1694 1709
1695 SubtreeLayoutScope layoutScope(*positionedObject); 1710 SubtreeLayoutScope layoutScope(*positionedObject);
1696 // A fixed position element with an absolute positioned ancestor has no way of knowing if the latter has changed position. So 1711 // A fixed position element with an absolute positioned ancestor has no way of knowing if the latter has changed position. So
1697 // if this is a fixed position element, mark it for layout if it has an abspos ancestor and needs to move with that ancestor, i.e. 1712 // if this is a fixed position element, mark it for layout if it has an abspos ancestor and needs to move with that ancestor, i.e.
1698 // it has static position. 1713 // it has static position.
1699 markFixedPositionObjectForLayoutIfNeeded(positionedObject, layoutScope); 1714 markFixedPositionObjectForLayoutIfNeeded(positionedObject, layoutScope);
1700 if (info == LayoutOnlyFixedPositionedObjects) { 1715 if (info == LayoutOnlyFixedPositionedObjects) {
1701 positionedObject->layoutIfNeeded(); 1716 positionedObject->layoutIfNeeded();
1702 continue; 1717 continue;
1703 } 1718 }
1704 1719
1705 // When a non-positioned block element moves, it may have positioned chi ldren that are implicitly positioned relative to the 1720 if (relayoutChildren || needsLayoutDueToStaticPosition(positionedObject, this))
1706 // non-positioned block. Rather than trying to detect all of these move ment cases, we just always lay out positioned
1707 // objects that are positioned implicitly like this. Such objects are r are, and so in typical DHTML menu usage (where everything is
1708 // positioned explicitly) this should not incur a performance penalty.
1709 if (relayoutChildren || (positionedObject->style()->hasStaticBlockPositi on(isHorizontalWritingMode()) && positionedObject->parent() != this))
1710 layoutScope.setChildNeedsLayout(positionedObject); 1721 layoutScope.setChildNeedsLayout(positionedObject);
1711 1722
1712 // If relayoutChildren is set and the child has percentage padding or an embedded content box, we also need to invalidate the childs pref widths. 1723 // If relayoutChildren is set and the child has percentage padding or an embedded content box, we also need to invalidate the childs pref widths.
1713 if (relayoutChildren && positionedObject->needsPreferredWidthsRecalculat ion()) 1724 if (relayoutChildren && positionedObject->needsPreferredWidthsRecalculat ion())
1714 positionedObject->setPreferredLogicalWidthsDirty(MarkOnlyThis); 1725 positionedObject->setPreferredLogicalWidthsDirty(MarkOnlyThis);
1715 1726
1716 if (!positionedObject->needsLayout()) 1727 if (!positionedObject->needsLayout())
1717 positionedObject->markForPaginationRelayoutIfNeeded(layoutScope); 1728 positionedObject->markForPaginationRelayoutIfNeeded(layoutScope);
1718 1729
1719 // If we are paginated or in a line grid, go ahead and compute a vertica l position for our object now. 1730 // If we are paginated or in a line grid, go ahead and compute a vertica l position for our object now.
(...skipping 2200 matching lines...) Expand 10 before | Expand all | Expand 10 after
3920 void LayoutBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Layout Object* obj) const 3931 void LayoutBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Layout Object* obj) const
3921 { 3932 {
3922 showLayoutObject(); 3933 showLayoutObject();
3923 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box()) 3934 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box())
3924 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1); 3935 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1);
3925 } 3936 }
3926 3937
3927 #endif 3938 #endif
3928 3939
3929 } // namespace blink 3940 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698