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

Unified Diff: third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp

Issue 1645433002: Basic implementation of @apply (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix expted.txt for failing test Created 4 years, 10 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: third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp
diff --git a/third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp b/third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp
index ace65cc6640890f98e432b6dc9a03eb46fd40026..54967284066931e9d8e457a466e3552366a1c97c 100644
--- a/third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp
+++ b/third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp
@@ -15,6 +15,7 @@
#include "core/css/parser/CSSParserTokenRange.h"
#include "core/css/parser/CSSParserValues.h"
#include "core/css/parser/CSSPropertyParser.h"
+#include "core/css/parser/CSSVariableParser.h"
#include "core/css/resolver/StyleBuilder.h"
#include "core/css/resolver/StyleResolverState.h"
#include "core/style/StyleVariableData.h"
@@ -87,6 +88,39 @@ bool CSSVariableResolver::resolveVariableReference(CSSParserTokenRange range, Ve
return true;
}
+void CSSVariableResolver::resolveApplyAtRule(CSSParserTokenRange& range,
+ Vector<CSSParserToken>& result)
+{
+ ASSERT(range.peek().type() == AtKeywordToken && range.peek().valueEqualsIgnoringASCIICase("apply"));
+ CSSParserTokenRange originalRange = range;
+
+ range.consumeIncludingWhitespace();
+ const CSSParserToken& variableName = range.consumeIncludingWhitespace();
+ if (!CSSVariableParser::isValidVariableName(variableName)
+ || !(range.atEnd() || range.peek().type() == SemicolonToken || range.peek().type() == RightBraceToken)) {
+ range = originalRange;
+ result.append(range.consume());
+ return;
+ }
+ if (range.peek().type() == SemicolonToken)
+ range.consume();
+
+ CSSVariableData* variableData = valueForCustomProperty(variableName.value());
+ if (!variableData)
+ return; // Invalid custom property
+
+ CSSParserTokenRange rule = variableData->tokenRange();
+ rule.consumeWhitespace();
+ if (rule.peek().type() != LeftBraceToken)
+ return;
+ CSSParserTokenRange ruleContents = rule.consumeBlock();
+ rule.consumeWhitespace();
+ if (!rule.atEnd())
+ return;
+
+ result.appendRange(ruleContents.begin(), ruleContents.end());
+}
+
bool CSSVariableResolver::resolveTokenRange(CSSParserTokenRange range,
Vector<CSSParserToken>& result)
{
@@ -94,6 +128,9 @@ bool CSSVariableResolver::resolveTokenRange(CSSParserTokenRange range,
while (!range.atEnd()) {
if (range.peek().functionId() == CSSValueVar) {
success &= resolveVariableReference(range.consumeBlock(), result);
+ } else if (range.peek().type() == AtKeywordToken && range.peek().valueEqualsIgnoringASCIICase("apply")
+ && RuntimeEnabledFeatures::cssApplyAtRulesEnabled()) {
+ resolveApplyAtRule(range, result);
} else {
result.append(range.consume());
}

Powered by Google App Engine
This is Rietveld 408576698