| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 RefPtr<CSSVariableData> newVariableData = | 63 RefPtr<CSSVariableData> newVariableData = |
| 64 resolveCustomProperty(name, *variableData); | 64 resolveCustomProperty(name, *variableData); |
| 65 if (!registration) { | 65 if (!registration) { |
| 66 m_inheritedVariables->setVariable(name, newVariableData); | 66 m_inheritedVariables->setVariable(name, newVariableData); |
| 67 return newVariableData.get(); | 67 return newVariableData.get(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 const CSSValue* parsedValue = nullptr; | 70 const CSSValue* parsedValue = nullptr; |
| 71 if (newVariableData) { | 71 if (newVariableData) { |
| 72 parsedValue = newVariableData->parseForSyntax(registration->syntax()); | 72 parsedValue = newVariableData->parseForSyntax(registration->syntax()); |
| 73 if (parsedValue) | 73 if (!parsedValue) |
| 74 parsedValue = &StyleBuilderConverter::convertRegisteredPropertyValue( | |
| 75 m_styleResolverState, *parsedValue); | |
| 76 else | |
| 77 newVariableData = nullptr; | 74 newVariableData = nullptr; |
| 78 } | 75 } |
| 79 if (registration->inherits()) { | 76 if (registration->inherits()) { |
| 80 m_inheritedVariables->setVariable(name, newVariableData); | 77 m_inheritedVariables->setVariable(name, newVariableData); |
| 81 m_inheritedVariables->setRegisteredVariable(name, parsedValue); | 78 m_inheritedVariables->setRegisteredVariable(name, parsedValue); |
| 82 } else { | 79 } else { |
| 83 m_nonInheritedVariables->setVariable(name, newVariableData); | 80 m_nonInheritedVariables->setVariable(name, newVariableData); |
| 84 m_nonInheritedVariables->setRegisteredVariable(name, parsedValue); | 81 m_nonInheritedVariables->setRegisteredVariable(name, parsedValue); |
| 85 } | 82 } |
| 86 if (!newVariableData) | 83 if (!newVariableData) |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 if (inheritedVariables) { | 291 if (inheritedVariables) { |
| 295 for (auto& variable : inheritedVariables->m_data) | 292 for (auto& variable : inheritedVariables->m_data) |
| 296 resolver.valueForCustomProperty(variable.key); | 293 resolver.valueForCustomProperty(variable.key); |
| 297 } | 294 } |
| 298 if (nonInheritedVariables) { | 295 if (nonInheritedVariables) { |
| 299 for (auto& variable : nonInheritedVariables->m_data) | 296 for (auto& variable : nonInheritedVariables->m_data) |
| 300 resolver.valueForCustomProperty(variable.key); | 297 resolver.valueForCustomProperty(variable.key); |
| 301 } | 298 } |
| 302 } | 299 } |
| 303 | 300 |
| 301 void CSSVariableResolver::computeRegisteredVariables( |
| 302 const StyleResolverState& state) { |
| 303 // const_cast is needed because Persistent<const ...> doesn't work properly. |
| 304 |
| 305 StyleInheritedVariables* inheritedVariables = |
| 306 state.style()->inheritedVariables(); |
| 307 if (inheritedVariables) { |
| 308 for (auto& variable : inheritedVariables->m_registeredData) { |
| 309 if (variable.value) { |
| 310 variable.value = const_cast<CSSValue*>( |
| 311 &StyleBuilderConverter::convertRegisteredPropertyValue( |
| 312 state, *variable.value)); |
| 313 } |
| 314 } |
| 315 } |
| 316 |
| 317 StyleNonInheritedVariables* nonInheritedVariables = |
| 318 state.style()->nonInheritedVariables(); |
| 319 if (nonInheritedVariables) { |
| 320 for (auto& variable : nonInheritedVariables->m_registeredData) { |
| 321 if (variable.value) { |
| 322 variable.value = const_cast<CSSValue*>( |
| 323 &StyleBuilderConverter::convertRegisteredPropertyValue( |
| 324 state, *variable.value)); |
| 325 } |
| 326 } |
| 327 } |
| 328 } |
| 329 |
| 304 CSSVariableResolver::CSSVariableResolver(const StyleResolverState& state) | 330 CSSVariableResolver::CSSVariableResolver(const StyleResolverState& state) |
| 305 : m_styleResolverState(state), | 331 : m_inheritedVariables(state.style()->inheritedVariables()), |
| 306 m_inheritedVariables(state.style()->inheritedVariables()), | |
| 307 m_nonInheritedVariables(state.style()->nonInheritedVariables()), | 332 m_nonInheritedVariables(state.style()->nonInheritedVariables()), |
| 308 m_registry(state.document().propertyRegistry()) {} | 333 m_registry(state.document().propertyRegistry()) {} |
| 309 | 334 |
| 310 DEFINE_TRACE(CSSVariableResolver) { | 335 DEFINE_TRACE(CSSVariableResolver) { |
| 311 visitor->trace(m_registry); | 336 visitor->trace(m_registry); |
| 312 } | 337 } |
| 313 | 338 |
| 314 } // namespace blink | 339 } // namespace blink |
| OLD | NEW |