small refactor of RenderFlexibleBox
authortony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2011 04:59:11 +0000 (04:59 +0000)
committertony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2011 04:59:11 +0000 (04:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=73854

Reviewed by Darin Adler.

No new tests, just a refactor.

* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::isLeftToRightFlow): Inline isReverseFlow since it's only used in one place.
(WebCore::RenderFlexibleBox::layoutAndPlaceChildren): Rename startEdge
to mainAxisOffset.  Rename logicalTop to crossAxisOffset.  Get rid of
logicalLeft local variable since it's confusing.  Move shouldFlipMainAxis
out of the for loop to avoid computing it each iteration.
* rendering/RenderFlexibleBox.h:

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

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

index 0f83a9b..ccc1a2d 100644 (file)
@@ -1,3 +1,20 @@
+2011-12-05  Tony Chang  <tony@chromium.org>
+
+        small refactor of RenderFlexibleBox
+        https://bugs.webkit.org/show_bug.cgi?id=73854
+
+        Reviewed by Darin Adler.
+
+        No new tests, just a refactor.
+
+        * rendering/RenderFlexibleBox.cpp:
+        (WebCore::RenderFlexibleBox::isLeftToRightFlow): Inline isReverseFlow since it's only used in one place.
+        (WebCore::RenderFlexibleBox::layoutAndPlaceChildren): Rename startEdge
+        to mainAxisOffset.  Rename logicalTop to crossAxisOffset.  Get rid of
+        logicalLeft local variable since it's confusing.  Move shouldFlipMainAxis
+        out of the for loop to avoid computing it each iteration.
+        * rendering/RenderFlexibleBox.h:
+
 2011-12-05  Florin Malita  <fmalita@google.com>
 
         Heap-buffer-overflow in WebCore::HTMLTreeBuilder::processEndTag
index b9a8ab2..88c77d8 100644 (file)
@@ -206,11 +206,6 @@ bool RenderFlexibleBox::isColumnFlow() const
     return style()->isColumnFlexFlow();
 }
 
-bool RenderFlexibleBox::isReverseFlow() const
-{
-    return style()->flexFlow() == FlowColumnReverse || style()->flexFlow() == FlowRowReverse;
-}
-
 bool RenderFlexibleBox::isHorizontalFlow() const
 {
     if (isHorizontalWritingMode())
@@ -222,7 +217,7 @@ bool RenderFlexibleBox::isLeftToRightFlow() const
 {
     if (isColumnFlow())
         return style()->writingMode() == TopToBottomWritingMode || style()->writingMode() == LeftToRightWritingMode;
-    return style()->isLeftToRightDirection() ^ isReverseFlow();
+    return style()->isLeftToRightDirection() ^ (style()->flexFlow() == FlowRowReverse);
 }
 
 Length RenderFlexibleBox::mainAxisLengthForChild(RenderBox* child) const
@@ -598,12 +593,13 @@ void RenderFlexibleBox::setLogicalOverrideSize(RenderBox* child, LayoutUnit chil
 
 void RenderFlexibleBox::layoutAndPlaceChildren(FlexOrderIterator& iterator, const WTF::Vector<LayoutUnit>& childSizes, LayoutUnit availableFreeSpace, float totalPositiveFlexibility)
 {
-    LayoutUnit startEdge = flowAwareBorderStart() + flowAwarePaddingStart();
-    startEdge += initialPackingOffset(availableFreeSpace, totalPositiveFlexibility, style()->flexPack());
+    LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart();
+    mainAxisOffset += initialPackingOffset(availableFreeSpace, totalPositiveFlexibility, style()->flexPack());
 
-    LayoutUnit logicalTop = flowAwareBorderBefore() + flowAwarePaddingBefore();
+    LayoutUnit crossAxisOffset = flowAwareBorderBefore() + flowAwarePaddingBefore();
     LayoutUnit totalMainExtent = mainAxisExtent();
     LayoutUnit maxAscent = 0, maxDescent = 0; // Used when flex-align: baseline.
+    bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow();
     size_t i = 0;
     for (RenderBox* child = iterator.first(); child; child = iterator.next(), ++i) {
         LayoutUnit childPreferredSize = childSizes[i] + mainAxisBorderAndPaddingExtentForChild(child);
@@ -624,20 +620,20 @@ void RenderFlexibleBox::layoutAndPlaceChildren(FlexOrderIterator& iterator, cons
         } else if (crossAxisLength().isAuto())
             setCrossAxisExtent(std::max(crossAxisExtent(), crossAxisBorderAndPaddingExtent() + crossAxisMarginExtentForChild(child) + crossAxisExtentForChild(child) + scrollbarLogicalHeight()));
 
-        startEdge += flowAwareMarginStartForChild(child);
+        mainAxisOffset += flowAwareMarginStartForChild(child);
 
         LayoutUnit childMainExtent = mainAxisExtentForChild(child);
-        bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow();
-        LayoutUnit logicalLeft = shouldFlipMainAxis ? totalMainExtent - startEdge - childMainExtent : startEdge;
+        IntPoint childLocation(shouldFlipMainAxis ? totalMainExtent - mainAxisOffset - childMainExtent : mainAxisOffset,
+            crossAxisOffset + flowAwareMarginBeforeForChild(child));
 
         // FIXME: Supporting layout deltas.
-        setFlowAwareLocationForChild(child, IntPoint(logicalLeft, logicalTop + flowAwareMarginBeforeForChild(child)));
-        startEdge += childMainExtent + flowAwareMarginEndForChild(child);
+        setFlowAwareLocationForChild(child, childLocation);
+        mainAxisOffset += childMainExtent + flowAwareMarginEndForChild(child);
 
-        startEdge += packingSpaceBetweenChildren(availableFreeSpace, totalPositiveFlexibility, style()->flexPack(), childSizes.size());
+        mainAxisOffset += packingSpaceBetweenChildren(availableFreeSpace, totalPositiveFlexibility, style()->flexPack(), childSizes.size());
 
         if (isColumnFlow())
-            setLogicalHeight(startEdge);
+            setLogicalHeight(mainAxisOffset);
     }
 
     if (style()->flexFlow() == FlowColumnReverse) {
index aac8470..fe0dfa2 100644 (file)
@@ -53,7 +53,6 @@ private:
 
     bool hasOrthogonalFlow(RenderBox* child) const;
     bool isColumnFlow() const;
-    bool isReverseFlow() const;
     bool isHorizontalFlow() const;
     bool isLeftToRightFlow() const;
     Length crossAxisLength() const;