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 void DetachFromAllSequences(); | |
sky
2012/01/30 22:20:19
Add a description of this. Maybe it should be name
| |
57 | |
58 AttachedSequences& attached_sequences() { return attached_sequences_; } | |
sky
2012/01/30 22:20:19
I don't think you want subclasses modifying this.
| |
46 | 59 |
47 private: | 60 private: |
48 friend class LayerAnimationSequence; | 61 friend class LayerAnimationSequence; |
49 | 62 |
50 // Called when |this| is added to |sequence|'s observer list. | 63 // Called when |this| is added to |sequence|'s observer list. |
51 void AttachedToSequence(LayerAnimationSequence* sequence); | 64 void AttachedToSequence(LayerAnimationSequence* sequence); |
52 | 65 |
53 // Called when |this| is removed to |sequence|'s observer list. | 66 // Called when |this| is removed to |sequence|'s observer list. |
54 void DetachedFromSequence(LayerAnimationSequence* sequence); | 67 void DetachedFromSequence(LayerAnimationSequence* sequence); |
55 | 68 |
56 std::set<LayerAnimationSequence*> attached_sequences_; | 69 AttachedSequences attached_sequences_; |
57 }; | 70 }; |
58 | 71 |
59 // An implicit animation observer is intended to be used in conjunction with a | 72 // An implicit animation observer is intended to be used in conjunction with a |
60 // ScopedLayerAnimationSettings object in order to receive a notification when | 73 // ScopedLayerAnimationSettings object in order to receive a notification when |
61 // all implicit animations complete. | 74 // all implicit animations complete. |
62 class COMPOSITOR_EXPORT ImplicitAnimationObserver | 75 class COMPOSITOR_EXPORT ImplicitAnimationObserver |
63 : public LayerAnimationObserver { | 76 : public LayerAnimationObserver { |
64 public: | 77 public: |
65 ImplicitAnimationObserver(); | 78 ImplicitAnimationObserver(); |
66 virtual ~ImplicitAnimationObserver(); | 79 virtual ~ImplicitAnimationObserver(); |
67 | 80 |
68 virtual void OnImplicitAnimationsCompleted() = 0; | 81 virtual void OnImplicitAnimationsCompleted() = 0; |
69 | 82 |
83 // Deactivates the observer and clears the collection of animations it is | |
84 // waiting for. | |
85 void StopObservingImplicitAnimations(); | |
sky
2012/01/30 22:20:19
Can this be protected?
| |
86 | |
70 private: | 87 private: |
71 friend class ScopedLayerAnimationSettings; | 88 friend class ScopedLayerAnimationSettings; |
72 | 89 |
90 // LayerAnimationObserver implementation | |
91 virtual void OnLayerAnimationEnded( | |
92 LayerAnimationSequence* sequence) OVERRIDE; | |
93 virtual void OnLayerAnimationAborted( | |
94 LayerAnimationSequence* sequence) OVERRIDE; | |
95 virtual void OnLayerAnimationScheduled( | |
96 LayerAnimationSequence* sequence) OVERRIDE; | |
97 virtual void OnAttachedToSequence( | |
98 LayerAnimationSequence* sequence) OVERRIDE; | |
99 virtual void OnDetachedFromSequence( | |
100 LayerAnimationSequence* sequence) OVERRIDE; | |
101 | |
73 // OnImplicitAnimationsCompleted is not fired unless the observer is active. | 102 // OnImplicitAnimationsCompleted is not fired unless the observer is active. |
74 bool active() const { return active_; } | 103 bool active() const { return active_; } |
75 void SetActive(bool active); | 104 void SetActive(bool active); |
76 | 105 |
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(); | 106 void CheckCompleted(); |
86 | 107 |
87 bool active_; | 108 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 }; | 109 }; |
94 | 110 |
95 } // namespace ui | 111 } // namespace ui |
96 | 112 |
97 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ | 113 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ |
OLD | NEW |