Index: Source/core/css/parser/CSSParserImpl.cpp |
diff --git a/Source/core/css/parser/CSSParserImpl.cpp b/Source/core/css/parser/CSSParserImpl.cpp |
index 57aa15886b1d6d77ac40822252dfc1da549b24df..8ce5abe62b74f9df493665b5e4454a95cbd2633f 100644 |
--- a/Source/core/css/parser/CSSParserImpl.cpp |
+++ b/Source/core/css/parser/CSSParserImpl.cpp |
@@ -5,6 +5,7 @@ |
#include "config.h" |
#include "core/css/parser/CSSParserImpl.h" |
+#include "core/css/CSSCustomVariableValue.h" |
#include "core/css/CSSKeyframesRule.h" |
#include "core/css/CSSStyleSheet.h" |
#include "core/css/StylePropertySet.h" |
@@ -19,6 +20,7 @@ |
#include "core/css/parser/CSSSelectorParser.h" |
#include "core/css/parser/CSSSupportsParser.h" |
#include "core/css/parser/CSSTokenizer.h" |
+#include "core/css/parser/CSSVariableParser.h" |
#include "core/css/parser/MediaQueryParser.h" |
#include "core/dom/Document.h" |
#include "core/dom/Element.h" |
@@ -57,7 +59,7 @@ static inline void filterProperties(bool important, const WillBeHeapVector<CSSPr |
if (property.isImportant() != important) |
continue; |
const unsigned propertyIDIndex = property.id() - firstCSSProperty; |
- if (seenProperties.get(propertyIDIndex)) |
+ if (seenProperties.get(propertyIDIndex) && property.id() != CSSPropertyVariable) |
continue; |
seenProperties.set(propertyIDIndex); |
output[--unusedEntries] = property; |
@@ -668,7 +670,8 @@ void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ |
CSSParserTokenRange rangeCopy = range; // For inspector callbacks |
ASSERT(range.peek().type() == IdentToken); |
- CSSPropertyID unresolvedProperty = range.consumeIncludingWhitespace().parseAsUnresolvedCSSPropertyID(); |
+ CSSParserToken token = range.consumeIncludingWhitespace(); |
+ CSSPropertyID unresolvedProperty = token.parseAsUnresolvedCSSPropertyID(); |
if (range.consume().type() != ColonToken) |
return; // Parse error |
@@ -677,6 +680,7 @@ void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ |
const CSSParserToken* last = range.end() - 1; |
while (last->type() == WhitespaceToken) |
--last; |
+ |
if (last->type() == IdentToken && last->valueEqualsIgnoringCase("important")) { |
--last; |
while (last->type() == WhitespaceToken) |
@@ -686,6 +690,12 @@ void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ |
declarationValueEnd = last; |
} |
} |
+ if (unresolvedProperty == CSSPropertyVariable) { |
+ ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled()); |
+ AtomicString variableName = token.value(); |
+ consumeVariableDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEnd), variableName, important); |
+ return; |
+ } |
if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule::Keyframes)) |
return; |
@@ -706,6 +716,34 @@ void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ |
consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEnd), unresolvedProperty, important, ruleType); |
} |
+void CSSParserImpl::consumeVariableDeclarationValue(CSSParserTokenRange range, const AtomicString& variableName, bool important) |
+{ |
+ switch (CSSVariableParser::parseVariableDefinition(range)) { |
alancutter (OOO until 2018)
2015/08/05 08:01:43
parseVariableDefinition() could just return a CSSC
|
+ case CSSVariableParser::Invalid: |
+ return; |
+ case CSSVariableParser::Variable: |
+ m_parsedProperties.append(CSSProperty(CSSPropertyVariable, |
+ CSSCustomVariableValue::create(variableName, CSSVariableData::create(range, false)), important)); |
+ return; |
+ case CSSVariableParser::VariableWithReferences: |
+ m_parsedProperties.append(CSSProperty(CSSPropertyVariable, |
+ CSSCustomVariableValue::create(variableName, CSSVariableData::create(range, true)), important)); |
+ return; |
+ case CSSVariableParser::Initial: |
+ m_parsedProperties.append(CSSProperty(CSSPropertyVariable, |
+ CSSCustomVariableValue::create(variableName, CSSValueInitial), important)); |
+ return; |
+ case CSSVariableParser::Inherit: |
+ m_parsedProperties.append(CSSProperty(CSSPropertyVariable, |
+ CSSCustomVariableValue::create(variableName, CSSValueInherit), important)); |
+ return; |
+ case CSSVariableParser::Unset: |
+ m_parsedProperties.append(CSSProperty(CSSPropertyVariable, |
+ CSSCustomVariableValue::create(variableName, CSSValueUnset), important)); |
+ return; |
+ } |
+} |
+ |
void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSPropertyID unresolvedProperty, bool important, StyleRule::Type ruleType) |
{ |
CSSParserValueList valueList(range); |