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

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: Addressed concerns from patch set 8. 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 // TODO(bruthig): Unify the CallbackLayerAnimationObserver with the
57 // ImplicitAnimationObserver. (See www.crbug.com/542825).
58 class COMPOSITOR_EXPORT CallbackLayerAnimationObserver
59 : public ui::LayerAnimationObserver {
60 public:
61 // The Callback type that will be invoked when all animation sequences have
62 // been started.
63 typedef base::Callback<void(const CallbackLayerAnimationObserver&)>
64 AnimationStartedCallback;
65
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
68 // returns true.
69 typedef base::Callback<bool(const CallbackLayerAnimationObserver&)>
70 AnimationEndedCallback;
71
72 CallbackLayerAnimationObserver(
73 AnimationStartedCallback animation_started_callback,
74 AnimationEndedCallback animation_ended_callback);
75 ~CallbackLayerAnimationObserver() override;
76
77 bool active() const { return active_; }
78
79 // 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
81 // finished.
82 void SetActive();
83
84 int aborted_count() const { return aborted_count_; }
85 int successful_count() const { return successful_count_; }
86
87 // ui::LayerAnimationObserver:
88 void OnLayerAnimationStarted(ui::LayerAnimationSequence* sequence) override;
89 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override;
90 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override;
91 void OnLayerAnimationScheduled(ui::LayerAnimationSequence* sequence) override;
92
93 protected:
94 // ui::LayerAnimationObserver:
95 bool RequiresNotificationWhenAnimatorDestroyed() const override;
96 void OnAttachedToSequence(ui::LayerAnimationSequence* sequence) override;
97 void OnDetachedFromSequence(ui::LayerAnimationSequence* sequence) override;
98
99 private:
100 int GetNumSequencesCompleted();
101
102 // Checks if all attached sequences have been started and invokes
103 // |animation_started_callback_| if |active_| is true.
104 void CheckAllSequencesStarted();
105
106 // Checks if all attached sequences have completed and invokes
107 // |animation_ended_callback_| if |active_| is true.
108 void CheckAllSequencesCompleted();
109
110 // Allows the callbacks to be invoked when true.
111 bool active_;
112
113 // The total number of animation sequences that have been attached.
114 int attached_sequence_count_;
115
116 // The total number of animation sequences that have been detached.
117 int detached_sequence_count_;
118
119 // The number of animation sequences that have been started.
120 int started_count_;
121
122 // The number of animation sequences that were aborted.
123 int aborted_count_;
124
125 // The number of animation sequences that completed successfully.
126 int successful_count_;
127
128 // The callback to invoke once all the animation sequences have been started.
129 AnimationStartedCallback animation_started_callback_;
130
131 // The callback to invoke once all the animation sequences have finished.
132 AnimationEndedCallback animation_ended_callback_;
133
134 // Set to true in the destructor (if non-NULL). Used to detect deletion while
135 // calling out.
136 bool* destroyed_;
137
138 DISALLOW_COPY_AND_ASSIGN(CallbackLayerAnimationObserver);
139 };
140
141 } // namespace ui
142
143 #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