Changeset 98373 in webkit
- Timestamp:
- Oct 25, 2011 12:26:04 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r98372 r98373 1 2011-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 1 21 2011-10-25 Fady Samuel <fsamuel@chromium.org> 2 22 -
trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp
r98024 r98373 229 229 } 230 230 231 Length RenderFlexibleBox::flowAwareLogicalWidthLengthForChild(RenderBox* child) const 232 { 233 return isHorizontalFlow() ? child->style()->width() : child->style()->height(); 234 } 235 231 236 bool RenderFlexibleBox::isFlowAwareLogicalHeightAuto() const 232 237 { … … 494 499 LayoutUnit RenderFlexibleBox::preferredLogicalContentWidthForFlexItem(RenderBox* child) const 495 500 { 496 Length width = isHorizontalFlow() ? child->style()->width() : child->style()->height();497 if ( width.isAuto()) {501 Length logicalWidthLength = flowAwareLogicalWidthLengthForChild(child); 502 if (logicalWidthLength.isAuto()) { 498 503 LayoutUnit logicalWidth = hasOrthogonalFlow(child) ? child->logicalHeight() : child->maxPreferredLogicalWidth(); 499 504 return logicalWidth - logicalBorderAndPaddingWidthForChild(child) - logicalScrollbarHeightForChild(child); 500 505 } 501 return isHorizontalFlow() ? child->contentWidth() : child->contentHeight();506 return logicalWidthLength.calcMinValue(flowAwareContentLogicalWidth()); 502 507 } 503 508 … … 555 560 LayoutUnit flexboxAvailableLogicalWidth = flowAwareContentLogicalWidth(); 556 561 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. 565 572 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(); 568 576 } 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(); 571 580 } 572 581 … … 671 680 } else if (isFlowAwareLogicalHeightAuto()) 672 681 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);678 682 679 683 startEdge += flowAwareMarginStartForChild(child); -
trunk/Source/WebCore/rendering/RenderFlexibleBox.h
r97801 r98373 59 59 bool isLeftToRightFlow() const; 60 60 bool isFlowAwareLogicalHeightAuto() const; 61 Length flowAwareLogicalWidthLengthForChild(RenderBox* child) const; 61 62 void setFlowAwareLogicalHeight(LayoutUnit); 62 63 LayoutUnit flowAwareLogicalHeightForChild(RenderBox* child);
Note: See TracChangeset
for help on using the changeset viewer.