Title: [98373] trunk/Source/WebCore
Revision
98373
Author
t...@chromium.org
Date
2011-10-25 12:26:04 -0700 (Tue, 25 Oct 2011)

Log Message

avoid unnecessary layouts of flex items during the flex pass
https://bugs.webkit.org/show_bug.cgi?id=70557

Reviewed by Ojan Vafai.

If the preferred size of a flex item is provided, we don't need to
layout the flex item when computing the preferred size.  This allows
us to only call layout on each flex item once in the common case.

No new tests, covered by existing tests.

* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::flowAwareLogicalWidthLengthForChild):
(WebCore::RenderFlexibleBox::preferredLogicalContentWidthForFlexItem):
(WebCore::RenderFlexibleBox::computePreferredLogicalWidth):
(WebCore::RenderFlexibleBox::layoutAndPlaceChildrenInlineDirection):
* rendering/RenderFlexibleBox.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (98372 => 98373)


--- trunk/Source/WebCore/ChangeLog	2011-10-25 19:10:58 UTC (rev 98372)
+++ trunk/Source/WebCore/ChangeLog	2011-10-25 19:26:04 UTC (rev 98373)
@@ -1,3 +1,23 @@
+2011-10-25  Tony Chang  <t...@chromium.org>
+
+        avoid unnecessary layouts of flex items during the flex pass
+        https://bugs.webkit.org/show_bug.cgi?id=70557
+
+        Reviewed by Ojan Vafai.
+
+        If the preferred size of a flex item is provided, we don't need to
+        layout the flex item when computing the preferred size.  This allows
+        us to only call layout on each flex item once in the common case.
+
+        No new tests, covered by existing tests.
+
+        * rendering/RenderFlexibleBox.cpp:
+        (WebCore::RenderFlexibleBox::flowAwareLogicalWidthLengthForChild):
+        (WebCore::RenderFlexibleBox::preferredLogicalContentWidthForFlexItem):
+        (WebCore::RenderFlexibleBox::computePreferredLogicalWidth):
+        (WebCore::RenderFlexibleBox::layoutAndPlaceChildrenInlineDirection):
+        * rendering/RenderFlexibleBox.h:
+
 2011-10-25  Fady Samuel  <fsam...@chromium.org>
 
         Crash in WebCore::RenderTableSection::addChild due to assert failure

Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp (98372 => 98373)


--- trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2011-10-25 19:10:58 UTC (rev 98372)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2011-10-25 19:26:04 UTC (rev 98373)
@@ -228,6 +228,11 @@
     return style()->isLeftToRightDirection();
 }
 
+Length RenderFlexibleBox::flowAwareLogicalWidthLengthForChild(RenderBox* child) const
+{
+    return isHorizontalFlow() ? child->style()->width() : child->style()->height();
+}
+
 bool RenderFlexibleBox::isFlowAwareLogicalHeightAuto() const
 {
     Length height = isHorizontalFlow() ? style()->height() : style()->width();
@@ -493,12 +498,12 @@
 
 LayoutUnit RenderFlexibleBox::preferredLogicalContentWidthForFlexItem(RenderBox* child) const
 {
-    Length width = isHorizontalFlow() ? child->style()->width() : child->style()->height();
-    if (width.isAuto()) {
+    Length logicalWidthLength = flowAwareLogicalWidthLengthForChild(child);
+    if (logicalWidthLength.isAuto()) {
         LayoutUnit logicalWidth = hasOrthogonalFlow(child) ? child->logicalHeight() : child->maxPreferredLogicalWidth();
         return logicalWidth - logicalBorderAndPaddingWidthForChild(child) - logicalScrollbarHeightForChild(child);
     }
-    return isHorizontalFlow() ? child->contentWidth() : child->contentHeight();
+    return logicalWidthLength.calcMinValue(flowAwareContentLogicalWidth());
 }
 
 void RenderFlexibleBox::layoutInlineDirection(bool relayoutChildren)
@@ -554,20 +559,24 @@
 
     LayoutUnit flexboxAvailableLogicalWidth = flowAwareContentLogicalWidth();
     for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
-        // We always have to lay out flexible objects again, since the flex distribution
-        // may have changed, and we need to reallocate space.
-        child->clearOverrideSize();
-        if (!relayoutChildren)
-            child->setChildNeedsLayout(true);
-        child->layoutIfNeeded();
+        if (flowAwareLogicalWidthLengthForChild(child).isAuto()) {
+            child->clearOverrideSize();
+            if (!relayoutChildren)
+                child->setChildNeedsLayout(true);
+            child->layoutIfNeeded();
+        }
 
-        // We can't just use marginStartForChild, et. al. because "auto" needs to be treated as 0.
+        // We set the margins because we want to make sure 'auto' has a margin
+        // of 0 and because if we're not auto sizing, we don't do a layout that
+        // computes the start/end margins.
         if (isHorizontalFlow()) {
-            preferredLogicalWidth += child->style()->marginLeft().calcMinValue(flexboxAvailableLogicalWidth);
-            preferredLogicalWidth += child->style()->marginRight().calcMinValue(flexboxAvailableLogicalWidth);
+            child->setMarginLeft(child->style()->marginLeft().calcMinValue(flexboxAvailableLogicalWidth));
+            child->setMarginRight(child->style()->marginRight().calcMinValue(flexboxAvailableLogicalWidth));
+            preferredLogicalWidth += child->marginLeft() + child->marginRight();
         } else {
-            preferredLogicalWidth += child->style()->marginTop().calcMinValue(flexboxAvailableLogicalWidth);
-            preferredLogicalWidth += child->style()->marginBottom().calcMinValue(flexboxAvailableLogicalWidth);
+            child->setMarginTop(child->style()->marginTop().calcMinValue(flexboxAvailableLogicalWidth));
+            child->setMarginBottom(child->style()->marginBottom().calcMinValue(flexboxAvailableLogicalWidth));
+            preferredLogicalWidth += child->marginTop() + child->marginBottom();
         }
 
         preferredLogicalWidth += logicalBorderAndPaddingWidthForChild(child);
@@ -671,11 +680,6 @@
         } else if (isFlowAwareLogicalHeightAuto())
             setFlowAwareLogicalHeight(std::max(flowAwareLogicalHeight(), flowAwareBorderAndPaddingLogicalHeight() + flowAwareMarginLogicalHeightForChild(child) + flowAwareLogicalHeightForChild(child) + scrollbarLogicalHeight()));
 
-        if (marginStartStyleForChild(child).isAuto())
-            setFlowAwareMarginStartForChild(child, 0);
-        if (marginEndStyleForChild(child).isAuto())
-            setFlowAwareMarginEndForChild(child, 0);
-
         startEdge += flowAwareMarginStartForChild(child);
 
         LayoutUnit childLogicalWidth = flowAwareLogicalWidthForChild(child);

Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.h (98372 => 98373)


--- trunk/Source/WebCore/rendering/RenderFlexibleBox.h	2011-10-25 19:10:58 UTC (rev 98372)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.h	2011-10-25 19:26:04 UTC (rev 98373)
@@ -58,6 +58,7 @@
     bool isHorizontalFlow() const;
     bool isLeftToRightFlow() const;
     bool isFlowAwareLogicalHeightAuto() const;
+    Length flowAwareLogicalWidthLengthForChild(RenderBox* child) const;
     void setFlowAwareLogicalHeight(LayoutUnit);
     LayoutUnit flowAwareLogicalHeightForChild(RenderBox* child);
     LayoutUnit flowAwareLogicalWidthForChild(RenderBox* child);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to