Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: Source/core/animation/StringKeyframe.cpp

Issue 851693007: Prepare for responsive CSS animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Attempt to re-snapshot only if needed Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/StringKeyframe.h"
7 7
8 #include "core/animation/ColorStyleInterpolation.h" 8 #include "core/animation/ColorStyleInterpolation.h"
9 #include "core/animation/DefaultStyleInterpolation.h" 9 #include "core/animation/DefaultStyleInterpolation.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/LengthPoint3DStyleInterpolation.h" 16 #include "core/animation/LengthPoint3DStyleInterpolation.h"
17 #include "core/animation/LengthStyleInterpolation.h" 17 #include "core/animation/LengthStyleInterpolation.h"
18 #include "core/animation/VisibilityStyleInterpolation.h" 18 #include "core/animation/VisibilityStyleInterpolation.h"
19 #include "core/animation/css/CSSAnimatableValueFactory.h"
19 #include "core/animation/css/CSSAnimations.h" 20 #include "core/animation/css/CSSAnimations.h"
20 #include "core/css/CSSPropertyMetadata.h" 21 #include "core/css/CSSPropertyMetadata.h"
21 #include "core/css/resolver/StyleResolver.h" 22 #include "core/css/resolver/StyleResolver.h"
22 #include "core/rendering/style/RenderStyle.h" 23 #include "core/rendering/style/RenderStyle.h"
23 24
24 namespace blink { 25 namespace blink {
25 26
26 StringKeyframe::StringKeyframe(const StringKeyframe& copyFrom) 27 StringKeyframe::StringKeyframe(const StringKeyframe& copyFrom)
27 : Keyframe(copyFrom.m_offset, copyFrom.m_composite, copyFrom.m_easing) 28 : Keyframe(copyFrom.m_offset, copyFrom.m_composite, copyFrom.m_easing)
28 , m_propertySet(copyFrom.m_propertySet->mutableCopy()) 29 , m_propertySet(copyFrom.m_propertySet->mutableCopy())
30 , m_cachedAnimatableValues(copyFrom.m_cachedAnimatableValues)
29 { 31 {
30 } 32 }
31 33
32 void StringKeyframe::setPropertyValue(CSSPropertyID property, const String& valu e, StyleSheetContents* styleSheetContents) 34 void StringKeyframe::setPropertyValue(CSSPropertyID property, const String& valu e, StyleSheetContents* styleSheetContents)
33 { 35 {
34 ASSERT(property != CSSPropertyInvalid); 36 ASSERT(property != CSSPropertyInvalid);
35 if (CSSAnimations::isAllowedAnimation(property)) 37 if (CSSAnimations::isAllowedAnimation(property))
36 m_propertySet->setProperty(property, value, false, styleSheetContents); 38 m_propertySet->setProperty(property, value, false, styleSheetContents);
37 } 39 }
38 40
41 void StringKeyframe::setPropertyValue(CSSPropertyID property, PassRefPtr<CSSValu e> value)
42 {
43 ASSERT(property != CSSPropertyInvalid);
44 if (CSSAnimations::isAllowedAnimation(property))
45 m_propertySet->setProperty(property, value, false); // FIXME: handle !im portant
46 }
47
48 void StringKeyframe::setPropertyAnimatableValue(CSSPropertyID property, PassRefP tr<AnimatableValue> value)
49 {
50 ASSERT(property != CSSPropertyInvalid);
51 if (CSSAnimations::isAllowedAnimation(property))
52 m_cachedAnimatableValues.set(property, value);
53 }
54
39 PropertySet StringKeyframe::properties() const 55 PropertySet StringKeyframe::properties() const
40 { 56 {
41 // This is not used in time-critical code, so we probably don't need to 57 // This is not used in time-critical code, so we probably don't need to
42 // worry about caching this result. 58 // worry about caching this result.
43 PropertySet properties; 59 PropertySet properties;
44 for (unsigned i = 0; i < m_propertySet->propertyCount(); ++i) 60 for (unsigned i = 0; i < m_propertySet->propertyCount(); ++i)
45 properties.add(m_propertySet->propertyAt(i).id()); 61 properties.add(m_propertySet->propertyAt(i).id());
46 return properties; 62 return properties;
47 } 63 }
48 64
49 PassRefPtrWillBeRawPtr<Keyframe> StringKeyframe::clone() const 65 PassRefPtrWillBeRawPtr<Keyframe> StringKeyframe::clone() const
50 { 66 {
51 return adoptRefWillBeNoop(new StringKeyframe(*this)); 67 return adoptRefWillBeNoop(new StringKeyframe(*this));
52 } 68 }
53 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::creat ePropertySpecificKeyframe(CSSPropertyID property) const 69 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::creat ePropertySpecificKeyframe(CSSPropertyID property) const
54 { 70 {
55 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset(), &easing(), propertyValue(property), composite())); 71 auto animatableValue = m_cachedAnimatableValues.find(property);
72 if (animatableValue == m_cachedAnimatableValues.end())
73 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset(), &easing (), propertyValue(property), composite()));
74 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset(), &easing(), propertyValue(property), composite(), animatableValue->value));
56 } 75 }
57 76
58 void StringKeyframe::trace(Visitor* visitor) 77 void StringKeyframe::trace(Visitor* visitor)
59 { 78 {
60 visitor->trace(m_propertySet); 79 visitor->trace(m_propertySet);
61 Keyframe::trace(visitor); 80 Keyframe::trace(visitor);
62 } 81 }
63 82
64 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset , PassRefPtr<TimingFunction> easing, CSSValue* value, AnimationEffect::Composite Operation op) 83 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset , PassRefPtr<TimingFunction> easing, CSSValue* value, AnimationEffect::Composite Operation op, PassRefPtr<AnimatableValue> valueCache)
Timothy Loh 2015/01/20 05:29:32 valueCache sounds like a cache of multiple values.
shend 2015/01/20 23:13:03 Done.
65 : Keyframe::PropertySpecificKeyframe(offset, easing, op) 84 : Keyframe::PropertySpecificKeyframe(offset, easing, op)
66 , m_value(value) 85 , m_value(value)
86 , m_animatableValueCache(valueCache)
67 { } 87 { }
68 88
69 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset , PassRefPtr<TimingFunction> easing, CSSValue* value) 89 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset , PassRefPtr<TimingFunction> easing, CSSValue* value)
70 : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::Compos iteReplace) 90 : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::Compos iteReplace)
71 , m_value(value) 91 , m_value(value)
72 { 92 {
73 ASSERT(!isNull(m_offset)); 93 ASSERT(!isNull(m_offset));
74 } 94 }
75 95
76 PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe:: createInterpolation(CSSPropertyID property, Keyframe::PropertySpecificKeyframe* end, Element* element) const 96 PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe:: createInterpolation(CSSPropertyID property, Keyframe::PropertySpecificKeyframe* end, Element* element) const
77 { 97 {
78 CSSValue* fromCSSValue = m_value.get(); 98 CSSValue* fromCSSValue = m_value.get();
79 CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end)->value(); 99 CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end)->value();
80 ValueRange range = ValueRangeAll; 100 ValueRange range = ValueRangeAll;
81 101
102 // FIXME: Remove this check once neutral keyframes are implemented in String Keyframes.
103 if (!fromCSSValue || !toCSSValue)
104 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSValue , property);
105
82 if (!CSSPropertyMetadata::isAnimatableProperty(property)) 106 if (!CSSPropertyMetadata::isAnimatableProperty(property))
83 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, prope rty); 107 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, prope rty);
84 108
85 bool useDefaultStyleInterpolation = true; 109 bool useDefaultStyleInterpolation = true;
86 110
87 switch (property) { 111 switch (property) {
88 case CSSPropertyLineHeight: 112 case CSSPropertyLineHeight:
89 // FIXME: Handle numbers. 113 // FIXME: Handle numbers.
90 useDefaultStyleInterpolation = false; 114 useDefaultStyleInterpolation = false;
91 // Fall through 115 // Fall through
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 break; 214 break;
191 215
192 default: 216 default:
193 useDefaultStyleInterpolation = false; 217 useDefaultStyleInterpolation = false;
194 break; 218 break;
195 } 219 }
196 220
197 if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(*fro mCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolv e(*toCSSValue)) 221 if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(*fro mCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolv e(*toCSSValue))
198 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSValue , property); 222 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSValue , property);
199 223
224 ASSERT(element);
200 if (useDefaultStyleInterpolation) { 225 if (useDefaultStyleInterpolation) {
201 ASSERT(AnimatableValue::usesDefaultInterpolation( 226 ASSERT(AnimatableValue::usesDefaultInterpolation(
202 StyleResolver::createAnimatableValueSnapshot(*element, property, *fr omCSSValue).get(), 227 StyleResolver::createAnimatableValueSnapshot(*element, property, *fr omCSSValue).get(),
203 StyleResolver::createAnimatableValueSnapshot(*element, property, *to CSSValue).get())); 228 StyleResolver::createAnimatableValueSnapshot(*element, property, *to CSSValue).get()));
204 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, prope rty); 229 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, prope rty);
205 } 230 }
206 231
207 // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here . 232 // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here .
208 // FIXME: Remove this cache 233 // FIXME: Remove this cache
209 ASSERT(element);
210 if (!m_animatableValueCache) 234 if (!m_animatableValueCache)
211 m_animatableValueCache = StyleResolver::createAnimatableValueSnapshot(*e lement, property, *fromCSSValue); 235 m_animatableValueCache = StyleResolver::createAnimatableValueSnapshot(*e lement, property, *fromCSSValue);
212 236
213 RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatableValu eSnapshot(*element, property, *toCSSValue); 237 RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatableValu eSnapshot(*element, property, *toCSSValue);
214 toStringPropertySpecificKeyframe(end)->m_animatableValueCache = to; 238 toStringPropertySpecificKeyframe(end)->m_animatableValueCache = to;
215 239
216 return LegacyStyleInterpolation::create(m_animatableValueCache.get(), to.rel ease(), property); 240 return LegacyStyleInterpolation::create(m_animatableValueCache.get(), to.rel ease(), property);
217 } 241 }
218 242
219 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> e asing) const 243 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> e asing) const
220 { 244 {
221 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, 0, An imationEffect::CompositeAdd)); 245 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, 0, An imationEffect::CompositeAdd));
222 } 246 }
223 247
224 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::cloneWithOffset(double offset) const 248 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::cloneWithOffset(double offset) const
225 { 249 {
226 Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe( offset, m_easing, m_value.get()); 250 Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe( offset, m_easing, m_value.get());
227 toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_anima tableValueCache; 251 toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_anima tableValueCache;
228 return adoptPtrWillBeNoop(theClone); 252 return adoptPtrWillBeNoop(theClone);
229 } 253 }
230 254
231 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor) 255 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor)
232 { 256 {
233 visitor->trace(m_value); 257 visitor->trace(m_value);
234 visitor->trace(m_animatableValueCache); 258 visitor->trace(m_animatableValueCache);
235 Keyframe::PropertySpecificKeyframe::trace(visitor); 259 Keyframe::PropertySpecificKeyframe::trace(visitor);
236 } 260 }
237 261
238 } 262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698