Chromium Code Reviews| Index: third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
| diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
| index 05d164421a65ccafbb6d5036b67afaaba731bdd6..46e85dbd371ce55a4de43c186fa08e86dae4a1f4 100644 |
| --- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
| +++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
| @@ -1825,6 +1825,14 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumePaintOrder(CSSParserTokenRange& r |
| return paintOrderList.release(); |
| } |
| +static PassRefPtrWillBeRawPtr<CSSValue> consumeFlexBasis(CSSParserTokenRange& range, CSSParserMode cssParserMode) |
| +{ |
| + // FIXME: Support intrinsic dimensions too. |
| + if (range.peek().id() == CSSValueAuto) |
| + return consumeIdent(range); |
| + return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative); |
| +} |
| + |
| PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID unresolvedProperty) |
| { |
| CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
| @@ -1981,6 +1989,11 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty |
| return consumePaint(m_range, m_context); |
| case CSSPropertyPaintOrder: |
| return consumePaintOrder(m_range); |
| + case CSSPropertyFlexBasis: |
| + return consumeFlexBasis(m_range, m_context.mode()); |
| + case CSSPropertyFlexGrow: |
| + case CSSPropertyFlexShrink: |
| + return consumeNumber(m_range, ValueRangeNonNegative); |
| default: |
| return nullptr; |
| } |
| @@ -2377,6 +2390,59 @@ bool CSSPropertyParser::consumeShorthandGreedily(const StylePropertyShorthand& s |
| return true; |
| } |
| +bool CSSPropertyParser::consumeFlex(bool important) |
| +{ |
| + ShorthandScope scope(this, CSSPropertyFlex); |
| + static const double unsetValue = -1; |
| + double flexGrow = unsetValue; |
| + double flexShrink = unsetValue; |
| + RefPtrWillBeRawPtr<CSSPrimitiveValue> flexBasis = nullptr; |
| + |
| + if (m_range.peek().id() == CSSValueNone) { |
| + flexGrow = flexShrink = 0; |
|
Timothy Loh
2015/11/19 05:36:59
Isn't this against the style guide? At least I nev
|
| + flexBasis = cssValuePool().createIdentifierValue(CSSValueAuto); |
| + m_range.consumeIncludingWhitespace(); |
| + } else { |
| + unsigned index = 0; |
| + while (!m_range.atEnd() && index++ < 3) { |
|
Timothy Loh
2015/11/19 05:36:59
I'd prefer a regular for loop here. I got a bit co
|
| + double num; |
| + if (consumeNumberRaw(m_range, num)) { |
| + if (num < 0) |
| + return false; |
| + if (flexGrow == unsetValue) |
| + flexGrow = num; |
| + else if (flexShrink == unsetValue) |
| + flexShrink = num; |
| + else if (!num) // flex only allows a basis of 0 (sans units) if flex-grow and flex-shrink values have already been set. |
| + flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::Pixels); |
| + else |
| + return false; |
| + } else if (!flexBasis) { |
| + if (m_range.peek().id() == CSSValueAuto) |
| + flexBasis = consumeIdent(m_range); |
| + if (!flexBasis) |
|
Timothy Loh
2015/11/19 05:36:59
Better to just write "else"
|
| + flexBasis = consumeLengthOrPercent(m_range, m_context.mode(), ValueRangeNonNegative); |
| + if (flexBasis && index == 2 && !m_range.atEnd()) |
|
Timothy Loh
2015/11/19 05:36:59
I guess this doesn't need to check flexBasis, I th
|
| + return false; |
| + } |
| + } |
| + } |
| + if (!m_range.atEnd()) |
| + return false; |
| + |
| + if (flexGrow == unsetValue) |
| + flexGrow = 1; |
| + if (flexShrink == unsetValue) |
| + flexShrink = 1; |
| + if (!flexBasis) |
| + flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::Percentage); |
| + |
| + addProperty(CSSPropertyFlexGrow, cssValuePool().createValue(clampTo<float>(flexGrow), CSSPrimitiveValue::UnitType::Number), important); |
| + addProperty(CSSPropertyFlexShrink, cssValuePool().createValue(clampTo<float>(flexShrink), CSSPrimitiveValue::UnitType::Number), important); |
| + addProperty(CSSPropertyFlexBasis, flexBasis, important); |
| + return true; |
| +} |
| + |
| bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool important) |
| { |
| CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
| @@ -2471,6 +2537,10 @@ bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im |
| return consumeShorthandGreedily(webkitBorderAfterShorthand(), important); |
| case CSSPropertyWebkitTextStroke: |
| return consumeShorthandGreedily(webkitTextStrokeShorthand(), important); |
| + case CSSPropertyFlex: |
| + return consumeFlex(important); |
| + case CSSPropertyFlexFlow: |
| + return consumeShorthandGreedily(flexFlowShorthand(), important); |
| default: |
| m_currentShorthand = oldShorthand; |
| return false; |