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 15 matching lines...) Loading... |
26 #include "wtf/Vector.h" | 26 #include "wtf/Vector.h" |
27 | 27 |
28 namespace blink { | 28 namespace blink { |
29 | 29 |
30 bool CSSVariableResolver::resolveFallback(CSSParserTokenRange range, | 30 bool CSSVariableResolver::resolveFallback(CSSParserTokenRange range, |
31 bool disallowAnimationTainted, | 31 bool disallowAnimationTainted, |
32 Vector<CSSParserToken>& result, | 32 Vector<CSSParserToken>& result, |
33 bool& resultIsAnimationTainted) { | 33 bool& resultIsAnimationTainted) { |
34 if (range.atEnd()) | 34 if (range.atEnd()) |
35 return false; | 35 return false; |
36 ASSERT(range.peek().type() == CommaToken); | 36 DCHECK_EQ(range.peek().type(), CommaToken); |
37 range.consume(); | 37 range.consume(); |
38 return resolveTokenRange(range, disallowAnimationTainted, result, | 38 return resolveTokenRange(range, disallowAnimationTainted, result, |
39 resultIsAnimationTainted); | 39 resultIsAnimationTainted); |
40 } | 40 } |
41 | 41 |
42 CSSVariableData* CSSVariableResolver::valueForCustomProperty( | 42 CSSVariableData* CSSVariableResolver::valueForCustomProperty( |
43 AtomicString name) { | 43 AtomicString name) { |
44 if (m_variablesSeen.contains(name)) { | 44 if (m_variablesSeen.contains(name)) { |
45 m_cycleStartPoints.insert(name); | 45 m_cycleStartPoints.insert(name); |
46 return nullptr; | 46 return nullptr; |
(...skipping 37 matching lines...) Loading... |
84 m_nonInheritedVariables->setRegisteredVariable(name, parsedValue); | 84 m_nonInheritedVariables->setRegisteredVariable(name, parsedValue); |
85 } | 85 } |
86 if (!newVariableData) | 86 if (!newVariableData) |
87 return registration->initialVariableData(); | 87 return registration->initialVariableData(); |
88 return newVariableData.get(); | 88 return newVariableData.get(); |
89 } | 89 } |
90 | 90 |
91 PassRefPtr<CSSVariableData> CSSVariableResolver::resolveCustomProperty( | 91 PassRefPtr<CSSVariableData> CSSVariableResolver::resolveCustomProperty( |
92 AtomicString name, | 92 AtomicString name, |
93 const CSSVariableData& variableData) { | 93 const CSSVariableData& variableData) { |
94 ASSERT(variableData.needsVariableResolution()); | 94 DCHECK(variableData.needsVariableResolution()); |
95 | 95 |
96 bool disallowAnimationTainted = false; | 96 bool disallowAnimationTainted = false; |
97 bool isAnimationTainted = variableData.isAnimationTainted(); | 97 bool isAnimationTainted = variableData.isAnimationTainted(); |
98 Vector<CSSParserToken> tokens; | 98 Vector<CSSParserToken> tokens; |
99 m_variablesSeen.insert(name); | 99 m_variablesSeen.insert(name); |
100 bool success = | 100 bool success = |
101 resolveTokenRange(variableData.tokens(), disallowAnimationTainted, tokens, | 101 resolveTokenRange(variableData.tokens(), disallowAnimationTainted, tokens, |
102 isAnimationTainted); | 102 isAnimationTainted); |
103 m_variablesSeen.erase(name); | 103 m_variablesSeen.erase(name); |
104 | 104 |
105 // The old variable data holds onto the backing string the new resolved | 105 // The old variable data holds onto the backing string the new resolved |
106 // CSSVariableData relies on. Ensure it will live beyond us overwriting the | 106 // CSSVariableData relies on. Ensure it will live beyond us overwriting the |
107 // RefPtr in StyleInheritedVariables. | 107 // RefPtr in StyleInheritedVariables. |
108 ASSERT(variableData.refCount() > 1); | 108 DCHECK_GT(variableData.refCount(), 1); |
109 | 109 |
110 if (!success || !m_cycleStartPoints.isEmpty()) { | 110 if (!success || !m_cycleStartPoints.isEmpty()) { |
111 m_cycleStartPoints.erase(name); | 111 m_cycleStartPoints.erase(name); |
112 return nullptr; | 112 return nullptr; |
113 } | 113 } |
114 return CSSVariableData::createResolved(tokens, variableData, | 114 return CSSVariableData::createResolved(tokens, variableData, |
115 isAnimationTainted); | 115 isAnimationTainted); |
116 } | 116 } |
117 | 117 |
118 bool CSSVariableResolver::resolveVariableReference( | 118 bool CSSVariableResolver::resolveVariableReference( |
119 CSSParserTokenRange range, | 119 CSSParserTokenRange range, |
120 bool disallowAnimationTainted, | 120 bool disallowAnimationTainted, |
121 Vector<CSSParserToken>& result, | 121 Vector<CSSParserToken>& result, |
122 bool& resultIsAnimationTainted) { | 122 bool& resultIsAnimationTainted) { |
123 range.consumeWhitespace(); | 123 range.consumeWhitespace(); |
124 ASSERT(range.peek().type() == IdentToken); | 124 DCHECK_EQ(range.peek().type(), IdentToken); |
125 AtomicString variableName = | 125 AtomicString variableName = |
126 range.consumeIncludingWhitespace().value().toAtomicString(); | 126 range.consumeIncludingWhitespace().value().toAtomicString(); |
127 ASSERT(range.atEnd() || (range.peek().type() == CommaToken)); | 127 DCHECK(range.atEnd() || (range.peek().type() == CommaToken)); |
128 | 128 |
129 CSSVariableData* variableData = valueForCustomProperty(variableName); | 129 CSSVariableData* variableData = valueForCustomProperty(variableName); |
130 if (!variableData || | 130 if (!variableData || |
131 (disallowAnimationTainted && variableData->isAnimationTainted())) { | 131 (disallowAnimationTainted && variableData->isAnimationTainted())) { |
132 // TODO(alancutter): Append the registered initial custom property value if | 132 // TODO(alancutter): Append the registered initial custom property value if |
133 // we are disallowing an animation tainted value. | 133 // we are disallowing an animation tainted value. |
134 return resolveFallback(range, disallowAnimationTainted, result, | 134 return resolveFallback(range, disallowAnimationTainted, result, |
135 resultIsAnimationTainted); | 135 resultIsAnimationTainted); |
136 } | 136 } |
137 | 137 |
(...skipping 53 matching lines...) Loading... |
191 } | 191 } |
192 } | 192 } |
193 return success; | 193 return success; |
194 } | 194 } |
195 | 195 |
196 const CSSValue* CSSVariableResolver::resolveVariableReferences( | 196 const CSSValue* CSSVariableResolver::resolveVariableReferences( |
197 const StyleResolverState& state, | 197 const StyleResolverState& state, |
198 CSSPropertyID id, | 198 CSSPropertyID id, |
199 const CSSValue& value, | 199 const CSSValue& value, |
200 bool disallowAnimationTainted) { | 200 bool disallowAnimationTainted) { |
201 ASSERT(!isShorthandProperty(id)); | 201 DCHECK(!isShorthandProperty(id)); |
202 | 202 |
203 if (value.isPendingSubstitutionValue()) { | 203 if (value.isPendingSubstitutionValue()) { |
204 return resolvePendingSubstitutions(state, id, | 204 return resolvePendingSubstitutions(state, id, |
205 toCSSPendingSubstitutionValue(value), | 205 toCSSPendingSubstitutionValue(value), |
206 disallowAnimationTainted); | 206 disallowAnimationTainted); |
207 } | 207 } |
208 | 208 |
209 if (value.isVariableReferenceValue()) { | 209 if (value.isVariableReferenceValue()) { |
210 return resolveVariableReferences(state, id, | 210 return resolveVariableReferences(state, id, |
211 toCSSVariableReferenceValue(value), | 211 toCSSVariableReferenceValue(value), |
(...skipping 122 matching lines...) Loading... |
334 } | 334 } |
335 } | 335 } |
336 } | 336 } |
337 | 337 |
338 CSSVariableResolver::CSSVariableResolver(const StyleResolverState& state) | 338 CSSVariableResolver::CSSVariableResolver(const StyleResolverState& state) |
339 : m_inheritedVariables(state.style()->inheritedVariables()), | 339 : m_inheritedVariables(state.style()->inheritedVariables()), |
340 m_nonInheritedVariables(state.style()->nonInheritedVariables()), | 340 m_nonInheritedVariables(state.style()->nonInheritedVariables()), |
341 m_registry(state.document().propertyRegistry()) {} | 341 m_registry(state.document().propertyRegistry()) {} |
342 | 342 |
343 } // namespace blink | 343 } // namespace blink |
OLD | NEW |