Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 #include "ui/gfx/compositor/layer_animation_sequence.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/debug/trace_event.h" | |
| 10 #include "ui/gfx/compositor/layer_animation_delegate.h" | |
| 11 #include "ui/gfx/compositor/layer_animation_element.h" | |
| 12 | |
| 13 namespace ui { | |
| 14 | |
| 15 LayerAnimationSequence::LayerAnimationSequence() | |
| 16 : is_cyclic_(false), | |
| 17 last_element_(0) { | |
| 18 } | |
| 19 | |
| 20 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element) | |
| 21 : is_cyclic_(false), | |
| 22 last_element_(0) { | |
| 23 AddElement(element); | |
| 24 } | |
| 25 | |
| 26 LayerAnimationSequence::~LayerAnimationSequence() { | |
| 27 } | |
| 28 | |
| 29 void LayerAnimationSequence::Progress(base::TimeDelta elapsed, | |
| 30 LayerAnimationDelegate* delegate) { | |
| 31 TRACE_EVENT0("LayerAnimationSequence", "Progress"); | |
|
sky
2011/10/19 00:06:33
Early out if empty?
| |
| 32 | |
| 33 Elements::size_type current_index = last_element_ % elements_.size(); | |
| 34 while (true) { | |
| 35 if (!is_cyclic_ && last_element_ >= elements_.size()) | |
|
sky
2011/10/19 00:06:33
If is_cyclic is true, I think this loop is problem
| |
| 36 break; | |
| 37 | |
| 38 if (last_start_ + elements_[current_index]->Duration() >= elapsed) | |
| 39 break; | |
| 40 | |
| 41 // let the element we're passing finish. | |
| 42 elements_[current_index]->Progress(1.0, delegate); | |
| 43 last_start_ += elements_[current_index]->Duration(); | |
| 44 ++last_element_; | |
| 45 current_index = last_element_ % elements_.size(); | |
| 46 } | |
| 47 | |
| 48 if (is_cyclic_ || last_element_ < elements_.size()) { | |
| 49 // calculate t. | |
| 50 double t = 1.0; | |
| 51 if (elements_[current_index]->Duration() > base::TimeDelta()) { | |
| 52 t = (elapsed - last_start_).InMillisecondsF() / | |
| 53 elements_[current_index]->Duration().InMillisecondsF(); | |
| 54 } | |
| 55 elements_[current_index]->Progress(t, delegate); | |
| 56 } | |
| 57 | |
| 58 if (!is_cyclic_ && elapsed == duration_) { | |
| 59 last_element_ = 0; | |
| 60 last_start_ = base::TimeDelta::FromMilliseconds(0); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 void LayerAnimationSequence::Abort() { | |
| 65 while (last_element_ < elements_.size()) { | |
| 66 elements_[last_element_]->Abort(); | |
| 67 ++last_element_; | |
| 68 } | |
| 69 last_element_ = 0; | |
| 70 last_start_ = base::TimeDelta::FromMilliseconds(0); | |
| 71 } | |
| 72 | |
| 73 void LayerAnimationSequence::AddElement(LayerAnimationElement* element) { | |
| 74 // Update duration and properties. | |
| 75 duration_ += element->Duration(); | |
| 76 LayerAnimationElement::AnimatableProperties::const_iterator iter = | |
| 77 element->Properties().begin(); | |
| 78 while (iter != element->Properties().end()) { | |
|
sky
2011/10/19 00:06:33
Use a for loop and pull 76 into it.
| |
| 79 properties_.insert(*iter); | |
| 80 ++iter; | |
| 81 } | |
| 82 | |
| 83 elements_.push_back(element); | |
| 84 } | |
| 85 | |
| 86 bool LayerAnimationSequence::HasCommonProperty( | |
| 87 const LayerAnimationElement::AnimatableProperties& other) const { | |
| 88 LayerAnimationElement::AnimatableProperties intersection; | |
| 89 std::insert_iterator<LayerAnimationElement::AnimatableProperties> ii( | |
| 90 intersection, intersection.begin()); | |
| 91 std::set_intersection(properties_.begin(), properties_.end(), | |
| 92 other.begin(), other.end(), | |
| 93 ii); | |
| 94 return intersection.size() > 0; | |
| 95 } | |
| 96 | |
| 97 } // namespace ui | |
| OLD | NEW |