| 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 void LayerAnimationSequence::Progress(base::TimeDelta elapsed, | 34 bool 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; | 39 return redraw_required; |
| 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 | |
| 77 if (!is_cyclic_ && elapsed == duration_) { | 72 if (!is_cyclic_ && elapsed == duration_) { |
| 78 last_element_ = 0; | 73 last_element_ = 0; |
| 79 last_start_ = base::TimeDelta::FromMilliseconds(0); | 74 last_start_ = base::TimeDelta::FromMilliseconds(0); |
| 80 NotifyEnded(); | 75 NotifyEnded(); |
| 81 } | 76 } |
| 77 |
| 78 return redraw_required; |
| 82 } | 79 } |
| 83 | 80 |
| 84 void LayerAnimationSequence::GetTargetValue( | 81 void LayerAnimationSequence::GetTargetValue( |
| 85 LayerAnimationElement::TargetValue* target) const { | 82 LayerAnimationElement::TargetValue* target) const { |
| 86 if (is_cyclic_) | 83 if (is_cyclic_) |
| 87 return; | 84 return; |
| 88 | 85 |
| 89 for (size_t i = last_element_; i < elements_.size(); ++i) | 86 for (size_t i = last_element_; i < elements_.size(); ++i) |
| 90 elements_[i]->GetTargetValue(target); | 87 elements_[i]->GetTargetValue(target); |
| 91 } | 88 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 OnLayerAnimationEnded(this)); | 159 OnLayerAnimationEnded(this)); |
| 163 } | 160 } |
| 164 | 161 |
| 165 void LayerAnimationSequence::NotifyAborted() { | 162 void LayerAnimationSequence::NotifyAborted() { |
| 166 FOR_EACH_OBSERVER(LayerAnimationObserver, | 163 FOR_EACH_OBSERVER(LayerAnimationObserver, |
| 167 observers_, | 164 observers_, |
| 168 OnLayerAnimationAborted(this)); | 165 OnLayerAnimationAborted(this)); |
| 169 } | 166 } |
| 170 | 167 |
| 171 } // namespace ui | 168 } // namespace ui |
| OLD | NEW |