Bug 696253, patch 7: implement parsing/computation for CSS property 'flex-basis'. r=dbaron

This commit is contained in:
Daniel Holbert 2012-07-06 17:06:23 -07:00
parent 240b1f795a
commit b8243ce2a2
9 changed files with 120 additions and 0 deletions

View File

@ -768,6 +768,9 @@ interface nsIDOMCSS2Properties : nsISupports
attribute DOMString MozAlignSelf;
// raises(DOMException) on setting
attribute DOMString MozFlexBasis;
// raises(DOMException) on setting
attribute DOMString MozFlexDirection;
// raises(DOMException) on setting

View File

@ -1532,6 +1532,18 @@ CSS_PROP_POSITION(
kAlignSelfKTable,
offsetof(nsStylePosition, mAlignSelf),
eStyleAnimType_EnumU8)
CSS_PROP_POSITION(
-moz-flex-basis,
flex_basis,
CSS_PROP_DOMPROP_PREFIXED(FlexBasis),
CSS_PROPERTY_PARSE_VALUE |
CSS_PROPERTY_VALUE_NONNEGATIVE |
CSS_PROPERTY_STORES_CALC,
"",
VARIANT_AHKLP | VARIANT_CALC,
kWidthKTable,
offsetof(nsStylePosition, mFlexBasis),
eStyleAnimType_Coord)
CSS_PROP_POSITION(
-moz-flex-direction,
flex_direction,

View File

@ -2961,6 +2961,27 @@ nsComputedDOMStyle::DoGetAlignSelf()
return val;
}
nsIDOMCSSValue*
nsComputedDOMStyle::DoGetFlexBasis()
{
nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
// XXXdholbert We could make this more automagic and resolve percentages
// if we wanted, by passing in a PercentageBaseGetter instead of nsnull
// below. Logic would go like this:
// if (i'm a flex item) {
// if (my flex container is horizontal) {
// percentageBaseGetter = &nsComputedDOMStyle::GetCBContentWidth;
// } else {
// percentageBaseGetter = &nsComputedDOMStyle::GetCBContentHeight;
// }
// }
SetValueToCoord(val, GetStylePosition()->mFlexBasis, true,
nsnull, nsCSSProps::kWidthKTable);
return val;
}
nsIDOMCSSValue*
nsComputedDOMStyle::DoGetFlexDirection()
{
@ -4725,6 +4746,7 @@ nsComputedDOMStyle::GetQueryablePropertyMap(PRUint32* aLength)
COMPUTED_STYLE_MAP_ENTRY(_moz_column_rule_width, ColumnRuleWidth),
COMPUTED_STYLE_MAP_ENTRY(_moz_column_width, ColumnWidth),
#ifdef MOZ_FLEXBOX
COMPUTED_STYLE_MAP_ENTRY(flex_basis, FlexBasis),
COMPUTED_STYLE_MAP_ENTRY(flex_direction, FlexDirection),
COMPUTED_STYLE_MAP_ENTRY(flex_grow, FlexGrow),
COMPUTED_STYLE_MAP_ENTRY(flex_shrink, FlexShrink),

View File

@ -361,6 +361,7 @@ private:
/* CSS Flexbox properties */
nsIDOMCSSValue* DoGetAlignItems();
nsIDOMCSSValue* DoGetAlignSelf();
nsIDOMCSSValue* DoGetFlexBasis();
nsIDOMCSSValue* DoGetFlexDirection();
nsIDOMCSSValue* DoGetFlexGrow();
nsIDOMCSSValue* DoGetFlexShrink();

View File

@ -6485,6 +6485,12 @@ nsRuleNode::ComputePositionData(void* aStartStruct,
0, 0, 0, 0);
}
// flex-basis: auto, length, percent, enum, calc, inherit, initial
// (Note: The flags here should match those used for 'width' property above.)
SetCoord(*aRuleData->ValueForFlexBasis(), pos->mFlexBasis, parentPos->mFlexBasis,
SETCOORD_LPAEH | SETCOORD_INITIAL_AUTO | SETCOORD_STORE_CALC,
aContext, mPresContext, canStoreInRuleTree);
// flex-direction: enum, inherit, initial
SetDiscrete(*aRuleData->ValueForFlexDirection(),
pos->mFlexDirection, canStoreInRuleTree,

View File

@ -1124,6 +1124,9 @@ nsStylePosition::nsStylePosition(void)
mHeight.SetAutoValue();
mMinHeight.SetCoordValue(0);
mMaxHeight.SetNoneValue();
#ifdef MOZ_FLEXBOX
mFlexBasis.SetAutoValue();
#endif // MOZ_FLEXBOX
mBoxSizing = NS_STYLE_BOX_SIZING_CONTENT;
#ifdef MOZ_FLEXBOX
mAlignItems = NS_STYLE_ALIGN_ITEMS_INITIAL_VALUE;
@ -1164,6 +1167,7 @@ nsChangeHint nsStylePosition::CalcDifference(const nsStylePosition& aOther) cons
// If we're in a multi-line flex container, it also may affect our size
// (and that of our container & siblings) by shuffling items between lines.
if (mAlignSelf != aOther.mAlignSelf ||
mFlexBasis != aOther.mFlexBasis ||
mFlexGrow != aOther.mFlexGrow ||
mFlexShrink != aOther.mFlexShrink ||
mOrder != aOther.mOrder) {

View File

@ -1092,6 +1092,9 @@ struct nsStylePosition {
nsStyleCoord mHeight; // [reset] coord, percent, calc, auto
nsStyleCoord mMinHeight; // [reset] coord, percent, calc
nsStyleCoord mMaxHeight; // [reset] coord, percent, calc, none
#ifdef MOZ_FLEXBOX
nsStyleCoord mFlexBasis; // [reset] coord, percent, enum, calc, auto
#endif // MOZ_FLEXBOX
PRUint8 mBoxSizing; // [reset] see nsStyleConsts.h
#ifdef MOZ_FLEXBOX
PRUint8 mAlignItems; // [reset] see nsStyleConsts.h

View File

@ -755,6 +755,73 @@ var gCSSProperties = {
other_values: [ "flex-start", "flex-end", "center", "baseline" ],
invalid_values: [ "space-between", "abc", "30px" ]
},
"-moz-flex-basis": {
domProp: "MozFlexBasis",
inherited: false,
type: CSS_TYPE_LONGHAND,
initial_values: [ " auto" ],
// NOTE: This is cribbed directly from the "width" chunk, since this
// property takes the exact same values as width (albeit with
// different semantics on 'auto').
// XXXdholbert (Maybe these should get separated out into
// a reusable array defined at the top of this file?)
other_values: [ "15px", "3em", "15%", "-moz-max-content", "-moz-min-content", "-moz-fit-content", "-moz-available",
// valid calc() values
"-moz-calc(-2px)",
"-moz-calc(2px)",
"-moz-calc(50%)",
"-moz-calc(50% + 2px)",
"-moz-calc( 50% + 2px)",
"-moz-calc(50% + 2px )",
"-moz-calc( 50% + 2px )",
"-moz-calc(50% - -2px)",
"-moz-calc(2px - -50%)",
"-moz-calc(3*25px)",
"-moz-calc(3 *25px)",
"-moz-calc(3 * 25px)",
"-moz-calc(3* 25px)",
"-moz-calc(25px*3)",
"-moz-calc(25px *3)",
"-moz-calc(25px* 3)",
"-moz-calc(25px * 3)",
"-moz-calc(3*25px + 50%)",
"-moz-calc(50% - 3em + 2px)",
"-moz-calc(50% - (3em + 2px))",
"-moz-calc((50% - 3em) + 2px)",
"-moz-calc(2em)",
"-moz-calc(50%)",
"-moz-calc(50px/2)",
"-moz-calc(50px/(2 - 1))"
],
invalid_values: [ "none", "-2px",
// invalid calc() values
"-moz-calc(50%+ 2px)",
"-moz-calc(50% +2px)",
"-moz-calc(50%+2px)",
"-moz-min()",
"-moz-calc(min())",
"-moz-max()",
"-moz-calc(max())",
"-moz-min(5px)",
"-moz-calc(min(5px))",
"-moz-max(5px)",
"-moz-calc(max(5px))",
"-moz-min(5px,2em)",
"-moz-calc(min(5px,2em))",
"-moz-max(5px,2em)",
"-moz-calc(max(5px,2em))",
"-moz-calc(50px/(2 - 2))",
// If we ever support division by values, which is
// complicated for the reasons described in
// http://lists.w3.org/Archives/Public/www-style/2010Jan/0007.html
// , we should support all 4 of these as described in
// http://lists.w3.org/Archives/Public/www-style/2009Dec/0296.html
"-moz-calc((3em / 100%) * 3em)",
"-moz-calc(3em / 100% * 3em)",
"-moz-calc(3em * (3em / 100%))",
"-moz-calc(3em * 3em / 100%)"
]
},
"-moz-flex-direction": {
domProp: "MozFlexDirection",
inherited: false,

View File

@ -118,6 +118,8 @@ var supported_properties = {
/* XXXdholbert In builds with MOZ_FLEXBOX enabled, this should be uncommented.
(This would be #ifdef MOZ_FLEXBOX, if that worked in JS files.)
"-moz-flex-basis": [ test_length_transition, test_percent_transition,
test_length_clamped, test_percent_clamped ],
"-moz-flex-grow": [ test_float_zeroToOne_transition,
test_float_aboveOne_transition ],
"-moz-flex-shrink": [ test_float_zeroToOne_transition,