Index: third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp |
diff --git a/third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp b/third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp |
index f0da1b94a74d9a419301b402ace11c45da31f176..c97508d1e96a3e1376b38fdc6139b2ed61d0e0bc 100644 |
--- a/third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp |
+++ b/third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp |
@@ -5,6 +5,7 @@ |
#include "config.h" |
#include "core/css/parser/CSSParserImpl.h" |
+#include "core/css/CSSCustomPropertyDeclaration.h" |
#include "core/css/CSSKeyframesRule.h" |
#include "core/css/CSSStyleSheet.h" |
#include "core/css/StylePropertySet.h" |
@@ -18,7 +19,7 @@ |
#include "core/css/parser/CSSPropertyParser.h" |
#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" |
@@ -55,8 +56,9 @@ static inline void filterProperties(bool important, const WillBeHeapVector<CSSPr |
const CSSProperty& property = input[i]; |
if (property.isImportant() != important) |
continue; |
- const unsigned propertyIDIndex = property.id() - firstCSSProperty; |
- if (seenProperties.get(propertyIDIndex)) |
+ // CSSPropertyVariable is asserted to be one number before the firstCSSProperty. We need to include it here. |
+ const unsigned propertyIDIndex = property.id() - CSSPropertyVariable; |
Timothy Loh
2015/09/30 02:09:27
This looks wrong, won't the last property access o
|
+ if (seenProperties.get(propertyIDIndex) && property.id() != CSSPropertyVariable) |
continue; |
seenProperties.set(propertyIDIndex); |
output[--unusedEntries] = property; |
@@ -660,12 +662,25 @@ void CSSParserImpl::consumeDeclarationList(CSSParserTokenRange range, StyleRule: |
} |
} |
+template <typename CharacterType> |
+static bool isCustomProperty(const CharacterType* propertyName, unsigned length) |
+{ |
+ return (length >= 2 && propertyName[0] == '-' && propertyName[1] == '-'); |
+} |
+ |
+inline bool isCustomProperty(CSSParserToken token) |
Timothy Loh
2015/09/30 02:09:27
This is duplicated between here and CSSVariablePar
|
+{ |
+ CSSParserString string = token.value(); |
+ return string.is8Bit() ? isCustomProperty(string.characters8(), string.length()) : isCustomProperty(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(); |
+ const CSSParserToken& token = range.consumeIncludingWhitespace(); |
+ CSSPropertyID unresolvedProperty = token.parseAsUnresolvedCSSPropertyID(); |
if (range.consume().type() != ColonToken) |
return; // Parse error |
@@ -683,6 +698,11 @@ void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ |
declarationValueEnd = last; |
} |
} |
+ if (RuntimeEnabledFeatures::cssVariablesEnabled() && unresolvedProperty == CSSPropertyInvalid && isCustomProperty(token)) { |
+ AtomicString variableName = token.value(); |
+ consumeVariableDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEnd), variableName, important); |
+ return; |
+ } |
if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule::Keyframes)) |
return; |
@@ -703,6 +723,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<CSSCustomPropertyDeclaration> value = CSSVariableParser::parseDeclarationValue(variableName, range)) |
Timothy Loh
2015/09/30 02:09:28
I think this is supposed to be:
if (RefPtr..<> va
|
+ m_parsedProperties.append(CSSProperty(CSSPropertyVariable, value, important)); |
+} |
+ |
void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSPropertyID unresolvedProperty, bool important, StyleRule::Type ruleType) |
{ |
CSSPropertyParser::parseValue(unresolvedProperty, important, range, m_context, m_parsedProperties, ruleType); |