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 8d4a1d8431d6d933f8e953af5627b2b2bc82b5ff..16486b4c53d4a61f2d33b8822f4025daf1b67edc 100644 |
| --- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
| +++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
| @@ -52,7 +52,7 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import |
| if (ruleType == StyleRule::Viewport) { |
| parseSuccess = (RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(context.mode())) |
| - && parser.parseViewportProperty(resolvedProperty, important); |
| + && parser.parseViewportDescriptor(resolvedProperty, important); |
| } else if (ruleType == StyleRule::FontFace) { |
| parseSuccess = parser.parseFontFaceDescriptor(resolvedProperty); |
| } else { |
| @@ -258,11 +258,9 @@ static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRan |
| return nullptr; |
| } |
| -static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLengthOrPercent(CSSParserTokenRange& range, CSSParserMode cssParserMode, ValueRange valueRange, UnitlessQuirk unitless = UnitlessQuirk::Forbid) |
| +static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumePercent(CSSParserTokenRange& range, ValueRange valueRange) |
| { |
| const CSSParserToken& token = range.peek(); |
| - if (token.type() == DimensionToken || token.type() == NumberToken) |
| - return consumeLength(range, cssParserMode, valueRange, unitless); |
| if (token.type() == PercentageToken) { |
| if (valueRange == ValueRangeNonNegative && token.numericValue() < 0) |
| return nullptr; |
| @@ -270,6 +268,26 @@ static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLengthOrPercent(CSSParse |
| } |
| CalcParser calcParser(range, valueRange); |
| if (const CSSCalcValue* calculation = calcParser.value()) { |
| + if (calculation->category() == CalcPercent) |
| + return calcParser.consumeValue(); |
| + } |
| + return nullptr; |
| +} |
| + |
| +static inline bool isCSSWideKeyword(const CSSValueID& id) |
|
Timothy Loh
2015/10/08 01:05:21
not sure if this was supposed to be moved?
|
| +{ |
| + return id == CSSValueInitial || id == CSSValueInherit || id == CSSValueUnset || id == CSSValueDefault; |
| +} |
| + |
| +static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLengthOrPercent(CSSParserTokenRange& range, CSSParserMode cssParserMode, ValueRange valueRange, UnitlessQuirk unitless = UnitlessQuirk::Forbid) |
| +{ |
| + const CSSParserToken& token = range.peek(); |
| + if (token.type() == DimensionToken || token.type() == NumberToken) |
| + return consumeLength(range, cssParserMode, valueRange, unitless); |
| + if (token.type() == PercentageToken) |
| + return consumePercent(range, valueRange); |
| + CalcParser calcParser(range, valueRange); |
| + if (const CSSCalcValue* calculation = calcParser.value()) { |
| if (calculation->category() == CalcLength || calculation->category() == CalcPercent || calculation->category() == CalcPercentLength) |
| return calcParser.consumeValue(); |
| } |
| @@ -298,11 +316,6 @@ static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeAngle(CSSParserTokenRang |
| return nullptr; |
| } |
| -static inline bool isCSSWideKeyword(const CSSValueID& id) |
| -{ |
| - return id == CSSValueInitial || id == CSSValueInherit || id == CSSValueUnset || id == CSSValueDefault; |
| -} |
| - |
| // Methods for consuming non-shorthand properties starts here. |
| static PassRefPtrWillBeRawPtr<CSSValue> consumeWillChange(CSSParserTokenRange& range) |
| { |
| @@ -908,6 +921,99 @@ bool CSSPropertyParser::consumeBorderSpacing(bool important) |
| return true; |
| } |
| +static PassRefPtrWillBeRawPtr<CSSValue> consumeSingleViewportDescriptor(CSSParserTokenRange& range, CSSPropertyID propId, CSSParserMode cssParserMode) |
| +{ |
| + CSSValueID id = range.peek().id(); |
| + switch (propId) { |
| + case CSSPropertyMinWidth: |
| + case CSSPropertyMaxWidth: |
| + case CSSPropertyMinHeight: |
| + case CSSPropertyMaxHeight: |
| + if (id == CSSValueAuto || id == CSSValueInternalExtendToZoom) |
| + return consumeIdent(range); |
| + return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative); |
| + case CSSPropertyMinZoom: |
| + case CSSPropertyMaxZoom: |
| + case CSSPropertyZoom: { |
| + if (id == CSSValueAuto) |
| + return consumeIdent(range); |
| + RefPtrWillBeRawPtr<CSSValue> parsedValue = consumeNumber(range, ValueRangeNonNegative); |
|
Timothy Loh
2015/10/08 01:05:21
I prefer:
if (RefPtrWillBeRawPtr<CSSValue> parsed
|
| + if (!parsedValue) |
| + parsedValue = consumePercent(range, ValueRangeNonNegative); |
| + return parsedValue.release(); |
| + } |
| + case CSSPropertyUserZoom: |
| + if (id == CSSValueZoom || id == CSSValueFixed) |
| + return consumeIdent(range); |
| + break; |
| + case CSSPropertyOrientation: |
| + if (id == CSSValueAuto || id == CSSValuePortrait || id == CSSValueLandscape) |
| + return consumeIdent(range); |
| + break; |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + break; |
| + } |
| + |
| + return nullptr; |
| +} |
| + |
| +bool CSSPropertyParser::parseViewportDescriptor(CSSPropertyID propId, bool important) |
| +{ |
| + ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_context.mode())); |
| + |
| + m_range.consumeWhitespace(); |
|
Timothy Loh
2015/10/08 01:05:21
We should probably do this up front somewhere so i
|
| + RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr; |
| + |
| + switch (propId) { |
| + case CSSPropertyWidth: { |
| + RefPtrWillBeRawPtr<CSSValue> minWidth = consumeSingleViewportDescriptor(m_range, CSSPropertyMinWidth, m_context.mode()); |
| + if (!minWidth) |
| + return false; |
| + RefPtrWillBeRawPtr<CSSValue> maxWidth = minWidth; |
| + if (!m_range.atEnd()) |
| + maxWidth = consumeSingleViewportDescriptor(m_range, CSSPropertyMaxWidth, m_context.mode()); |
| + if (!maxWidth || !m_range.atEnd()) |
| + return false; |
| + addProperty(CSSPropertyMinWidth, minWidth.release(), important); |
| + addProperty(CSSPropertyMaxWidth, maxWidth.release(), important); |
| + return true; |
| + } |
| + case CSSPropertyHeight: { |
| + RefPtrWillBeRawPtr<CSSValue> minHeight = consumeSingleViewportDescriptor(m_range, CSSPropertyMinHeight, m_context.mode()); |
| + if (!minHeight) |
| + return false; |
| + RefPtrWillBeRawPtr<CSSValue> maxHeight = minHeight; |
| + if (!m_range.atEnd()) |
| + maxHeight = consumeSingleViewportDescriptor(m_range, CSSPropertyMaxHeight, m_context.mode()); |
| + if (!maxHeight || !m_range.atEnd()) |
| + return false; |
| + addProperty(CSSPropertyMinHeight, minHeight.release(), important); |
| + addProperty(CSSPropertyMaxHeight, maxHeight.release(), important); |
| + return true; |
| + } |
| + case CSSPropertyMinWidth: |
| + case CSSPropertyMaxWidth: |
| + case CSSPropertyMinHeight: |
| + case CSSPropertyMaxHeight: |
| + case CSSPropertyMinZoom: |
| + case CSSPropertyMaxZoom: |
| + case CSSPropertyZoom: |
| + case CSSPropertyUserZoom: |
| + case CSSPropertyOrientation: |
| + parsedValue = consumeSingleViewportDescriptor(m_range, propId, m_context.mode()); |
|
Timothy Loh
2015/10/08 01:05:21
if we only set parsedValue here, we should just mo
|
| + break; |
| + default: |
| + return false; |
| + } |
| + |
| + if (!parsedValue || !m_range.atEnd()) |
| + return false; |
| + |
| + addProperty(propId, parsedValue.release(), important); |
| + return true; |
| +} |
| + |
| bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important) |
| { |
| m_range.consumeWhitespace(); |