OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_CALLBACK_LAYER_ANIMATION_OBSERVER_H_ | 5 #ifndef UI_COMPOSITOR_CALLBACK_LAYER_ANIMATION_OBSERVER_H_ |
6 #define UI_COMPOSITOR_CALLBACK_LAYER_ANIMATION_OBSERVER_H_ | 6 #define UI_COMPOSITOR_CALLBACK_LAYER_ANIMATION_OBSERVER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "ui/compositor/compositor_export.h" | 9 #include "ui/compositor/compositor_export.h" |
10 #include "ui/compositor/layer_animation_observer.h" | 10 #include "ui/compositor/layer_animation_observer.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // been started. | 62 // been started. |
63 typedef base::Callback<void(const CallbackLayerAnimationObserver&)> | 63 typedef base::Callback<void(const CallbackLayerAnimationObserver&)> |
64 AnimationStartedCallback; | 64 AnimationStartedCallback; |
65 | 65 |
66 // The Callback type that will be invoked when all animation sequences have | 66 // The Callback type that will be invoked when all animation sequences have |
67 // finished. |this| will be destroyed after invoking the Callback if it | 67 // finished. |this| will be destroyed after invoking the Callback if it |
68 // returns true. | 68 // returns true. |
69 typedef base::Callback<bool(const CallbackLayerAnimationObserver&)> | 69 typedef base::Callback<bool(const CallbackLayerAnimationObserver&)> |
70 AnimationEndedCallback; | 70 AnimationEndedCallback; |
71 | 71 |
| 72 // A dummy no-op AnimationStartedCallback. |
| 73 static void DummyAnimationStartedCallback( |
| 74 const CallbackLayerAnimationObserver&); |
| 75 |
| 76 // A dummy no-op AnimationEndedCallback that will return |
| 77 // |should_delete_observer|. |
| 78 // |
| 79 // Example usage: |
| 80 // |
| 81 // ui::CallbackLayerAnimationObserver* animation_observer = |
| 82 // new ui::CallbackLayerAnimationObserver( |
| 83 // base::Bind(&ui::CallbackLayerAnimationObserver:: |
| 84 // DummyAnimationStartedCallback), |
| 85 // base::Bind(&ui::CallbackLayerAnimationObserver:: |
| 86 // DummyAnimationEndedCallback, false)); |
| 87 static bool DummyAnimationEndedCallback( |
| 88 bool should_delete_observer, |
| 89 const CallbackLayerAnimationObserver&); |
| 90 |
| 91 // Create an instance that will invoke the |animation_started_callback| when |
| 92 // the animation has started and the |animation_ended_callback| when the |
| 93 // animation has ended. |
72 CallbackLayerAnimationObserver( | 94 CallbackLayerAnimationObserver( |
73 AnimationStartedCallback animation_started_callback, | 95 AnimationStartedCallback animation_started_callback, |
74 AnimationEndedCallback animation_ended_callback); | 96 AnimationEndedCallback animation_ended_callback); |
| 97 |
| 98 // Create an instance that will invoke the |animation_started_callback| when |
| 99 // the animation has started and will delete |this| when the animations have |
| 100 // ended if |should_delete_observer| is true. |
| 101 CallbackLayerAnimationObserver( |
| 102 AnimationStartedCallback animation_started_callback, |
| 103 bool should_delete_observer); |
| 104 |
| 105 // Create an instance that will invoke the |animation_ended_callback| when the |
| 106 // animations have ended. |
| 107 explicit CallbackLayerAnimationObserver( |
| 108 AnimationEndedCallback animation_ended_callback); |
| 109 |
75 ~CallbackLayerAnimationObserver() override; | 110 ~CallbackLayerAnimationObserver() override; |
76 | 111 |
77 bool active() const { return active_; } | 112 bool active() const { return active_; } |
78 | 113 |
79 // The callbacks will not be invoked until SetActive() has been called. This | 114 // The callbacks will not be invoked until SetActive() has been called. This |
80 // allows each sequence to be attached before checking if the sequences have | 115 // allows each sequence to be attached before checking if the sequences have |
81 // finished. | 116 // finished. |
82 void SetActive(); | 117 void SetActive(); |
83 | 118 |
84 int aborted_count() const { return aborted_count_; } | 119 int aborted_count() const { return aborted_count_; } |
(...skipping 16 matching lines...) Expand all Loading... |
101 | 136 |
102 // Checks if all attached sequences have been started and invokes | 137 // Checks if all attached sequences have been started and invokes |
103 // |animation_started_callback_| if |active_| is true. | 138 // |animation_started_callback_| if |active_| is true. |
104 void CheckAllSequencesStarted(); | 139 void CheckAllSequencesStarted(); |
105 | 140 |
106 // Checks if all attached sequences have completed and invokes | 141 // Checks if all attached sequences have completed and invokes |
107 // |animation_ended_callback_| if |active_| is true. | 142 // |animation_ended_callback_| if |active_| is true. |
108 void CheckAllSequencesCompleted(); | 143 void CheckAllSequencesCompleted(); |
109 | 144 |
110 // Allows the callbacks to be invoked when true. | 145 // Allows the callbacks to be invoked when true. |
111 bool active_; | 146 bool active_ = false; |
112 | 147 |
113 // The total number of animation sequences that have been attached. | 148 // The total number of animation sequences that have been attached. |
114 int attached_sequence_count_; | 149 int attached_sequence_count_ = 0; |
115 | 150 |
116 // The total number of animation sequences that have been detached. | 151 // The total number of animation sequences that have been detached. |
117 int detached_sequence_count_; | 152 int detached_sequence_count_ = 0; |
118 | 153 |
119 // The number of animation sequences that have been started. | 154 // The number of animation sequences that have been started. |
120 int started_count_; | 155 int started_count_ = 0; |
121 | 156 |
122 // The number of animation sequences that were aborted. | 157 // The number of animation sequences that were aborted. |
123 int aborted_count_; | 158 int aborted_count_ = 0; |
124 | 159 |
125 // The number of animation sequences that completed successfully. | 160 // The number of animation sequences that completed successfully. |
126 int successful_count_; | 161 int successful_count_ = 0; |
127 | 162 |
128 // The callback to invoke once all the animation sequences have been started. | 163 // The callback to invoke once all the animation sequences have been started. |
129 AnimationStartedCallback animation_started_callback_; | 164 AnimationStartedCallback animation_started_callback_; |
130 | 165 |
131 // The callback to invoke once all the animation sequences have finished. | 166 // The callback to invoke once all the animation sequences have finished. |
132 AnimationEndedCallback animation_ended_callback_; | 167 AnimationEndedCallback animation_ended_callback_; |
133 | 168 |
134 // Set to true in the destructor (if non-NULL). Used to detect deletion while | 169 // Set to true in the destructor (if non-NULL). Used to detect deletion while |
135 // calling out. | 170 // calling out. |
136 bool* destroyed_; | 171 bool* destroyed_ = nullptr; |
137 | 172 |
138 DISALLOW_COPY_AND_ASSIGN(CallbackLayerAnimationObserver); | 173 DISALLOW_COPY_AND_ASSIGN(CallbackLayerAnimationObserver); |
139 }; | 174 }; |
140 | 175 |
141 } // namespace ui | 176 } // namespace ui |
142 | 177 |
143 #endif // UI_COMPOSITOR_CALLBACK_LAYER_ANIMATION_OBSERVER_H_ | 178 #endif // UI_COMPOSITOR_CALLBACK_LAYER_ANIMATION_OBSERVER_H_ |
OLD | NEW |