Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Unified Diff: Source/core/css/parser/CSSParserImpl.cpp

Issue 1192983003: CSS Custom Properties (Variables) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove unnecessary enum Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/css/parser/CSSParserImpl.cpp
diff --git a/Source/core/css/parser/CSSParserImpl.cpp b/Source/core/css/parser/CSSParserImpl.cpp
index 9998d53ba617b90460269c363ef4511dde2b1f99..2a366f846823900f84f8b4b68359d5578e04fdca 100644
--- a/Source/core/css/parser/CSSParserImpl.cpp
+++ b/Source/core/css/parser/CSSParserImpl.cpp
@@ -7,6 +7,7 @@
#include "core/css/CSSKeyframesRule.h"
#include "core/css/CSSStyleSheet.h"
+#include "core/css/CSSCustomVariableValue.h"
#include "core/css/StylePropertySet.h"
#include "core/css/StyleRuleImport.h"
#include "core/css/StyleRuleKeyframe.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;
@@ -656,7 +658,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
@@ -665,6 +668,14 @@ void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ
const CSSParserToken* last = range.end() - 1;
while (last->type() == WhitespaceToken)
--last;
+
+ if (unresolvedProperty == CSSPropertyVariable) {
+ ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
+ AtomicString variableName = token.value();
+ m_styleSheet->parserSetUsesVariables(true);
+ consumeVariableDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEnd), variableName);
+ return;
+ }
if (last->type() == IdentToken && last->valueEqualsIgnoringCase("important")) {
--last;
while (last->type() == WhitespaceToken)
@@ -685,6 +696,7 @@ void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ
m_observerWrapper->observer().observeProperty(
m_observerWrapper->startOffset(rangeCopy), m_observerWrapper->endOffset(rangeCopy),
important, m_parsedProperties.size() != propertiesCount);
+ consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEnd), unresolvedProperty, important, ruleType);
alancutter (OOO until 2018) 2015/07/14 06:12:57 Wrong indentation.
return;
}
@@ -694,14 +706,42 @@ void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRule::Typ
consumeDeclarationValue(range.makeSubRange(&range.peek(), declarationValueEnd), unresolvedProperty, important, ruleType);
}
+void CSSParserImpl::consumeVariableDeclarationValue(CSSParserTokenRange range, const AtomicString& variableName)
+{
+ switch (CSSVariableParser::parseVariableDefinition(range)) {
+ case CSSVariableParser::Invalid:
+ return;
+ case CSSVariableParser::Variable:
+ m_parsedProperties.append(CSSProperty(CSSPropertyVariable,
+ CSSCustomVariableValue::create(variableName, CSSVariableData::create(range, false))));
+ return;
+ case CSSVariableParser::VariableWithReferences:
+ m_parsedProperties.append(CSSProperty(CSSPropertyVariable,
+ CSSCustomVariableValue::create(variableName, CSSVariableData::create(range, true))));
+ return;
+ case CSSVariableParser::Initial:
+ m_parsedProperties.append(CSSProperty(CSSPropertyVariable,
+ CSSCustomVariableValue::create(variableName, CSSValueInitial)));
+ return;
+ case CSSVariableParser::Inherit:
+ m_parsedProperties.append(CSSProperty(CSSPropertyVariable,
+ CSSCustomVariableValue::create(variableName, CSSValueInherit)));
+ return;
+ }
+}
+
void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSPropertyID unresolvedProperty, bool important, StyleRule::Type ruleType)
{
- bool usesRemUnits;
- CSSParserValueList valueList(range, usesRemUnits);
+ bool usesRemUnits, usesVariables;
+ CSSParserValueList valueList(range, usesRemUnits, usesVariables);
alancutter (OOO until 2018) 2015/07/14 06:12:57 Out parameters on a constructor make me sad. Optio
if (!valueList.size())
return; // Parser error
- if (usesRemUnits && m_styleSheet)
- m_styleSheet->parserSetUsesRemUnits(true);
+ if (m_styleSheet) {
+ if (usesRemUnits)
+ m_styleSheet->parserSetUsesRemUnits(true);
+ if (usesVariables)
+ m_styleSheet->parserSetUsesVariables(true);
+ }
CSSPropertyParser::parseValue(unresolvedProperty, important, &valueList, m_context, m_parsedProperties, ruleType);
}

Powered by Google App Engine
This is Rietveld 408576698