Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 28 { | 28 { |
| 29 if (range.atEnd()) | 29 if (range.atEnd()) |
| 30 return false; | 30 return false; |
| 31 ASSERT(range.peek().type() == CommaToken); | 31 ASSERT(range.peek().type() == CommaToken); |
| 32 range.consume(); | 32 range.consume(); |
| 33 return resolveTokenRange(range, result); | 33 return resolveTokenRange(range, result); |
| 34 } | 34 } |
| 35 | 35 |
| 36 CSSVariableData* CSSVariableResolver::valueForCustomProperty(AtomicString name) | 36 CSSVariableData* CSSVariableResolver::valueForCustomProperty(AtomicString name) |
| 37 { | 37 { |
| 38 // TODO(timloh): Registered properties shouldn't return nullptr in failure | |
| 39 // cases (aside from cycles?), but instead return the initial/inherited valu e. | |
| 40 if (m_variablesSeen.contains(name)) { | 38 if (m_variablesSeen.contains(name)) { |
| 41 m_cycleStartPoints.add(name); | 39 m_cycleStartPoints.add(name); |
| 42 return nullptr; | 40 return nullptr; |
| 43 } | 41 } |
| 44 | 42 |
| 45 if (!m_styleVariableData) | 43 DCHECK(m_registry || !RuntimeEnabledFeatures::cssVariables2Enabled()); |
| 46 return nullptr; | 44 const PropertyRegistry::Registration* registration = m_registry ? m_registry ->registration(name) : nullptr; |
| 47 CSSVariableData* variableData = m_styleVariableData->getVariable(name); | 45 |
| 46 CSSVariableData* variableData = nullptr; | |
| 47 if (m_styleVariableData) | |
| 48 variableData = m_styleVariableData->getVariable(name); | |
| 48 if (!variableData) | 49 if (!variableData) |
| 49 return nullptr; | 50 return registration ? registration->initialVariableData() : nullptr; |
| 50 if (!variableData->needsVariableResolution()) | 51 if (!variableData->needsVariableResolution()) |
| 51 return variableData; | 52 return variableData; |
| 53 | |
| 52 RefPtr<CSSVariableData> newVariableData = resolveCustomProperty(name, *varia bleData); | 54 RefPtr<CSSVariableData> newVariableData = resolveCustomProperty(name, *varia bleData); |
| 53 | 55 if (registration) { |
| 54 DCHECK(m_registry || !RuntimeEnabledFeatures::cssVariables2Enabled()); | 56 const CSSValue* parsedValue = nullptr; |
| 55 if (m_registry) { | 57 if (newVariableData) { |
| 56 const PropertyRegistry::Registration* registration = m_registry->registr ation(name); | 58 parsedValue = newVariableData->parseForSyntax(registration->syntax() ); |
| 57 if (registration) { | 59 if (parsedValue) |
| 58 const CSSValue* parsedValue = nullptr; | 60 parsedValue = &StyleBuilderConverter::convertRegisteredPropertyV alue(m_styleResolverState, *parsedValue); |
| 59 if (newVariableData) { | 61 else |
| 60 parsedValue = newVariableData->parseForSyntax(registration->synt ax()); | 62 newVariableData = nullptr; |
| 61 if (parsedValue) | |
| 62 parsedValue = &StyleBuilderConverter::convertRegisteredPrope rtyValue(m_styleResolverState, *parsedValue); | |
| 63 else | |
| 64 newVariableData = nullptr; | |
| 65 } | |
| 66 m_styleVariableData->setVariable(name, newVariableData); | |
| 67 m_styleVariableData->setRegisteredInheritedProperty(name, parsedValu e); | |
| 68 return newVariableData.get(); | |
| 69 } | 63 } |
| 64 m_styleVariableData->setVariable(name, newVariableData); | |
| 65 m_styleVariableData->setRegisteredInheritedProperty(name, parsedValue); | |
| 66 if (!newVariableData) | |
| 67 return registration->initialVariableData(); | |
|
Timothy Loh
2016/09/22 10:01:25
We could alternatively set the initial values into
meade_UTC10
2016/09/23 01:16:50
seems fine as is.
| |
| 68 return newVariableData.get(); | |
| 70 } | 69 } |
| 71 | 70 |
| 72 m_styleVariableData->setVariable(name, newVariableData); | 71 m_styleVariableData->setVariable(name, newVariableData); |
| 73 return newVariableData.get(); | 72 return newVariableData.get(); |
| 74 } | 73 } |
| 75 | 74 |
| 76 PassRefPtr<CSSVariableData> CSSVariableResolver::resolveCustomProperty(AtomicStr ing name, const CSSVariableData& variableData) | 75 PassRefPtr<CSSVariableData> CSSVariableResolver::resolveCustomProperty(AtomicStr ing name, const CSSVariableData& variableData) |
| 77 { | 76 { |
| 78 ASSERT(variableData.needsVariableResolution()); | 77 ASSERT(variableData.needsVariableResolution()); |
| 79 | 78 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 CSSVariableResolver::CSSVariableResolver(const StyleResolverState& state) | 228 CSSVariableResolver::CSSVariableResolver(const StyleResolverState& state) |
| 230 : m_styleResolverState(state) | 229 : m_styleResolverState(state) |
| 231 , m_styleVariableData(state.style()->variables()) | 230 , m_styleVariableData(state.style()->variables()) |
| 232 , m_registry(state.document().propertyRegistry()) | 231 , m_registry(state.document().propertyRegistry()) |
| 233 { | 232 { |
| 234 } | 233 } |
| 235 | 234 |
| 236 DEFINE_TRACE(CSSVariableResolver) { visitor->trace(m_registry); } | 235 DEFINE_TRACE(CSSVariableResolver) { visitor->trace(m_registry); } |
| 237 | 236 |
| 238 } // namespace blink | 237 } // namespace blink |
| OLD | NEW |