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/compositor/layer_animation_sequence.h" | 5 #include "ui/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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 last_element_(0) { | 24 last_element_(0) { |
25 AddElement(element); | 25 AddElement(element); |
26 } | 26 } |
27 | 27 |
28 LayerAnimationSequence::~LayerAnimationSequence() { | 28 LayerAnimationSequence::~LayerAnimationSequence() { |
29 FOR_EACH_OBSERVER(LayerAnimationObserver, | 29 FOR_EACH_OBSERVER(LayerAnimationObserver, |
30 observers_, | 30 observers_, |
31 DetachedFromSequence(this, true)); | 31 DetachedFromSequence(this, true)); |
32 } | 32 } |
33 | 33 |
34 bool LayerAnimationSequence::Progress(base::TimeDelta elapsed, | 34 void LayerAnimationSequence::Progress(base::TimeDelta elapsed, |
35 LayerAnimationDelegate* delegate) { | 35 LayerAnimationDelegate* delegate) { |
36 bool redraw_required = false; | 36 bool redraw_required = false; |
37 | 37 |
38 if (elements_.empty()) | 38 if (elements_.empty()) |
39 return redraw_required; | 39 return; |
40 | 40 |
41 if (is_cyclic_ && duration_ > base::TimeDelta()) { | 41 if (is_cyclic_ && duration_ > base::TimeDelta()) { |
42 // If delta = elapsed - last_start_ is huge, we can skip ahead by complete | 42 // If delta = elapsed - last_start_ is huge, we can skip ahead by complete |
43 // loops to save time. | 43 // loops to save time. |
44 base::TimeDelta delta = elapsed - last_start_; | 44 base::TimeDelta delta = elapsed - last_start_; |
45 int64 k = delta.ToInternalValue() / duration_.ToInternalValue() - 1; | 45 int64 k = delta.ToInternalValue() / duration_.ToInternalValue() - 1; |
46 | 46 |
47 last_start_ += base::TimeDelta::FromInternalValue( | 47 last_start_ += base::TimeDelta::FromInternalValue( |
48 k * duration_.ToInternalValue()); | 48 k * duration_.ToInternalValue()); |
49 } | 49 } |
(...skipping 12 matching lines...) Expand all Loading... |
62 if (is_cyclic_ || last_element_ < elements_.size()) { | 62 if (is_cyclic_ || last_element_ < elements_.size()) { |
63 double t = 1.0; | 63 double t = 1.0; |
64 if (elements_[current_index]->duration() > base::TimeDelta()) { | 64 if (elements_[current_index]->duration() > base::TimeDelta()) { |
65 t = (elapsed - last_start_).InMillisecondsF() / | 65 t = (elapsed - last_start_).InMillisecondsF() / |
66 elements_[current_index]->duration().InMillisecondsF(); | 66 elements_[current_index]->duration().InMillisecondsF(); |
67 } | 67 } |
68 if (elements_[current_index]->Progress(t, delegate)) | 68 if (elements_[current_index]->Progress(t, delegate)) |
69 redraw_required = true; | 69 redraw_required = true; |
70 } | 70 } |
71 | 71 |
| 72 // Since the delegate may be deleted due to the notifications below, it is |
| 73 // important that we schedule a draw before sending them. |
| 74 if (redraw_required) |
| 75 delegate->ScheduleDrawForAnimation(); |
| 76 |
72 if (!is_cyclic_ && elapsed == duration_) { | 77 if (!is_cyclic_ && elapsed == duration_) { |
73 last_element_ = 0; | 78 last_element_ = 0; |
74 last_start_ = base::TimeDelta::FromMilliseconds(0); | 79 last_start_ = base::TimeDelta::FromMilliseconds(0); |
75 NotifyEnded(); | 80 NotifyEnded(); |
76 } | 81 } |
77 | |
78 return redraw_required; | |
79 } | 82 } |
80 | 83 |
81 void LayerAnimationSequence::GetTargetValue( | 84 void LayerAnimationSequence::GetTargetValue( |
82 LayerAnimationElement::TargetValue* target) const { | 85 LayerAnimationElement::TargetValue* target) const { |
83 if (is_cyclic_) | 86 if (is_cyclic_) |
84 return; | 87 return; |
85 | 88 |
86 for (size_t i = last_element_; i < elements_.size(); ++i) | 89 for (size_t i = last_element_; i < elements_.size(); ++i) |
87 elements_[i]->GetTargetValue(target); | 90 elements_[i]->GetTargetValue(target); |
88 } | 91 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 OnLayerAnimationEnded(this)); | 162 OnLayerAnimationEnded(this)); |
160 } | 163 } |
161 | 164 |
162 void LayerAnimationSequence::NotifyAborted() { | 165 void LayerAnimationSequence::NotifyAborted() { |
163 FOR_EACH_OBSERVER(LayerAnimationObserver, | 166 FOR_EACH_OBSERVER(LayerAnimationObserver, |
164 observers_, | 167 observers_, |
165 OnLayerAnimationAborted(this)); | 168 OnLayerAnimationAborted(this)); |
166 } | 169 } |
167 | 170 |
168 } // namespace ui | 171 } // namespace ui |
OLD | NEW |