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 const 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 const 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 const LayerAnimationSequence* sequence) = 0; |
35 | 36 |
37 protected: | |
38 LayerAnimationObserver(); | |
39 virtual ~LayerAnimationObserver(); | |
40 | |
36 // If the animator is destroyed during an animation, the animations are | 41 // If the animator is destroyed during an animation, the animations are |
37 // aborted. The resulting NotifyAborted notifications will NOT be sent to | 42 // aborted. The resulting NotifyAborted notifications will NOT be sent to |
38 // this observer if this function returns false. NOTE: IF YOU OVERRIDE THIS | 43 // 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 | 44 // FUNCTION TO RETURN TRUE, YOU MUST REMEMBER TO REMOVE YOURSELF AS AN |
40 // OBSERVER WHEN YOU ARE DESTROYED. | 45 // OBSERVER WHEN YOU ARE DESTROYED. |
41 virtual bool RequiresNotificationWhenAnimatorDestroyed() const; | 46 virtual bool RequiresNotificationWhenAnimatorDestroyed() const; |
42 | 47 |
43 protected: | 48 // Called when |this| is added to |sequence|'s observer list. |
44 LayerAnimationObserver(); | 49 virtual void OnAttachedToSequence(LayerAnimationSequence* sequence); |
sky
2012/01/30 15:58:55
Where is this invoked from?
| |
45 virtual ~LayerAnimationObserver(); | 50 |
51 // Called when |this| is removed to |sequence|'s observer list. | |
52 virtual void OnDetachedFromSequence(LayerAnimationSequence* sequence); | |
46 | 53 |
47 private: | 54 private: |
48 friend class LayerAnimationSequence; | 55 friend class LayerAnimationSequence; |
49 | 56 |
50 // Called when |this| is added to |sequence|'s observer list. | 57 // Called when |this| is added to |sequence|'s observer list. |
51 void AttachedToSequence(LayerAnimationSequence* sequence); | 58 void AttachedToSequence(LayerAnimationSequence* sequence); |
52 | 59 |
53 // Called when |this| is removed to |sequence|'s observer list. | 60 // Called when |this| is removed to |sequence|'s observer list. |
54 void DetachedFromSequence(LayerAnimationSequence* sequence); | 61 void DetachedFromSequence(LayerAnimationSequence* sequence); |
55 | 62 |
56 std::set<LayerAnimationSequence*> attached_sequences_; | 63 std::set<LayerAnimationSequence*> attached_sequences_; |
57 }; | 64 }; |
58 | 65 |
59 // An implicit animation observer is intended to be used in conjunction with a | 66 // An implicit animation observer is intended to be used in conjunction with a |
60 // ScopedLayerAnimationSettings object in order to receive a notification when | 67 // ScopedLayerAnimationSettings object in order to receive a notification when |
61 // all implicit animations complete. | 68 // all implicit animations complete. |
62 class COMPOSITOR_EXPORT ImplicitAnimationObserver | 69 class COMPOSITOR_EXPORT ImplicitAnimationObserver |
63 : public LayerAnimationObserver { | 70 : public LayerAnimationObserver { |
64 public: | 71 public: |
65 ImplicitAnimationObserver(); | 72 ImplicitAnimationObserver(); |
66 virtual ~ImplicitAnimationObserver(); | 73 virtual ~ImplicitAnimationObserver(); |
67 | 74 |
68 virtual void OnImplicitAnimationsCompleted() = 0; | 75 virtual void OnImplicitAnimationsCompleted() = 0; |
69 | 76 |
70 private: | |
71 friend class ScopedLayerAnimationSettings; | |
72 | |
73 // OnImplicitAnimationsCompleted is not fired unless the observer is active. | 77 // OnImplicitAnimationsCompleted is not fired unless the observer is active. |
74 bool active() const { return active_; } | 78 bool active() const { return active_; } |
75 void SetActive(bool active); | 79 void SetActive(bool active); |
76 | 80 |
81 private: | |
77 // LayerAnimationObserver implementation | 82 // LayerAnimationObserver implementation |
78 virtual void OnLayerAnimationEnded( | 83 virtual void OnLayerAnimationEnded( |
79 const LayerAnimationSequence* sequence) OVERRIDE; | 84 const LayerAnimationSequence* sequence) OVERRIDE; |
80 virtual void OnLayerAnimationAborted( | 85 virtual void OnLayerAnimationAborted( |
81 const LayerAnimationSequence* sequence) OVERRIDE; | 86 const LayerAnimationSequence* sequence) OVERRIDE; |
82 virtual void OnLayerAnimationScheduled( | 87 virtual void OnLayerAnimationScheduled( |
83 const LayerAnimationSequence* sequence) OVERRIDE; | 88 const LayerAnimationSequence* sequence) OVERRIDE; |
89 virtual void OnAttachedToSequence( | |
90 LayerAnimationSequence* sequence) OVERRIDE; | |
91 virtual void OnDetachedFromSequence( | |
92 LayerAnimationSequence* sequence) OVERRIDE; | |
84 | 93 |
85 void CheckCompleted(); | 94 void CheckCompleted(); |
86 | 95 |
87 bool active_; | 96 bool active_; |
88 | 97 |
89 // This tracks the number of scheduled animations that have yet to complete. | 98 // This tracks the scheduled animations that have yet to complete. |
90 // If this value is zero, and the observer is active, then | 99 // When this is empty, and the observer is active, then |
91 // OnImplicitAnimationsCompleted is fired. | 100 // OnImplicitAnimationsCompleted is fired. |
92 size_t animation_count_; | 101 std::set<const LayerAnimationSequence*> unfinished_animations_; |
sky
2012/01/30 15:58:55
Is this the same as attached_sequences_?
| |
93 }; | 102 }; |
94 | 103 |
95 } // namespace ui | 104 } // namespace ui |
96 | 105 |
97 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ | 106 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATION_OBSERVER_H_ |
OLD | NEW |