Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: ui/compositor/callback_layer_animation_observer.h

Issue 1369393002: Added a CallbackLayerAnimationObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor fixes. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/compositor/BUILD.gn ('k') | ui/compositor/callback_layer_animation_observer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef UI_COMPOSITOR_CALLBACK_LAYER_ANIMATION_OBSERVER_H_
6 #define UI_COMPOSITOR_CALLBACK_LAYER_ANIMATION_OBSERVER_H_
7
8 #include "base/callback.h"
9 #include "ui/compositor/compositor_export.h"
10 #include "ui/compositor/layer_animation_observer.h"
11
12 namespace ui {
13
14 class LayerAnimationSequence;
15
16 // A LayerAnimationObserver that invokes a Callback when all observed
17 // LayerAnimationSequence's have started and finished.
18 //
19 // Example usage:
20 // class Foobar {
21 // // The Callback that will be invoked when all the animation sequences have
22 // // started.
23 // void AnimationStartedCallback(
24 // const CallbackLayerAnimationObserver& observer) {
25 // // Do stuff.
26 // }
27 //
28 // // The Callback that will be invoked when all the animation sequences have
29 // // finished.
30 // bool AnimationEndedCallback(
31 // const CallbackLayerAnimationObserver& observer) {
32 // // Do stuff.
33 // return true; // Returns true so that |observer| destroys itself.
34 // }
35 //
36 // // Example method that uses the CallbackLayerAnimationObserver.
37 // void Animate() {
38 // ui::LayerAnimator* animator_1 = layer_1->GetAnimator();
39 // ui::LayerAnimator* animator_2 = layer_2->GetAnimator();
40 // CallbackLayerAnimationObserver* observer =
41 // new CallbackLayerAnimationObserver(
42 // base::Bind(&Foobar::AnimationStartedCallback),
43 // base::Unretained(this));
44 // base::Bind(&Foobar::AnimationEndedCallback),
45 // base::Unretained(this));
46 // animator_1->AddObserver(observer);
47 // animator_2->AddObserver(observer);
48 //
49 // // Set up animation sequences on |animator_1| and |animator_2|.
50 //
51 // // The callback won't be invoked until SetActive() is called.
52 // observer->SetActive();
53 // }
54 // }
55 //
56 class COMPOSITOR_EXPORT CallbackLayerAnimationObserver
57 : public ui::LayerAnimationObserver {
58 public:
59 // The Callback type that will be invoked when all animation sequences have
60 // been started.
61 typedef base::Callback<void(const CallbackLayerAnimationObserver&)>
62 AnimationStartedCallback;
63
64 // The Callback type that will be invoked when all animation sequences have
65 // finished. |this| will be destroyed after invoking the Callback if it
66 // returns true.
67 typedef base::Callback<bool(const CallbackLayerAnimationObserver&)>
68 AnimationEndedCallback;
69
70 CallbackLayerAnimationObserver(
71 AnimationStartedCallback animation_started_callback,
72 AnimationEndedCallback animation_ended_callback);
73 ~CallbackLayerAnimationObserver() override;
74
75 bool active() const { return active_; }
76
77 // The callbacks will not be invoked until SetActive() has been called. This
78 // allows each sequence to be attached before checking if the sequences have
79 // finished.
80 void SetActive();
81
82 int aborted_count() const { return aborted_count_; }
83 int successful_count() const { return successful_count_; }
84
85 // ui::LayerAnimationObserver:
86 void OnLayerAnimationStarted(ui::LayerAnimationSequence* sequence) override;
87 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override;
88 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override;
89 void OnLayerAnimationScheduled(ui::LayerAnimationSequence* sequence) override;
90
91 protected:
92 // ui::LayerAnimationObserver:
93 bool RequiresNotificationWhenAnimatorDestroyed() const override;
94 void OnAttachedToSequence(ui::LayerAnimationSequence* sequence) override;
95 void OnDetachedFromSequence(ui::LayerAnimationSequence* sequence) override;
96
97 private:
98 int GetNumSequencesCompleted();
99
100 // Checks if all attached sequences have been started and invokes
101 // |animation_started_callback_| if |active_| is true.
102 void CheckAllSequencesStarted();
103
104 // Checks if all attached sequences have completed and invokes
105 // |animation_ended_callback_| if |active_| is true.
106 void CheckAllSequencesCompleted();
107
108 // Allows the callbacks to be invoked when true.
109 bool active_;
110
111 // The total number of animation sequences that have been attached.
112 int attached_sequence_count_;
113
114 // The total number of animation sequences that have been detached.
115 int detached_sequence_count_;
116
117 // The number of animation sequences that have been started.
118 int started_count_;
119
120 // The number of animation sequences that were aborted.
121 int aborted_count_;
122
123 // The number of animation sequences that completed successfully.
124 int successful_count_;
125
126 // The callback to invoke once all the animation sequences have been started.
127 AnimationStartedCallback animation_started_callback_;
128
129 // The callback to invoke once all the animation sequences have finished.
130 AnimationEndedCallback animation_ended_callback_;
131
132 DISALLOW_COPY_AND_ASSIGN(CallbackLayerAnimationObserver);
sadrul 2015/10/08 00:51:52 Like ImplicitAnimationObserver, does this need to
bruthig 2015/10/08 20:32:18 Done.
133 };
134
135 } // namespace ui
136
137 #endif // UI_COMPOSITOR_CALLBACK_LAYER_ANIMATION_OBSERVER_H_
OLDNEW
« no previous file with comments | « ui/compositor/BUILD.gn ('k') | ui/compositor/callback_layer_animation_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698