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

Unified 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: Fixed the diff delta to be based off the correct branch. 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 side-by-side diff with in-line comments
Download patch
Index: ui/compositor/callback_layer_animation_observer.h
diff --git a/ui/compositor/callback_layer_animation_observer.h b/ui/compositor/callback_layer_animation_observer.h
new file mode 100644
index 0000000000000000000000000000000000000000..9e966e08ecde91a289b739bc112bb20d273ae7e4
--- /dev/null
+++ b/ui/compositor/callback_layer_animation_observer.h
@@ -0,0 +1,137 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_COMPOSITOR_CALLBACK_LAYER_ANIMATION_OBSERVER_H_
+#define UI_COMPOSITOR_CALLBACK_LAYER_ANIMATION_OBSERVER_H_
+
+#include "base/callback.h"
+#include "ui/compositor/compositor_export.h"
+#include "ui/compositor/layer_animation_observer.h"
+
+namespace ui {
+
+class LayerAnimationSequence;
+
+// A LayerAnimationObserver that invokes a Callback when all observed
+// LayerAnimationSequence's have started and finished.
+//
+// Example usage:
+// class Foobar {
+// // The Callback that will be invoked when all the animation sequences have
+// // started.
+// void AnimationStartedCallback(
+// const CallbackLayerAnimationObserver& observer) {
+// // Do stuff.
+// }
+//
+// // The Callback that will be invoked when all the animation sequences have
+// // finished.
+// bool AnimationEndedCallback(
+// const CallbackLayerAnimationObserver& observer) {
+// // Do stuff.
+// return true; // Returns true so that |observer| destroys itself.
+// }
+//
+// // Example method that uses the CallbackLayerAnimationObserver.
+// void Animate() {
+// ui::LayerAnimator* animator_1 = layer_->GetAnimator();
+// ui::LayerAnimator* animator_2 = layer_->GetAnimator();
ajuma 2015/10/07 20:14:55 Should these by layer_1 and layer_2, not the same
bruthig 2015/10/07 21:37:29 Yes, good catch!
+// CallbackLayerAnimationObserver* observer =
+// new CallbackLayerAnimationObserver(
+// base::Bind(&Foobar::AnimationStartedCallback),
+// base::Unretained(this));
+// base::Bind(&Foobar::AnimationEndedCallback),
+// base::Unretained(this));
+// animator_1->AddObserver(observer);
+// animator_2->AddObserver(observer);
+//
+// // Set up animation sequences on |animator_1| and |animator_2|.
+//
+// // The callback won't be invoked until SetActive() is called.
+// observer->SetActive();
+// }
+// }
+//
+class COMPOSITOR_EXPORT CallbackLayerAnimationObserver
+ : public ui::LayerAnimationObserver {
+ public:
+ // The Callback type that will be invoked when all animation sequences have
+ // been started.
+ typedef base::Callback<void(const CallbackLayerAnimationObserver&)>
+ AnimationStartedCallback;
+
+ // The Callback type that will be invoked when all animation sequences have
+ // finished. |this| will be destroyed after invoking the Callback if it
+ // returns true.
+ typedef base::Callback<bool(const CallbackLayerAnimationObserver&)>
+ AnimationEndedCallback;
+
+ explicit CallbackLayerAnimationObserver(
bruthig 2015/10/06 21:30:37 TODO: Remove explicit.
bruthig 2015/10/07 21:37:29 Done.
+ AnimationStartedCallback animation_started_callback,
+ AnimationEndedCallback animation_ended_callback);
+ ~CallbackLayerAnimationObserver() override;
+
+ bool active() const { return active_; }
+
+ // The callbacks will not be invoked until SetActive() has been called. This
+ // allows each sequence to be attached before checking if the sequences have
+ // finished.
+ void SetActive();
+
+ int aborted_count() const { return aborted_count_; }
+ int successful_count() const { return successful_count_; }
+
+ // ui::LayerAnimationObserver:
+ void OnLayerAnimationStarted(ui::LayerAnimationSequence* sequence) override;
danakj 2015/10/07 15:11:10 This isn't a member of LayerAnimationObserver?
bruthig 2015/10/07 15:21:23 It's being added in my pending CL here: https://co
+ void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override;
+ void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override;
+ void OnLayerAnimationScheduled(ui::LayerAnimationSequence* sequence) override;
+
+ protected:
+ // ui::LayerAnimationObserver:
+ bool RequiresNotificationWhenAnimatorDestroyed() const override;
+ void OnAttachedToSequence(ui::LayerAnimationSequence* sequence) override;
+ void OnDetachedFromSequence(ui::LayerAnimationSequence* sequence) override;
+
+ private:
+ int GetNumSequencesCompleted();
+
+ // Checks if all attached sequences have been started and invokes
+ // |animation_started_callback_| if |active_| is true.
+ void CheckAllSequencesStarted();
+
+ // Checks if all attached sequences have completed and invokes
+ // |animation_ended_callback_| if |active_| is true.
+ void CheckAllSequencesCompleted();
+
+ // Allows the callbacks to be invoked when true.
+ bool active_;
+
+ // The total number of animation sequences that have been attached.
+ int attached_sequence_count_;
+
+ // The total number of animation sequences that have been detached.
+ int detached_sequence_count_;
+
+ // The number of animation sequences that have been started.
+ int started_count_;
+
+ // The number of animation sequences that were aborted.
+ int aborted_count_;
+
+ // The number of animation sequences that completed successfully.
+ int successful_count_;
+
+ // The callback to invoke once all the animation sequences have been started.
+ AnimationStartedCallback animation_started_callback_;
+
+ // The callback to invoke once all the animation sequences have finished.
+ AnimationEndedCallback animation_ended_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(CallbackLayerAnimationObserver);
+};
+
+} // namespace ui
+
+#endif // UI_COMPOSITOR_CALLBACK_LAYER_ANIMATION_OBSERVER_H_

Powered by Google App Engine
This is Rietveld 408576698