| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/css/resolver/CSSVariableResolver.h" | 5 #include "core/css/resolver/CSSVariableResolver.h" |
| 6 | 6 |
| 7 #include "core/CSSPropertyNames.h" | 7 #include "core/CSSPropertyNames.h" |
| 8 #include "core/CSSValueKeywords.h" | 8 #include "core/CSSValueKeywords.h" |
| 9 #include "core/StyleBuilderFunctions.h" | 9 #include "core/StyleBuilderFunctions.h" |
| 10 #include "core/StylePropertyShorthand.h" | 10 #include "core/StylePropertyShorthand.h" |
| 11 #include "core/css/CSSPendingSubstitutionValue.h" |
| 11 #include "core/css/CSSUnsetValue.h" | 12 #include "core/css/CSSUnsetValue.h" |
| 12 #include "core/css/CSSVariableData.h" | 13 #include "core/css/CSSVariableData.h" |
| 13 #include "core/css/CSSVariableReferenceValue.h" | 14 #include "core/css/CSSVariableReferenceValue.h" |
| 14 #include "core/css/parser/CSSParserToken.h" | 15 #include "core/css/parser/CSSParserToken.h" |
| 15 #include "core/css/parser/CSSParserTokenRange.h" | 16 #include "core/css/parser/CSSParserTokenRange.h" |
| 16 #include "core/css/parser/CSSPropertyParser.h" | 17 #include "core/css/parser/CSSPropertyParser.h" |
| 17 #include "core/css/resolver/StyleBuilder.h" | 18 #include "core/css/resolver/StyleBuilder.h" |
| 18 #include "core/css/resolver/StyleResolverState.h" | 19 #include "core/css/resolver/StyleResolverState.h" |
| 19 #include "core/style/StyleVariableData.h" | 20 #include "core/style/StyleVariableData.h" |
| 20 #include "wtf/Vector.h" | 21 #include "wtf/Vector.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 CSSVariableResolver resolver(styleVariableData); | 137 CSSVariableResolver resolver(styleVariableData); |
| 137 Vector<CSSParserToken> tokens; | 138 Vector<CSSParserToken> tokens; |
| 138 if (!resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens)
) | 139 if (!resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens)
) |
| 139 return CSSUnsetValue::create(); | 140 return CSSUnsetValue::create(); |
| 140 CSSValue* result = CSSPropertyParser::parseSingleValue(id, tokens, strictCSS
ParserContext()); | 141 CSSValue* result = CSSPropertyParser::parseSingleValue(id, tokens, strictCSS
ParserContext()); |
| 141 if (!result) | 142 if (!result) |
| 142 return CSSUnsetValue::create(); | 143 return CSSUnsetValue::create(); |
| 143 return result; | 144 return result; |
| 144 } | 145 } |
| 145 | 146 |
| 146 void CSSVariableResolver::resolveAndApplyVariableReferences(StyleResolverState&
state, CSSPropertyID id, const CSSVariableReferenceValue& value) | 147 const CSSValue* CSSVariableResolver::resolveVariableReferences(StyleResolverStat
e& state, CSSPropertyID id, const CSSVariableReferenceValue& value) |
| 147 { | 148 { |
| 149 // Non-shorthand variable references follow this path. |
| 148 CSSVariableResolver resolver(state.style()->variables()); | 150 CSSVariableResolver resolver(state.style()->variables()); |
| 149 | 151 |
| 150 Vector<CSSParserToken> tokens; | 152 Vector<CSSParserToken> tokens; |
| 151 if (resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens))
{ | 153 if (resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens))
{ |
| 152 CSSParserContext context(HTMLStandardMode, 0); | 154 CSSParserContext context(HTMLStandardMode, 0); |
| 153 | 155 |
| 154 HeapVector<CSSProperty, 256> parsedProperties; | 156 CSSValue* value = CSSPropertyParser::parseSingleValue(id, CSSParserToken
Range(tokens), context); |
| 155 | 157 if (value) |
| 156 // TODO: Non-shorthands should just call CSSPropertyParser::parseSingleV
alue | 158 return value; |
| 157 if (CSSPropertyParser::parseValue(id, false, CSSParserTokenRange(tokens)
, context, parsedProperties, StyleRule::RuleType::Style)) { | |
| 158 unsigned parsedPropertiesCount = parsedProperties.size(); | |
| 159 for (unsigned i = 0; i < parsedPropertiesCount; ++i) | |
| 160 StyleBuilder::applyProperty(parsedProperties[i].id(), state, *pa
rsedProperties[i].value()); | |
| 161 return; | |
| 162 } | |
| 163 } | 159 } |
| 164 | 160 |
| 165 CSSUnsetValue* unset = CSSUnsetValue::create(); | 161 return CSSUnsetValue::create(); |
| 166 if (isShorthandProperty(id)) { | 162 } |
| 167 StylePropertyShorthand shorthand = shorthandForProperty(id); | 163 |
| 168 for (unsigned i = 0; i < shorthand.length(); i++) | 164 const CSSValue* CSSVariableResolver::resolvePendingSubstitutions(StyleResolverSt
ate& state, CSSPropertyID id, const CSSPendingSubstitutionValue& pendingValue) |
| 169 StyleBuilder::applyProperty(shorthand.properties()[i], state, *unset
); | 165 { |
| 170 return; | 166 // Longhands from shorthand references follow this path. |
| 167 HeapHashMap<CSSPropertyID, Member<const CSSValue>>& propertyCache = state.pa
rsedPropertiesForPendingSubstitution(pendingValue); |
| 168 |
| 169 const CSSValue* value = propertyCache.get(id); |
| 170 if (!value) { |
| 171 // TODO(timloh): We shouldn't retry this for all longhands if the shorth
and ends up invalid |
| 172 CSSVariableReferenceValue* shorthandValue = pendingValue.shorthandValue(
); |
| 173 CSSPropertyID shorthandPropertyId = pendingValue.shorthandPropertyId(); |
| 174 |
| 175 CSSVariableResolver resolver(state.style()->variables()); |
| 176 |
| 177 Vector<CSSParserToken> tokens; |
| 178 if (resolver.resolveTokenRange(shorthandValue->variableDataValue()->toke
ns(), tokens)) { |
| 179 CSSParserContext context(HTMLStandardMode, 0); |
| 180 |
| 181 HeapVector<CSSProperty, 256> parsedProperties; |
| 182 |
| 183 if (CSSPropertyParser::parseValue(shorthandPropertyId, false, CSSPar
serTokenRange(tokens), context, parsedProperties, StyleRule::RuleType::Style)) { |
| 184 unsigned parsedPropertiesCount = parsedProperties.size(); |
| 185 for (unsigned i = 0; i < parsedPropertiesCount; ++i) { |
| 186 propertyCache.set(parsedProperties[i].id(), parsedProperties
[i].value()); |
| 187 } |
| 188 } |
| 189 } |
| 190 value = propertyCache.get(id); |
| 171 } | 191 } |
| 172 | 192 |
| 173 StyleBuilder::applyProperty(id, state, *unset); | 193 if (value) |
| 194 return value; |
| 195 |
| 196 return CSSUnsetValue::create(); |
| 174 } | 197 } |
| 175 | 198 |
| 199 |
| 176 void CSSVariableResolver::resolveVariableDefinitions(StyleVariableData* variable
s) | 200 void CSSVariableResolver::resolveVariableDefinitions(StyleVariableData* variable
s) |
| 177 { | 201 { |
| 178 if (!variables) | 202 if (!variables) |
| 179 return; | 203 return; |
| 180 | 204 |
| 181 CSSVariableResolver resolver(variables); | 205 CSSVariableResolver resolver(variables); |
| 182 for (auto& variable : variables->m_data) { | 206 for (auto& variable : variables->m_data) { |
| 183 if (variable.value && variable.value->needsVariableResolution()) | 207 if (variable.value && variable.value->needsVariableResolution()) |
| 184 variable.value = resolver.resolveCustomProperty(variable.key, *varia
ble.value); | 208 variable.value = resolver.resolveCustomProperty(variable.key, *varia
ble.value); |
| 185 } | 209 } |
| 186 } | 210 } |
| 187 | 211 |
| 188 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData) | 212 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData) |
| 189 : m_styleVariableData(styleVariableData) | 213 : m_styleVariableData(styleVariableData) |
| 190 { | 214 { |
| 191 } | 215 } |
| 192 | 216 |
| 193 } // namespace blink | 217 } // namespace blink |
| OLD | NEW |