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

Side by Side Diff: Source/core/animation/KeyframeEffectModel.h

Issue 215883005: Web Animations: Introduce String based KeyframeEffectModel (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 8 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef KeyframeEffectModel_h 31 #ifndef KeyframeEffectModel_h
32 #define KeyframeEffectModel_h 32 #define KeyframeEffectModel_h
33 33
34 #include "core/animation/AnimatableValue.h" 34 #include "core/animation/AnimatableValueKeyframe.h"
35 #include "core/animation/AnimationEffect.h" 35 #include "core/animation/AnimationEffect.h"
36 #include "core/animation/InterpolationEffect.h" 36 #include "core/animation/InterpolationEffect.h"
37 #include "core/animation/StringKeyframe.h"
38 #include "core/animation/TimedItem.h"
37 #include "heap/Handle.h" 39 #include "heap/Handle.h"
38 #include "platform/animation/TimingFunction.h" 40 #include "platform/animation/TimingFunction.h"
39 #include "wtf/HashMap.h" 41 #include "wtf/HashMap.h"
40 #include "wtf/HashSet.h" 42 #include "wtf/HashSet.h"
41 #include "wtf/PassOwnPtr.h" 43 #include "wtf/PassOwnPtr.h"
42 #include "wtf/PassRefPtr.h" 44 #include "wtf/PassRefPtr.h"
43 #include "wtf/RefCounted.h" 45 #include "wtf/RefCounted.h"
44 #include "wtf/Vector.h" 46 #include "wtf/Vector.h"
45 47
46 namespace WebCore { 48 namespace WebCore {
47 49
48 typedef HashSet<CSSPropertyID> PropertySet;
49
50 class KeyframeEffectModelTest; 50 class KeyframeEffectModelTest;
51 51
52 // Represents the keyframes set through the API. 52 class KeyframeEffectModelBase : public AnimationEffect {
53 class Keyframe : public RefCountedWillBeGarbageCollectedFinalized<Keyframe> {
54 public: 53 public:
55 static PassRefPtrWillBeRawPtr<Keyframe> create() 54 // FIXME: Implement accumulation.
56 {
57 return adoptRefWillBeNoop(new Keyframe);
58 }
59 static bool compareOffsets(const RefPtrWillBeRawPtr<Keyframe>& a, const RefP trWillBeRawPtr<Keyframe>& b)
60 {
61 return a->offset() < b->offset();
62 }
63 void setOffset(double offset) { m_offset = offset; }
64 double offset() const { return m_offset; }
65 void setComposite(AnimationEffect::CompositeOperation composite) { m_composi te = composite; }
66 AnimationEffect::CompositeOperation composite() const { return m_composite; }
67 void setEasing(PassRefPtr<TimingFunction>);
68 TimingFunction* easing() const { return m_easing.get(); }
69 void setPropertyValue(CSSPropertyID, const AnimatableValue*);
70 void clearPropertyValue(CSSPropertyID);
71 const AnimatableValue* propertyValue(CSSPropertyID) const;
72 PropertySet properties() const;
73 PassRefPtrWillBeRawPtr<Keyframe> clone() const { return adoptRefWillBeNoop(n ew Keyframe(*this)); }
74 PassRefPtrWillBeRawPtr<Keyframe> cloneWithOffset(double offset) const;
75 55
76 void trace(Visitor*); 56 // Represents the keyframes set through the API.
alancutter (OOO until 2018) 2014/04/01 01:09:40 It's not clear what this comment is attached to. K
shans 2014/04/01 04:01:27 Deleted.
77 57
78 private: 58 typedef Vector<OwnPtr<Keyframe::PropertySpecificKeyframe> > PropertySpecific KeyframeVector;
79 Keyframe(); 59 class PropertySpecificKeyframeGroup {
80 Keyframe(const Keyframe&); 60 public:
81 double m_offset; 61 void appendKeyframe(PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKey frame>);
82 AnimationEffect::CompositeOperation m_composite; 62 const PropertySpecificKeyframeVector& keyframes() const { return m_keyfr ames; }
83 RefPtr<TimingFunction> m_easing;
84 typedef WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<AnimatableValue> > PropertyValueMap;
85 PropertyValueMap m_propertyValues;
86 };
87 63
88 class KeyframeEffectModel FINAL : public AnimationEffect { 64 void trace(Visitor*);
89 public:
90 class PropertySpecificKeyframe;
91 typedef WillBeHeapVector<RefPtrWillBeMember<Keyframe> > KeyframeVector;
92 typedef WillBeHeapVector<OwnPtrWillBeMember<PropertySpecificKeyframe> > Prop ertySpecificKeyframeVector;
93 // FIXME: Implement accumulation.
94 static PassRefPtrWillBeRawPtr<KeyframeEffectModel> create(const KeyframeVect or& keyframes)
95 {
96 return adoptRefWillBeNoop(new KeyframeEffectModel(keyframes));
97 }
98 65
99 virtual bool affects(CSSPropertyID property) OVERRIDE 66 private:
100 { 67 void removeRedundantKeyframes();
101 ensureKeyframeGroups(); 68 void addSyntheticKeyframeIfRequired(const KeyframeEffectModelBase *conte xt);
102 return m_keyframeGroups->contains(property);
103 }
104 69
105 // AnimationEffect implementation. 70 PropertySpecificKeyframeVector m_keyframes;
106 virtual PassOwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpola tion> > > sample(int iteration, double fraction, double iterationDuration) const OVERRIDE;
107 71
108 // FIXME: Implement setFrames() 72 friend class KeyframeEffectModelBase;
109 const KeyframeVector& getFrames() const { return m_keyframes; } 73 };
110
111 virtual bool isKeyframeEffectModel() const OVERRIDE { return true; }
112 74
113 bool isReplaceOnly(); 75 bool isReplaceOnly();
114 76
115 PropertySet properties() const; 77 PropertySet properties() const;
116 78
117 class PropertySpecificKeyframe : public NoBaseWillBeGarbageCollectedFinalize d<PropertySpecificKeyframe> { 79 typedef WillBeHeapVector<RefPtrWillBeMember<Keyframe> > KeyframeVector;
118 public: 80 const KeyframeVector& getFrames() const { return m_keyframes; }
119 PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easin g, const AnimatableValue*, CompositeOperation); 81 // FIXME: Implement setFrames()
120 double offset() const { return m_offset; }
121 TimingFunction* easing() const { return m_easing.get(); }
122 const AnimatableValue* value() const { return m_value.get(); }
123 AnimationEffect::CompositeOperation composite() const { return m_composi te; }
124 PassOwnPtrWillBeRawPtr<PropertySpecificKeyframe> cloneWithOffset(double offset) const;
125
126 void trace(Visitor*);
127
128 private:
129 // Used by cloneWithOffset().
130 PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easin g, PassRefPtrWillBeRawPtr<AnimatableValue>, CompositeOperation);
131 double m_offset;
132 RefPtr<TimingFunction> m_easing;
133 RefPtrWillBeMember<AnimatableValue> m_value;
134 AnimationEffect::CompositeOperation m_composite;
135 };
136
137 class PropertySpecificKeyframeGroup : public NoBaseWillBeGarbageCollectedFin alized<PropertySpecificKeyframeGroup> {
138 public:
139 void appendKeyframe(PassOwnPtrWillBeRawPtr<PropertySpecificKeyframe>);
140 const PropertySpecificKeyframeVector& keyframes() const { return m_keyfr ames; }
141
142 void trace(Visitor*);
143
144 private:
145 PropertySpecificKeyframeVector m_keyframes;
146 void removeRedundantKeyframes();
147 void addSyntheticKeyframeIfRequired();
148
149 friend class KeyframeEffectModel;
150 };
151 82
152 const PropertySpecificKeyframeVector& getPropertySpecificKeyframes(CSSProper tyID id) const 83 const PropertySpecificKeyframeVector& getPropertySpecificKeyframes(CSSProper tyID id) const
153 { 84 {
154 ensureKeyframeGroups(); 85 ensureKeyframeGroups();
155 return m_keyframeGroups->get(id)->keyframes(); 86 return m_keyframeGroups->get(id)->keyframes();
156 } 87 }
157 88
89 // AnimationEffect implementation.
90 virtual PassOwnPtr<Vector<RefPtr<Interpolation> > > sample(int iteration, do uble fraction, double iterationDuration) const OVERRIDE;
91
92 virtual bool isKeyframeEffectModel() const OVERRIDE { return true; }
93
94 virtual bool isAnimatableValueKeyframeEffectModel() const { return false; }
95 virtual bool isStringKeyframeEffectModel() const { return false; }
96
158 virtual void trace(Visitor*) OVERRIDE; 97 virtual void trace(Visitor*) OVERRIDE;
159 98
160 private: 99 protected:
161 KeyframeEffectModel(const KeyframeVector& keyframes);
162
163 static KeyframeVector normalizedKeyframes(const KeyframeVector& keyframes); 100 static KeyframeVector normalizedKeyframes(const KeyframeVector& keyframes);
164 101
165 // Lazily computes the groups of property-specific keyframes. 102 // Lazily computes the groups of property-specific keyframes.
166 void ensureKeyframeGroups() const; 103 void ensureKeyframeGroups() const;
167 void ensureInterpolationEffect() const; 104 void ensureInterpolationEffect() const;
168 105
169 KeyframeVector m_keyframes; 106 KeyframeVector m_keyframes;
170 // The spec describes filtering the normalized keyframes at sampling time 107 // The spec describes filtering the normalized keyframes at sampling time
171 // to get the 'property-specific keyframes'. For efficiency, we cache the 108 // to get the 'property-specific keyframes'. For efficiency, we cache the
172 // property-specific lists. 109 // property-specific lists.
173 typedef WillBeHeapHashMap<CSSPropertyID, OwnPtrWillBeMember<PropertySpecific KeyframeGroup> > KeyframeGroupMap; 110 typedef WillBeHeapHashMap<CSSPropertyID, OwnPtrWillBeMember<PropertySpecific KeyframeGroup> > KeyframeGroupMap;
174 mutable OwnPtrWillBeMember<KeyframeGroupMap> m_keyframeGroups; 111 mutable OwnPtrWillBeMember<KeyframeGroupMap> m_keyframeGroups;
175 112 mutable RefPtr<InterpolationEffect> m_interpolationEffect;
176 mutable RefPtrWillBeMember<InterpolationEffect> m_interpolationEffect;
177 113
178 friend class KeyframeEffectModelTest; 114 friend class KeyframeEffectModelTest;
115
116 bool affects(CSSPropertyID property)
117 {
118 ensureKeyframeGroups();
119 return m_keyframeGroups->contains(property);
120 }
179 }; 121 };
180 122
181 DEFINE_TYPE_CASTS(KeyframeEffectModel, AnimationEffect, value, value->isKeyframe EffectModel(), value.isKeyframeEffectModel()); 123 template <class Keyframe>
alancutter (OOO until 2018) 2014/04/01 01:09:40 This template variable name is the same as the Key
shans 2014/04/01 04:01:27 I think this is fine. I don't want to make this Ev
124 class KeyframeEffectModel FINAL : public KeyframeEffectModelBase {
125 public:
126 typedef WillBeHeapVector<RefPtrWillBeMember<Keyframe> > KeyframeVector;
127 static PassRefPtrWillBeRawPtr<KeyframeEffectModel<Keyframe> > create(const K eyframeVector& keyframes) { return adoptRefWillBeNoop(new KeyframeEffectModel(ke yframes)); }
128
129 private:
130 KeyframeEffectModel(const KeyframeVector& keyframes)
131 {
132 m_keyframes.appendVector(keyframes);
133 }
134
135 virtual bool isAnimatableValueKeyframeEffectModel() const { return false; }
136 virtual bool isStringKeyframeEffectModel() const { return false; }
137
138 };
139
140 typedef KeyframeEffectModelBase::KeyframeVector KeyframeVector;
141 typedef Keyframe::PropertySpecificKeyframe PropertySpecificKeyframe;
142 typedef KeyframeEffectModelBase::PropertySpecificKeyframeVector PropertySpecific KeyframeVector;
143
144 typedef KeyframeEffectModel<AnimatableValueKeyframe> AnimatableValueKeyframeEffe ctModel;
145 typedef AnimatableValueKeyframeEffectModel::KeyframeVector AnimatableValueKeyfra meVector;
146 typedef AnimatableValueKeyframe::PropertySpecificKeyframe AnimatableValuePropert ySpecificKeyframe;
147 typedef AnimatableValueKeyframeEffectModel::PropertySpecificKeyframeVector Anima tableValuePropertySpecificKeyframeVector;
148
149 typedef KeyframeEffectModel<StringKeyframe> StringKeyframeEffectModel;
150 typedef StringKeyframeEffectModel::KeyframeVector StringKeyframeVector;
151 typedef StringKeyframe::PropertySpecificKeyframe StringPropertySpecificKeyframe;
152 typedef StringKeyframeEffectModel::PropertySpecificKeyframeVector StringProperty SpecificKeyframeVector;
153
154 DEFINE_TYPE_CASTS(KeyframeEffectModelBase, AnimationEffect, value, value->isKeyf rameEffectModel(), value.isKeyframeEffectModel());
155 DEFINE_TYPE_CASTS(AnimatableValueKeyframe, Keyframe, value, value->isAnimatableV alueKeyframe(), value.isAnimatableValueKeyframe());
156 DEFINE_TYPE_CASTS(AnimatableValuePropertySpecificKeyframe, PropertySpecificKeyfr ame, value, value->isAnimatableValuePropertySpecificKeyframe(), value.isAnimatab leValuePropertySpecificKeyframe());
157 DEFINE_TYPE_CASTS(AnimatableValueKeyframeEffectModel, KeyframeEffectModelBase, v alue, value->isAnimatableValueKeyframeEffectModel(), value.isAnimatableValueKeyf rameEffectModel());
158
159 inline const AnimatableValueKeyframeEffectModel* toAnimatableValueKeyframeEffect Model(const AnimationEffect *base)
160 {
161 return toAnimatableValueKeyframeEffectModel(toKeyframeEffectModelBase(base)) ;
162 }
163
164 inline AnimatableValueKeyframeEffectModel* toAnimatableValueKeyframeEffectModel( AnimationEffect *base)
165 {
166 return toAnimatableValueKeyframeEffectModel(toKeyframeEffectModelBase(base)) ;
167 }
182 168
183 } // namespace WebCore 169 } // namespace WebCore
184 170
185 #endif // KeyframeEffectModel_h 171 #endif // KeyframeEffectModel_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698