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..b295e45e95934e52bc77e678a8552dd91f68b293 100644 |
--- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
+++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp |
@@ -126,6 +126,82 @@ 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)) |
alancutter (OOO until 2018)
2015/09/28 23:40:04
No need to cast.
|
+ return nullptr; |
+ return cssValuePool().createValue(range.consumeIncludingWhitespace().numericValue(), token.unitType()); |
+ } |
+ if (token.functionId() == CSSValueCalc || token.functionId() == CSSValueWebkitCalc) { |
+ RefPtrWillBeRawPtr<CSSCalcValue> calculation = CSSCalcValue::create(consumeFunction(range), ValueRangeAll); |
+ if (!calculation || calculation->category() != CalcNumber || !calculation->isInt()) |
+ return nullptr; |
+ double value = calculation->doubleValue(); |
+ if (value < minimumValue) |
+ return nullptr; |
alancutter (OOO until 2018)
2015/09/28 23:40:04
calc()s are special and clamp to the allowed range
|
+ 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(consumeFunction(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 +472,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 = consumeInteger(range, cssParserMode, 0); |
+ if (parsedValue) |
+ return parsedValue; |
+ return consumeLength(range, cssParserMode, ValueRangeNonNegative); |
+} |
+ |
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID propId) |
{ |
m_range.consumeWhitespace(); |
@@ -418,6 +510,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; |
} |