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_GFX_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ | 5 #ifndef UI_GFX_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ |
6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ | 6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "ui/gfx/compositor/compositor_export.h" | 13 #include "ui/gfx/compositor/compositor_export.h" |
14 | 14 |
15 namespace ui { | 15 namespace ui { |
16 | 16 |
17 class LayerAnimationSequence; | 17 class LayerAnimationSequence; |
18 class ScopedLayerAnimationSettings; | 18 class ScopedLayerAnimationSettings; |
19 class ImplicitAnimationObserver; | |
20 | 19 |
21 // LayerAnimationObservers are notified when animations complete. | 20 // LayerAnimationObservers are notified when animations complete. |
22 class COMPOSITOR_EXPORT LayerAnimationObserver { | 21 class COMPOSITOR_EXPORT LayerAnimationObserver { |
23 public: | 22 public: |
24 // Called when the |sequence| ends. Not called if |sequence| is aborted. | 23 // Called when the |sequence| ends. Not called if |sequence| is aborted. |
25 virtual void OnLayerAnimationEnded( | 24 virtual void OnLayerAnimationEnded( |
26 LayerAnimationSequence* sequence) = 0; | 25 const LayerAnimationSequence* sequence) = 0; |
27 | 26 |
28 // Called if |sequence| is aborted for any reason. Should never do anything | 27 // Called if |sequence| is aborted for any reason. Should never do anything |
29 // that may cause another animation to be started. | 28 // that may cause another animation to be started. |
30 virtual void OnLayerAnimationAborted( | 29 virtual void OnLayerAnimationAborted( |
31 LayerAnimationSequence* sequence) = 0; | 30 const LayerAnimationSequence* sequence) = 0; |
32 | 31 |
33 // Called when the animation is scheduled. | 32 // Called when the animation is scheduled. |
34 virtual void OnLayerAnimationScheduled( | 33 virtual void OnLayerAnimationScheduled( |
35 LayerAnimationSequence* sequence) = 0; | 34 const LayerAnimationSequence* sequence) = 0; |
36 | |
37 protected: | |
38 typedef std::set<LayerAnimationSequence*> AttachedSequences; | |
39 | |
40 LayerAnimationObserver(); | |
41 virtual ~LayerAnimationObserver(); | |
42 | 35 |
43 // If the animator is destroyed during an animation, the animations are | 36 // If the animator is destroyed during an animation, the animations are |
44 // aborted. The resulting NotifyAborted notifications will NOT be sent to | 37 // aborted. The resulting NotifyAborted notifications will NOT be sent to |
45 // this observer if this function returns false. NOTE: IF YOU OVERRIDE THIS | 38 // this observer if this function returns false. NOTE: IF YOU OVERRIDE THIS |
46 // FUNCTION TO RETURN TRUE, YOU MUST REMEMBER TO REMOVE YOURSELF AS AN | 39 // FUNCTION TO RETURN TRUE, YOU MUST REMEMBER TO REMOVE YOURSELF AS AN |
47 // OBSERVER WHEN YOU ARE DESTROYED. | 40 // OBSERVER WHEN YOU ARE DESTROYED. |
48 virtual bool RequiresNotificationWhenAnimatorDestroyed() const; | 41 virtual bool RequiresNotificationWhenAnimatorDestroyed() const; |
49 | 42 |
50 // Called when |this| is added to |sequence|'s observer list. | 43 protected: |
51 virtual void OnAttachedToSequence(LayerAnimationSequence* sequence); | 44 LayerAnimationObserver(); |
52 | 45 virtual ~LayerAnimationObserver(); |
53 // Called when |this| is removed to |sequence|'s observer list. | |
54 virtual void OnDetachedFromSequence(LayerAnimationSequence* sequence); | |
55 | |
56 // Detaches this observer from all sequences it is currently observing. | |
57 void StopObserving(); | |
58 | |
59 const AttachedSequences& attached_sequences() const { | |
60 return attached_sequences_; | |
61 } | |
62 | 46 |
63 private: | 47 private: |
64 friend class LayerAnimationSequence; | 48 friend class LayerAnimationSequence; |
65 | 49 |
66 // Called when |this| is added to |sequence|'s observer list. | 50 // Called when |this| is added to |sequence|'s observer list. |
67 void AttachedToSequence(LayerAnimationSequence* sequence); | 51 void AttachedToSequence(LayerAnimationSequence* sequence); |
68 | 52 |
69 // Called when |this| is removed to |sequence|'s observer list. | 53 // Called when |this| is removed to |sequence|'s observer list. |
70 void DetachedFromSequence(LayerAnimationSequence* sequence); | 54 void DetachedFromSequence(LayerAnimationSequence* sequence); |
71 | 55 |
72 AttachedSequences attached_sequences_; | 56 std::set<LayerAnimationSequence*> attached_sequences_; |
73 }; | 57 }; |
74 | 58 |
75 // An implicit animation observer is intended to be used in conjunction with a | 59 // An implicit animation observer is intended to be used in conjunction with a |
76 // ScopedLayerAnimationSettings object in order to receive a notification when | 60 // ScopedLayerAnimationSettings object in order to receive a notification when |
77 // all implicit animations complete. | 61 // all implicit animations complete. |
78 class COMPOSITOR_EXPORT ImplicitAnimationObserver | 62 class COMPOSITOR_EXPORT ImplicitAnimationObserver |
79 : public LayerAnimationObserver { | 63 : public LayerAnimationObserver { |
80 public: | 64 public: |
81 ImplicitAnimationObserver(); | 65 ImplicitAnimationObserver(); |
82 virtual ~ImplicitAnimationObserver(); | 66 virtual ~ImplicitAnimationObserver(); |
83 | 67 |
84 virtual void OnImplicitAnimationsCompleted() = 0; | 68 virtual void OnImplicitAnimationsCompleted() = 0; |
85 | 69 |
86 protected: | |
87 // Deactivates the observer and clears the collection of animations it is | |
88 // waiting for. | |
89 void StopObservingImplicitAnimations(); | |
90 | |
91 private: | 70 private: |
92 friend class ScopedLayerAnimationSettings; | 71 friend class ScopedLayerAnimationSettings; |
93 | 72 |
94 // LayerAnimationObserver implementation | |
95 virtual void OnLayerAnimationEnded( | |
96 LayerAnimationSequence* sequence) OVERRIDE; | |
97 virtual void OnLayerAnimationAborted( | |
98 LayerAnimationSequence* sequence) OVERRIDE; | |
99 virtual void OnLayerAnimationScheduled( | |
100 LayerAnimationSequence* sequence) OVERRIDE; | |
101 virtual void OnAttachedToSequence( | |
102 LayerAnimationSequence* sequence) OVERRIDE; | |
103 virtual void OnDetachedFromSequence( | |
104 LayerAnimationSequence* sequence) OVERRIDE; | |
105 | |
106 // OnImplicitAnimationsCompleted is not fired unless the observer is active. | 73 // OnImplicitAnimationsCompleted is not fired unless the observer is active. |
107 bool active() const { return active_; } | 74 bool active() const { return active_; } |
108 void SetActive(bool active); | 75 void SetActive(bool active); |
109 | 76 |
| 77 // LayerAnimationObserver implementation |
| 78 virtual void OnLayerAnimationEnded( |
| 79 const LayerAnimationSequence* sequence) OVERRIDE; |
| 80 virtual void OnLayerAnimationAborted( |
| 81 const LayerAnimationSequence* sequence) OVERRIDE; |
| 82 virtual void OnLayerAnimationScheduled( |
| 83 const LayerAnimationSequence* sequence) OVERRIDE; |
| 84 |
110 void CheckCompleted(); | 85 void CheckCompleted(); |
111 | 86 |
112 bool active_; | 87 bool active_; |
| 88 |
| 89 // This tracks the number of scheduled animations that have yet to complete. |
| 90 // If this value is zero, and the observer is active, then |
| 91 // OnImplicitAnimationsCompleted is fired. |
| 92 size_t animation_count_; |
113 }; | 93 }; |
114 | 94 |
115 } // namespace ui | 95 } // namespace ui |
116 | 96 |
117 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ | 97 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ |
OLD | NEW |