Changeset 136324 in webkit


Ignore:
Timestamp:
Dec 2, 2012 2:39:51 AM (11 years ago)
Author:
tony@chromium.org
Message:

Avoid a second layout of flex items in layoutAndPlaceChildren()
https://bugs.webkit.org/show_bug.cgi?id=102352

Reviewed by Ojan Vafai.

Source/WebCore:

Avoid doing a second layout if we're going to get the same size as before.
This prevents us from doing an exponential number of layouts in some
common cases.

Test: css3/flexbox/stretch-after-sibling-size-change.html

  • html/shadow/SliderThumbElement.cpp:

(WebCore::RenderSliderContainer::layout): Force a layout of the track, which positions the thumb.

  • rendering/RenderFlexibleBox.cpp:

(WebCore::RenderFlexibleBox::needToStretchChild): Determine if a child is going to stretch.
(WebCore::RenderFlexibleBox::resetAutoMarginsAndLogicalTopInCrossAxis): Makes sure we're in a consistent state before
we apply auto margins.
(WebCore::RenderFlexibleBox::layoutAndPlaceChildren):

  • rendering/RenderFlexibleBox.h: Add needToStretchChild.

LayoutTests:

Add a test case to make sure we relayout when a sibling is stretching.

  • css3/flexbox/stretch-after-sibling-size-change-expected.txt: Added.
  • css3/flexbox/stretch-after-sibling-size-change.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r136323 r136324  
     12012-12-02  Tony Chang  <tony@chromium.org>
     2
     3        Avoid a second layout of flex items in layoutAndPlaceChildren()
     4        https://bugs.webkit.org/show_bug.cgi?id=102352
     5
     6        Reviewed by Ojan Vafai.
     7
     8        Add a test case to make sure we relayout when a sibling is stretching.
     9
     10        * css3/flexbox/stretch-after-sibling-size-change-expected.txt: Added.
     11        * css3/flexbox/stretch-after-sibling-size-change.html: Added.
     12
    1132012-12-02  Yongjun Zhang  <yongjun_zhang@apple.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r136323 r136324  
     12012-12-02  Tony Chang  <tony@chromium.org>
     2
     3        Avoid a second layout of flex items in layoutAndPlaceChildren()
     4        https://bugs.webkit.org/show_bug.cgi?id=102352
     5
     6        Reviewed by Ojan Vafai.
     7
     8        Avoid doing a second layout if we're going to get the same size as before.
     9        This prevents us from doing an exponential number of layouts in some
     10        common cases.
     11
     12        Test: css3/flexbox/stretch-after-sibling-size-change.html
     13
     14        * html/shadow/SliderThumbElement.cpp:
     15        (WebCore::RenderSliderContainer::layout): Force a layout of the track, which positions the thumb.
     16        * rendering/RenderFlexibleBox.cpp:
     17        (WebCore::RenderFlexibleBox::needToStretchChild): Determine if a child is going to stretch.
     18        (WebCore::RenderFlexibleBox::resetAutoMarginsAndLogicalTopInCrossAxis): Makes sure we're in a consistent state before
     19        we apply auto margins.
     20        (WebCore::RenderFlexibleBox::layoutAndPlaceChildren):
     21        * rendering/RenderFlexibleBox.h: Add needToStretchChild.
     22
    1232012-12-02  Yongjun Zhang  <yongjun_zhang@apple.com>
    224
  • trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp

    r135913 r136324  
    179179
    180180    RenderBox* thumb = 0;
     181    RenderBox* track = 0;
    181182    if (input->sliderThumbElement() && input->sliderThumbElement()->renderer()) {
    182183        thumb = toRenderBox(input->sliderThumbElement()->renderer());
    183         // Reset the thumb location before layout.
    184         thumb->setLocation(LayoutPoint());
     184        track = toRenderBox(thumb->parent());
     185        // Force a layout to reset the position of the thumb so the code below doesn't move the thumb to the wrong place.
     186        // FIXME: Make a custom Render class for the track and move the thumb positioning code there.
     187        track->setChildNeedsLayout(true, MarkOnlyThis);
    185188    }
    186189
     
    191194    if (!thumb)
    192195        return;
    193     RenderBox* track = toRenderBox(thumb->parent());
    194196
    195197    double percentageOffset = sliderPosition(input).toDouble();
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp

    r134683 r136324  
    10661066}
    10671067
     1068bool RenderFlexibleBox::needToStretchChild(RenderBox* child)
     1069{
     1070    if (alignmentForChild(child) != AlignStretch)
     1071        return false;
     1072
     1073    Length crossAxisLength = isHorizontalFlow() ? child->style()->height() : child->style()->width();
     1074    return crossAxisLength.isAuto();
     1075}
     1076
     1077void RenderFlexibleBox::resetAutoMarginsAndLogicalTopInCrossAxis(RenderBox* child)
     1078{
     1079    if (hasAutoMarginsInCrossAxis(child))
     1080        child->updateLogicalHeight();
     1081}
     1082
    10681083void RenderFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, const OrderedFlexItemList& children, const WTF::Vector<LayoutUnit>& childSizes, LayoutUnit availableFreeSpace, WTF::Vector<LineContext>& lineContexts)
    10691084{
     
    10911106        setLogicalOverrideSize(child, childPreferredSize);
    10921107        // FIXME: Can avoid laying out here in some cases. See https://webkit.org/b/87905.
    1093         child->setChildNeedsLayout(true, MarkOnlyThis);
     1108        if (needToStretchChild(child) || childPreferredSize != mainAxisExtentForChild(child))
     1109            child->setChildNeedsLayout(true, MarkOnlyThis);
     1110        else {
     1111            // To avoid double applying margin changes in updateAutoMarginsInCrossAxis, we reset the margins here.
     1112            resetAutoMarginsAndLogicalTopInCrossAxis(child);
     1113        }
    10941114        child->layoutIfNeeded();
    10951115
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.h

    r134683 r136324  
    135135    void freezeViolations(const WTF::Vector<Violation>&, LayoutUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexShrink, InflexibleFlexItemSize&);
    136136
     137    void resetAutoMarginsAndLogicalTopInCrossAxis(RenderBox*);
     138    bool needToStretchChild(RenderBox*);
    137139    void setLogicalOverrideSize(RenderBox* child, LayoutUnit childPreferredSize);
    138140    void prepareChildForPositionedLayout(RenderBox* child, LayoutUnit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode);
Note: See TracChangeset for help on using the changeset viewer.