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

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: 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
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 destroyed_(nullptr) {}
23
24 CallbackLayerAnimationObserver::~CallbackLayerAnimationObserver() {
25 if (destroyed_)
26 *destroyed_ = true;
27 }
28
29 void CallbackLayerAnimationObserver::SetActive() {
30 active_ = true;
31
32 bool destroyed = false;
33 destroyed_ = &destroyed;
34
35 CheckAllSequencesStarted();
36
37 if (destroyed)
38 return;
39 destroyed_ = nullptr;
40
41 CheckAllSequencesCompleted();
42 }
43
44 void CallbackLayerAnimationObserver::OnLayerAnimationStarted(
45 ui::LayerAnimationSequence* sequence) {
46 CHECK_LT(started_count_, attached_sequence_count_);
47 ++started_count_;
48 CheckAllSequencesStarted();
49 }
50
51 void CallbackLayerAnimationObserver::OnLayerAnimationEnded(
52 ui::LayerAnimationSequence* sequence) {
53 CHECK_LT(GetNumSequencesCompleted(), attached_sequence_count_);
54 ++successful_count_;
55 CheckAllSequencesCompleted();
56 }
57
58 void CallbackLayerAnimationObserver::OnLayerAnimationAborted(
59 ui::LayerAnimationSequence* sequence) {
60 CHECK_LT(GetNumSequencesCompleted(), attached_sequence_count_);
61 ++aborted_count_;
62 CheckAllSequencesCompleted();
63 }
64
65 void CallbackLayerAnimationObserver::OnLayerAnimationScheduled(
66 ui::LayerAnimationSequence* sequence) {}
67
68 bool CallbackLayerAnimationObserver::RequiresNotificationWhenAnimatorDestroyed()
69 const {
70 return true;
71 }
72
73 void CallbackLayerAnimationObserver::OnAttachedToSequence(
74 ui::LayerAnimationSequence* sequence) {
75 ++attached_sequence_count_;
76 }
77
78 void CallbackLayerAnimationObserver::OnDetachedFromSequence(
79 ui::LayerAnimationSequence* sequence) {
80 CHECK_LT(detached_sequence_count_, attached_sequence_count_);
81 ++detached_sequence_count_;
82 }
83
84 int CallbackLayerAnimationObserver::GetNumSequencesCompleted() {
85 return aborted_count_ + successful_count_;
86 }
87
88 void CallbackLayerAnimationObserver::CheckAllSequencesStarted() {
89 if (active_ && attached_sequence_count_ == started_count_)
90 animation_started_callback_.Run(*this);
91 }
92
93 void CallbackLayerAnimationObserver::CheckAllSequencesCompleted() {
94 if (active_ && GetNumSequencesCompleted() == attached_sequence_count_) {
95 active_ = false;
96 bool destroyed = false;
97 destroyed_ = &destroyed;
98
99 bool should_delete = animation_ended_callback_.Run(*this);
100
101 if (destroyed) {
102 if (should_delete)
103 LOG(WARNING) << "CallbackLayerAnimationObserver was explicitly "
104 "destroyed AND was requested to be destroyed via the "
105 "AnimationEndedCallback's return value.";
106 return;
107 }
108 destroyed_ = nullptr;
109
110 if (should_delete)
111 delete this;
112 }
113 }
114
115 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/callback_layer_animation_observer.h ('k') | ui/compositor/callback_layer_animation_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698