Changeset 98373 in webkit


Ignore:
Timestamp:
Oct 25, 2011 12:26:04 PM (12 years ago)
Author:
tony@chromium.org
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:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r98372 r98373  
     12011-10-25  Tony Chang  <tony@chromium.org>
     2
     3        avoid unnecessary layouts of flex items during the flex pass
     4        https://bugs.webkit.org/show_bug.cgi?id=70557
     5
     6        Reviewed by Ojan Vafai.
     7
     8        If the preferred size of a flex item is provided, we don't need to
     9        layout the flex item when computing the preferred size.  This allows
     10        us to only call layout on each flex item once in the common case.
     11
     12        No new tests, covered by existing tests.
     13
     14        * rendering/RenderFlexibleBox.cpp:
     15        (WebCore::RenderFlexibleBox::flowAwareLogicalWidthLengthForChild):
     16        (WebCore::RenderFlexibleBox::preferredLogicalContentWidthForFlexItem):
     17        (WebCore::RenderFlexibleBox::computePreferredLogicalWidth):
     18        (WebCore::RenderFlexibleBox::layoutAndPlaceChildrenInlineDirection):
     19        * rendering/RenderFlexibleBox.h:
     20
    1212011-10-25  Fady Samuel  <fsamuel@chromium.org>
    222
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp

    r98024 r98373  
    229229}
    230230
     231Length RenderFlexibleBox::flowAwareLogicalWidthLengthForChild(RenderBox* child) const
     232{
     233    return isHorizontalFlow() ? child->style()->width() : child->style()->height();
     234}
     235
    231236bool RenderFlexibleBox::isFlowAwareLogicalHeightAuto() const
    232237{
     
    494499LayoutUnit RenderFlexibleBox::preferredLogicalContentWidthForFlexItem(RenderBox* child) const
    495500{
    496     Length width = isHorizontalFlow() ? child->style()->width() : child->style()->height();
    497     if (width.isAuto()) {
     501    Length logicalWidthLength = flowAwareLogicalWidthLengthForChild(child);
     502    if (logicalWidthLength.isAuto()) {
    498503        LayoutUnit logicalWidth = hasOrthogonalFlow(child) ? child->logicalHeight() : child->maxPreferredLogicalWidth();
    499504        return logicalWidth - logicalBorderAndPaddingWidthForChild(child) - logicalScrollbarHeightForChild(child);
    500505    }
    501     return isHorizontalFlow() ? child->contentWidth() : child->contentHeight();
     506    return logicalWidthLength.calcMinValue(flowAwareContentLogicalWidth());
    502507}
    503508
     
    555560    LayoutUnit flexboxAvailableLogicalWidth = flowAwareContentLogicalWidth();
    556561    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
    557         // We always have to lay out flexible objects again, since the flex distribution
    558         // may have changed, and we need to reallocate space.
    559         child->clearOverrideSize();
    560         if (!relayoutChildren)
    561             child->setChildNeedsLayout(true);
    562         child->layoutIfNeeded();
    563 
    564         // We can't just use marginStartForChild, et. al. because "auto" needs to be treated as 0.
     562        if (flowAwareLogicalWidthLengthForChild(child).isAuto()) {
     563            child->clearOverrideSize();
     564            if (!relayoutChildren)
     565                child->setChildNeedsLayout(true);
     566            child->layoutIfNeeded();
     567        }
     568
     569        // We set the margins because we want to make sure 'auto' has a margin
     570        // of 0 and because if we're not auto sizing, we don't do a layout that
     571        // computes the start/end margins.
    565572        if (isHorizontalFlow()) {
    566             preferredLogicalWidth += child->style()->marginLeft().calcMinValue(flexboxAvailableLogicalWidth);
    567             preferredLogicalWidth += child->style()->marginRight().calcMinValue(flexboxAvailableLogicalWidth);
     573            child->setMarginLeft(child->style()->marginLeft().calcMinValue(flexboxAvailableLogicalWidth));
     574            child->setMarginRight(child->style()->marginRight().calcMinValue(flexboxAvailableLogicalWidth));
     575            preferredLogicalWidth += child->marginLeft() + child->marginRight();
    568576        } else {
    569             preferredLogicalWidth += child->style()->marginTop().calcMinValue(flexboxAvailableLogicalWidth);
    570             preferredLogicalWidth += child->style()->marginBottom().calcMinValue(flexboxAvailableLogicalWidth);
     577            child->setMarginTop(child->style()->marginTop().calcMinValue(flexboxAvailableLogicalWidth));
     578            child->setMarginBottom(child->style()->marginBottom().calcMinValue(flexboxAvailableLogicalWidth));
     579            preferredLogicalWidth += child->marginTop() + child->marginBottom();
    571580        }
    572581
     
    671680        } else if (isFlowAwareLogicalHeightAuto())
    672681            setFlowAwareLogicalHeight(std::max(flowAwareLogicalHeight(), flowAwareBorderAndPaddingLogicalHeight() + flowAwareMarginLogicalHeightForChild(child) + flowAwareLogicalHeightForChild(child) + scrollbarLogicalHeight()));
    673 
    674         if (marginStartStyleForChild(child).isAuto())
    675             setFlowAwareMarginStartForChild(child, 0);
    676         if (marginEndStyleForChild(child).isAuto())
    677             setFlowAwareMarginEndForChild(child, 0);
    678682
    679683        startEdge += flowAwareMarginStartForChild(child);
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.h

    r97801 r98373  
    5959    bool isLeftToRightFlow() const;
    6060    bool isFlowAwareLogicalHeightAuto() const;
     61    Length flowAwareLogicalWidthLengthForChild(RenderBox* child) const;
    6162    void setFlowAwareLogicalHeight(LayoutUnit);
    6263    LayoutUnit flowAwareLogicalHeightForChild(RenderBox* child);
Note: See TracChangeset for help on using the changeset viewer.