Chromium Code Reviews| Index: Source/core/css/parser/CSSPropertyParser.cpp |
| diff --git a/Source/core/css/parser/CSSPropertyParser.cpp b/Source/core/css/parser/CSSPropertyParser.cpp |
| index e1f79d30d75d0cf1591f02e91a98c9279f57ece4..62044389ce506c797d319083e16b7c645c300d49 100644 |
| --- a/Source/core/css/parser/CSSPropertyParser.cpp |
| +++ b/Source/core/css/parser/CSSPropertyParser.cpp |
| @@ -51,6 +51,7 @@ |
| #include "core/css/CSSTimingFunctionValue.h" |
| #include "core/css/CSSUnicodeRangeValue.h" |
| #include "core/css/CSSValuePool.h" |
| +#include "core/css/CSSVariableValue.h" |
| #include "core/css/Counter.h" |
| #include "core/css/HashTools.h" |
| #include "core/css/Pair.h" |
| @@ -213,6 +214,9 @@ bool CSSPropertyParser::validCalculationUnit(CSSParserValue* value, Units unitfl |
| case CalcFrequency: |
| b = (unitflags & FFrequency); |
| break; |
| + case CalcVariable: |
| + b = true; |
| + break; |
| case CalcOther: |
| break; |
| } |
| @@ -235,6 +239,9 @@ bool CSSPropertyParser::validUnit(CSSParserValue* value, Units unitflags, CSSPar |
| if (isCalculation(value)) |
| return validCalculationUnit(value, unitflags, releaseCalc); |
| + if (RuntimeEnabledFeatures::cssVariablesEnabled() && isVariableReference(value)) |
| + return true; |
| + |
| if (unitflags & FNonNeg && value->fValue < 0) |
| return false; |
| switch (value->unit) { |
| @@ -294,6 +301,8 @@ PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::createPrimitiveNume |
| ASSERT(isCalculation(value)); |
| return CSSPrimitiveValue::create(m_parsedCalculation.release()); |
| } |
| + if (isVariableReference(value)) |
| + return createPrimitiveVariableReferenceValue(value); |
| ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ) |
| || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_CHS) |
| @@ -302,6 +311,12 @@ PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::createPrimitiveNume |
| return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveValue::UnitType>(value->unit)); |
| } |
| +inline PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::createPrimitiveVariableReferenceValue(CSSParserValue* value) |
| +{ |
| + ASSERT(value->unit == CSSParserValue::VariableValue); |
| + return CSSPrimitiveValue::create(value->variableData); |
| +} |
| + |
| inline PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::createPrimitiveStringValue(CSSParserValue* value) |
| { |
| ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPrimitiveValue::CSS_IDENT); |
| @@ -392,6 +407,8 @@ inline PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseValidPr |
| return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPrimitiveValue::CSS_EMS); |
| if (isCalculation(value)) |
| return CSSPrimitiveValue::create(m_parsedCalculation.release()); |
| + if (isVariableReference(value)) |
| + return createPrimitiveVariableReferenceValue(value); |
| return nullptr; |
| } |
| @@ -441,8 +458,16 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import |
| return true; |
| } |
| + |
| int num = inShorthand() ? 1 : m_valueList->size(); |
| + if (RuntimeEnabledFeatures::cssVariablesEnabled() && isVariableReference(value)) { |
| + // We don't expand the shorthand here because crazypants. |
| + m_parsedProperties.append(CSSProperty(propId, createPrimitiveVariableReferenceValue(value), important, false, 0, m_implicitShorthand)); |
|
alancutter (OOO until 2018)
2015/06/26 06:56:07
Is this the only call to createPrimitiveVariableRe
|
| + m_valueList->next(); |
| + return true; |
| + } |
| + |
| if (CSSParserFastPaths::isKeywordPropertyID(propId)) { |
| if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(propId, id)) |
| return false; |
| @@ -1563,7 +1588,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import |
| case CSSPropertyUserZoom: |
| validPrimitive = false; |
| break; |
| - |
| case CSSPropertyScrollSnapPointsX: |
| case CSSPropertyScrollSnapPointsY: |
| parsedValue = parseScrollSnapPoints(); |
| @@ -1573,8 +1597,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import |
| break; |
| case CSSPropertyScrollSnapDestination: |
| parsedValue = parsePosition(m_valueList); |
| - break; |
|
alancutter (OOO until 2018)
2015/06/26 06:56:08
Accidental removal?
|
| - |
| default: |
| return parseSVGValue(propId, important); |
| } |
| @@ -4943,6 +4965,11 @@ bool CSSPropertyParser::isCalculation(CSSParserValue* value) |
| || value->function->id == CSSValueWebkitCalc); |
| } |
| +bool CSSPropertyParser::isVariableReference(CSSParserValue* value) |
| +{ |
| + return value->unit == CSSParserValue::VariableValue; |
| +} |
| + |
| inline int CSSPropertyParser::colorIntFromValue(CSSParserValue* v) |
| { |
| bool isPercent; |
| @@ -5311,15 +5338,19 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseReflect() |
| // Direction comes first. |
| CSSParserValue* val = m_valueList->current(); |
| RefPtrWillBeRawPtr<CSSPrimitiveValue> direction = nullptr; |
| - switch (val->id) { |
| - case CSSValueAbove: |
| - case CSSValueBelow: |
| - case CSSValueLeft: |
| - case CSSValueRight: |
| - direction = cssValuePool().createIdentifierValue(val->id); |
| - break; |
| - default: |
| - return nullptr; |
| + if (isVariableReference(val)) { |
| + direction = createPrimitiveVariableReferenceValue(val); |
| + } else { |
| + switch (val->id) { |
| + case CSSValueAbove: |
| + case CSSValueBelow: |
| + case CSSValueLeft: |
| + case CSSValueRight: |
| + direction = cssValuePool().createIdentifierValue(val->id); |
| + break; |
| + default: |
| + return nullptr; |
| + } |
| } |
| // The offset comes next. |
| @@ -7579,22 +7610,34 @@ bool CSSPropertyParser::parseViewportShorthand(CSSPropertyID propId, CSSProperty |
| } |
| template <typename CharacterType> |
| +static bool isVariableDefinition(const CharacterType* propertyName, unsigned length) |
| +{ |
| + return (length >= 2 && propertyName[0] == '-' && propertyName[1] == '-'); |
| +} |
| + |
| +template <typename CharacterType> |
| static CSSPropertyID unresolvedCSSPropertyID(const CharacterType* propertyName, unsigned length) |
| { |
| char buffer[maxCSSPropertyNameLength + 1]; // 1 for null character |
| for (unsigned i = 0; i != length; ++i) { |
| CharacterType c = propertyName[i]; |
| - if (c == 0 || c >= 0x7F) |
| + if (c == 0 || c >= 0x7F) { |
| + if (isVariableDefinition(propertyName, length)) |
| + return CSSPropertyVariable; |
| return CSSPropertyInvalid; // illegal character |
| + } |
| buffer[i] = toASCIILower(c); |
| } |
| buffer[length] = '\0'; |
| const char* name = buffer; |
| const Property* hashTableEntry = findProperty(name, length); |
| - if (!hashTableEntry) |
| + if (!hashTableEntry) { |
| + if (isVariableDefinition(propertyName, length)) |
| + return CSSPropertyVariable; |
| return CSSPropertyInvalid; |
| + } |
| CSSPropertyID property = static_cast<CSSPropertyID>(hashTableEntry->id); |
| if (!CSSPropertyMetadata::isEnabledProperty(property)) |
| return CSSPropertyInvalid; |
| @@ -7607,8 +7650,11 @@ CSSPropertyID unresolvedCSSPropertyID(const String& string) |
| if (!length) |
| return CSSPropertyInvalid; |
| - if (length > maxCSSPropertyNameLength) |
| + if (length > maxCSSPropertyNameLength) { |
| + if (string.is8Bit() ? isVariableDefinition(string.characters8(), length) : isVariableDefinition(string.characters16(), length)) |
| + return CSSPropertyVariable; |
| return CSSPropertyInvalid; |
| + } |
| return string.is8Bit() ? unresolvedCSSPropertyID(string.characters8(), length) : unresolvedCSSPropertyID(string.characters16(), length); |
| } |
| @@ -7619,8 +7665,11 @@ CSSPropertyID unresolvedCSSPropertyID(const CSSParserString& string) |
| if (!length) |
| return CSSPropertyInvalid; |
| - if (length > maxCSSPropertyNameLength) |
| + if (length > maxCSSPropertyNameLength) { |
| + if (string.is8Bit() ? isVariableDefinition(string.characters8(), length) : isVariableDefinition(string.characters16(), length)) |
| + return CSSPropertyVariable; |
| return CSSPropertyInvalid; |
| + } |
| return string.is8Bit() ? unresolvedCSSPropertyID(string.characters8(), length) : unresolvedCSSPropertyID(string.characters16(), length); |
| } |