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

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

Issue 216603008: Revert "Web Animations: Introduce String based KeyframeEffectModel" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
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 | Annotate | Revision Log
« no previous file with comments | « Source/core/animation/Keyframe.h ('k') | Source/core/animation/KeyframeEffectModel.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/AnimatableValueKeyframe.h" 34 #include "core/animation/AnimatableValue.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"
39 #include "heap/Handle.h" 37 #include "heap/Handle.h"
40 #include "platform/animation/TimingFunction.h" 38 #include "platform/animation/TimingFunction.h"
41 #include "wtf/HashMap.h" 39 #include "wtf/HashMap.h"
42 #include "wtf/HashSet.h" 40 #include "wtf/HashSet.h"
43 #include "wtf/PassOwnPtr.h" 41 #include "wtf/PassOwnPtr.h"
44 #include "wtf/PassRefPtr.h" 42 #include "wtf/PassRefPtr.h"
45 #include "wtf/RefCounted.h" 43 #include "wtf/RefCounted.h"
46 #include "wtf/Vector.h" 44 #include "wtf/Vector.h"
47 45
48 namespace WebCore { 46 namespace WebCore {
49 47
48 typedef HashSet<CSSPropertyID> PropertySet;
49
50 class KeyframeEffectModelTest; 50 class KeyframeEffectModelTest;
51 51
52 class KeyframeEffectModelBase : public AnimationEffect { 52 // Represents the keyframes set through the API.
53 class Keyframe : public RefCountedWillBeGarbageCollectedFinalized<Keyframe> {
53 public: 54 public:
55 static PassRefPtrWillBeRawPtr<Keyframe> create()
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
76 void trace(Visitor*);
77
78 private:
79 Keyframe();
80 Keyframe(const Keyframe&);
81 double m_offset;
82 AnimationEffect::CompositeOperation m_composite;
83 RefPtr<TimingFunction> m_easing;
84 typedef WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<AnimatableValue> > PropertyValueMap;
85 PropertyValueMap m_propertyValues;
86 };
87
88 class KeyframeEffectModel FINAL : public AnimationEffect {
89 public:
90 class PropertySpecificKeyframe;
91 typedef WillBeHeapVector<RefPtrWillBeMember<Keyframe> > KeyframeVector;
92 typedef WillBeHeapVector<OwnPtrWillBeMember<PropertySpecificKeyframe> > Prop ertySpecificKeyframeVector;
54 // FIXME: Implement accumulation. 93 // FIXME: Implement accumulation.
94 static PassRefPtrWillBeRawPtr<KeyframeEffectModel> create(const KeyframeVect or& keyframes)
95 {
96 return adoptRefWillBeNoop(new KeyframeEffectModel(keyframes));
97 }
55 98
56 typedef Vector<OwnPtr<Keyframe::PropertySpecificKeyframe> > PropertySpecific KeyframeVector; 99 virtual bool affects(CSSPropertyID property) OVERRIDE
57 class PropertySpecificKeyframeGroup { 100 {
101 ensureKeyframeGroups();
102 return m_keyframeGroups->contains(property);
103 }
104
105 // AnimationEffect implementation.
106 virtual PassOwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpola tion> > > sample(int iteration, double fraction, double iterationDuration) const OVERRIDE;
107
108 // FIXME: Implement setFrames()
109 const KeyframeVector& getFrames() const { return m_keyframes; }
110
111 virtual bool isKeyframeEffectModel() const OVERRIDE { return true; }
112
113 bool isReplaceOnly();
114
115 PropertySet properties() const;
116
117 class PropertySpecificKeyframe : public NoBaseWillBeGarbageCollectedFinalize d<PropertySpecificKeyframe> {
58 public: 118 public:
59 void appendKeyframe(PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKey frame>); 119 PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easin g, const AnimatableValue*, CompositeOperation);
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>);
60 const PropertySpecificKeyframeVector& keyframes() const { return m_keyfr ames; } 140 const PropertySpecificKeyframeVector& keyframes() const { return m_keyfr ames; }
61 141
62 void trace(Visitor*); 142 void trace(Visitor*);
63 143
64 private: 144 private:
145 PropertySpecificKeyframeVector m_keyframes;
65 void removeRedundantKeyframes(); 146 void removeRedundantKeyframes();
66 void addSyntheticKeyframeIfRequired(const KeyframeEffectModelBase* conte xt); 147 void addSyntheticKeyframeIfRequired();
67 148
68 PropertySpecificKeyframeVector m_keyframes; 149 friend class KeyframeEffectModel;
69
70 friend class KeyframeEffectModelBase;
71 }; 150 };
72 151
73 bool isReplaceOnly();
74
75 PropertySet properties() const;
76
77 typedef WillBeHeapVector<RefPtrWillBeMember<Keyframe> > KeyframeVector;
78 const KeyframeVector& getFrames() const { return m_keyframes; }
79 // FIXME: Implement setFrames()
80
81 const PropertySpecificKeyframeVector& getPropertySpecificKeyframes(CSSProper tyID id) const 152 const PropertySpecificKeyframeVector& getPropertySpecificKeyframes(CSSProper tyID id) const
82 { 153 {
83 ensureKeyframeGroups(); 154 ensureKeyframeGroups();
84 return m_keyframeGroups->get(id)->keyframes(); 155 return m_keyframeGroups->get(id)->keyframes();
85 } 156 }
86 157
87 // AnimationEffect implementation.
88 virtual PassOwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpola tion> > > sample(int iteration, double fraction, double iterationDuration) const OVERRIDE;
89
90 virtual bool isKeyframeEffectModel() const OVERRIDE { return true; }
91
92 virtual bool isAnimatableValueKeyframeEffectModel() const { return false; }
93 virtual bool isStringKeyframeEffectModel() const { return false; }
94
95 virtual void trace(Visitor*) OVERRIDE; 158 virtual void trace(Visitor*) OVERRIDE;
96 159
97 protected: 160 private:
161 KeyframeEffectModel(const KeyframeVector& keyframes);
162
98 static KeyframeVector normalizedKeyframes(const KeyframeVector& keyframes); 163 static KeyframeVector normalizedKeyframes(const KeyframeVector& keyframes);
99 164
100 // Lazily computes the groups of property-specific keyframes. 165 // Lazily computes the groups of property-specific keyframes.
101 void ensureKeyframeGroups() const; 166 void ensureKeyframeGroups() const;
102 void ensureInterpolationEffect() const; 167 void ensureInterpolationEffect() const;
103 168
104 KeyframeVector m_keyframes; 169 KeyframeVector m_keyframes;
105 // The spec describes filtering the normalized keyframes at sampling time 170 // The spec describes filtering the normalized keyframes at sampling time
106 // to get the 'property-specific keyframes'. For efficiency, we cache the 171 // to get the 'property-specific keyframes'. For efficiency, we cache the
107 // property-specific lists. 172 // property-specific lists.
108 typedef WillBeHeapHashMap<CSSPropertyID, OwnPtrWillBeMember<PropertySpecific KeyframeGroup> > KeyframeGroupMap; 173 typedef WillBeHeapHashMap<CSSPropertyID, OwnPtrWillBeMember<PropertySpecific KeyframeGroup> > KeyframeGroupMap;
109 mutable OwnPtrWillBeMember<KeyframeGroupMap> m_keyframeGroups; 174 mutable OwnPtrWillBeMember<KeyframeGroupMap> m_keyframeGroups;
110 mutable RefPtr<InterpolationEffect> m_interpolationEffect; 175
176 mutable RefPtrWillBeMember<InterpolationEffect> m_interpolationEffect;
111 177
112 friend class KeyframeEffectModelTest; 178 friend class KeyframeEffectModelTest;
113
114 bool affects(CSSPropertyID property)
115 {
116 ensureKeyframeGroups();
117 return m_keyframeGroups->contains(property);
118 }
119 }; 179 };
120 180
121 template <class Keyframe> 181 DEFINE_TYPE_CASTS(KeyframeEffectModel, AnimationEffect, value, value->isKeyframe EffectModel(), value.isKeyframeEffectModel());
122 class KeyframeEffectModel FINAL : public KeyframeEffectModelBase {
123 public:
124 typedef WillBeHeapVector<RefPtrWillBeMember<Keyframe> > KeyframeVector;
125 static PassRefPtrWillBeRawPtr<KeyframeEffectModel<Keyframe> > create(const K eyframeVector& keyframes) { return adoptRefWillBeNoop(new KeyframeEffectModel(ke yframes)); }
126
127 private:
128 KeyframeEffectModel(const KeyframeVector& keyframes)
129 {
130 m_keyframes.appendVector(keyframes);
131 }
132
133 virtual bool isAnimatableValueKeyframeEffectModel() const { return false; }
134 virtual bool isStringKeyframeEffectModel() const { return false; }
135
136 };
137
138 typedef KeyframeEffectModelBase::KeyframeVector KeyframeVector;
139 typedef KeyframeEffectModelBase::PropertySpecificKeyframeVector PropertySpecific KeyframeVector;
140
141 typedef KeyframeEffectModel<AnimatableValueKeyframe> AnimatableValueKeyframeEffe ctModel;
142 typedef AnimatableValueKeyframeEffectModel::KeyframeVector AnimatableValueKeyfra meVector;
143 typedef AnimatableValueKeyframeEffectModel::PropertySpecificKeyframeVector Anima tableValuePropertySpecificKeyframeVector;
144
145 typedef KeyframeEffectModel<StringKeyframe> StringKeyframeEffectModel;
146 typedef StringKeyframeEffectModel::KeyframeVector StringKeyframeVector;
147 typedef StringKeyframeEffectModel::PropertySpecificKeyframeVector StringProperty SpecificKeyframeVector;
148
149 DEFINE_TYPE_CASTS(KeyframeEffectModelBase, AnimationEffect, value, value->isKeyf rameEffectModel(), value.isKeyframeEffectModel());
150 DEFINE_TYPE_CASTS(AnimatableValueKeyframeEffectModel, KeyframeEffectModelBase, v alue, value->isAnimatableValueKeyframeEffectModel(), value.isAnimatableValueKeyf rameEffectModel());
151
152 inline const AnimatableValueKeyframeEffectModel* toAnimatableValueKeyframeEffect Model(const AnimationEffect* base)
153 {
154 return toAnimatableValueKeyframeEffectModel(toKeyframeEffectModelBase(base)) ;
155 }
156
157 inline AnimatableValueKeyframeEffectModel* toAnimatableValueKeyframeEffectModel( AnimationEffect* base)
158 {
159 return toAnimatableValueKeyframeEffectModel(toKeyframeEffectModelBase(base)) ;
160 }
161 182
162 } // namespace WebCore 183 } // namespace WebCore
163 184
164 #endif // KeyframeEffectModel_h 185 #endif // KeyframeEffectModel_h
OLDNEW
« no previous file with comments | « Source/core/animation/Keyframe.h ('k') | Source/core/animation/KeyframeEffectModel.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698