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 b8661ea5d7ab6d062ef2ae17acbecf1a9999e8dd..bbbc6e07d0f593c73aeefea595bb12f47660d26b 100644 |
| --- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
| +++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
| @@ -126,6 +126,83 @@ static CSSParserTokenRange consumeFunction(CSSParserTokenRange& range) |
| return contents; |
| } |
| +static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeInteger(CSSParserTokenRange& range, CSSParserMode cssParserMode, double minimumValue = std::numeric_limits<int>::min()) |
| +{ |
| + const CSSParserToken& token = range.peek(); |
| + if (token.type() == NumberToken) { |
| + if (token.numericValueType() == NumberValueType || token.numericValue() < static_cast<double>(minimumValue)) |
| + return nullptr; |
| + return cssValuePool().createValue(range.consumeIncludingWhitespace().numericValue(), token.unitType()); |
| + } |
| + if (token.functionId() == CSSValueCalc || token.functionId() == CSSValueWebkitCalc) { |
| + RefPtrWillBeRawPtr<CSSCalcValue> calculation = CSSCalcValue::create(range, ValueRangeAll); |
| + if (!calculation || calculation->category() != CalcNumber || !calculation->isInt()) |
| + return nullptr; |
| + double value = calculation->doubleValue(); |
| + if (value < minimumValue) |
| + return nullptr; |
| + // TODO: Always resolve calc() to a UnitType::Number if there are no non-numbers specified in the unitflags. |
|
alancutter (OOO until 2018)
2015/09/27 23:13:38
No more unitflags, this can be resolved now. (:
|
| + return CSSPrimitiveValue::create(calculation.release()); |
| + } |
| + return nullptr; |
| +} |
| + |
| +inline bool shouldAcceptUnitLessValues(double fValue, CSSParserMode cssParserMode) |
| +{ |
| + // Quirks mode for certain properties and presentation attributes accept unit-less values for certain units. |
| + return !fValue // 0 can always be unitless. |
| + || isUnitLessLengthParsingEnabledForMode(cssParserMode) // HTML and SVG attribute values can always be unitless. |
| + || cssParserMode == HTMLQuirksMode; |
| +} |
| + |
| +static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRange& range, CSSParserMode cssParserMode, ValueRange valueRange, UnitlessQuirk unitless = UnitlessQuirk::Forbid) |
| +{ |
| + const CSSParserToken& token = range.peek(); |
| + if (token.type() == DimensionToken) { |
| + bool validNumber = false; |
| + switch (token.unitType()) { |
| + case CSSPrimitiveValue::UnitType::QuirkyEms: |
| + if (cssParserMode != UASheetMode) |
| + return nullptr; |
| + /* fallthrough intentional */ |
| + case CSSPrimitiveValue::UnitType::Ems: |
| + case CSSPrimitiveValue::UnitType::Rems: |
| + case CSSPrimitiveValue::UnitType::Chs: |
| + case CSSPrimitiveValue::UnitType::Exs: |
| + case CSSPrimitiveValue::UnitType::Pixels: |
| + case CSSPrimitiveValue::UnitType::Centimeters: |
| + case CSSPrimitiveValue::UnitType::Millimeters: |
| + case CSSPrimitiveValue::UnitType::Inches: |
| + case CSSPrimitiveValue::UnitType::Points: |
| + case CSSPrimitiveValue::UnitType::Picas: |
| + case CSSPrimitiveValue::UnitType::ViewportWidth: |
| + case CSSPrimitiveValue::UnitType::ViewportHeight: |
| + case CSSPrimitiveValue::UnitType::ViewportMin: |
| + case CSSPrimitiveValue::UnitType::ViewportMax: |
| + validNumber = true; |
| + break; |
| + default: |
| + break; |
| + } |
| + if (!validNumber || (valueRange == ValueRangeNonNegative && token.numericValue() < 0)) |
| + return nullptr; |
| + return cssValuePool().createValue(range.consumeIncludingWhitespace().numericValue(), token.unitType()); |
| + } |
| + if (token.type() == NumberToken) { |
| + if (unitless == UnitlessQuirk::Forbid || !shouldAcceptUnitLessValues(token.numericValue(), cssParserMode) |
| + || (valueRange == ValueRangeNonNegative && token.numericValue() < 0)) |
| + return nullptr; |
| + return cssValuePool().createValue(range.consumeIncludingWhitespace().numericValue(), CSSPrimitiveValue::UnitType::Pixels); |
| + } |
| + if (token.functionId() == CSSValueCalc || token.functionId() == CSSValueWebkitCalc) { |
| + RefPtrWillBeRawPtr<CSSCalcValue> calculation = CSSCalcValue::create(range, valueRange); |
| + if (!calculation || calculation->category() != CalcLength) |
| + return nullptr; |
| + return CSSPrimitiveValue::create(calculation.release()); |
| + } |
| + return nullptr; |
| +} |
| + |
| static inline bool isCSSWideKeyword(const CSSValueID& id) |
| { |
| return id == CSSValueInitial || id == CSSValueInherit || id == CSSValueUnset || id == CSSValueDefault; |
| @@ -396,6 +473,22 @@ static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFamily(CSSParserTokenRang |
| return list.release(); |
| } |
| +static PassRefPtrWillBeRawPtr<CSSValue> consumeSpacing(CSSParserTokenRange& range, CSSParserMode cssParserMode) |
| +{ |
| + if (range.peek().id() == CSSValueNormal) |
| + return consumeIdent(range); |
| + // TODO(timloh): Don't allow unitless values, and allow <percentage>s in word-spacing. |
| + return consumeLength(range, cssParserMode, ValueRangeAll, UnitlessQuirk::Allow); |
| +} |
| + |
| +static PassRefPtrWillBeRawPtr<CSSValue> consumeTabSize(CSSParserTokenRange& range, CSSParserMode cssParserMode) |
| +{ |
| + RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue = nullptr; |
| + if ((parsedValue = consumeInteger(range, cssParserMode, 0))) |
|
alancutter (OOO until 2018)
2015/09/27 23:13:38
May as well do the assignment in the declaration,
|
| + return parsedValue; |
| + return consumeLength(range, cssParserMode, ValueRangeNonNegative); |
| +} |
| + |
| PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID propId) |
| { |
| m_range.consumeWhitespace(); |
| @@ -418,6 +511,11 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty |
| return consumeFontFamily(m_range); |
| case CSSPropertyFontWeight: |
| return consumeFontWeight(m_range); |
| + case CSSPropertyLetterSpacing: |
| + case CSSPropertyWordSpacing: |
| + return consumeSpacing(m_range, m_context.mode()); |
| + case CSSPropertyTabSize: |
| + return consumeTabSize(m_range, m_context.mode()); |
| default: |
| return nullptr; |
| } |