1 // Copyright (c) 2012 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.
5 #include "ui/compositor/layer_animation_observer.h"
7 #include "ui/compositor/layer_animation_sequence.h"
11 ////////////////////////////////////////////////////////////////////////////////
12 // LayerAnimationObserver
14 LayerAnimationObserver::LayerAnimationObserver() {
17 LayerAnimationObserver::~LayerAnimationObserver() {
21 bool LayerAnimationObserver::RequiresNotificationWhenAnimatorDestroyed() const {
25 void LayerAnimationObserver::OnAttachedToSequence(
26 LayerAnimationSequence
* sequence
) {
29 void LayerAnimationObserver::OnDetachedFromSequence(
30 LayerAnimationSequence
* sequence
) {
33 void LayerAnimationObserver::StopObserving() {
34 while (!attached_sequences_
.empty()) {
35 LayerAnimationSequence
* sequence
= *attached_sequences_
.begin();
36 sequence
->RemoveObserver(this);
40 void LayerAnimationObserver::AttachedToSequence(
41 LayerAnimationSequence
* sequence
) {
42 DCHECK(attached_sequences_
.find(sequence
) == attached_sequences_
.end());
43 attached_sequences_
.insert(sequence
);
44 OnAttachedToSequence(sequence
);
47 void LayerAnimationObserver::DetachedFromSequence(
48 LayerAnimationSequence
* sequence
, bool send_notification
) {
49 if (attached_sequences_
.find(sequence
) != attached_sequences_
.end())
50 attached_sequences_
.erase(sequence
);
51 if (send_notification
)
52 OnDetachedFromSequence(sequence
);
55 ////////////////////////////////////////////////////////////////////////////////
56 // ImplicitAnimationObserver
58 ImplicitAnimationObserver::ImplicitAnimationObserver()
61 first_sequence_scheduled_(false) {
64 ImplicitAnimationObserver::~ImplicitAnimationObserver() {
69 void ImplicitAnimationObserver::SetActive(bool active
) {
74 void ImplicitAnimationObserver::StopObservingImplicitAnimations() {
79 void ImplicitAnimationObserver::OnLayerAnimationEnded(
80 LayerAnimationSequence
* sequence
) {
81 bool destroyed
= false;
82 destroyed_
= &destroyed
;
83 sequence
->RemoveObserver(this);
87 DCHECK(attached_sequences().find(sequence
) == attached_sequences().end());
91 void ImplicitAnimationObserver::OnLayerAnimationAborted(
92 LayerAnimationSequence
* sequence
) {
93 sequence
->RemoveObserver(this);
94 DCHECK(attached_sequences().find(sequence
) == attached_sequences().end());
98 void ImplicitAnimationObserver::OnLayerAnimationScheduled(
99 LayerAnimationSequence
* sequence
) {
100 if (!first_sequence_scheduled_
) {
101 first_sequence_scheduled_
= true;
102 OnImplicitAnimationsScheduled();
106 void ImplicitAnimationObserver::OnAttachedToSequence(
107 LayerAnimationSequence
* sequence
) {
110 void ImplicitAnimationObserver::OnDetachedFromSequence(
111 LayerAnimationSequence
* sequence
) {
112 DCHECK(attached_sequences().find(sequence
) == attached_sequences().end());
116 void ImplicitAnimationObserver::CheckCompleted() {
117 if (active_
&& attached_sequences().empty()) {
119 OnImplicitAnimationsCompleted();