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

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

Issue 1113173003: Web Animations: Update naming to reflect spec changes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: No, really. Created 5 years, 7 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
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 Animation_h 31 #ifndef Animation_h
32 #define Animation_h 32 #define Animation_h
33 33
34 #include "bindings/core/v8/ScriptPromise.h"
35 #include "bindings/core/v8/ScriptPromiseProperty.h"
36 #include "core/CSSPropertyNames.h"
34 #include "core/CoreExport.h" 37 #include "core/CoreExport.h"
35 #include "core/animation/AnimationEffect.h" 38 #include "core/animation/AnimationEffect.h"
36 #include "core/animation/AnimationNode.h" 39 #include "core/dom/ActiveDOMObject.h"
37 #include "core/animation/EffectInput.h" 40 #include "core/dom/DOMException.h"
38 #include "core/animation/TimingInput.h" 41 #include "core/events/EventTarget.h"
39 #include "platform/heap/Handle.h" 42 #include "platform/heap/Handle.h"
43 #include "public/platform/WebCompositorAnimationDelegate.h"
44 #include "public/platform/WebCompositorAnimationPlayerClient.h"
40 #include "wtf/RefPtr.h" 45 #include "wtf/RefPtr.h"
41 46
42 namespace blink { 47 namespace blink {
43 48
44 class AnimationTimingProperties; 49 class AnimationTimeline;
45 class Dictionary;
46 class Element; 50 class Element;
47 class ExceptionState; 51 class ExceptionState;
48 class PropertyHandle; 52 class WebCompositorAnimationPlayer;
49 class SampledEffect; 53
50 54 class CORE_EXPORT Animation final
51 class CORE_EXPORT Animation final : public AnimationNode { 55 : public EventTargetWithInlineData
56 , public RefCountedWillBeNoBase<Animation>
57 , public ActiveDOMObject
58 , public WebCompositorAnimationDelegate
59 , public WebCompositorAnimationPlayerClient {
52 DEFINE_WRAPPERTYPEINFO(); 60 DEFINE_WRAPPERTYPEINFO();
61 REFCOUNTED_EVENT_TARGET(Animation);
62 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Animation);
53 public: 63 public:
54 enum Priority { DefaultPriority, TransitionPriority }; 64 enum AnimationPlayState {
55 65 Idle,
56 static PassRefPtrWillBeRawPtr<Animation> create(Element*, PassRefPtrWillBeRa wPtr<AnimationEffect>, const Timing&, Priority = DefaultPriority, PassOwnPtrWill BeRawPtr<EventDelegate> = nullptr); 66 Pending,
57 // Web Animations API Bindings constructors. 67 Running,
58 static PassRefPtrWillBeRawPtr<Animation> create(Element*, const Vector<Dicti onary>& keyframeDictionaryVector, double duration, ExceptionState&); 68 Paused,
59 static PassRefPtrWillBeRawPtr<Animation> create(Element*, const Vector<Dicti onary>& keyframeDictionaryVector, const AnimationTimingProperties& timingInput, ExceptionState&); 69 Finished
60 static PassRefPtrWillBeRawPtr<Animation> create(Element*, const Vector<Dicti onary>& keyframeDictionaryVector, ExceptionState&); 70 };
61 71
62 virtual ~Animation(); 72 ~Animation();
63 73 static PassRefPtrWillBeRawPtr<Animation> create(AnimationEffect*, AnimationT imeline*);
64 virtual bool isAnimation() const override { return true; } 74
65 75 // Returns whether the animation is finished.
66 bool affects(PropertyHandle) const; 76 bool update(TimingUpdateReason);
67 const AnimationEffect* effect() const { return m_effect.get(); } 77
68 AnimationEffect* effect() { return m_effect.get(); } 78 // timeToEffectChange returns:
69 void setEffect(PassRefPtrWillBeRawPtr<AnimationEffect> effect) { m_effect = effect; } 79 // infinity - if this animation is no longer in effect
70 Priority priority() const { return m_priority; } 80 // 0 - if this animation requires an update on the next frame
71 Element* target() const { return m_target; } 81 // n - if this animation requires an update after 'n' units of time
82 double timeToEffectChange();
83
84 void cancel();
85
86 double currentTime(bool& isNull);
87 double currentTime();
88 void setCurrentTime(double newCurrentTime);
89
90 double currentTimeInternal() const;
91 double unlimitedCurrentTimeInternal() const;
92
93 void setCurrentTimeInternal(double newCurrentTime, TimingUpdateReason = Timi ngUpdateOnDemand);
94 bool paused() const { return m_paused && !m_isPausedForTesting; }
95 static const char* playStateString(AnimationPlayState);
96 String playState() const { return playStateString(playStateInternal()); }
97 AnimationPlayState playStateInternal() const;
98
99 void pause();
100 void play();
101 void reverse();
102 void finish(ExceptionState&);
103
104 ScriptPromise finished(ScriptState*);
105 ScriptPromise ready(ScriptState*);
106
107 bool playing() const { return !(playStateInternal() == Idle || limited() || m_paused || m_isPausedForTesting); }
108 bool limited() const { return limited(currentTimeInternal()); }
109 bool finishedInternal() const { return m_finished; }
110
111 DEFINE_ATTRIBUTE_EVENT_LISTENER(finish);
112
113 virtual const AtomicString& interfaceName() const override;
114 virtual ExecutionContext* executionContext() const override;
115 virtual bool hasPendingActivity() const override;
116 virtual void stop() override;
117 virtual bool dispatchEvent(PassRefPtrWillBeRawPtr<Event>) override;
118
119 double playbackRate() const;
120 void setPlaybackRate(double);
121 const AnimationTimeline* timeline() const { return m_timeline; }
122 AnimationTimeline* timeline() { return m_timeline; }
72 123
73 #if !ENABLE(OILPAN) 124 #if !ENABLE(OILPAN)
74 void notifyElementDestroyed(); 125 void detachFromTimeline();
75 #endif 126 #endif
76 127
77 bool isCandidateForAnimationOnCompositor(double playerPlaybackRate) const; 128 double calculateStartTime(double currentTime) const;
78 // Must only be called once. 129 bool hasStartTime() const { return !isNull(m_startTime); }
79 bool maybeStartAnimationOnCompositor(int group, double startTime, double tim eOffset, double playerPlaybackRate); 130 double startTime(bool& isNull) const;
80 bool hasActiveAnimationsOnCompositor() const; 131 double startTime() const;
81 bool hasActiveAnimationsOnCompositor(CSSPropertyID) const; 132 double startTimeInternal() const { return m_startTime; }
82 bool cancelAnimationOnCompositor(); 133 void setStartTime(double);
134 void setStartTimeInternal(double);
135
136 const AnimationEffect* source() const { return m_content.get(); }
137 AnimationEffect* source() { return m_content.get(); }
138 void setSource(AnimationEffect*);
139
140 // Pausing via this method is not reflected in the value returned by
141 // paused() and must never overlap with pausing via pause().
142 void pauseForTesting(double pauseTime);
143 // This should only be used for CSS
144 void unpause();
145
146 void setOutdated();
147 bool outdated() { return m_outdated; }
148
149 bool canStartAnimationOnCompositor() const;
150 bool isCandidateForAnimationOnCompositor() const;
151 bool maybeStartAnimationOnCompositor();
152 void cancelAnimationOnCompositor();
83 void restartAnimationOnCompositor(); 153 void restartAnimationOnCompositor();
84 void cancelIncompatibleAnimationsOnCompositor(); 154 void cancelIncompatibleAnimationsOnCompositor();
85 void pauseAnimationForTestingOnCompositor(double pauseTime); 155 bool hasActiveAnimationsOnCompositor();
86 156 void setCompositorPending(bool sourceChanged = false);
87 bool canAttachCompositedLayers() const; 157 void notifyCompositorStartTime(double timelineTime);
158 void notifyStartTime(double timelineTime);
159 // WebCompositorAnimationPlayerClient implementation.
160 WebCompositorAnimationPlayer* compositorPlayer() const override { return m_c ompositorPlayer.get(); }
161
162 bool affects(const Element&, CSSPropertyID) const;
163
164 void preCommit(int compositorGroup, bool startOnCompositor);
165 void postCommit(double timelineTime);
166
167 unsigned sequenceNumber() const { return m_sequenceNumber; }
168 int compositorGroup() const { return m_compositorGroup; }
169
170 static bool hasLowerPriority(const Animation* animation1, const Animation* a nimation2)
171 {
172 return animation1->sequenceNumber() < animation2->sequenceNumber();
173 }
174
175 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<Even tListener>, bool useCapture = false) override;
176
177 DECLARE_VIRTUAL_TRACE();
178
179 private:
180 Animation(ExecutionContext*, AnimationTimeline&, AnimationEffect*);
181
182 double sourceEnd() const;
183 bool limited(double currentTime) const;
184
185 AnimationPlayState calculatePlayState();
186 double calculateCurrentTime() const;
187
188 void unpauseInternal();
189 void setPlaybackRateInternal(double);
190 void updateCurrentTimingState(TimingUpdateReason);
191
192 void beginUpdatingState();
193 void endUpdatingState();
194
195 void createCompositorPlayer();
196 void destroyCompositorPlayer();
197 void attachCompositorTimeline();
198 void detachCompositorTimeline();
88 void attachCompositedLayers(); 199 void attachCompositedLayers();
89 200 void detachCompositedLayers();
90 void setCompositorAnimationIdsForTesting(const Vector<int>& compositorAnimat ionIds) { m_compositorAnimationIds = compositorAnimationIds; } 201 // WebCompositorAnimationDelegate implementation.
91 202 void notifyAnimationStarted(double monotonicTime, int group) override;
92 DECLARE_VIRTUAL_TRACE(); 203 void notifyAnimationFinished(double monotonicTime, int group) override { }
93 204
94 void downgradeToNormalAnimation() { m_priority = DefaultPriority; } 205 AnimationPlayState m_playState;
95 206 double m_playbackRate;
96 protected: 207 double m_startTime;
97 void applyEffects(); 208 double m_holdTime;
98 void clearEffects(); 209
99 virtual void updateChildrenAndEffects() const override; 210 unsigned m_sequenceNumber;
100 virtual void attach(AnimationPlayer*) override; 211
101 virtual void detach() override; 212 typedef ScriptPromiseProperty<RawPtrWillBeMember<Animation>, RawPtrWillBeMem ber<Animation>, Member<DOMException>> AnimationPromise;
102 virtual void specifiedTimingChanged() override; 213 PersistentWillBeMember<AnimationPromise> m_finishedPromise;
103 virtual double calculateTimeToEffectChange(bool forwards, double inheritedTi me, double timeToNextIteration) const override; 214 PersistentWillBeMember<AnimationPromise> m_readyPromise;
104 215
105 private: 216 RefPtrWillBeMember<AnimationEffect> m_content;
106 Animation(Element*, PassRefPtrWillBeRawPtr<AnimationEffect>, const Timing&, Priority, PassOwnPtrWillBeRawPtr<EventDelegate>); 217 RawPtrWillBeMember<AnimationTimeline> m_timeline;
107 218 // Reflects all pausing, including via pauseForTesting().
108 RawPtrWillBeMember<Element> m_target; 219 bool m_paused;
109 RefPtrWillBeMember<AnimationEffect> m_effect; 220 bool m_held;
110 RawPtrWillBeMember<SampledEffect> m_sampledEffect; 221 bool m_isPausedForTesting;
111 222
112 Priority m_priority; 223 // This indicates timing information relevant to the animation's effect
113 224 // has changed by means other than the ordinary progression of time
114 Vector<int> m_compositorAnimationIds; 225 bool m_outdated;
115 226
116 friend class AnimationAnimationV8Test; 227 bool m_finished;
228 // Holds a 'finished' event queued for asynchronous dispatch via the
229 // ScriptedAnimationController. This object remains active until the
230 // event is actually dispatched.
231 RefPtrWillBeMember<Event> m_pendingFinishedEvent;
232
233 enum CompositorAction {
234 None,
235 Pause,
236 Start,
237 PauseThenStart
238 };
239
240 class CompositorState {
241 public:
242 CompositorState(Animation& animation)
243 : startTime(animation.m_startTime)
244 , holdTime(animation.m_holdTime)
245 , playbackRate(animation.m_playbackRate)
246 , sourceChanged(false)
247 , pendingAction(Start)
248 { }
249 double startTime;
250 double holdTime;
251 double playbackRate;
252 bool sourceChanged;
253 CompositorAction pendingAction;
254 };
255
256 enum CompositorPendingChange {
257 SetCompositorPending,
258 SetCompositorPendingWithSourceChanged,
259 DoNotSetCompositorPending,
260 };
261
262 class PlayStateUpdateScope {
263 STACK_ALLOCATED();
264 public:
265 PlayStateUpdateScope(Animation&, TimingUpdateReason, CompositorPendingCh ange = SetCompositorPending);
266 ~PlayStateUpdateScope();
267 private:
268 RawPtrWillBeMember<Animation> m_animation;
269 AnimationPlayState m_initialPlayState;
270 CompositorPendingChange m_compositorPendingChange;
271 };
272
273 // This mirrors the known compositor state. It is created when a compositor
274 // animation is started. Updated once the start time is known and each time
275 // modifications are pushed to the compositor.
276 OwnPtr<CompositorState> m_compositorState;
277 bool m_compositorPending;
278 int m_compositorGroup;
279
280 OwnPtr<WebCompositorAnimationPlayer> m_compositorPlayer;
281
282 bool m_currentTimePending;
283 bool m_stateIsBeingUpdated;
117 }; 284 };
118 285
119 DEFINE_TYPE_CASTS(Animation, AnimationNode, animationNode, animationNode->isAnim ation(), animationNode.isAnimation());
120
121 } // namespace blink 286 } // namespace blink
122 287
123 #endif // Animation_h 288 #endif // Animation_h
OLDNEW
« no previous file with comments | « LayoutTests/webexposed/web-animations-api-expected.txt ('k') | Source/core/animation/Animation.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698