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" |
13 #include "core/css/CSSValuePool.h" | |
Timothy Loh
2016/06/27 04:19:09
unneeded
Andy Mutton
2016/06/28 03:18:51
Done.
| |
12 #include "core/css/CSSVariableData.h" | 14 #include "core/css/CSSVariableData.h" |
13 #include "core/css/CSSVariableReferenceValue.h" | 15 #include "core/css/CSSVariableReferenceValue.h" |
14 #include "core/css/parser/CSSParserToken.h" | 16 #include "core/css/parser/CSSParserToken.h" |
15 #include "core/css/parser/CSSParserTokenRange.h" | 17 #include "core/css/parser/CSSParserTokenRange.h" |
16 #include "core/css/parser/CSSPropertyParser.h" | 18 #include "core/css/parser/CSSPropertyParser.h" |
17 #include "core/css/resolver/StyleBuilder.h" | 19 #include "core/css/resolver/StyleBuilder.h" |
18 #include "core/css/resolver/StyleResolverState.h" | 20 #include "core/css/resolver/StyleResolverState.h" |
19 #include "core/style/StyleVariableData.h" | 21 #include "core/style/StyleVariableData.h" |
20 #include "wtf/Vector.h" | 22 #include "wtf/Vector.h" |
21 | 23 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 CSSVariableResolver resolver(styleVariableData); | 138 CSSVariableResolver resolver(styleVariableData); |
137 Vector<CSSParserToken> tokens; | 139 Vector<CSSParserToken> tokens; |
138 if (!resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens) ) | 140 if (!resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens) ) |
139 return CSSUnsetValue::create(); | 141 return CSSUnsetValue::create(); |
140 CSSValue* result = CSSPropertyParser::parseSingleValue(id, tokens, strictCSS ParserContext()); | 142 CSSValue* result = CSSPropertyParser::parseSingleValue(id, tokens, strictCSS ParserContext()); |
141 if (!result) | 143 if (!result) |
142 return CSSUnsetValue::create(); | 144 return CSSUnsetValue::create(); |
143 return result; | 145 return result; |
144 } | 146 } |
145 | 147 |
146 void CSSVariableResolver::resolveAndApplyVariableReferences(StyleResolverState& state, CSSPropertyID id, const CSSVariableReferenceValue& value) | 148 const CSSValue* CSSVariableResolver::resolveVariableReferences(StyleResolverStat e& state, CSSPropertyID id, const CSSVariableReferenceValue& value) |
147 { | 149 { |
150 // Non-shorthand variable references follow this path. | |
148 CSSVariableResolver resolver(state.style()->variables()); | 151 CSSVariableResolver resolver(state.style()->variables()); |
149 | 152 |
150 Vector<CSSParserToken> tokens; | 153 Vector<CSSParserToken> tokens; |
151 if (resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens)) { | 154 if (resolver.resolveTokenRange(value.variableDataValue()->tokens(), tokens)) { |
152 CSSParserContext context(HTMLStandardMode, 0); | 155 CSSParserContext context(HTMLStandardMode, 0); |
153 | 156 |
154 HeapVector<CSSProperty, 256> parsedProperties; | 157 CSSValue* value = CSSPropertyParser::parseSingleValue(id, CSSParserToken Range(tokens), context); |
155 | 158 if (value) |
156 // TODO: Non-shorthands should just call CSSPropertyParser::parseSingleV alue | 159 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 } | 160 } |
164 | 161 |
165 CSSUnsetValue* unset = CSSUnsetValue::create(); | 162 return CSSUnsetValue::create(); |
166 if (isShorthandProperty(id)) { | 163 } |
167 StylePropertyShorthand shorthand = shorthandForProperty(id); | 164 |
168 for (unsigned i = 0; i < shorthand.length(); i++) | 165 const CSSValue* CSSVariableResolver::resolvePendingSubstitutions(StyleResolverSt ate& state, CSSPropertyID id, const CSSPendingSubstitutionValue& pendingValue) |
169 StyleBuilder::applyProperty(shorthand.properties()[i], state, *unset ); | 166 { |
170 return; | 167 // Longhands from shorthand references follow this path. |
168 HeapHashMap<CSSPropertyID, Member<const CSSValue>>& propertyCache = state.pa rsedPropertiesForPendingSubstitution(pendingValue); | |
169 | |
170 const CSSValue* value = propertyCache.get(id); | |
171 if (!value) { | |
172 // 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)
| |
173 CSSVariableReferenceValue* shorthandValue = pendingValue.shorthandValue( ); | |
174 CSSPropertyID shorthandPropertyId = pendingValue.shorthandPropertyId(); | |
175 | |
176 CSSVariableResolver resolver(state.style()->variables()); | |
177 | |
178 Vector<CSSParserToken> tokens; | |
179 if (resolver.resolveTokenRange(shorthandValue->variableDataValue()->toke ns(), tokens)) { | |
180 CSSParserContext context(HTMLStandardMode, 0); | |
181 | |
182 HeapVector<CSSProperty, 256> parsedProperties; | |
183 | |
184 if (CSSPropertyParser::parseValue(shorthandPropertyId, false, CSSPar serTokenRange(tokens), context, parsedProperties, StyleRule::RuleType::Style)) { | |
185 unsigned parsedPropertiesCount = parsedProperties.size(); | |
186 for (unsigned i = 0; i < parsedPropertiesCount; ++i) { | |
187 propertyCache.set(parsedProperties[i].id(), parsedProperties [i].value()); | |
188 } | |
189 } | |
190 } | |
191 value = propertyCache.get(id); | |
171 } | 192 } |
172 | 193 |
173 StyleBuilder::applyProperty(id, state, *unset); | 194 if (value) |
195 return value; | |
196 | |
197 return CSSUnsetValue::create(); | |
174 } | 198 } |
175 | 199 |
200 | |
176 void CSSVariableResolver::resolveVariableDefinitions(StyleVariableData* variable s) | 201 void CSSVariableResolver::resolveVariableDefinitions(StyleVariableData* variable s) |
177 { | 202 { |
178 if (!variables) | 203 if (!variables) |
179 return; | 204 return; |
180 | 205 |
181 CSSVariableResolver resolver(variables); | 206 CSSVariableResolver resolver(variables); |
182 for (auto& variable : variables->m_data) { | 207 for (auto& variable : variables->m_data) { |
183 if (variable.value && variable.value->needsVariableResolution()) | 208 if (variable.value && variable.value->needsVariableResolution()) |
184 variable.value = resolver.resolveCustomProperty(variable.key, *varia ble.value); | 209 variable.value = resolver.resolveCustomProperty(variable.key, *varia ble.value); |
185 } | 210 } |
186 } | 211 } |
187 | 212 |
188 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData) | 213 CSSVariableResolver::CSSVariableResolver(StyleVariableData* styleVariableData) |
189 : m_styleVariableData(styleVariableData) | 214 : m_styleVariableData(styleVariableData) |
190 { | 215 { |
191 } | 216 } |
192 | 217 |
193 } // namespace blink | 218 } // namespace blink |
OLD | NEW |