Refactor duplicate code into RenderFlexibleBox::mainAxisContentExtent
authortony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Sep 2012 19:49:34 +0000 (19:49 +0000)
committertony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Sep 2012 19:49:34 +0000 (19:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=96676

Reviewed by Eric Seidel.

There was computeAvailableFreeSpace() and lineBreakLength() shared some very similar code.
Merge this code into mainAxisContentExtent().

No new tests, this is just a refactor.

* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::mainAxisContentExtent): Take contentLogicalHeight as a parameter,
which is needed when determining the logical height.
(WebCore::RenderFlexibleBox::computeAvailableFreeSpace): Use mainAxisContentExtent() and inline.
(WebCore::RenderFlexibleBox::computeNextFlexLine): Use mainAxisContentExtent().
* rendering/RenderFlexibleBox.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@128494 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderFlexibleBox.cpp
Source/WebCore/rendering/RenderFlexibleBox.h

index eb043a7..7584f4a 100644 (file)
@@ -1,3 +1,22 @@
+2012-09-13  Tony Chang  <tony@chromium.org>
+
+        Refactor duplicate code into RenderFlexibleBox::mainAxisContentExtent
+        https://bugs.webkit.org/show_bug.cgi?id=96676
+
+        Reviewed by Eric Seidel.
+
+        There was computeAvailableFreeSpace() and lineBreakLength() shared some very similar code.
+        Merge this code into mainAxisContentExtent().
+
+        No new tests, this is just a refactor.
+
+        * rendering/RenderFlexibleBox.cpp:
+        (WebCore::RenderFlexibleBox::mainAxisContentExtent): Take contentLogicalHeight as a parameter,
+        which is needed when determining the logical height.
+        (WebCore::RenderFlexibleBox::computeAvailableFreeSpace): Use mainAxisContentExtent() and inline.
+        (WebCore::RenderFlexibleBox::computeNextFlexLine): Use mainAxisContentExtent().
+        * rendering/RenderFlexibleBox.h:
+
 2012-09-13  Glenn Hartmann  <hartmanng@chromium.org>
 
         Add new accelerated compositing for overflow scroll setting.
index 69895f2..85a5fe2 100644 (file)
@@ -393,11 +393,11 @@ LayoutUnit RenderFlexibleBox::crossAxisContentExtent() const
     return isHorizontalFlow() ? contentHeight() : contentWidth();
 }
 
-LayoutUnit RenderFlexibleBox::mainAxisContentExtent()
+LayoutUnit RenderFlexibleBox::mainAxisContentExtent(LayoutUnit contentLogicalHeight)
 {
     if (isColumnFlow()) {
         LogicalExtentComputedValues computedValues;
-        computeLogicalHeight(logicalHeight(), logicalTop(), computedValues);
+        computeLogicalHeight(contentLogicalHeight, logicalTop(), computedValues);
         return std::max(LayoutUnit(0), computedValues.m_extent - borderAndPaddingLogicalHeight() - scrollbarLogicalHeight());
     }
     return contentLogicalWidth();
@@ -611,21 +611,6 @@ LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox*
     return std::max(LayoutUnit(0), computeMainAxisExtentForChild(child, MainOrPreferredSize, flexBasis));
 }
 
-LayoutUnit RenderFlexibleBox::computeAvailableFreeSpace(LayoutUnit preferredMainAxisExtent)
-{
-    LayoutUnit contentExtent = 0;
-    if (!isColumnFlow())
-        contentExtent = mainAxisContentExtent();
-    else {
-        // FIXME: Refactor to avoid similar code in mainAxisContentExtent().
-        LogicalExtentComputedValues computedValues;
-        computeLogicalHeight(preferredMainAxisExtent, logicalTop(), computedValues);
-        contentExtent = computedValues.m_extent - borderAndPaddingLogicalHeight() - scrollbarLogicalHeight();
-    }
-
-    return contentExtent - preferredMainAxisExtent;
-}
-
 void RenderFlexibleBox::layoutFlexItems(OrderIterator& iterator, WTF::Vector<LineContext>& lineContexts)
 {
     OrderedFlexItemList orderedChildren;
@@ -636,7 +621,7 @@ void RenderFlexibleBox::layoutFlexItems(OrderIterator& iterator, WTF::Vector<Lin
 
     LayoutUnit crossAxisOffset = flowAwareBorderBefore() + flowAwarePaddingBefore();
     while (computeNextFlexLine(iterator, orderedChildren, preferredMainAxisExtent, totalFlexGrow, totalWeightedFlexShrink, minMaxAppliedMainAxisExtent)) {
-        LayoutUnit availableFreeSpace = computeAvailableFreeSpace(preferredMainAxisExtent);
+        LayoutUnit availableFreeSpace = mainAxisContentExtent(preferredMainAxisExtent) - preferredMainAxisExtent;
         FlexSign flexSign = (minMaxAppliedMainAxisExtent < preferredMainAxisExtent + availableFreeSpace) ? PositiveFlexibility : NegativeFlexibility;
         InflexibleFlexItemSize inflexibleItems;
         WTF::Vector<LayoutUnit> childSizes;
@@ -790,17 +775,6 @@ void RenderFlexibleBox::computeMainAxisPreferredSizes(bool relayoutChildren, Ord
     }
 }
 
-LayoutUnit RenderFlexibleBox::lineBreakLength()
-{
-    if (!isColumnFlow())
-        return mainAxisContentExtent();
-
-    // FIXME: Refactor to avoid similar code in mainAxisContentExtent().
-    LogicalExtentComputedValues computedValues;
-    computeLogicalHeight(MAX_LAYOUT_UNIT, logicalTop(), computedValues);
-    return computedValues.m_extent - borderAndPaddingLogicalHeight() - scrollbarLogicalHeight();
-}
-
 LayoutUnit RenderFlexibleBox::adjustChildSizeForMinAndMax(RenderBox* child, LayoutUnit childSize)
 {
     // FIXME: Support intrinsic min/max lengths.
@@ -832,7 +806,7 @@ bool RenderFlexibleBox::computeNextFlexLine(OrderIterator& iterator, OrderedFlex
     if (!iterator.currentChild())
         return false;
 
-    LayoutUnit lineBreak = lineBreakLength();
+    LayoutUnit lineBreakLength = mainAxisContentExtent(MAX_LAYOUT_UNIT);
 
     for (RenderBox* child = iterator.currentChild(); child; child = iterator.next()) {
         if (child->isOutOfFlowPositioned()) {
@@ -844,7 +818,7 @@ bool RenderFlexibleBox::computeNextFlexLine(OrderIterator& iterator, OrderedFlex
         LayoutUnit childMainAxisMarginBoxExtent = mainAxisBorderAndPaddingExtentForChild(child) + childMainAxisExtent;
         childMainAxisMarginBoxExtent += isHorizontalFlow() ? child->marginWidth() : child->marginHeight();
 
-        if (isMultiline() && preferredMainAxisExtent + childMainAxisMarginBoxExtent > lineBreak && orderedChildren.size() > 0)
+        if (isMultiline() && preferredMainAxisExtent + childMainAxisMarginBoxExtent > lineBreakLength && orderedChildren.size() > 0)
             break;
         orderedChildren.append(child);
         preferredMainAxisExtent += childMainAxisMarginBoxExtent;
index c95105f..7533c58 100644 (file)
@@ -85,7 +85,7 @@ private:
     LayoutUnit crossAxisExtent() const;
     LayoutUnit mainAxisExtent() const;
     LayoutUnit crossAxisContentExtent() const;
-    LayoutUnit mainAxisContentExtent();
+    LayoutUnit mainAxisContentExtent(LayoutUnit contentLogicalHeight);
     LayoutUnit computeMainAxisExtentForChild(RenderBox* child, SizeType, const Length& size);
     WritingMode transformedWritingMode() const;
     LayoutUnit flowAwareBorderStart() const;
@@ -122,10 +122,8 @@ private:
 
     LayoutUnit computeChildMarginValue(Length margin, RenderView*);
     void computeMainAxisPreferredSizes(bool relayoutChildren, OrderHashSet&);
-    LayoutUnit lineBreakLength();
     LayoutUnit adjustChildSizeForMinAndMax(RenderBox*, LayoutUnit childSize);
     bool computeNextFlexLine(OrderIterator&, OrderedFlexItemList& orderedChildren, LayoutUnit& preferredMainAxisExtent, float& totalFlexGrow, float& totalWeightedFlexShrink, LayoutUnit& minMaxAppliedMainAxisExtent);
-    LayoutUnit computeAvailableFreeSpace(LayoutUnit preferredMainAxisExtent);
 
     bool resolveFlexibleLengths(FlexSign, const OrderedFlexItemList&, LayoutUnit& availableFreeSpace, float& totalFlexGrow, float& totalWeightedFlexShrink, InflexibleFlexItemSize&, WTF::Vector<LayoutUnit>& childSizes);
     void freezeViolations(const WTF::Vector<Violation>&, LayoutUnit& availableFreeSpace, float& totalFlexGrow, float& totalWeightedFlexShrink, InflexibleFlexItemSize&);