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..fa9fe92e79f318bb1b01c20df0390d91f2c73070 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/CSSCustomVariableValue.h" |
#include "core/css/Counter.h" |
#include "core/css/HashTools.h" |
#include "core/css/Pair.h" |
@@ -235,6 +236,9 @@ bool CSSPropertyParser::validUnit(CSSParserValue* value, Units unitflags, CSSPar |
if (isCalculation(value)) |
return validCalculationUnit(value, unitflags, releaseCalc); |
+ if (RuntimeEnabledFeatures::cssVariablesEnabled() && isVariableReference(value)) |
+ return true; |
alancutter (OOO until 2018)
2015/07/14 06:12:57
Is this ever hit?
|
+ |
if (unitflags & FNonNeg && value->fValue < 0) |
return false; |
switch (value->unit) { |
@@ -302,6 +306,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); |
alancutter (OOO until 2018)
2015/07/14 06:12:57
I think we can inline this.
The ASSERT is implicit
|
+} |
+ |
inline PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::createPrimitiveStringValue(CSSParserValue* value) |
{ |
ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPrimitiveValue::CSS_IDENT); |
@@ -441,8 +451,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)); |
+ m_valueList->next(); |
+ return true; |
+ } |
+ |
if (CSSParserFastPaths::isKeywordPropertyID(propId)) { |
if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(propId, id)) |
return false; |
@@ -1563,7 +1581,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import |
case CSSPropertyUserZoom: |
validPrimitive = false; |
break; |
- |
case CSSPropertyScrollSnapPointsX: |
case CSSPropertyScrollSnapPointsY: |
parsedValue = parseScrollSnapPoints(); |
@@ -1574,7 +1591,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import |
case CSSPropertyScrollSnapDestination: |
parsedValue = parsePosition(m_valueList); |
break; |
- |
default: |
return parseSVGValue(propId, important); |
} |
@@ -4943,6 +4959,11 @@ bool CSSPropertyParser::isCalculation(CSSParserValue* value) |
|| value->function->id == CSSValueWebkitCalc); |
} |
+bool CSSPropertyParser::isVariableReference(CSSParserValue* value) |
+{ |
+ return value->unit == CSSParserValue::VariableValue; |
+} |
alancutter (OOO until 2018)
2015/07/14 06:12:57
Inlining this check will make it clearer that the
|
+ |
inline int CSSPropertyParser::colorIntFromValue(CSSParserValue* v) |
{ |
bool isPercent; |
@@ -7579,22 +7600,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 +7640,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 +7655,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); |
} |