OLD | NEW |
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 Loading... |
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 typedef Vector<OwnPtr<Keyframe::PropertySpecificKeyframe> > PropertySpecific
KeyframeVector; |
| 57 class PropertySpecificKeyframeGroup { |
| 58 public: |
| 59 void appendKeyframe(PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKey
frame>); |
| 60 const PropertySpecificKeyframeVector& keyframes() const { return m_keyfr
ames; } |
77 | 61 |
78 private: | 62 void trace(Visitor*); |
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 | 63 |
88 class KeyframeEffectModel FINAL : public AnimationEffect { | 64 private: |
89 public: | 65 void removeRedundantKeyframes(); |
90 class PropertySpecificKeyframe; | 66 void addSyntheticKeyframeIfRequired(const KeyframeEffectModelBase* conte
xt); |
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 | 67 |
99 virtual bool affects(CSSPropertyID property) OVERRIDE | 68 PropertySpecificKeyframeVector m_keyframes; |
100 { | |
101 ensureKeyframeGroups(); | |
102 return m_keyframeGroups->contains(property); | |
103 } | |
104 | 69 |
105 // AnimationEffect implementation. | 70 friend class KeyframeEffectModelBase; |
106 virtual PassOwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpola
tion> > > sample(int iteration, double fraction, double iterationDuration) const
OVERRIDE; | 71 }; |
107 | |
108 // FIXME: Implement setFrames() | |
109 const KeyframeVector& getFrames() const { return m_keyframes; } | |
110 | |
111 virtual bool isKeyframeEffectModel() const OVERRIDE { return true; } | |
112 | 72 |
113 bool isReplaceOnly(); | 73 bool isReplaceOnly(); |
114 | 74 |
115 PropertySet properties() const; | 75 PropertySet properties() const; |
116 | 76 |
117 class PropertySpecificKeyframe : public NoBaseWillBeGarbageCollectedFinalize
d<PropertySpecificKeyframe> { | 77 typedef WillBeHeapVector<RefPtrWillBeMember<Keyframe> > KeyframeVector; |
118 public: | 78 const KeyframeVector& getFrames() const { return m_keyframes; } |
119 PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easin
g, const AnimatableValue*, CompositeOperation); | 79 // 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 | 80 |
152 const PropertySpecificKeyframeVector& getPropertySpecificKeyframes(CSSProper
tyID id) const | 81 const PropertySpecificKeyframeVector& getPropertySpecificKeyframes(CSSProper
tyID id) const |
153 { | 82 { |
154 ensureKeyframeGroups(); | 83 ensureKeyframeGroups(); |
155 return m_keyframeGroups->get(id)->keyframes(); | 84 return m_keyframeGroups->get(id)->keyframes(); |
156 } | 85 } |
157 | 86 |
| 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 |
158 virtual void trace(Visitor*) OVERRIDE; | 95 virtual void trace(Visitor*) OVERRIDE; |
159 | 96 |
160 private: | 97 protected: |
161 KeyframeEffectModel(const KeyframeVector& keyframes); | |
162 | |
163 static KeyframeVector normalizedKeyframes(const KeyframeVector& keyframes); | 98 static KeyframeVector normalizedKeyframes(const KeyframeVector& keyframes); |
164 | 99 |
165 // Lazily computes the groups of property-specific keyframes. | 100 // Lazily computes the groups of property-specific keyframes. |
166 void ensureKeyframeGroups() const; | 101 void ensureKeyframeGroups() const; |
167 void ensureInterpolationEffect() const; | 102 void ensureInterpolationEffect() const; |
168 | 103 |
169 KeyframeVector m_keyframes; | 104 KeyframeVector m_keyframes; |
170 // The spec describes filtering the normalized keyframes at sampling time | 105 // The spec describes filtering the normalized keyframes at sampling time |
171 // to get the 'property-specific keyframes'. For efficiency, we cache the | 106 // to get the 'property-specific keyframes'. For efficiency, we cache the |
172 // property-specific lists. | 107 // property-specific lists. |
173 typedef WillBeHeapHashMap<CSSPropertyID, OwnPtrWillBeMember<PropertySpecific
KeyframeGroup> > KeyframeGroupMap; | 108 typedef WillBeHeapHashMap<CSSPropertyID, OwnPtrWillBeMember<PropertySpecific
KeyframeGroup> > KeyframeGroupMap; |
174 mutable OwnPtrWillBeMember<KeyframeGroupMap> m_keyframeGroups; | 109 mutable OwnPtrWillBeMember<KeyframeGroupMap> m_keyframeGroups; |
175 | 110 mutable RefPtr<InterpolationEffect> m_interpolationEffect; |
176 mutable RefPtrWillBeMember<InterpolationEffect> m_interpolationEffect; | |
177 | 111 |
178 friend class KeyframeEffectModelTest; | 112 friend class KeyframeEffectModelTest; |
| 113 |
| 114 bool affects(CSSPropertyID property) |
| 115 { |
| 116 ensureKeyframeGroups(); |
| 117 return m_keyframeGroups->contains(property); |
| 118 } |
179 }; | 119 }; |
180 | 120 |
181 DEFINE_TYPE_CASTS(KeyframeEffectModel, AnimationEffect, value, value->isKeyframe
EffectModel(), value.isKeyframeEffectModel()); | 121 template <class Keyframe> |
| 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 } |
182 | 161 |
183 } // namespace WebCore | 162 } // namespace WebCore |
184 | 163 |
185 #endif // KeyframeEffectModel_h | 164 #endif // KeyframeEffectModel_h |
OLD | NEW |