OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/compositor/layer_animation_observer.h" | 5 #include "ui/gfx/compositor/layer_animation_observer.h" |
6 | 6 |
7 #include "ui/gfx/compositor/layer_animation_sequence.h" | 7 #include "ui/gfx/compositor/layer_animation_sequence.h" |
8 | 8 |
9 namespace ui { | 9 namespace ui { |
10 | 10 |
11 //////////////////////////////////////////////////////////////////////////////// | 11 //////////////////////////////////////////////////////////////////////////////// |
12 // LayerAnimationObserver | 12 // LayerAnimationObserver |
13 | 13 |
| 14 bool LayerAnimationObserver::RequiresNotificationWhenAnimatorDestroyed() const { |
| 15 return false; |
| 16 } |
| 17 |
14 LayerAnimationObserver::LayerAnimationObserver() { | 18 LayerAnimationObserver::LayerAnimationObserver() { |
15 } | 19 } |
16 | 20 |
17 LayerAnimationObserver::~LayerAnimationObserver() { | 21 LayerAnimationObserver::~LayerAnimationObserver() { |
18 StopObserving(); | |
19 } | |
20 | |
21 bool LayerAnimationObserver::RequiresNotificationWhenAnimatorDestroyed() const { | |
22 return false; | |
23 } | |
24 | |
25 void LayerAnimationObserver::OnAttachedToSequence( | |
26 LayerAnimationSequence* sequence) { | |
27 } | |
28 | |
29 void LayerAnimationObserver::OnDetachedFromSequence( | |
30 LayerAnimationSequence* sequence) { | |
31 } | |
32 | |
33 void LayerAnimationObserver::StopObserving() { | |
34 while (!attached_sequences_.empty()) { | 22 while (!attached_sequences_.empty()) { |
35 LayerAnimationSequence* sequence = *attached_sequences_.begin(); | 23 LayerAnimationSequence* sequence = *attached_sequences_.begin(); |
36 sequence->RemoveObserver(this); | 24 sequence->RemoveObserver(this); |
37 } | 25 } |
38 } | 26 } |
39 | 27 |
40 void LayerAnimationObserver::AttachedToSequence( | 28 void LayerAnimationObserver::AttachedToSequence( |
41 LayerAnimationSequence* sequence) { | 29 LayerAnimationSequence* sequence) { |
42 DCHECK(attached_sequences_.find(sequence) == attached_sequences_.end()); | 30 DCHECK(attached_sequences_.find(sequence) == attached_sequences_.end()); |
43 attached_sequences_.insert(sequence); | 31 attached_sequences_.insert(sequence); |
44 OnAttachedToSequence(sequence); | |
45 } | 32 } |
46 | 33 |
47 void LayerAnimationObserver::DetachedFromSequence( | 34 void LayerAnimationObserver::DetachedFromSequence( |
48 LayerAnimationSequence* sequence) { | 35 LayerAnimationSequence* sequence) { |
49 if (attached_sequences_.find(sequence) != attached_sequences_.end()) | 36 if (attached_sequences_.find(sequence) != attached_sequences_.end()) |
50 attached_sequences_.erase(sequence); | 37 attached_sequences_.erase(sequence); |
51 OnDetachedFromSequence(sequence); | |
52 } | 38 } |
53 | 39 |
54 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
55 // ImplicitAnimationObserver | 41 // ImplicitAnimationObserver |
56 | 42 |
57 ImplicitAnimationObserver::ImplicitAnimationObserver() | 43 ImplicitAnimationObserver::ImplicitAnimationObserver() |
58 : active_(false) { | 44 : active_(false), |
| 45 animation_count_(0) { |
59 } | 46 } |
60 | 47 |
61 ImplicitAnimationObserver::~ImplicitAnimationObserver() {} | 48 ImplicitAnimationObserver::~ImplicitAnimationObserver() {} |
62 | 49 |
63 void ImplicitAnimationObserver::SetActive(bool active) { | 50 void ImplicitAnimationObserver::SetActive(bool active) { |
64 active_ = active; | 51 active_ = active; |
65 CheckCompleted(); | 52 CheckCompleted(); |
66 } | 53 } |
67 | 54 |
68 void ImplicitAnimationObserver::StopObservingImplicitAnimations() { | |
69 SetActive(false); | |
70 StopObserving(); | |
71 } | |
72 | |
73 void ImplicitAnimationObserver::OnLayerAnimationEnded( | 55 void ImplicitAnimationObserver::OnLayerAnimationEnded( |
74 LayerAnimationSequence* sequence) { | 56 const LayerAnimationSequence* sequence) { |
75 sequence->RemoveObserver(this); | 57 animation_count_--; |
76 DCHECK(attached_sequences().find(sequence) == attached_sequences().end()); | |
77 CheckCompleted(); | 58 CheckCompleted(); |
78 } | 59 } |
79 | 60 |
80 void ImplicitAnimationObserver::OnLayerAnimationAborted( | 61 void ImplicitAnimationObserver::OnLayerAnimationAborted( |
81 LayerAnimationSequence* sequence) { | 62 const LayerAnimationSequence* sequence) { |
82 sequence->RemoveObserver(this); | 63 animation_count_--; |
83 DCHECK(attached_sequences().find(sequence) == attached_sequences().end()); | |
84 CheckCompleted(); | 64 CheckCompleted(); |
85 } | 65 } |
86 | 66 |
87 void ImplicitAnimationObserver::OnLayerAnimationScheduled( | 67 void ImplicitAnimationObserver::OnLayerAnimationScheduled( |
88 LayerAnimationSequence* sequence) { | 68 const LayerAnimationSequence* sequence) { |
89 } | 69 animation_count_++; |
90 | |
91 void ImplicitAnimationObserver::OnAttachedToSequence( | |
92 LayerAnimationSequence* sequence) { | |
93 } | |
94 | |
95 void ImplicitAnimationObserver::OnDetachedFromSequence( | |
96 LayerAnimationSequence* sequence) { | |
97 DCHECK(attached_sequences().find(sequence) == attached_sequences().end()); | |
98 CheckCompleted(); | |
99 } | 70 } |
100 | 71 |
101 void ImplicitAnimationObserver::CheckCompleted() { | 72 void ImplicitAnimationObserver::CheckCompleted() { |
102 if (active_ && attached_sequences().empty()) { | 73 if (active_ && animation_count_ == 0) |
103 OnImplicitAnimationsCompleted(); | 74 OnImplicitAnimationsCompleted(); |
104 active_ = false; | |
105 } | |
106 } | 75 } |
107 | 76 |
108 } // namespace ui | 77 } // namespace ui |
OLD | NEW |