Implement flex-pack:distribute
authorojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2012 06:26:54 +0000 (06:26 +0000)
committerojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2012 06:26:54 +0000 (06:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76864

Reviewed by Tony Chang.

Source/WebCore:

See http://dev.w3.org/csswg/css3-flexbox/#flex-pack.

* css/CSSParser.cpp:
(WebCore::CSSParser::parseValue):
* css/CSSPrimitiveValueMappings.h:
(WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::operator EFlexPack):
* css/CSSValueKeywords.in:
* rendering/RenderFlexibleBox.cpp:
(WebCore::initialPackingOffset):
(WebCore::packingSpaceBetweenChildren):
(WebCore::RenderFlexibleBox::layoutAndPlaceChildren):
(WebCore::RenderFlexibleBox::layoutColumnReverse):
* rendering/style/RenderStyleConstants.h:
* rendering/style/StyleFlexibleBoxData.h:

LayoutTests:

* css3/flexbox/004-expected.txt:
* css3/flexbox/004.html:

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

LayoutTests/ChangeLog
LayoutTests/css3/flexbox/004-expected.txt
LayoutTests/css3/flexbox/004.html
Source/WebCore/ChangeLog
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSPrimitiveValueMappings.h
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/rendering/RenderFlexibleBox.cpp
Source/WebCore/rendering/style/RenderStyleConstants.h
Source/WebCore/rendering/style/StyleFlexibleBoxData.h

index eb13a22..c0047d5 100644 (file)
@@ -1,3 +1,13 @@
+2012-01-23  Ojan Vafai  <ojan@chromium.org>
+
+        Implement flex-pack:distribute
+        https://bugs.webkit.org/show_bug.cgi?id=76864
+
+        Reviewed by Tony Chang.
+
+        * css3/flexbox/004-expected.txt:
+        * css3/flexbox/004.html:
+
 2012-01-23  Tom Sepez  <tsepez@chromium.org>
 
         decodeEscapeSequences() not correct for some encodings (GBK, Big5, ...).
index 568806e..0fe0747 100644 (file)
@@ -60,6 +60,20 @@ if (window.layoutTestController)
   <div data-expected-width="100" data-offset-x="0" style="width: -webkit-flex(1 0 0); max-width: 100px;"></div>
 </div>
 
+<div class="flexbox" style="-webkit-flex-pack: distribute">
+  <div data-expected-width="100" data-offset-x="50" style="width: -webkit-flex(1 0 0); max-width: 100px;"></div>
+  <div data-expected-width="100" data-offset-x="250" style="width: 100px;"></div>
+  <div data-expected-width="100" data-offset-x="450" style="width: 100px;"></div>
+</div>
+
+<!-- If there's only one child, we pack center. -->
+<div class="flexbox" style="-webkit-flex-pack: distribute">
+  <div data-expected-width="100" data-offset-x="250" style="width: -webkit-flex(1 0 0); max-width: 100px;"></div>
+</div>
+
+<!-- Make sure we don't crash with no children. -->
+<div class="flexbox" style="-webkit-flex-pack: distribute"></div>
+
 <!-- margin:auto does nothing here. -->
 <div class="flexbox" style="-webkit-flex-pack: end">
   <div data-expected-width="100" data-offset-x="300" style="width: 100px;"></div>
index 7b33857..d98f253 100644 (file)
@@ -1,3 +1,26 @@
+2012-01-23  Ojan Vafai  <ojan@chromium.org>
+
+        Implement flex-pack:distribute
+        https://bugs.webkit.org/show_bug.cgi?id=76864
+
+        Reviewed by Tony Chang.
+
+        See http://dev.w3.org/csswg/css3-flexbox/#flex-pack.
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseValue):
+        * css/CSSPrimitiveValueMappings.h:
+        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
+        (WebCore::CSSPrimitiveValue::operator EFlexPack):
+        * css/CSSValueKeywords.in:
+        * rendering/RenderFlexibleBox.cpp:
+        (WebCore::initialPackingOffset):
+        (WebCore::packingSpaceBetweenChildren):
+        (WebCore::RenderFlexibleBox::layoutAndPlaceChildren):
+        (WebCore::RenderFlexibleBox::layoutColumnReverse):
+        * rendering/style/RenderStyleConstants.h:
+        * rendering/style/StyleFlexibleBoxData.h:
+
 2012-01-23  Luke Macpherson   <macpherson@chromium.org>
 
         Implement CSS clip property in CSSStyleApplyProperty.
index 47ba1ee..3be734d 100644 (file)
@@ -1636,7 +1636,7 @@ bool CSSParser::parseValue(int propId, bool important)
         }
         break;
     case CSSPropertyWebkitFlexPack:
-        validPrimitive = id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter || id == CSSValueJustify;
+        validPrimitive = id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter || id == CSSValueJustify || id == CSSValueDistribute;
         break;
     case CSSPropertyWebkitFlexAlign:
         validPrimitive = id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter || id == CSSValueBaseline || id == CSSValueStretch;
index 17f5ccc..6096d93 100644 (file)
@@ -1218,6 +1218,9 @@ template<> inline CSSPrimitiveValue::CSSPrimitiveValue(EFlexPack e)
     case PackJustify:
         m_value.ident = CSSValueJustify;
         break;
+    case PackDistribute:
+        m_value.ident = CSSValueDistribute;
+        break;
     }
 }
 
@@ -1232,6 +1235,8 @@ template<> inline CSSPrimitiveValue::operator EFlexPack() const
         return PackCenter;
     case CSSValueJustify:
         return PackJustify;
+    case CSSValueDistribute:
+        return PackDistribute;
     default:
         ASSERT_NOT_REACHED();
         return PackStart;
index 931e57e..fd10528 100644 (file)
@@ -492,6 +492,13 @@ multiple
 // baseline
 // stretch
 
+// CSS_PROP_FLEX_PACK
+// start
+// end
+// center
+// justify
+distribute
+
 // CSS_PROP_FLEX_FLOW
 row
 row-reverse
index 53997a1..21bd9bd 100644 (file)
@@ -573,21 +573,27 @@ static bool hasPackingSpace(LayoutUnit availableFreeSpace, float totalPositiveFl
     return availableFreeSpace > 0 && !totalPositiveFlexibility;
 }
 
-static LayoutUnit initialPackingOffset(LayoutUnit availableFreeSpace, float totalPositiveFlexibility, EFlexPack flexPack)
+static LayoutUnit initialPackingOffset(LayoutUnit availableFreeSpace, float totalPositiveFlexibility, EFlexPack flexPack, size_t numberOfChildren)
 {
     if (hasPackingSpace(availableFreeSpace, totalPositiveFlexibility)) {
         if (flexPack == PackEnd)
             return availableFreeSpace;
         if (flexPack == PackCenter)
             return availableFreeSpace / 2;
+        if (flexPack == PackDistribute && numberOfChildren)
+            return availableFreeSpace / (2 * numberOfChildren);
     }
     return 0;
 }
 
 static LayoutUnit packingSpaceBetweenChildren(LayoutUnit availableFreeSpace, float totalPositiveFlexibility, EFlexPack flexPack, size_t numberOfChildren)
 {
-    if (hasPackingSpace(availableFreeSpace, totalPositiveFlexibility) && flexPack == PackJustify && numberOfChildren > 1)
-        return availableFreeSpace / (numberOfChildren - 1);
+    if (hasPackingSpace(availableFreeSpace, totalPositiveFlexibility) && numberOfChildren > 1) {
+        if (flexPack == PackJustify)
+            return availableFreeSpace / (numberOfChildren - 1);
+        if (flexPack == PackDistribute)
+            return availableFreeSpace / numberOfChildren;
+    }
     return 0;
 }
 
@@ -629,7 +635,7 @@ static EFlexAlign flexAlignForChild(RenderBox* child)
 void RenderFlexibleBox::layoutAndPlaceChildren(FlexOrderIterator& iterator, const WTF::Vector<LayoutUnit>& childSizes, LayoutUnit availableFreeSpace, float totalPositiveFlexibility)
 {
     LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart();
-    mainAxisOffset += initialPackingOffset(availableFreeSpace, totalPositiveFlexibility, style()->flexPack());
+    mainAxisOffset += initialPackingOffset(availableFreeSpace, totalPositiveFlexibility, style()->flexPack(), childSizes.size());
 
     LayoutUnit crossAxisOffset = flowAwareBorderBefore() + flowAwarePaddingBefore();
     LayoutUnit totalMainExtent = mainAxisExtent();
@@ -692,7 +698,7 @@ void RenderFlexibleBox::layoutColumnReverse(FlexOrderIterator& iterator, const W
     // starting from the end of the flexbox. We also don't need to layout anything since we're
     // just moving the children to a new position.
     LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwarePaddingEnd();
-    mainAxisOffset -= initialPackingOffset(availableFreeSpace, totalPositiveFlexibility, style()->flexPack());
+    mainAxisOffset -= initialPackingOffset(availableFreeSpace, totalPositiveFlexibility, style()->flexPack(), childSizes.size());
 
     LayoutUnit crossAxisOffset = flowAwareBorderBefore() + flowAwarePaddingBefore();
     size_t i = 0;
index 8109e3e..334ce23 100644 (file)
@@ -176,7 +176,7 @@ enum EBoxDirection { BNORMAL, BREVERSE };
 
 // CSS3 Flexbox Properties
 
-enum EFlexPack { PackStart, PackEnd, PackCenter, PackJustify };
+enum EFlexPack { PackStart, PackEnd, PackCenter, PackJustify, PackDistribute };
 enum EFlexAlign { AlignAuto, AlignStart, AlignEnd, AlignCenter, AlignStretch, AlignBaseline };
 enum EFlexDirection { FlowRow, FlowRowReverse, FlowColumn, FlowColumnReverse };
 enum EFlexWrap { FlexNoWrap, FlexWrap, FlexWrapReverse };
index 840549b..c3bf5c3 100644 (file)
@@ -49,7 +49,7 @@ public:
 
     int m_flexOrder;
 
-    unsigned m_flexPack : 2; // EFlexPack
+    unsigned m_flexPack : 3; // EFlexPack
     unsigned m_flexAlign : 3; // EFlexAlign
     unsigned m_flexItemAlign : 3; // EFlexAlign
     unsigned m_flexDirection : 2; // EFlexDirection