| 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/CSSCustomPropertyDeclaration.h" |
| 11 #include "core/css/CSSPendingSubstitutionValue.h" | 12 #include "core/css/CSSPendingSubstitutionValue.h" |
| 12 #include "core/css/CSSUnsetValue.h" | 13 #include "core/css/CSSUnsetValue.h" |
| 13 #include "core/css/CSSVariableData.h" | 14 #include "core/css/CSSVariableData.h" |
| 14 #include "core/css/CSSVariableReferenceValue.h" | 15 #include "core/css/CSSVariableReferenceValue.h" |
| 15 #include "core/css/PropertyRegistry.h" | 16 #include "core/css/PropertyRegistry.h" |
| 16 #include "core/css/parser/CSSParserToken.h" | 17 #include "core/css/parser/CSSParserToken.h" |
| 17 #include "core/css/parser/CSSParserTokenRange.h" | 18 #include "core/css/parser/CSSParserTokenRange.h" |
| 18 #include "core/css/parser/CSSPropertyParser.h" | 19 #include "core/css/parser/CSSPropertyParser.h" |
| 19 #include "core/css/resolver/StyleBuilder.h" | 20 #include "core/css/resolver/StyleBuilder.h" |
| 20 #include "core/css/resolver/StyleBuilderConverter.h" | 21 #include "core/css/resolver/StyleBuilderConverter.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 PassRefPtr<CSSVariableData> CSSVariableResolver::ResolveCustomProperty( | 94 PassRefPtr<CSSVariableData> CSSVariableResolver::ResolveCustomProperty( |
| 94 AtomicString name, | 95 AtomicString name, |
| 95 const CSSVariableData& variable_data) { | 96 const CSSVariableData& variable_data) { |
| 96 DCHECK(variable_data.NeedsVariableResolution()); | 97 DCHECK(variable_data.NeedsVariableResolution()); |
| 97 | 98 |
| 98 bool disallow_animation_tainted = false; | 99 bool disallow_animation_tainted = false; |
| 99 bool is_animation_tainted = variable_data.IsAnimationTainted(); | 100 bool is_animation_tainted = variable_data.IsAnimationTainted(); |
| 100 Vector<CSSParserToken> tokens; | 101 Vector<CSSParserToken> tokens; |
| 101 Vector<String> backing_strings; | 102 Vector<String> backing_strings; |
| 102 backing_strings.AppendVector(variable_data.BackingStrings()); | 103 backing_strings.AppendVector(variable_data.BackingStrings()); |
| 104 DCHECK(!variables_seen_.Contains(name)); |
| 103 variables_seen_.insert(name); | 105 variables_seen_.insert(name); |
| 104 bool success = | 106 bool success = |
| 105 ResolveTokenRange(variable_data.Tokens(), disallow_animation_tainted, | 107 ResolveTokenRange(variable_data.Tokens(), disallow_animation_tainted, |
| 106 tokens, backing_strings, is_animation_tainted); | 108 tokens, backing_strings, is_animation_tainted); |
| 107 variables_seen_.erase(name); | 109 variables_seen_.erase(name); |
| 108 | 110 |
| 109 if (!success || !cycle_start_points_.IsEmpty()) { | 111 if (!success || !cycle_start_points_.IsEmpty()) { |
| 110 cycle_start_points_.erase(name); | 112 cycle_start_points_.erase(name); |
| 111 return nullptr; | 113 return nullptr; |
| 112 } | 114 } |
| 113 return CSSVariableData::CreateResolved(tokens, std::move(backing_strings), | 115 return CSSVariableData::CreateResolved(tokens, std::move(backing_strings), |
| 114 is_animation_tainted); | 116 is_animation_tainted); |
| 115 } | 117 } |
| 116 | 118 |
| 117 bool CSSVariableResolver::ResolveVariableReference( | 119 bool CSSVariableResolver::ResolveVariableReference( |
| 118 CSSParserTokenRange range, | 120 CSSParserTokenRange range, |
| 119 bool disallow_animation_tainted, | 121 bool disallow_animation_tainted, |
| 120 Vector<CSSParserToken>& result, | 122 Vector<CSSParserToken>& result, |
| 121 Vector<String>& result_backing_strings, | 123 Vector<String>& result_backing_strings, |
| 122 bool& result_is_animation_tainted) { | 124 bool& result_is_animation_tainted) { |
| 123 range.ConsumeWhitespace(); | 125 range.ConsumeWhitespace(); |
| 124 DCHECK_EQ(range.Peek().GetType(), kIdentToken); | 126 DCHECK_EQ(range.Peek().GetType(), kIdentToken); |
| 125 AtomicString variable_name = | 127 AtomicString variable_name = |
| 126 range.ConsumeIncludingWhitespace().Value().ToAtomicString(); | 128 range.ConsumeIncludingWhitespace().Value().ToAtomicString(); |
| 127 DCHECK(range.AtEnd() || (range.Peek().GetType() == kCommaToken)); | 129 DCHECK(range.AtEnd() || (range.Peek().GetType() == kCommaToken)); |
| 128 | 130 |
| 131 PropertyHandle property(variable_name); |
| 132 if (state_.AnimationPendingCustomProperties().Contains(property) && |
| 133 !variables_seen_.Contains(variable_name)) { |
| 134 // We make the StyleResolverState mutable for animated custom properties as |
| 135 // an optimisation. Without this we would need to compute animated values on |
| 136 // the stack without saving the result or perform an expensive and complex |
| 137 // value dependency graph analysis to compute them in the required order. |
| 138 StyleResolver::ApplyAnimatedCustomProperty( |
| 139 const_cast<StyleResolverState&>(state_), *this, property); |
| 140 // Null custom property storage may become non-null after application, we |
| 141 // must refresh these cached values. |
| 142 inherited_variables_ = state_.Style()->InheritedVariables(); |
| 143 non_inherited_variables_ = state_.Style()->NonInheritedVariables(); |
| 144 } |
| 129 CSSVariableData* variable_data = ValueForCustomProperty(variable_name); | 145 CSSVariableData* variable_data = ValueForCustomProperty(variable_name); |
| 130 if (!variable_data || | 146 if (!variable_data || |
| 131 (disallow_animation_tainted && variable_data->IsAnimationTainted())) { | 147 (disallow_animation_tainted && variable_data->IsAnimationTainted())) { |
| 132 // TODO(alancutter): Append the registered initial custom property value if | 148 // TODO(alancutter): Append the registered initial custom property value if |
| 133 // we are disallowing an animation tainted value. | 149 // we are disallowing an animation tainted value. |
| 134 return ResolveFallback(range, disallow_animation_tainted, result, | 150 return ResolveFallback(range, disallow_animation_tainted, result, |
| 135 result_backing_strings, result_is_animation_tainted); | 151 result_backing_strings, result_is_animation_tainted); |
| 136 } | 152 } |
| 137 | 153 |
| 138 result.AppendVector(variable_data->Tokens()); | 154 result.AppendVector(variable_data->Tokens()); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 292 } |
| 277 value = property_cache.at(id); | 293 value = property_cache.at(id); |
| 278 } | 294 } |
| 279 | 295 |
| 280 if (value) | 296 if (value) |
| 281 return value; | 297 return value; |
| 282 | 298 |
| 283 return CSSUnsetValue::Create(); | 299 return CSSUnsetValue::Create(); |
| 284 } | 300 } |
| 285 | 301 |
| 302 const CSSValue* |
| 303 CSSVariableResolver::ResolveRegisteredCustomPropertyAnimationKeyframe( |
| 304 const PropertyRegistration& registration, |
| 305 const CSSCustomPropertyDeclaration& keyframe) { |
| 306 DCHECK(keyframe.Value()); |
| 307 const AtomicString& name = keyframe.GetName(); |
| 308 DCHECK_EQ(registry_->Registration(name), ®istration); |
| 309 |
| 310 if (variables_seen_.Contains(name)) { |
| 311 cycle_start_points_.insert(name); |
| 312 return nullptr; |
| 313 } |
| 314 |
| 315 if (!keyframe.Value()->NeedsVariableResolution()) { |
| 316 return keyframe.Value()->ParseForSyntax(registration.Syntax()); |
| 317 } |
| 318 |
| 319 RefPtr<CSSVariableData> resolved_tokens = |
| 320 ResolveCustomProperty(name, *keyframe.Value()); |
| 321 if (!resolved_tokens) { |
| 322 return nullptr; |
| 323 } |
| 324 return resolved_tokens->ParseForSyntax(registration.Syntax()); |
| 325 } |
| 326 |
| 286 void CSSVariableResolver::ResolveVariableDefinitions() { | 327 void CSSVariableResolver::ResolveVariableDefinitions() { |
| 287 if (!inherited_variables_ && !non_inherited_variables_) | 328 if (!inherited_variables_ && !non_inherited_variables_) |
| 288 return; | 329 return; |
| 289 | 330 |
| 290 int variable_count = 0; | 331 int variable_count = 0; |
| 291 if (inherited_variables_) { | 332 if (inherited_variables_) { |
| 292 for (auto& variable : inherited_variables_->data_) | 333 for (auto& variable : inherited_variables_->data_) |
| 293 ValueForCustomProperty(variable.key); | 334 ValueForCustomProperty(variable.key); |
| 294 variable_count += inherited_variables_->data_.size(); | 335 variable_count += inherited_variables_->data_.size(); |
| 295 } | 336 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 326 } | 367 } |
| 327 } | 368 } |
| 328 | 369 |
| 329 CSSVariableResolver::CSSVariableResolver(const StyleResolverState& state) | 370 CSSVariableResolver::CSSVariableResolver(const StyleResolverState& state) |
| 330 : state_(state), | 371 : state_(state), |
| 331 inherited_variables_(state.Style()->InheritedVariables()), | 372 inherited_variables_(state.Style()->InheritedVariables()), |
| 332 non_inherited_variables_(state.Style()->NonInheritedVariables()), | 373 non_inherited_variables_(state.Style()->NonInheritedVariables()), |
| 333 registry_(state.GetDocument().GetPropertyRegistry()) {} | 374 registry_(state.GetDocument().GetPropertyRegistry()) {} |
| 334 | 375 |
| 335 } // namespace blink | 376 } // namespace blink |
| OLD | NEW |