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..32106e145ed2e5f616667fe1e3e378ecb0d97a79 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; |
@@ -663,12 +665,25 @@ void CSSParserImpl::consumeDeclarationList(CSSParserTokenRange range, StyleRule: |
} |
} |
+template <typename CharacterType> |
+static bool isVariableDefinition(const CharacterType* propertyName, unsigned length) |
Timothy Loh
2015/08/25 09:21:10
isCustomProperty
|
+{ |
+ return (length >= 2 && propertyName[0] == '-' && propertyName[1] == '-'); |
+} |
+ |
+inline bool isVariableDefinition(CSSParserToken token) |
+{ |
+ CSSParserString string = token.value(); |
+ return string.is8Bit() ? isVariableDefinition(string.characters8(), string.length()) : isVariableDefinition(string.characters16(), string.length()); |
+} |
+ |
void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Type ruleType) |
{ |
CSSParserTokenRange rangeCopy = range; // For inspector callbacks |
ASSERT(range.peek().type() == IdentToken); |
- CSSPropertyID unresolvedProperty = range.consumeIncludingWhitespace().parseAsUnresolvedCSSPropertyID(); |
+ CSSParserToken token = range.consumeIncludingWhitespace(); |
Timothy Loh
2015/08/25 09:21:10
const CSSParserToken&
|
+ CSSPropertyID unresolvedProperty = token.parseAsUnresolvedCSSPropertyID(); |
if (range.consume().type() != ColonToken) |
return; // Parse error |
@@ -677,6 +692,7 @@ void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ |
const CSSParserToken* last = range.end() - 1; |
while (last->type() == WhitespaceToken) |
--last; |
+ |
Timothy Loh
2015/08/25 09:21:10
unrelated (this block is about consuming !importan
|
if (last->type() == IdentToken && last->valueEqualsIgnoringCase("important")) { |
--last; |
while (last->type() == WhitespaceToken) |
@@ -686,6 +702,12 @@ void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ |
declarationValueEnd = last; |
} |
} |
+ if (unresolvedProperty == CSSPropertyInvalid && isVariableDefinition(token)) { |
+ 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 +728,12 @@ 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) |
+{ |
+ if (PassRefPtrWillBeRawPtr<CSSCustomVariableValue> value = CSSVariableParser::parseDeclarationValue(variableName, range)) |
+ m_parsedProperties.append(CSSProperty(CSSPropertyVariable, value, important)); |
+} |
+ |
void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSPropertyID unresolvedProperty, bool important, StyleRule::Type ruleType) |
{ |
CSSParserValueList valueList(range); |