| 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" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 RuntimeEnabledFeatures::cssApplyAtRulesEnabled()) { | 195 RuntimeEnabledFeatures::cssApplyAtRulesEnabled()) { |
| 196 ResolveApplyAtRule(range, result, result_backing_strings); | 196 ResolveApplyAtRule(range, result, result_backing_strings); |
| 197 } else { | 197 } else { |
| 198 result.push_back(range.Consume()); | 198 result.push_back(range.Consume()); |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 return success; | 201 return success; |
| 202 } | 202 } |
| 203 | 203 |
| 204 const CSSValue* CSSVariableResolver::ResolveVariableReferences( | 204 const CSSValue* CSSVariableResolver::ResolveVariableReferences( |
| 205 const StyleResolverState& state, | |
| 206 CSSPropertyID id, | 205 CSSPropertyID id, |
| 207 const CSSValue& value, | 206 const CSSValue& value, |
| 208 bool disallow_animation_tainted) { | 207 bool disallow_animation_tainted) { |
| 209 DCHECK(!isShorthandProperty(id)); | 208 DCHECK(!isShorthandProperty(id)); |
| 210 | 209 |
| 211 if (value.IsPendingSubstitutionValue()) { | 210 if (value.IsPendingSubstitutionValue()) { |
| 212 return ResolvePendingSubstitutions(state, id, | 211 return ResolvePendingSubstitutions(id, ToCSSPendingSubstitutionValue(value), |
| 213 ToCSSPendingSubstitutionValue(value), | |
| 214 disallow_animation_tainted); | 212 disallow_animation_tainted); |
| 215 } | 213 } |
| 216 | 214 |
| 217 if (value.IsVariableReferenceValue()) { | 215 if (value.IsVariableReferenceValue()) { |
| 218 return ResolveVariableReferences(state, id, | 216 return ResolveVariableReferences(id, ToCSSVariableReferenceValue(value), |
| 219 ToCSSVariableReferenceValue(value), | |
| 220 disallow_animation_tainted); | 217 disallow_animation_tainted); |
| 221 } | 218 } |
| 222 | 219 |
| 223 NOTREACHED(); | 220 NOTREACHED(); |
| 224 return nullptr; | 221 return nullptr; |
| 225 } | 222 } |
| 226 | 223 |
| 227 const CSSValue* CSSVariableResolver::ResolveVariableReferences( | 224 const CSSValue* CSSVariableResolver::ResolveVariableReferences( |
| 228 const StyleResolverState& state, | |
| 229 CSSPropertyID id, | 225 CSSPropertyID id, |
| 230 const CSSVariableReferenceValue& value, | 226 const CSSVariableReferenceValue& value, |
| 231 bool disallow_animation_tainted) { | 227 bool disallow_animation_tainted) { |
| 232 CSSVariableResolver resolver(state); | |
| 233 Vector<CSSParserToken> tokens; | 228 Vector<CSSParserToken> tokens; |
| 234 Vector<String> backing_strings; | 229 Vector<String> backing_strings; |
| 235 bool is_animation_tainted = false; | 230 bool is_animation_tainted = false; |
| 236 if (!resolver.ResolveTokenRange(value.VariableDataValue()->Tokens(), | 231 if (!ResolveTokenRange(value.VariableDataValue()->Tokens(), |
| 237 disallow_animation_tainted, tokens, | 232 disallow_animation_tainted, tokens, backing_strings, |
| 238 backing_strings, is_animation_tainted)) | 233 is_animation_tainted)) { |
| 239 return CSSUnsetValue::Create(); | 234 return CSSUnsetValue::Create(); |
| 235 } |
| 240 const CSSValue* result = | 236 const CSSValue* result = |
| 241 CSSPropertyParser::ParseSingleValue(id, tokens, value.ParserContext()); | 237 CSSPropertyParser::ParseSingleValue(id, tokens, value.ParserContext()); |
| 242 if (!result) | 238 if (!result) |
| 243 return CSSUnsetValue::Create(); | 239 return CSSUnsetValue::Create(); |
| 244 return result; | 240 return result; |
| 245 } | 241 } |
| 246 | 242 |
| 247 const CSSValue* CSSVariableResolver::ResolvePendingSubstitutions( | 243 const CSSValue* CSSVariableResolver::ResolvePendingSubstitutions( |
| 248 const StyleResolverState& state, | |
| 249 CSSPropertyID id, | 244 CSSPropertyID id, |
| 250 const CSSPendingSubstitutionValue& pending_value, | 245 const CSSPendingSubstitutionValue& pending_value, |
| 251 bool disallow_animation_tainted) { | 246 bool disallow_animation_tainted) { |
| 252 // Longhands from shorthand references follow this path. | 247 // Longhands from shorthand references follow this path. |
| 253 HeapHashMap<CSSPropertyID, Member<const CSSValue>>& property_cache = | 248 HeapHashMap<CSSPropertyID, Member<const CSSValue>>& property_cache = |
| 254 state.ParsedPropertiesForPendingSubstitutionCache(pending_value); | 249 state_.ParsedPropertiesForPendingSubstitutionCache(pending_value); |
| 255 | 250 |
| 256 const CSSValue* value = property_cache.at(id); | 251 const CSSValue* value = property_cache.at(id); |
| 257 if (!value) { | 252 if (!value) { |
| 258 // TODO(timloh): We shouldn't retry this for all longhands if the shorthand | 253 // TODO(timloh): We shouldn't retry this for all longhands if the shorthand |
| 259 // ends up invalid. | 254 // ends up invalid. |
| 260 CSSVariableReferenceValue* shorthand_value = pending_value.ShorthandValue(); | 255 CSSVariableReferenceValue* shorthand_value = pending_value.ShorthandValue(); |
| 261 CSSPropertyID shorthand_property_id = pending_value.ShorthandPropertyId(); | 256 CSSPropertyID shorthand_property_id = pending_value.ShorthandPropertyId(); |
| 262 | 257 |
| 263 CSSVariableResolver resolver(state); | |
| 264 | |
| 265 Vector<CSSParserToken> tokens; | 258 Vector<CSSParserToken> tokens; |
| 266 Vector<String> backing_strings; | 259 Vector<String> backing_strings; |
| 267 bool is_animation_tainted = false; | 260 bool is_animation_tainted = false; |
| 268 if (resolver.ResolveTokenRange( | 261 if (ResolveTokenRange(shorthand_value->VariableDataValue()->Tokens(), |
| 269 shorthand_value->VariableDataValue()->Tokens(), | 262 disallow_animation_tainted, tokens, backing_strings, |
| 270 disallow_animation_tainted, tokens, backing_strings, | 263 is_animation_tainted)) { |
| 271 is_animation_tainted)) { | |
| 272 HeapVector<CSSProperty, 256> parsed_properties; | 264 HeapVector<CSSProperty, 256> parsed_properties; |
| 273 | 265 |
| 274 if (CSSPropertyParser::ParseValue( | 266 if (CSSPropertyParser::ParseValue( |
| 275 shorthand_property_id, false, CSSParserTokenRange(tokens), | 267 shorthand_property_id, false, CSSParserTokenRange(tokens), |
| 276 shorthand_value->ParserContext(), parsed_properties, | 268 shorthand_value->ParserContext(), parsed_properties, |
| 277 StyleRule::RuleType::kStyle)) { | 269 StyleRule::RuleType::kStyle)) { |
| 278 unsigned parsed_properties_count = parsed_properties.size(); | 270 unsigned parsed_properties_count = parsed_properties.size(); |
| 279 for (unsigned i = 0; i < parsed_properties_count; ++i) { | 271 for (unsigned i = 0; i < parsed_properties_count; ++i) { |
| 280 property_cache.Set(parsed_properties[i].Id(), | 272 property_cache.Set(parsed_properties[i].Id(), |
| 281 parsed_properties[i].Value()); | 273 parsed_properties[i].Value()); |
| 282 } | 274 } |
| 283 } | 275 } |
| 284 } | 276 } |
| 285 value = property_cache.at(id); | 277 value = property_cache.at(id); |
| 286 } | 278 } |
| 287 | 279 |
| 288 if (value) | 280 if (value) |
| 289 return value; | 281 return value; |
| 290 | 282 |
| 291 return CSSUnsetValue::Create(); | 283 return CSSUnsetValue::Create(); |
| 292 } | 284 } |
| 293 | 285 |
| 294 void CSSVariableResolver::ResolveVariableDefinitions( | 286 void CSSVariableResolver::ResolveVariableDefinitions() { |
| 295 const StyleResolverState& state) { | 287 if (!inherited_variables_ && !non_inherited_variables_) |
| 296 StyleInheritedVariables* inherited_variables = | |
| 297 state.Style()->InheritedVariables(); | |
| 298 StyleNonInheritedVariables* non_inherited_variables = | |
| 299 state.Style()->NonInheritedVariables(); | |
| 300 if (!inherited_variables && !non_inherited_variables) | |
| 301 return; | 288 return; |
| 302 | 289 |
| 303 CSSVariableResolver resolver(state); | |
| 304 int variable_count = 0; | 290 int variable_count = 0; |
| 305 if (inherited_variables) { | 291 if (inherited_variables_) { |
| 306 for (auto& variable : inherited_variables->data_) | 292 for (auto& variable : inherited_variables_->data_) |
| 307 resolver.ValueForCustomProperty(variable.key); | 293 ValueForCustomProperty(variable.key); |
| 308 variable_count += inherited_variables->data_.size(); | 294 variable_count += inherited_variables_->data_.size(); |
| 309 } | 295 } |
| 310 if (non_inherited_variables) { | 296 if (non_inherited_variables_) { |
| 311 for (auto& variable : non_inherited_variables->data_) | 297 for (auto& variable : non_inherited_variables_->data_) |
| 312 resolver.ValueForCustomProperty(variable.key); | 298 ValueForCustomProperty(variable.key); |
| 313 variable_count += non_inherited_variables->data_.size(); | 299 variable_count += non_inherited_variables_->data_.size(); |
| 314 } | 300 } |
| 315 INCREMENT_STYLE_STATS_COUNTER(state.GetDocument().GetStyleEngine(), | 301 INCREMENT_STYLE_STATS_COUNTER(state_.GetDocument().GetStyleEngine(), |
| 316 custom_properties_applied, variable_count); | 302 custom_properties_applied, variable_count); |
| 317 } | 303 } |
| 318 | 304 |
| 319 void CSSVariableResolver::ComputeRegisteredVariables( | 305 void CSSVariableResolver::ComputeRegisteredVariables() { |
| 320 const StyleResolverState& state) { | |
| 321 // const_cast is needed because Persistent<const ...> doesn't work properly. | 306 // const_cast is needed because Persistent<const ...> doesn't work properly. |
| 322 | 307 |
| 323 StyleInheritedVariables* inherited_variables = | 308 if (inherited_variables_) { |
| 324 state.Style()->InheritedVariables(); | 309 for (auto& variable : inherited_variables_->registered_data_) { |
| 325 if (inherited_variables) { | |
| 326 for (auto& variable : inherited_variables->registered_data_) { | |
| 327 if (variable.value) { | 310 if (variable.value) { |
| 328 variable.value = const_cast<CSSValue*>( | 311 variable.value = const_cast<CSSValue*>( |
| 329 &StyleBuilderConverter::ConvertRegisteredPropertyValue( | 312 &StyleBuilderConverter::ConvertRegisteredPropertyValue( |
| 330 state, *variable.value)); | 313 state_, *variable.value)); |
| 331 } | 314 } |
| 332 } | 315 } |
| 333 } | 316 } |
| 334 | 317 |
| 335 StyleNonInheritedVariables* non_inherited_variables = | 318 if (non_inherited_variables_) { |
| 336 state.Style()->NonInheritedVariables(); | 319 for (auto& variable : non_inherited_variables_->registered_data_) { |
| 337 if (non_inherited_variables) { | |
| 338 for (auto& variable : non_inherited_variables->registered_data_) { | |
| 339 if (variable.value) { | 320 if (variable.value) { |
| 340 variable.value = const_cast<CSSValue*>( | 321 variable.value = const_cast<CSSValue*>( |
| 341 &StyleBuilderConverter::ConvertRegisteredPropertyValue( | 322 &StyleBuilderConverter::ConvertRegisteredPropertyValue( |
| 342 state, *variable.value)); | 323 state_, *variable.value)); |
| 343 } | 324 } |
| 344 } | 325 } |
| 345 } | 326 } |
| 346 } | 327 } |
| 347 | 328 |
| 348 CSSVariableResolver::CSSVariableResolver(const StyleResolverState& state) | 329 CSSVariableResolver::CSSVariableResolver(const StyleResolverState& state) |
| 349 : inherited_variables_(state.Style()->InheritedVariables()), | 330 : state_(state), |
| 331 inherited_variables_(state.Style()->InheritedVariables()), |
| 350 non_inherited_variables_(state.Style()->NonInheritedVariables()), | 332 non_inherited_variables_(state.Style()->NonInheritedVariables()), |
| 351 registry_(state.GetDocument().GetPropertyRegistry()) {} | 333 registry_(state.GetDocument().GetPropertyRegistry()) {} |
| 352 | 334 |
| 353 } // namespace blink | 335 } // namespace blink |
| OLD | NEW |