Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 | 14 |
| 14 namespace ui { | 15 namespace ui { |
| 15 | 16 |
| 16 LayerAnimationSequence::LayerAnimationSequence() | 17 LayerAnimationSequence::LayerAnimationSequence() |
| 17 : is_cyclic_(false), | 18 : is_cyclic_(false), |
| 18 last_element_(0) { | 19 last_element_(0) { |
| 19 } | 20 } |
| 20 | 21 |
| 21 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element) | 22 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element) |
| 22 : is_cyclic_(false), | 23 : is_cyclic_(false), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 if (elements_[current_index]->duration() > base::TimeDelta()) { | 59 if (elements_[current_index]->duration() > base::TimeDelta()) { |
| 59 t = (elapsed - last_start_).InMillisecondsF() / | 60 t = (elapsed - last_start_).InMillisecondsF() / |
| 60 elements_[current_index]->duration().InMillisecondsF(); | 61 elements_[current_index]->duration().InMillisecondsF(); |
| 61 } | 62 } |
| 62 elements_[current_index]->Progress(t, delegate); | 63 elements_[current_index]->Progress(t, delegate); |
| 63 } | 64 } |
| 64 | 65 |
| 65 if (!is_cyclic_ && elapsed == duration_) { | 66 if (!is_cyclic_ && elapsed == duration_) { |
| 66 last_element_ = 0; | 67 last_element_ = 0; |
| 67 last_start_ = base::TimeDelta::FromMilliseconds(0); | 68 last_start_ = base::TimeDelta::FromMilliseconds(0); |
| 69 NotifyEnded(); | |
| 68 } | 70 } |
| 69 } | 71 } |
| 70 | 72 |
| 71 void LayerAnimationSequence::GetTargetValue( | 73 void LayerAnimationSequence::GetTargetValue( |
| 72 LayerAnimationElement::TargetValue* target) const { | 74 LayerAnimationElement::TargetValue* target) const { |
| 73 if (is_cyclic_) | 75 if (is_cyclic_) |
| 74 return; | 76 return; |
| 75 | 77 |
| 76 for (size_t i = last_element_; i < elements_.size(); ++i) | 78 for (size_t i = last_element_; i < elements_.size(); ++i) |
| 77 elements_[i]->GetTargetValue(target); | 79 elements_[i]->GetTargetValue(target); |
| 78 } | 80 } |
| 79 | 81 |
| 80 void LayerAnimationSequence::Abort() { | 82 void LayerAnimationSequence::Abort() { |
| 81 size_t current_index = last_element_ % elements_.size(); | 83 size_t current_index = last_element_ % elements_.size(); |
| 82 while (current_index < elements_.size()) { | 84 while (current_index < elements_.size()) { |
| 83 elements_[current_index]->Abort(); | 85 elements_[current_index]->Abort(); |
| 84 ++current_index; | 86 ++current_index; |
| 85 } | 87 } |
| 86 last_element_ = 0; | 88 last_element_ = 0; |
| 87 last_start_ = base::TimeDelta::FromMilliseconds(0); | 89 last_start_ = base::TimeDelta::FromMilliseconds(0); |
| 90 NotifyAborted(); | |
| 88 } | 91 } |
| 89 | 92 |
| 90 void LayerAnimationSequence::AddElement(LayerAnimationElement* element) { | 93 void LayerAnimationSequence::AddElement(LayerAnimationElement* element) { |
| 91 // Update duration and properties. | 94 // Update duration and properties. |
| 92 duration_ += element->duration(); | 95 duration_ += element->duration(); |
| 93 properties_.insert(element->properties().begin(), | 96 properties_.insert(element->properties().begin(), |
| 94 element->properties().end()); | 97 element->properties().end()); |
| 95 elements_.push_back(make_linked_ptr(element)); | 98 elements_.push_back(make_linked_ptr(element)); |
| 96 } | 99 } |
| 97 | 100 |
| 98 bool LayerAnimationSequence::HasCommonProperty( | 101 bool LayerAnimationSequence::HasCommonProperty( |
| 99 const LayerAnimationElement::AnimatableProperties& other) const { | 102 const LayerAnimationElement::AnimatableProperties& other) const { |
| 100 LayerAnimationElement::AnimatableProperties intersection; | 103 LayerAnimationElement::AnimatableProperties intersection; |
| 101 std::insert_iterator<LayerAnimationElement::AnimatableProperties> ii( | 104 std::insert_iterator<LayerAnimationElement::AnimatableProperties> ii( |
| 102 intersection, intersection.begin()); | 105 intersection, intersection.begin()); |
| 103 std::set_intersection(properties_.begin(), properties_.end(), | 106 std::set_intersection(properties_.begin(), properties_.end(), |
| 104 other.begin(), other.end(), | 107 other.begin(), other.end(), |
| 105 ii); | 108 ii); |
| 106 return intersection.size() > 0; | 109 return intersection.size() > 0; |
| 107 } | 110 } |
| 108 | 111 |
| 112 void LayerAnimationSequence::AddObserver(LayerAnimationObserver* observer) { | |
| 113 if (!observers_.HasObserver(observer)) | |
|
sky
2011/10/28 22:11:38
Don't do this, there's a DCHECK that you don't add
| |
| 114 observers_.AddObserver(observer); | |
| 115 } | |
| 116 | |
| 117 void LayerAnimationSequence::RemoveObserver(LayerAnimationObserver* observer) { | |
| 118 observers_.RemoveObserver(observer); | |
| 119 } | |
| 120 | |
| 121 void LayerAnimationSequence::OnScheduled() { | |
| 122 NotifyScheduled(); | |
| 123 } | |
| 124 | |
| 125 void LayerAnimationSequence::NotifyScheduled() { | |
| 126 FOR_EACH_OBSERVER(LayerAnimationObserver, | |
| 127 observers_, | |
| 128 OnLayerAnimationScheduled(this)); | |
| 129 } | |
| 130 | |
| 131 void LayerAnimationSequence::NotifyEnded() { | |
| 132 FOR_EACH_OBSERVER(LayerAnimationObserver, | |
| 133 observers_, | |
| 134 OnLayerAnimationEnded(this)); | |
| 135 } | |
| 136 | |
| 137 void LayerAnimationSequence::NotifyAborted() { | |
| 138 FOR_EACH_OBSERVER(LayerAnimationObserver, | |
| 139 observers_, | |
| 140 OnLayerAnimationAborted(this)); | |
| 141 } | |
| 142 | |
| 109 } // namespace ui | 143 } // namespace ui |
| OLD | NEW |