OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ | 5 #ifndef UI_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ |
6 #define UI_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ | 6 #define UI_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | |
11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
12 #include "ui/compositor/compositor_export.h" | 13 #include "ui/compositor/compositor_export.h" |
13 | 14 |
14 namespace ui { | 15 namespace ui { |
15 | 16 |
16 class LayerAnimationSequence; | 17 class LayerAnimationSequence; |
17 class ScopedLayerAnimationSettings; | 18 class ScopedLayerAnimationSettings; |
18 class ImplicitAnimationObserver; | 19 class ImplicitAnimationObserver; |
19 | 20 |
20 // LayerAnimationObservers are notified when animations complete. | 21 // LayerAnimationObservers are notified when animations complete. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 bool active_; | 119 bool active_; |
119 | 120 |
120 // Set to true in the destructor (if non-NULL). Used to detect deletion while | 121 // Set to true in the destructor (if non-NULL). Used to detect deletion while |
121 // calling out. | 122 // calling out. |
122 bool* destroyed_; | 123 bool* destroyed_; |
123 | 124 |
124 // True if OnLayerAnimationScheduled() has been called at least once. | 125 // True if OnLayerAnimationScheduled() has been called at least once. |
125 bool first_sequence_scheduled_; | 126 bool first_sequence_scheduled_; |
126 }; | 127 }; |
127 | 128 |
129 // This observer is intended to use in cases when some action have to be taken | |
130 // once some animation successfully completes (i.e. it was not aborted). | |
131 // Observer will count a number of sequences it is attached to, and a number of | |
132 // finished sequences (either Ended or Aborted). Once these two numbers are | |
133 // equal, observer will delete itself, calling callback passed to constructor if | |
134 // there was no aborted animations. | |
135 // This way it can be either used to wait for some animation to be finished in | |
136 // multiple layers, to wait once a sequence of animations is finished in one | |
137 // layer or the mixture of both. | |
Ian Vollick
2012/12/05 17:36:20
I worry about the addition of so many special purp
Denis Kuznetsov (DE-MUC)
2012/12/05 18:32:17
Current usage of this observer is a lock animation
| |
138 class COMPOSITOR_EXPORT AnimationFinishedObserver | |
139 : public LayerAnimationObserver { | |
140 public: | |
141 explicit AnimationFinishedObserver(base::Closure &callback); | |
142 virtual ~AnimationFinishedObserver(); | |
143 | |
144 // Pauses observer: no checks will be made while paused. It can be used when | |
145 // sequence have some immediate animations in the beginning. | |
146 void Pause(); | |
147 | |
148 // Unpauses observer. It does a check ant calls callback if conditions are | |
149 // met. | |
150 void Unpause(); | |
151 | |
152 private: | |
153 // LayerAnimationObserver implementation | |
154 virtual void OnLayerAnimationEnded( | |
155 LayerAnimationSequence* sequence) OVERRIDE; | |
156 virtual void OnLayerAnimationAborted( | |
157 LayerAnimationSequence* sequence) OVERRIDE; | |
158 virtual void OnLayerAnimationScheduled( | |
159 LayerAnimationSequence* sequence) OVERRIDE {}; | |
160 virtual void OnAttachedToSequence( | |
161 LayerAnimationSequence* sequence) OVERRIDE; | |
162 | |
163 // Callback to be called. | |
164 base::Closure callback_; | |
165 | |
166 // Number of sequences this observer was attached to. | |
167 int sequences_attached_; | |
168 | |
169 // Number of sequences either ended or aborted. | |
170 int sequences_completed_; | |
171 | |
172 bool paused_; | |
173 | |
174 DISALLOW_COPY_AND_ASSIGN(AnimationFinishedObserver); | |
175 }; | |
176 | |
177 // This observer is intended to use in cases when some action have to be taken | |
178 // once some animation was aborted. Observer will count a number of sequences it | |
179 // is attached to, and a number of finished sequences (either Ended or Aborted). | |
180 // Once these two numbers are equal, observer will delete itself, calling | |
181 // callback passed to constructor if there was at least one aborted animation. | |
182 // This way it can be either used to wait for some animation to be cancelled in | |
183 // multiple layers, to wait once a sequence of animations is cancelled in one | |
184 // layer or the mixture of both. | |
185 // If this observer is deleted before all animations complete, it will call | |
186 // |callback|, so it is safe to use it in conjunction with | |
187 // AnimationFinishedObserver to clean up resources. | |
188 | |
189 class COMPOSITOR_EXPORT AnimationAbortedObserver | |
190 : public LayerAnimationObserver { | |
191 public: | |
192 explicit AnimationAbortedObserver(base::Closure &callback); | |
193 virtual ~AnimationAbortedObserver(); | |
194 | |
195 // Pauses observer: no checks will be made while paused. It can be used when | |
196 // sequence have some immediate animations in the beginning. | |
197 void Pause(); | |
198 | |
199 // Unpauses observer. It does a check ant calls callback if conditions are | |
200 // met. | |
201 void Unpause(); | |
202 | |
203 private: | |
204 // LayerAnimationObserver implementation | |
205 virtual void OnLayerAnimationEnded( | |
206 LayerAnimationSequence* sequence) OVERRIDE; | |
207 virtual void OnLayerAnimationAborted( | |
208 LayerAnimationSequence* sequence) OVERRIDE; | |
209 virtual void OnLayerAnimationScheduled( | |
210 LayerAnimationSequence* sequence) OVERRIDE {}; | |
211 virtual void OnAttachedToSequence( | |
212 LayerAnimationSequence* sequence) OVERRIDE; | |
213 | |
214 // Callback to be called. | |
215 base::Closure callback_; | |
216 | |
217 // Number of sequences this observer was attached to. | |
218 int sequences_attached_; | |
219 | |
220 // Number of sequences either ended or aborted. | |
221 int sequences_completed_; | |
222 | |
223 // True if at lease one sequence was aborted. | |
224 bool aborted_; | |
225 | |
226 bool paused_; | |
227 | |
228 DISALLOW_COPY_AND_ASSIGN(AnimationAbortedObserver); | |
229 }; | |
230 | |
128 } // namespace ui | 231 } // namespace ui |
129 | 232 |
130 #endif // UI_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ | 233 #endif // UI_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ |
OLD | NEW |