OLD | NEW |
1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
6 #include "core/animation/StringKeyframe.h" | 6 #include "core/animation/InterpolationFactory.h" |
7 | 7 |
8 #include "core/animation/ColorStyleInterpolation.h" | 8 #include "core/animation/ColorStyleInterpolation.h" |
9 #include "core/animation/ConstantStyleInterpolation.h" | 9 #include "core/animation/ConstantStyleInterpolation.h" |
10 #include "core/animation/DeferredLegacyStyleInterpolation.h" | 10 #include "core/animation/DeferredLegacyStyleInterpolation.h" |
11 #include "core/animation/DoubleStyleInterpolation.h" | 11 #include "core/animation/DoubleStyleInterpolation.h" |
12 #include "core/animation/ImageStyleInterpolation.h" | 12 #include "core/animation/ImageStyleInterpolation.h" |
13 #include "core/animation/LegacyStyleInterpolation.h" | 13 #include "core/animation/LegacyStyleInterpolation.h" |
14 #include "core/animation/LengthBoxStyleInterpolation.h" | 14 #include "core/animation/LengthBoxStyleInterpolation.h" |
15 #include "core/animation/LengthPairStyleInterpolation.h" | 15 #include "core/animation/LengthPairStyleInterpolation.h" |
16 #include "core/animation/LengthStyleInterpolation.h" | 16 #include "core/animation/LengthStyleInterpolation.h" |
17 #include "core/animation/ListStyleInterpolation.h" | 17 #include "core/animation/ListStyleInterpolation.h" |
18 #include "core/animation/SVGLengthStyleInterpolation.h" | 18 #include "core/animation/SVGLengthStyleInterpolation.h" |
19 #include "core/animation/ShadowStyleInterpolation.h" | 19 #include "core/animation/ShadowStyleInterpolation.h" |
20 #include "core/animation/VisibilityStyleInterpolation.h" | 20 #include "core/animation/VisibilityStyleInterpolation.h" |
21 #include "core/animation/css/CSSAnimations.h" | |
22 #include "core/css/CSSPropertyMetadata.h" | 21 #include "core/css/CSSPropertyMetadata.h" |
23 #include "core/css/resolver/StyleResolver.h" | 22 #include "core/css/resolver/StyleResolver.h" |
24 #include "core/layout/style/LayoutStyle.h" | |
25 | 23 |
26 namespace blink { | 24 namespace blink { |
27 | 25 |
28 StringKeyframe::StringKeyframe(const StringKeyframe& copyFrom) | 26 PassRefPtrWillBeRawPtr<Interpolation> InterpolationFactory::maybeCreateInterpola
tion( |
29 : Keyframe(copyFrom.m_offset, copyFrom.m_composite, copyFrom.m_easing) | 27 CSSPropertyID property, |
30 , m_propertySet(copyFrom.m_propertySet->mutableCopy()) | 28 CSSValue* fromCSSValue, |
| 29 CSSValue* toCSSValue, |
| 30 AnimationEffect::CompositeOperation fromComposite, |
| 31 AnimationEffect::CompositeOperation toComposite, |
| 32 RefPtrWillBeRawPtr<AnimatableValue>* fromAnimatableValueCache, |
| 33 RefPtrWillBeRawPtr<AnimatableValue>* toAnimatableValueCache, |
| 34 Element* element) |
31 { | 35 { |
32 } | |
33 | |
34 void StringKeyframe::setPropertyValue(CSSPropertyID property, const String& valu
e, StyleSheetContents* styleSheetContents) | |
35 { | |
36 ASSERT(property != CSSPropertyInvalid); | |
37 if (CSSAnimations::isAllowedAnimation(property)) | |
38 m_propertySet->setProperty(property, value, false, styleSheetContents); | |
39 } | |
40 | |
41 PropertySet StringKeyframe::properties() const | |
42 { | |
43 // This is not used in time-critical code, so we probably don't need to | |
44 // worry about caching this result. | |
45 PropertySet properties; | |
46 for (unsigned i = 0; i < m_propertySet->propertyCount(); ++i) | |
47 properties.add(m_propertySet->propertyAt(i).id()); | |
48 return properties; | |
49 } | |
50 | |
51 PassRefPtrWillBeRawPtr<Keyframe> StringKeyframe::clone() const | |
52 { | |
53 return adoptRefWillBeNoop(new StringKeyframe(*this)); | |
54 } | |
55 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::creat
ePropertySpecificKeyframe(CSSPropertyID property) const | |
56 { | |
57 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset(), &easing(),
propertyValue(property), composite())); | |
58 } | |
59 | |
60 void StringKeyframe::trace(Visitor* visitor) | |
61 { | |
62 visitor->trace(m_propertySet); | |
63 Keyframe::trace(visitor); | |
64 } | |
65 | |
66 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset
, PassRefPtr<TimingFunction> easing, CSSValue* value, AnimationEffect::Composite
Operation op) | |
67 : Keyframe::PropertySpecificKeyframe(offset, easing, op) | |
68 , m_value(value) | |
69 { } | |
70 | |
71 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset
, PassRefPtr<TimingFunction> easing, CSSValue* value) | |
72 : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::Compos
iteReplace) | |
73 , m_value(value) | |
74 { | |
75 ASSERT(!isNull(m_offset)); | |
76 } | |
77 | |
78 // FIXME: Refactor this into a generic piece that lives in InterpolationEffect,
and a template parameter specific converter. | |
79 PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
maybeCreateInterpolation(CSSPropertyID property, Keyframe::PropertySpecificKeyfr
ame& end, Element* element) const | |
80 { | |
81 CSSValue* fromCSSValue = m_value.get(); | |
82 CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end).value(); | |
83 InterpolationRange range = RangeAll; | 36 InterpolationRange range = RangeAll; |
84 bool fallBackToLegacy = false; | 37 bool fallBackToLegacy = false; |
85 | 38 |
86 // FIXME: Remove this flag once we can rely on legacy's behaviour being corr
ect. | 39 // FIXME: Remove this flag once we can rely on legacy's behaviour being corr
ect. |
87 bool forceDefaultInterpolation = false; | 40 bool forceDefaultInterpolation = false; |
88 | 41 |
89 if (!CSSPropertyMetadata::isAnimatableProperty(property)) { | 42 if (!CSSPropertyMetadata::isAnimatableProperty(property)) { |
90 if (fromCSSValue == toCSSValue) | 43 if (fromCSSValue == toCSSValue) |
91 return ConstantStyleInterpolation::create(fromCSSValue, property); | 44 return ConstantStyleInterpolation::create(fromCSSValue, property, fr
omComposite, toComposite); |
92 | 45 |
93 return nullptr; | 46 return nullptr; |
94 } | 47 } |
95 | 48 |
96 // FIXME: Generate this giant switch statement. | 49 // FIXME: Generate this giant switch statement. |
97 switch (property) { | 50 switch (property) { |
98 case CSSPropertyLineHeight: | 51 case CSSPropertyLineHeight: |
99 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl
eInterpolation::canCreateFrom(*toCSSValue)) | 52 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl
eInterpolation::canCreateFrom(*toCSSValue)) |
100 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue,
property, RangeNonNegative); | 53 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue,
property, RangeNonNegative); |
101 | 54 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 case CSSPropertyMarginBottom: | 88 case CSSPropertyMarginBottom: |
136 case CSSPropertyMarginLeft: | 89 case CSSPropertyMarginLeft: |
137 case CSSPropertyMarginRight: | 90 case CSSPropertyMarginRight: |
138 case CSSPropertyMarginTop: | 91 case CSSPropertyMarginTop: |
139 case CSSPropertyOutlineOffset: | 92 case CSSPropertyOutlineOffset: |
140 case CSSPropertyRight: | 93 case CSSPropertyRight: |
141 case CSSPropertyTop: | 94 case CSSPropertyTop: |
142 case CSSPropertyVerticalAlign: | 95 case CSSPropertyVerticalAlign: |
143 case CSSPropertyWordSpacing: | 96 case CSSPropertyWordSpacing: |
144 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl
eInterpolation::canCreateFrom(*toCSSValue)) | 97 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl
eInterpolation::canCreateFrom(*toCSSValue)) |
145 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue,
property, range); | 98 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue,
property, range, fromComposite, toComposite); |
146 | 99 |
147 // FIXME: Handle keywords e.g. 'none'. | 100 // FIXME: Handle keywords e.g. 'none'. |
148 if (property == CSSPropertyPerspective) | 101 if (property == CSSPropertyPerspective) |
149 fallBackToLegacy = true; | 102 fallBackToLegacy = true; |
150 | 103 |
151 // FIXME: Handle keywords e.g. 'smaller', 'larger'. | 104 // FIXME: Handle keywords e.g. 'smaller', 'larger'. |
152 if (property == CSSPropertyFontSize) | 105 if (property == CSSPropertyFontSize) |
153 fallBackToLegacy = true; | 106 fallBackToLegacy = true; |
154 | 107 |
155 // FIXME: Handle keywords e.g. 'normal' | 108 // FIXME: Handle keywords e.g. 'normal' |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 if (fromCSSValue == toCSSValue) | 226 if (fromCSSValue == toCSSValue) |
274 return ConstantStyleInterpolation::create(fromCSSValue, property); | 227 return ConstantStyleInterpolation::create(fromCSSValue, property); |
275 | 228 |
276 if (forceDefaultInterpolation) | 229 if (forceDefaultInterpolation) |
277 return nullptr; | 230 return nullptr; |
278 | 231 |
279 if (fromCSSValue->isUnsetValue() || fromCSSValue->isInheritedValue() || from
CSSValue->isInitialValue() | 232 if (fromCSSValue->isUnsetValue() || fromCSSValue->isInheritedValue() || from
CSSValue->isInitialValue() |
280 || toCSSValue->isUnsetValue() || toCSSValue->isInheritedValue() || toCSS
Value->isInitialValue()) | 233 || toCSSValue->isUnsetValue() || toCSSValue->isInheritedValue() || toCSS
Value->isInitialValue()) |
281 fallBackToLegacy = true; | 234 fallBackToLegacy = true; |
282 | 235 |
| 236 ASSERT(element); |
283 if (fallBackToLegacy) { | 237 if (fallBackToLegacy) { |
| 238 ASSERT(fromAnimatableValueCache); |
| 239 ASSERT(toAnimatableValueCache); |
| 240 |
284 if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(
*fromCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleRe
solve(*toCSSValue)) { | 241 if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(
*fromCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleRe
solve(*toCSSValue)) { |
285 // FIXME: Handle these cases outside of DeferredLegacyStyleInterpola
tion. | 242 // FIXME: Handle these cases outside of DeferredLegacyStyleInterpola
tion. |
286 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSV
alue, property); | 243 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSV
alue, property); |
287 } | 244 } |
288 | 245 |
289 // FIXME: Remove the use of AnimatableValues, LayoutStyles and Elements
here. | 246 // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements
here. |
290 // FIXME: Remove this cache | 247 // FIXME: Remove this cache |
291 ASSERT(element); | 248 if (!*fromAnimatableValueCache) |
292 if (!m_animatableValueCache) | 249 *fromAnimatableValueCache = StyleResolver::createAnimatableValueSnap
shot(*element, property, *fromCSSValue); |
293 m_animatableValueCache = StyleResolver::createAnimatableValueSnapsho
t(*element, property, *fromCSSValue); | |
294 | 250 |
295 RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatable
ValueSnapshot(*element, property, *toCSSValue); | 251 RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatable
ValueSnapshot(*element, property, *toCSSValue); |
296 toStringPropertySpecificKeyframe(end).m_animatableValueCache = to; | 252 *toAnimatableValueCache = to; |
297 | 253 |
298 return LegacyStyleInterpolation::create(m_animatableValueCache.get(), to
.release(), property); | 254 return LegacyStyleInterpolation::create((*fromAnimatableValueCache).get(
), to.release(), property); |
299 } | 255 } |
300 | 256 |
301 ASSERT(AnimatableValue::usesDefaultInterpolation( | 257 ASSERT(AnimatableValue::usesDefaultInterpolation( |
302 StyleResolver::createAnimatableValueSnapshot(*element, property, *fromCS
SValue).get(), | 258 StyleResolver::createAnimatableValueSnapshot(*element, property, *fromCS
SValue).get(), |
303 StyleResolver::createAnimatableValueSnapshot(*element, property, *toCSSV
alue).get())); | 259 StyleResolver::createAnimatableValueSnapshot(*element, property, *toCSSV
alue).get())); |
304 | 260 |
305 return nullptr; | 261 return nullptr; |
306 | |
307 } | 262 } |
308 | 263 |
309 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope
rtySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> e
asing) const | 264 PassRefPtrWillBeRawPtr<Interpolation> InterpolationFactory::createConstantInterp
olation( |
| 265 CSSPropertyID property, |
| 266 CSSValue* value, |
| 267 AnimationEffect::CompositeOperation fromComposite, |
| 268 AnimationEffect::CompositeOperation toComposite) |
310 { | 269 { |
311 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, 0, An
imationEffect::CompositeAdd)); | 270 RefPtrWillBeRawPtr<Interpolation> interpolation = InterpolationFactory::mayb
eCreateInterpolation( |
312 } | 271 property, |
| 272 value, |
| 273 value, |
| 274 fromComposite, |
| 275 toComposite); |
313 | 276 |
314 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope
rtySpecificKeyframe::cloneWithOffset(double offset) const | 277 ASSERT(interpolation); |
315 { | |
316 Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe(
offset, m_easing, m_value.get()); | |
317 toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_anima
tableValueCache; | |
318 return adoptPtrWillBeNoop(theClone); | |
319 } | |
320 | 278 |
321 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor) | 279 return interpolation.release(); |
322 { | |
323 visitor->trace(m_value); | |
324 visitor->trace(m_animatableValueCache); | |
325 Keyframe::PropertySpecificKeyframe::trace(visitor); | |
326 } | 280 } |
327 | 281 |
328 } | 282 } |
OLD | NEW |