Chromium Code Reviews| 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 4f998d6c5b74ced729373a54c10632d34b981cde..137685efa3e1e004b4da01acdbb6f4378f897aae 100644 |
| --- a/third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp |
| +++ b/third_party/WebKit/Source/core/css/resolver/CSSVariableResolver.cpp |
| @@ -8,7 +8,9 @@ |
| #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/CSSValuePool.h" |
|
Timothy Loh
2016/06/27 04:19:09
unneeded
Andy Mutton
2016/06/28 03:18:51
Done.
|
| #include "core/css/CSSVariableData.h" |
| #include "core/css/CSSVariableReferenceValue.h" |
| #include "core/css/parser/CSSParserToken.h" |
| @@ -143,36 +145,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) { |
| + // Property cache is unset. Let's fill it. |
|
Timothy Loh
2016/06/27 04:19:09
This would alternatively mean that we already got
Andy Mutton
2016/06/28 03:18:51
Done. (Happy for you to have a TODO)
|
| + 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) |