OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/animation/CSSInterpolationType.h" | 5 #include "core/animation/CSSInterpolationType.h" |
6 | 6 |
7 #include "core/StylePropertyShorthand.h" | 7 #include "core/StylePropertyShorthand.h" |
8 #include "core/animation/StringKeyframe.h" | 8 #include "core/animation/StringKeyframe.h" |
9 #include "core/css/CSSCustomPropertyDeclaration.h" | 9 #include "core/css/CSSCustomPropertyDeclaration.h" |
10 #include "core/css/CSSValue.h" | 10 #include "core/css/CSSValue.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 m_initialValue(initialValue) {} | 80 m_initialValue(initialValue) {} |
81 | 81 |
82 bool isValid(const InterpolationEnvironment& environment, | 82 bool isValid(const InterpolationEnvironment& environment, |
83 const InterpolationValue&) const final { | 83 const InterpolationValue&) const final { |
84 const CSSValue* inheritedValue = | 84 const CSSValue* inheritedValue = |
85 environment.state().parentStyle()->getRegisteredVariable( | 85 environment.state().parentStyle()->getRegisteredVariable( |
86 m_name, m_isInheritedProperty); | 86 m_name, m_isInheritedProperty); |
87 if (!inheritedValue) { | 87 if (!inheritedValue) { |
88 inheritedValue = m_initialValue.get(); | 88 inheritedValue = m_initialValue.get(); |
89 } | 89 } |
| 90 if (inheritedValue == m_inheritedValue.get()) { |
| 91 return true; |
| 92 } |
| 93 if (!inheritedValue || !m_inheritedValue) { |
| 94 return false; |
| 95 } |
90 return m_inheritedValue->equals(*inheritedValue); | 96 return m_inheritedValue->equals(*inheritedValue); |
91 } | 97 } |
92 | 98 |
93 const AtomicString& m_name; | 99 const AtomicString& m_name; |
94 const bool m_isInheritedProperty; | 100 const bool m_isInheritedProperty; |
95 Persistent<const CSSValue> m_inheritedValue; | 101 Persistent<const CSSValue> m_inheritedValue; |
96 Persistent<const CSSValue> m_initialValue; | 102 Persistent<const CSSValue> m_initialValue; |
97 }; | 103 }; |
98 | 104 |
99 CSSInterpolationType::CSSInterpolationType(PropertyHandle property) | 105 CSSInterpolationType::CSSInterpolationType(PropertyHandle property) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // Unregistered custom properties inherit: | 206 // Unregistered custom properties inherit: |
201 // https://www.w3.org/TR/css-variables-1/#defining-variables | 207 // https://www.w3.org/TR/css-variables-1/#defining-variables |
202 bool isInheritedProperty = registration ? registration->inherits() : true; | 208 bool isInheritedProperty = registration ? registration->inherits() : true; |
203 DCHECK(declaration.isInitial(isInheritedProperty) || | 209 DCHECK(declaration.isInitial(isInheritedProperty) || |
204 declaration.isInherit(isInheritedProperty)); | 210 declaration.isInherit(isInheritedProperty)); |
205 | 211 |
206 if (!registration) { | 212 if (!registration) { |
207 return nullptr; | 213 return nullptr; |
208 } | 214 } |
209 | 215 |
| 216 const CSSValue* value = nullptr; |
210 if (declaration.isInitial(isInheritedProperty)) { | 217 if (declaration.isInitial(isInheritedProperty)) { |
211 return maybeConvertValue(*registration->initial(), state, | 218 value = registration->initial(); |
212 conversionCheckers); | 219 } else { |
| 220 value = |
| 221 state.parentStyle()->getRegisteredVariable(name, isInheritedProperty); |
| 222 if (!value) { |
| 223 value = registration->initial(); |
| 224 } |
| 225 conversionCheckers.push_back(InheritedCustomPropertyChecker::create( |
| 226 name, isInheritedProperty, value, registration->initial())); |
| 227 } |
| 228 if (!value) { |
| 229 return nullptr; |
213 } | 230 } |
214 | 231 |
215 DCHECK(declaration.isInherit(isInheritedProperty)); | 232 return maybeConvertValue(*value, state, conversionCheckers); |
216 const CSSValue* inheritedValue = | |
217 state.parentStyle()->getRegisteredVariable(name, isInheritedProperty); | |
218 if (!inheritedValue) { | |
219 inheritedValue = registration->initial(); | |
220 } | |
221 conversionCheckers.push_back(InheritedCustomPropertyChecker::create( | |
222 name, isInheritedProperty, inheritedValue, registration->initial())); | |
223 return maybeConvertValue(*inheritedValue, state, conversionCheckers); | |
224 } | 233 } |
225 | 234 |
226 if (declaration.value()->needsVariableResolution()) { | 235 if (declaration.value()->needsVariableResolution()) { |
227 // TODO(alancutter): Support smooth interpolation with var() values for | 236 // TODO(alancutter): Support smooth interpolation with var() values for |
228 // registered custom properties. This requires integrating animated custom | 237 // registered custom properties. This requires integrating animated custom |
229 // property value application with the CSSVariableResolver to apply them in | 238 // property value application with the CSSVariableResolver to apply them in |
230 // the appropriate order defined by the chain of var() dependencies. | 239 // the appropriate order defined by the chain of var() dependencies. |
231 // All CSSInterpolationTypes should fail convertion here except for | 240 // All CSSInterpolationTypes should fail convertion here except for |
232 // CSSValueInterpolationType. | 241 // CSSValueInterpolationType. |
233 return nullptr; | 242 return nullptr; |
(...skipping 22 matching lines...) Expand all Loading... |
256 const PropertyRegistry::Registration* registration = | 265 const PropertyRegistry::Registration* registration = |
257 getRegistration(state, name); | 266 getRegistration(state, name); |
258 if (!registration) { | 267 if (!registration) { |
259 return nullptr; | 268 return nullptr; |
260 } | 269 } |
261 const CSSValue* underlyingValue = | 270 const CSSValue* underlyingValue = |
262 state.style()->getRegisteredVariable(name, registration->inherits()); | 271 state.style()->getRegisteredVariable(name, registration->inherits()); |
263 if (!underlyingValue) { | 272 if (!underlyingValue) { |
264 underlyingValue = registration->initial(); | 273 underlyingValue = registration->initial(); |
265 } | 274 } |
| 275 if (!underlyingValue) { |
| 276 return nullptr; |
| 277 } |
266 // TODO(alancutter): Remove the need for passing in conversion checkers. | 278 // TODO(alancutter): Remove the need for passing in conversion checkers. |
267 ConversionCheckers dummyConversionCheckers; | 279 ConversionCheckers dummyConversionCheckers; |
268 return maybeConvertValue(*underlyingValue, environment.state(), | 280 return maybeConvertValue(*underlyingValue, environment.state(), |
269 dummyConversionCheckers); | 281 dummyConversionCheckers); |
270 } | 282 } |
271 | 283 |
272 void CSSInterpolationType::apply( | 284 void CSSInterpolationType::apply( |
273 const InterpolableValue& interpolableValue, | 285 const InterpolableValue& interpolableValue, |
274 const NonInterpolableValue* nonInterpolableValue, | 286 const NonInterpolableValue* nonInterpolableValue, |
275 InterpolationEnvironment& environment) const { | 287 InterpolationEnvironment& environment) const { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 if (registration->inherits()) { | 323 if (registration->inherits()) { |
312 style.setResolvedInheritedVariable(propertyName, variableData.release(), | 324 style.setResolvedInheritedVariable(propertyName, variableData.release(), |
313 cssValue); | 325 cssValue); |
314 } else { | 326 } else { |
315 style.setResolvedNonInheritedVariable(propertyName, variableData.release(), | 327 style.setResolvedNonInheritedVariable(propertyName, variableData.release(), |
316 cssValue); | 328 cssValue); |
317 } | 329 } |
318 } | 330 } |
319 | 331 |
320 } // namespace blink | 332 } // namespace blink |
OLD | NEW |