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

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

Issue 2089593002: Add expansion of shorthands with custom properties to longhands using a pending substition value. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renames, signature update and master merge Created 4 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: 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 756afb7e995c7a631974df25ce4a6450b2be2148..f2a47a2b3545a96761de7a5e1725b82132582e33 100644
--- a/third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp
+++ b/third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp
@@ -8,6 +8,7 @@
#include "core/CSSValueKeywords.h"
#include "core/StyleBuilderFunctions.h"
#include "core/StylePropertyShorthand.h"
+#include "core/css/CSSPendingSubstitutionValue.h"
#include "core/css/CSSUnsetValue.h"
#include "core/css/CSSVariableData.h"
#include "core/css/CSSVariableReferenceValue.h"
@@ -143,36 +144,59 @@ CSSValue* CSSVariableResolver::resolveVariableReferences(StyleVariableData* styl
return result;
}
-void CSSVariableResolver::resolveAndApplyVariableReferences(StyleResolverState& state, CSSPropertyID id, const CSSVariableReferenceValue& value)
+const CSSValue* CSSVariableResolver::resolveVariableReferences(StyleResolverState& state, CSSPropertyID id, const CSSVariableReferenceValue& value)
{
+ // Non-shorthand variable references follow this path.
CSSVariableResolver resolver(state.style()->variables());
Vector<CSSParserToken> tokens;
if (resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens)) {
CSSParserContext context(HTMLStandardMode, 0);
- HeapVector<CSSProperty, 256> parsedProperties;
+ CSSValue* value = CSSPropertyParser::parseSingleValue(id, CSSParserTokenRange(tokens), context);
+ if (value)
+ return value;
+ }
+
+ return CSSUnsetValue::create();
+}
+
+const CSSValue* CSSVariableResolver::resolvePendingSubstitutions(StyleResolverState& state, CSSPropertyID id, const CSSPendingSubstitutionValue& pendingValue)
+{
+ // Longhands from shorthand references follow this path.
+ HeapHashMap<CSSPropertyID, Member<const CSSValue>>& propertyCache = state.parsedPropertiesForPendingSubstitution(pendingValue);
+
+ const CSSValue* value = propertyCache.get(id);
+ if (!value) {
+ // TODO(timloh): We shouldn't retry this for all longhands if the shorthand ends up invalid
+ CSSVariableReferenceValue* shorthandValue = pendingValue.shorthandValue();
+ CSSPropertyID shorthandPropertyId = pendingValue.shorthandPropertyId();
- // TODO: Non-shorthands should just call CSSPropertyParser::parseSingleValue
- if (CSSPropertyParser::parseValue(id, false, CSSParserTokenRange(tokens), context, parsedProperties, StyleRule::RuleType::Style)) {
- unsigned parsedPropertiesCount = parsedProperties.size();
- for (unsigned i = 0; i < parsedPropertiesCount; ++i)
- StyleBuilder::applyProperty(parsedProperties[i].id(), state, *parsedProperties[i].value());
- return;
+ CSSVariableResolver resolver(state.style()->variables());
+
+ Vector<CSSParserToken> tokens;
+ if (resolver.resolveTokenRange(shorthandValue->variableDataValue()->tokens(), tokens)) {
+ CSSParserContext context(HTMLStandardMode, 0);
+
+ HeapVector<CSSProperty, 256> parsedProperties;
+
+ if (CSSPropertyParser::parseValue(shorthandPropertyId, false, CSSParserTokenRange(tokens), context, parsedProperties, StyleRule::RuleType::Style)) {
+ unsigned parsedPropertiesCount = parsedProperties.size();
+ for (unsigned i = 0; i < parsedPropertiesCount; ++i) {
+ propertyCache.set(parsedProperties[i].id(), parsedProperties[i].value());
+ }
+ }
}
+ value = propertyCache.get(id);
}
- CSSUnsetValue* unset = CSSUnsetValue::create();
- if (isShorthandProperty(id)) {
- StylePropertyShorthand shorthand = shorthandForProperty(id);
- for (unsigned i = 0; i < shorthand.length(); i++)
- StyleBuilder::applyProperty(shorthand.properties()[i], state, *unset);
- return;
- }
+ if (value)
+ return value;
- StyleBuilder::applyProperty(id, state, *unset);
+ return CSSUnsetValue::create();
}
+
void CSSVariableResolver::resolveVariableDefinitions(StyleVariableData* variables)
{
if (!variables)

Powered by Google App Engine
This is Rietveld 408576698