fix negative flexing in auto sized columns
authortony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Mar 2012 22:56:15 +0000 (22:56 +0000)
committertony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Mar 2012 22:56:15 +0000 (22:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=80069

Reviewed by Ojan Vafai.

Source/WebCore:

New test cases in css3/flexbox/columns-auto-size.html.

* rendering/RenderFlexibleBox.cpp:
(WebCore):
(WebCore::RenderFlexibleBox::computeAvailableFreeSpace): Properly compute this for auto sizing columns. Previously, we would always return 0.
(WebCore::RenderFlexibleBox::layoutFlexItems):
(WebCore::RenderFlexibleBox::runFreeSpaceAllocationAlgorithm): Drop an unnecessary check against undefined. isSpecified covers this for us.
* rendering/RenderFlexibleBox.h:
(RenderFlexibleBox):

LayoutTests:

* css3/flexbox/columns-auto-size-expected.txt:
* css3/flexbox/columns-auto-size.html:

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

LayoutTests/ChangeLog
LayoutTests/css3/flexbox/columns-auto-size-expected.txt
LayoutTests/css3/flexbox/columns-auto-size.html
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderFlexibleBox.cpp
Source/WebCore/rendering/RenderFlexibleBox.h

index 85e2fe7..0817f05 100644 (file)
@@ -1,3 +1,13 @@
+2012-03-14  Tony Chang  <tony@chromium.org>
+
+        fix negative flexing in auto sized columns
+        https://bugs.webkit.org/show_bug.cgi?id=80069
+
+        Reviewed by Ojan Vafai.
+
+        * css3/flexbox/columns-auto-size-expected.txt:
+        * css3/flexbox/columns-auto-size.html:
+
 2012-03-14  Adam Barth  <abarth@webkit.org>
 
         Update baselines for these URL tests.  These tests exist to document
index 4284a9c..b33fd72 100644 (file)
@@ -76,6 +76,26 @@ if (window.layoutTestController)
   <div data-expected-height="20" data-offset-y="50" style="padding-top: 10px"><div data-expected-height="10" data-offset-y="60" style="height: 10px"></div></div>
 </div>
 
+<div class="flexbox horizontal" data-expected-height="20">
+  <div data-expected-height="10" data-offset-y="0" style="height: -webkit-flex(0 1 auto)"><div style="height: 10px"></div></div>
+  <div data-expected-height="10" data-offset-y="10" style="height: -webkit-flex(0 2 auto)"><div style="height: 10px"></div></div>
+</div>
+
+<div class="flexbox horizontal" style="min-height: 10px" data-expected-height="20">
+  <div data-expected-height="10" data-offset-y="0" style="height: -webkit-flex(0 1 auto)"><div style="height: 10px"></div></div>
+  <div data-expected-height="10" data-offset-y="10" style="height: -webkit-flex(0 2 auto)"><div style="height: 10px"></div></div>
+</div>
+
+<div class="flexbox horizontal" style="min-height: 5px; max-height: 17px;" data-expected-height="17">
+  <div data-expected-height="9" data-offset-y="0" style="height: -webkit-flex(0 1 auto)"><div style="height: 10px"></div></div>
+  <div data-expected-height="8" data-offset-y="9" style="height: -webkit-flex(0 2 auto)"><div style="height: 10px"></div></div>
+</div>
+
+<div class="flexbox horizontal" style="min-height: 5px; max-height: 30px; padding-top: 1px; padding-bottom: 2px;" data-expected-height="33">
+  <div data-expected-height="15" data-offset-y="1" style="height: -webkit-flex(0 1 auto)"><div style="height: 20px"></div></div>
+  <div data-expected-height="15" data-offset-y="16" style="height: -webkit-flex(0 1 auto)"><div style="height: 20px"></div></div>
+</div>
+
 <div class="flexbox vertical">
   <div data-expected-width="10" data-offset-x="20" style="width: -webkit-flex(1 0 10px)"></div>
   <div data-expected-width="10" data-offset-x="10" style="width: 10px;"></div>
index ff910c4..387f6bc 100644 (file)
@@ -1,3 +1,20 @@
+2012-03-14  Tony Chang  <tony@chromium.org>
+
+        fix negative flexing in auto sized columns
+        https://bugs.webkit.org/show_bug.cgi?id=80069
+
+        Reviewed by Ojan Vafai.
+
+        New test cases in css3/flexbox/columns-auto-size.html.
+
+        * rendering/RenderFlexibleBox.cpp:
+        (WebCore):
+        (WebCore::RenderFlexibleBox::computeAvailableFreeSpace): Properly compute this for auto sizing columns. Previously, we would always return 0.
+        (WebCore::RenderFlexibleBox::layoutFlexItems):
+        (WebCore::RenderFlexibleBox::runFreeSpaceAllocationAlgorithm): Drop an unnecessary check against undefined. isSpecified covers this for us.
+        * rendering/RenderFlexibleBox.h:
+        (RenderFlexibleBox):
+
 2012-03-14  Grace Ku  <gracek@codeaurora.org>
 
         Incorrect handling of sizes in "em" when first-line changes font size
index 14b6d05..5ea5b04 100644 (file)
@@ -576,6 +576,27 @@ LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox*
     return mainAxisLength.calcMinValue(mainAxisContentExtent());
 }
 
+LayoutUnit RenderFlexibleBox::computeAvailableFreeSpace(LayoutUnit preferredMainAxisExtent)
+{
+    if (!isColumnFlow())
+        return mainAxisContentExtent() - preferredMainAxisExtent;
+
+    if (hasOverrideHeight())
+        return overrideHeight();
+
+    LayoutUnit heightResult = computeContentLogicalHeightUsing(style()->logicalHeight());
+    if (heightResult == -1)
+        heightResult = preferredMainAxisExtent;
+    LayoutUnit minHeight = computeContentLogicalHeightUsing(style()->logicalMinHeight()); // Leave as -1 if unset.
+    LayoutUnit maxHeight = style()->logicalMaxHeight().isUndefined() ? heightResult : computeContentLogicalHeightUsing(style()->logicalMaxHeight());
+    if (maxHeight == -1)
+        maxHeight = heightResult;
+    heightResult = std::min(maxHeight, heightResult);
+    heightResult = std::max(minHeight, heightResult);
+
+    return heightResult - preferredMainAxisExtent;
+}
+
 void RenderFlexibleBox::layoutFlexItems(bool relayoutChildren)
 {
     FlexOrderHashSet flexOrderValues;
@@ -592,9 +613,8 @@ void RenderFlexibleBox::layoutFlexItems(bool relayoutChildren)
     WrapReverseContext wrapReverseContext(style()->flexWrap());
 
     LayoutUnit crossAxisOffset = flowAwareBorderBefore() + flowAwarePaddingBefore();
-    LayoutUnit mainAxisFlexibleSpace = mainAxisContentExtent();
     while (computeNextFlexLine(flexIterator, orderedChildren, preferredMainAxisExtent, totalPositiveFlexibility, totalNegativeFlexibility)) {
-        LayoutUnit availableFreeSpace = mainAxisFlexibleSpace - preferredMainAxisExtent;
+        LayoutUnit availableFreeSpace = computeAvailableFreeSpace(preferredMainAxisExtent);
         InflexibleFlexItemSize inflexibleItems;
         WTF::Vector<LayoutUnit> childSizes;
         while (!runFreeSpaceAllocationAlgorithm(orderedChildren, availableFreeSpace, totalPositiveFlexibility, totalNegativeFlexibility, inflexibleItems, childSizes)) {
@@ -738,7 +758,7 @@ bool RenderFlexibleBox::runFreeSpaceAllocationAlgorithm(const OrderedFlexItemLis
                 childPreferredSize += lroundf(availableFreeSpace * positiveFlexForChild(child) / totalPositiveFlexibility);
 
                 Length childLogicalMaxWidth = isHorizontalFlow() ? child->style()->maxWidth() : child->style()->maxHeight();
-                if (!childLogicalMaxWidth.isUndefined() && childLogicalMaxWidth.isSpecified() && childPreferredSize > childLogicalMaxWidth.calcValue(flexboxAvailableContentExtent)) {
+                if (childLogicalMaxWidth.isSpecified() && childPreferredSize > childLogicalMaxWidth.calcValue(flexboxAvailableContentExtent)) {
                     childPreferredSize = childLogicalMaxWidth.calcValue(flexboxAvailableContentExtent);
                     availableFreeSpace -= childPreferredSize - preferredMainAxisContentExtentForChild(child);
                     totalPositiveFlexibility -= positiveFlexForChild(child);
@@ -750,7 +770,7 @@ bool RenderFlexibleBox::runFreeSpaceAllocationAlgorithm(const OrderedFlexItemLis
                 childPreferredSize += lroundf(availableFreeSpace * negativeFlexForChild(child) / totalNegativeFlexibility);
 
                 Length childLogicalMinWidth = isHorizontalFlow() ? child->style()->minWidth() : child->style()->minHeight();
-                if (!childLogicalMinWidth.isUndefined() && childLogicalMinWidth.isSpecified() && childPreferredSize < childLogicalMinWidth.calcValue(flexboxAvailableContentExtent)) {
+                if (childLogicalMinWidth.isSpecified() && childPreferredSize < childLogicalMinWidth.calcValue(flexboxAvailableContentExtent)) {
                     childPreferredSize = childLogicalMinWidth.calcValue(flexboxAvailableContentExtent);
                     availableFreeSpace += preferredMainAxisContentExtentForChild(child) - childPreferredSize;
                     totalNegativeFlexibility -= negativeFlexForChild(child);
index 1887611..979c9aa 100644 (file)
@@ -105,6 +105,7 @@ private:
     void computeMainAxisPreferredSizes(bool relayoutChildren, FlexOrderHashSet&);
     LayoutUnit lineBreakLength();
     bool computeNextFlexLine(FlexOrderIterator&, OrderedFlexItemList& orderedChildren, LayoutUnit& preferredMainAxisExtent, float& totalPositiveFlexibility, float& totalNegativeFlexibility);
+    LayoutUnit computeAvailableFreeSpace(LayoutUnit preferredMainAxisExtent);
     bool runFreeSpaceAllocationAlgorithm(const OrderedFlexItemList&, LayoutUnit& availableFreeSpace, float& totalPositiveFlexibility, float& totalNegativeFlexibility, InflexibleFlexItemSize&, WTF::Vector<LayoutUnit>& childSizes);
     void setLogicalOverrideSize(RenderBox* child, LayoutUnit childPreferredSize);
     void prepareChildForPositionedLayout(RenderBox* child, LayoutUnit mainAxisOffset, LayoutUnit crossAxisOffset);