Commit a625ad3a authored by ojan@chromium.org's avatar ojan@chromium.org

Implement flex-pack:distribute

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: http://svn.webkit.org/repository/webkit/trunk@105694 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 02ec7bc8
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, ...).
......@@ -5,3 +5,6 @@ PASS
PASS
PASS
PASS
PASS
PASS
PASS
......@@ -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>
......
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.
......@@ -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;
......
......@@ -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;
......
......@@ -492,6 +492,13 @@ multiple
// baseline
// stretch
// CSS_PROP_FLEX_PACK
// start
// end
// center
// justify
distribute
// CSS_PROP_FLEX_FLOW
row
row-reverse
......
......@@ -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;
......
......@@ -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 };
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment