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