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

Side by Side 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: 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 unified diff | Download patch
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 #include "ui/compositor/callback_layer_animation_observer.h"
6
7 #include "ui/compositor/layer_animation_sequence.h"
8
9 namespace ui {
10
11 CallbackLayerAnimationObserver::CallbackLayerAnimationObserver(
12 AnimationStartedCallback animation_started_callback,
13 AnimationEndedCallback animation_ended_callback)
14 : active_(false),
15 attached_sequence_count_(0),
16 detached_sequence_count_(0),
17 started_count_(0),
18 aborted_count_(0),
19 successful_count_(0),
20 animation_started_callback_(animation_started_callback),
21 animation_ended_callback_(animation_ended_callback) {}
22
23 CallbackLayerAnimationObserver::~CallbackLayerAnimationObserver() {}
24
25 void CallbackLayerAnimationObserver::SetActive() {
26 active_ = true;
27 CheckAllSequencesStarted();
28 CheckAllSequencesCompleted();
29 }
30
31 void CallbackLayerAnimationObserver::OnLayerAnimationStarted(
32 ui::LayerAnimationSequence* sequence) {
33 CHECK_LT(started_count_, attached_sequence_count_);
34 ++started_count_;
35 CheckAllSequencesStarted();
36 }
37
38 void CallbackLayerAnimationObserver::OnLayerAnimationEnded(
39 ui::LayerAnimationSequence* sequence) {
40 CHECK_LT(GetNumSequencesCompleted(), attached_sequence_count_);
41 ++successful_count_;
42 CheckAllSequencesCompleted();
43 }
44
45 void CallbackLayerAnimationObserver::OnLayerAnimationAborted(
46 ui::LayerAnimationSequence* sequence) {
47 CHECK_LT(GetNumSequencesCompleted(), attached_sequence_count_);
48 ++aborted_count_;
49 CheckAllSequencesCompleted();
50 }
51
52 void CallbackLayerAnimationObserver::OnLayerAnimationScheduled(
53 ui::LayerAnimationSequence* sequence) {}
54
55 bool CallbackLayerAnimationObserver::RequiresNotificationWhenAnimatorDestroyed()
56 const {
57 return true;
58 }
59
60 void CallbackLayerAnimationObserver::OnAttachedToSequence(
61 ui::LayerAnimationSequence* sequence) {
62 ++attached_sequence_count_;
63 }
64
65 void CallbackLayerAnimationObserver::OnDetachedFromSequence(
66 ui::LayerAnimationSequence* sequence) {
67 CHECK_LT(detached_sequence_count_, attached_sequence_count_);
68 ++detached_sequence_count_;
69 }
70
71 int CallbackLayerAnimationObserver::GetNumSequencesCompleted() {
72 return aborted_count_ + successful_count_;
73 }
74
75 void CallbackLayerAnimationObserver::CheckAllSequencesStarted() {
76 if (active_ && attached_sequence_count_ == started_count_)
77 animation_started_callback_.Run(*this);
78 }
79
80 void CallbackLayerAnimationObserver::CheckAllSequencesCompleted() {
81 if (active_ && GetNumSequencesCompleted() == attached_sequence_count_) {
82 active_ = false;
83 if (animation_ended_callback_.Run(*this))
84 delete this;
85 }
86 }
87
88 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698