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

Side by Side Diff: ui/gfx/compositor/layer_animator.h

Issue 8395046: Allows observers to be notified when layer animations complete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge with master Created 9 years, 1 month 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 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ 5 #ifndef UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_
6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ 6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include <deque> 9 #include <deque>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
14 #include "base/time.h" 15 #include "base/time.h"
15 #include "ui/base/animation/animation_container_element.h" 16 #include "ui/base/animation/animation_container_element.h"
16 #include "ui/gfx/compositor/compositor_export.h" 17 #include "ui/gfx/compositor/compositor_export.h"
17 #include "ui/gfx/compositor/layer_animation_element.h" 18 #include "ui/gfx/compositor/layer_animation_element.h"
18 19
19 namespace gfx { 20 namespace gfx {
20 class Rect; 21 class Rect;
21 } 22 }
22 23
23 namespace ui { 24 namespace ui {
24 class Animation; 25 class Animation;
25 class Layer; 26 class Layer;
26 class LayerAnimationSequence; 27 class LayerAnimationSequence;
27 class LayerAnimatorDelegate; 28 class LayerAnimationDelegate;
29 class LayerAnimationObserver;
28 class Transform; 30 class Transform;
29 31
30 // When a property of layer needs to be changed it is set by way of 32 // When a property of layer needs to be changed it is set by way of
31 // LayerAnimator. This enables LayerAnimator to animate property changes. 33 // LayerAnimator. This enables LayerAnimator to animate property changes.
32 class COMPOSITOR_EXPORT LayerAnimator : public AnimationContainerElement { 34 class COMPOSITOR_EXPORT LayerAnimator : public AnimationContainerElement {
33 public: 35 public:
34 enum PreemptionStrategy { 36 enum PreemptionStrategy {
35 IMMEDIATELY_SET_NEW_TARGET, 37 IMMEDIATELY_SET_NEW_TARGET,
36 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 38 IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
37 ENQUEUE_NEW_ANIMATION, 39 ENQUEUE_NEW_ANIMATION,
(...skipping 17 matching lines...) Expand all
55 // Sets the bounds on the delegate. May cause an implicit animation. 57 // Sets the bounds on the delegate. May cause an implicit animation.
56 virtual void SetBounds(const gfx::Rect& bounds); 58 virtual void SetBounds(const gfx::Rect& bounds);
57 gfx::Rect GetTargetBounds() const; 59 gfx::Rect GetTargetBounds() const;
58 60
59 // Sets the opacity on the delegate. May cause an implicit animation. 61 // Sets the opacity on the delegate. May cause an implicit animation.
60 virtual void SetOpacity(float opacity); 62 virtual void SetOpacity(float opacity);
61 float GetTargetOpacity() const; 63 float GetTargetOpacity() const;
62 64
63 // Sets the layer animation delegate the animator is associated with. The 65 // Sets the layer animation delegate the animator is associated with. The
64 // animator does not own the delegate. 66 // animator does not own the delegate.
65 void SetDelegate(LayerAnimatorDelegate* delegate); 67 void SetDelegate(LayerAnimationDelegate* delegate);
66 68
67 // Sets the animation preemption strategy. This determines the behaviour if 69 // Sets the animation preemption strategy. This determines the behaviour if
68 // a property is set during an animation. The default is 70 // a property is set during an animation. The default is
69 // IMMEDIATELY_SET_NEW_TARGET (see ImmediatelySetNewTarget below). 71 // IMMEDIATELY_SET_NEW_TARGET (see ImmediatelySetNewTarget below).
70 void set_preemption_strategy(PreemptionStrategy strategy) { 72 void set_preemption_strategy(PreemptionStrategy strategy) {
71 preemption_strategy_ = strategy; 73 preemption_strategy_ = strategy;
72 } 74 }
73 75
74 // Start an animation sequence. If an animation for the same property is in 76 // Start an animation sequence. If an animation for the same property is in
75 // progress, it needs to be interrupted with the new animation. The animator 77 // progress, it needs to be interrupted with the new animation. The animator
76 // takes ownership of this animation sequence. 78 // takes ownership of this animation sequence.
77 void StartAnimation(LayerAnimationSequence* animation); 79 void StartAnimation(LayerAnimationSequence* animation);
78 80
79 // Schedule an animation to be run when possible. The animator takes ownership 81 // Schedule an animation to be run when possible. The animator takes ownership
80 // of this animation sequence. 82 // of this animation sequence.
81 void ScheduleAnimation(LayerAnimationSequence* animation); 83 void ScheduleAnimation(LayerAnimationSequence* animation);
82 84
83 // Schedules the animations to be run together. Obviously will no work if 85 // Schedules the animations to be run together. Obviously will no work if
84 // they animate any common properties. The animator takes ownership of the 86 // they animate any common properties. The animator takes ownership of the
85 // animation sequences. 87 // animation sequences.
86 void ScheduleTogether(const std::vector<LayerAnimationSequence*>& animations); 88 void ScheduleTogether(const std::vector<LayerAnimationSequence*>& animations);
87 89
88 // These are cover functions that create sequences for you to wrap the given
89 // elements. These sequences are then passed to the corresponding function
90 // above.
91 void StartAnimationElement(LayerAnimationElement* element);
92 void ScheduleAnimationElement(LayerAnimationElement* element);
93 void ScheduleElementsTogether(
94 const std::vector<LayerAnimationElement*>& element);
95
96 // Returns true if there is an animation in the queue (animations remain in 90 // Returns true if there is an animation in the queue (animations remain in
97 // the queue until they complete). 91 // the queue until they complete).
98 bool is_animating() const { return !animation_queue_.empty(); } 92 bool is_animating() const { return !animation_queue_.empty(); }
99 93
100 // Stops animating the given property. No effect if there is no running 94 // Stops animating the given property. No effect if there is no running
101 // animation for the given property. Skips to the final state of the 95 // animation for the given property. Skips to the final state of the
102 // animation. 96 // animation.
103 void StopAnimatingProperty( 97 void StopAnimatingProperty(
104 LayerAnimationElement::AnimatableProperty property); 98 LayerAnimationElement::AnimatableProperty property);
105 99
106 // Stops all animation and clears any queued animations. 100 // Stops all animation and clears any queued animations.
107 void StopAnimating(); 101 void StopAnimating();
108 102
109 // For testing purposes only. 103 // For testing purposes only.
110 void set_disable_timer_for_test(bool enabled) { 104 void set_disable_timer_for_test(bool enabled) {
111 disable_timer_for_test_ = enabled; 105 disable_timer_for_test_ = enabled;
112 } 106 }
113 base::TimeTicks get_last_step_time_for_test() { return last_step_time_; } 107 base::TimeTicks get_last_step_time_for_test() { return last_step_time_; }
114 108
109 // These functions are used for adding or removing observers from the observer
110 // list. The observers are notified when animations end.
111 void AddObserver(LayerAnimationObserver* observer);
112 void RemoveObserver(LayerAnimationObserver* observer);
113
115 // Scoped settings allow you to temporarily change the animator's settings and 114 // Scoped settings allow you to temporarily change the animator's settings and
116 // these changes are reverted when the object is destroyed. NOTE: when the 115 // these changes are reverted when the object is destroyed. NOTE: when the
117 // settings object is created, it applies the default transition duration 116 // settings object is created, it applies the default transition duration
118 // (200ms). 117 // (200ms).
119 class ScopedSettings { 118 class ScopedSettings {
120 public: 119 public:
121 explicit ScopedSettings(LayerAnimator* animator); 120 explicit ScopedSettings(LayerAnimator* animator);
122 virtual ~ScopedSettings(); 121 virtual ~ScopedSettings();
123 122
123 void AddObserver(LayerAnimationObserver* observer);
124 void SetTransitionDuration(base::TimeDelta duration); 124 void SetTransitionDuration(base::TimeDelta duration);
125 125
126 private: 126 private:
127 LayerAnimator* animator_; 127 LayerAnimator* animator_;
128 base::TimeDelta old_transition_duration_; 128 base::TimeDelta old_transition_duration_;
129 std::vector<LayerAnimationObserver*> observers_;
129 130
130 DISALLOW_COPY_AND_ASSIGN(ScopedSettings); 131 DISALLOW_COPY_AND_ASSIGN(ScopedSettings);
131 }; 132 };
132 133
133 protected: 134 protected:
134 LayerAnimatorDelegate* delegate() { return delegate_; } 135 LayerAnimationDelegate* delegate() { return delegate_; }
135 136
136 private: 137 private:
137 friend class TransientSettings; 138 friend class ScopedSettings;
138 139
139 // We need to keep track of the start time of every running animation. 140 // We need to keep track of the start time of every running animation.
140 struct RunningAnimation { 141 struct RunningAnimation {
141 RunningAnimation(LayerAnimationSequence* sequence, 142 RunningAnimation(LayerAnimationSequence* sequence,
142 base::TimeTicks start_time) 143 base::TimeTicks start_time)
143 : sequence(sequence), 144 : sequence(sequence),
144 start_time(start_time) { 145 start_time(start_time) {
145 } 146 }
146 LayerAnimationSequence* sequence; 147 LayerAnimationSequence* sequence;
147 base::TimeTicks start_time; 148 base::TimeTicks start_time;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 205
205 // Attempts to add the sequence to the list of running animations. Returns 206 // Attempts to add the sequence to the list of running animations. Returns
206 // false if there is an animation running that already animates one of the 207 // false if there is an animation running that already animates one of the
207 // properties affected by |sequence|. 208 // properties affected by |sequence|.
208 bool StartSequenceImmediately(LayerAnimationSequence* sequence); 209 bool StartSequenceImmediately(LayerAnimationSequence* sequence);
209 210
210 // Sets the value of target as if all the running and queued animations were 211 // Sets the value of target as if all the running and queued animations were
211 // allowed to finish. 212 // allowed to finish.
212 void GetTargetValue(LayerAnimationElement::TargetValue* target) const; 213 void GetTargetValue(LayerAnimationElement::TargetValue* target) const;
213 214
215 // Notifies the observers that the sequence has ended.
216 void NotifyAnimationEnded(LayerAnimationSequence* sequence);
217
218 // Associates observers_ with sequence
219 void AddObserversToSequence(LayerAnimationSequence* sequence);
220
214 // This is the queue of animations to run. 221 // This is the queue of animations to run.
215 AnimationQueue animation_queue_; 222 AnimationQueue animation_queue_;
216 223
217 // The target of all layer animations. 224 // The target of all layer animations.
218 LayerAnimatorDelegate* delegate_; 225 LayerAnimationDelegate* delegate_;
219 226
220 // The currently running animations. 227 // The currently running animations.
221 RunningAnimations running_animations_; 228 RunningAnimations running_animations_;
222 229
223 // Determines how animations are replaced. 230 // Determines how animations are replaced.
224 PreemptionStrategy preemption_strategy_; 231 PreemptionStrategy preemption_strategy_;
225 232
226 // The default length of animations. 233 // The default length of animations.
227 base::TimeDelta transition_duration_; 234 base::TimeDelta transition_duration_;
228 235
229 // Used for coordinating the starting of animations. 236 // Used for coordinating the starting of animations.
230 base::TimeTicks last_step_time_; 237 base::TimeTicks last_step_time_;
231 238
232 // True if we are being stepped by our container. 239 // True if we are being stepped by our container.
233 bool is_started_; 240 bool is_started_;
234 241
235 // This prevents the animator from automatically stepping through animations 242 // This prevents the animator from automatically stepping through animations
236 // and allows for manual stepping. 243 // and allows for manual stepping.
237 bool disable_timer_for_test_; 244 bool disable_timer_for_test_;
238 245
246 // These parties are notified when layer animations end.
sky 2011/10/27 19:29:19 parties -> observers
247 ObserverList<LayerAnimationObserver> observers_;
248
239 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); 249 DISALLOW_COPY_AND_ASSIGN(LayerAnimator);
240 }; 250 };
241 251
242 } // namespace ui 252 } // namespace ui
243 253
244 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ 254 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698