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

Unified Diff: ui/compositor/callback_layer_animation_observer.cc

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 side-by-side diff with in-line comments
Download patch
Index: ui/compositor/callback_layer_animation_observer.cc
diff --git a/ui/compositor/callback_layer_animation_observer.cc b/ui/compositor/callback_layer_animation_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b3fca2a82d55e31c6e6089de80a8bca939a52f8f
--- /dev/null
+++ b/ui/compositor/callback_layer_animation_observer.cc
@@ -0,0 +1,88 @@
+// 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.
+
+#include "ui/compositor/callback_layer_animation_observer.h"
+
+#include "ui/compositor/layer_animation_sequence.h"
+
+namespace ui {
+
+CallbackLayerAnimationObserver::CallbackLayerAnimationObserver(
+ AnimationStartedCallback animation_started_callback,
+ AnimationEndedCallback animation_ended_callback)
+ : active_(false),
+ attached_sequence_count_(0),
+ detached_sequence_count_(0),
+ started_count_(0),
+ aborted_count_(0),
+ successful_count_(0),
+ animation_started_callback_(animation_started_callback),
+ animation_ended_callback_(animation_ended_callback) {}
+
+CallbackLayerAnimationObserver::~CallbackLayerAnimationObserver() {}
+
+void CallbackLayerAnimationObserver::SetActive() {
+ active_ = true;
+ CheckAllSequencesStarted();
+ CheckAllSequencesCompleted();
+}
+
+void CallbackLayerAnimationObserver::OnLayerAnimationStarted(
+ ui::LayerAnimationSequence* sequence) {
+ CHECK_LT(started_count_, attached_sequence_count_);
+ ++started_count_;
+ CheckAllSequencesStarted();
+}
+
+void CallbackLayerAnimationObserver::OnLayerAnimationEnded(
+ ui::LayerAnimationSequence* sequence) {
+ CHECK_LT(GetNumSequencesCompleted(), attached_sequence_count_);
+ ++successful_count_;
+ CheckAllSequencesCompleted();
+}
+
+void CallbackLayerAnimationObserver::OnLayerAnimationAborted(
+ ui::LayerAnimationSequence* sequence) {
+ CHECK_LT(GetNumSequencesCompleted(), attached_sequence_count_);
+ ++aborted_count_;
+ CheckAllSequencesCompleted();
+}
+
+void CallbackLayerAnimationObserver::OnLayerAnimationScheduled(
+ ui::LayerAnimationSequence* sequence) {}
+
+bool CallbackLayerAnimationObserver::RequiresNotificationWhenAnimatorDestroyed()
+ const {
+ return true;
+}
+
+void CallbackLayerAnimationObserver::OnAttachedToSequence(
+ ui::LayerAnimationSequence* sequence) {
+ ++attached_sequence_count_;
+}
+
+void CallbackLayerAnimationObserver::OnDetachedFromSequence(
+ ui::LayerAnimationSequence* sequence) {
+ CHECK_LT(detached_sequence_count_, attached_sequence_count_);
+ ++detached_sequence_count_;
+}
+
+int CallbackLayerAnimationObserver::GetNumSequencesCompleted() {
+ return aborted_count_ + successful_count_;
+}
+
+void CallbackLayerAnimationObserver::CheckAllSequencesStarted() {
+ if (active_ && attached_sequence_count_ == started_count_)
+ animation_started_callback_.Run(*this);
+}
+
+void CallbackLayerAnimationObserver::CheckAllSequencesCompleted() {
+ if (active_ && GetNumSequencesCompleted() == attached_sequence_count_) {
+ active_ = false;
+ if (animation_ended_callback_.Run(*this))
+ delete this;
+ }
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698