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_sequence.h" | 5 #include "ui/gfx/compositor/layer_animation_sequence.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "ui/gfx/compositor/layer_animation_delegate.h" | 11 #include "ui/gfx/compositor/layer_animation_delegate.h" |
12 #include "ui/gfx/compositor/layer_animation_element.h" | 12 #include "ui/gfx/compositor/layer_animation_element.h" |
13 #include "ui/gfx/compositor/layer_animation_observer.h" | 13 #include "ui/gfx/compositor/layer_animation_observer.h" |
14 | 14 |
15 namespace ui { | 15 namespace ui { |
16 | 16 |
17 LayerAnimationSequence::LayerAnimationSequence() | 17 LayerAnimationSequence::LayerAnimationSequence() |
18 : is_cyclic_(false), | 18 : is_cyclic_(false), |
| 19 is_animating_(false), |
19 last_element_(0) { | 20 last_element_(0) { |
20 } | 21 } |
21 | 22 |
22 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element) | 23 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element) |
23 : is_cyclic_(false), | 24 : is_cyclic_(false), |
| 25 is_animating_(false), |
24 last_element_(0) { | 26 last_element_(0) { |
25 AddElement(element); | 27 AddElement(element); |
26 } | 28 } |
27 | 29 |
28 LayerAnimationSequence::~LayerAnimationSequence() { | 30 LayerAnimationSequence::~LayerAnimationSequence() { |
29 FOR_EACH_OBSERVER(LayerAnimationObserver, | 31 FOR_EACH_OBSERVER(LayerAnimationObserver, |
30 observers_, | 32 observers_, |
31 DetachedFromSequence(this)); | 33 DetachedFromSequence(this)); |
32 } | 34 } |
33 | 35 |
34 void LayerAnimationSequence::Progress(base::TimeDelta elapsed, | 36 void LayerAnimationSequence::Progress(base::TimeDelta elapsed, |
35 LayerAnimationDelegate* delegate) { | 37 LayerAnimationDelegate* delegate) { |
36 if (elements_.empty()) | 38 if (elements_.empty()) |
37 return; | 39 return; |
38 | 40 |
| 41 // We are now animating. |
| 42 is_animating_ = true; |
| 43 |
39 if (is_cyclic_ && duration_ > base::TimeDelta()) { | 44 if (is_cyclic_ && duration_ > base::TimeDelta()) { |
40 // If delta = elapsed - last_start_ is huge, we can skip ahead by complete | 45 // If delta = elapsed - last_start_ is huge, we can skip ahead by complete |
41 // loops to save time. | 46 // loops to save time. |
42 base::TimeDelta delta = elapsed - last_start_; | 47 base::TimeDelta delta = elapsed - last_start_; |
43 int64 k = delta.ToInternalValue() / duration_.ToInternalValue() - 1; | 48 int64 k = delta.ToInternalValue() / duration_.ToInternalValue() - 1; |
44 if (k > 0) { | 49 if (k > 0) { |
45 last_start_ += base::TimeDelta::FromInternalValue( | 50 last_start_ += base::TimeDelta::FromInternalValue( |
46 k * duration_.ToInternalValue()); | 51 k * duration_.ToInternalValue()); |
47 } | 52 } |
48 } | 53 } |
(...skipping 13 matching lines...) Expand all Loading... |
62 if (elements_[current_index]->duration() > base::TimeDelta()) { | 67 if (elements_[current_index]->duration() > base::TimeDelta()) { |
63 t = (elapsed - last_start_).InMillisecondsF() / | 68 t = (elapsed - last_start_).InMillisecondsF() / |
64 elements_[current_index]->duration().InMillisecondsF(); | 69 elements_[current_index]->duration().InMillisecondsF(); |
65 } | 70 } |
66 elements_[current_index]->Progress(t, delegate); | 71 elements_[current_index]->Progress(t, delegate); |
67 } | 72 } |
68 | 73 |
69 if (!is_cyclic_ && elapsed == duration_) { | 74 if (!is_cyclic_ && elapsed == duration_) { |
70 last_element_ = 0; | 75 last_element_ = 0; |
71 last_start_ = base::TimeDelta::FromMilliseconds(0); | 76 last_start_ = base::TimeDelta::FromMilliseconds(0); |
| 77 is_animating_ = false; |
72 NotifyEnded(); | 78 NotifyEnded(); |
73 } | 79 } |
74 } | 80 } |
75 | 81 |
76 void LayerAnimationSequence::GetTargetValue( | 82 void LayerAnimationSequence::GetTargetValue( |
77 LayerAnimationElement::TargetValue* target) const { | 83 LayerAnimationElement::TargetValue* target) const { |
78 if (is_cyclic_) | 84 if (is_cyclic_) |
79 return; | 85 return; |
80 | 86 |
81 for (size_t i = last_element_; i < elements_.size(); ++i) | 87 for (size_t i = last_element_; i < elements_.size(); ++i) |
82 elements_[i]->GetTargetValue(target); | 88 elements_[i]->GetTargetValue(target); |
83 } | 89 } |
84 | 90 |
85 void LayerAnimationSequence::Abort() { | 91 void LayerAnimationSequence::Abort() { |
86 size_t current_index = last_element_ % elements_.size(); | 92 size_t current_index = last_element_ % elements_.size(); |
87 while (current_index < elements_.size()) { | 93 while (current_index < elements_.size()) { |
88 elements_[current_index]->Abort(); | 94 elements_[current_index]->Abort(); |
89 ++current_index; | 95 ++current_index; |
90 } | 96 } |
91 last_element_ = 0; | 97 last_element_ = 0; |
92 last_start_ = base::TimeDelta::FromMilliseconds(0); | 98 last_start_ = base::TimeDelta::FromMilliseconds(0); |
| 99 is_animating_ = false; |
93 NotifyAborted(); | 100 NotifyAborted(); |
94 } | 101 } |
95 | 102 |
96 void LayerAnimationSequence::AddElement(LayerAnimationElement* element) { | 103 void LayerAnimationSequence::AddElement(LayerAnimationElement* element) { |
97 // Update duration and properties. | 104 // Update duration and properties. |
98 duration_ += element->duration(); | 105 duration_ += element->duration(); |
99 properties_.insert(element->properties().begin(), | 106 properties_.insert(element->properties().begin(), |
100 element->properties().end()); | 107 element->properties().end()); |
101 elements_.push_back(make_linked_ptr(element)); | 108 elements_.push_back(make_linked_ptr(element)); |
102 } | 109 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 OnLayerAnimationEnded(this)); | 157 OnLayerAnimationEnded(this)); |
151 } | 158 } |
152 | 159 |
153 void LayerAnimationSequence::NotifyAborted() { | 160 void LayerAnimationSequence::NotifyAborted() { |
154 FOR_EACH_OBSERVER(LayerAnimationObserver, | 161 FOR_EACH_OBSERVER(LayerAnimationObserver, |
155 observers_, | 162 observers_, |
156 OnLayerAnimationAborted(this)); | 163 OnLayerAnimationAborted(this)); |
157 } | 164 } |
158 | 165 |
159 } // namespace ui | 166 } // namespace ui |
OLD | NEW |