Index: ui/gfx/compositor/layer_animation_sequence.cc |
diff --git a/ui/gfx/compositor/layer_animation_sequence.cc b/ui/gfx/compositor/layer_animation_sequence.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..86b79e6d937770ef19ce81d5c9e89520bef75f47 |
--- /dev/null |
+++ b/ui/gfx/compositor/layer_animation_sequence.cc |
@@ -0,0 +1,88 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/gfx/compositor/layer_animation_sequence.h" |
+ |
+#include <algorithm> |
+//#include <iterator> |
+ |
+#include "ui/gfx/compositor/layer_animation_delegate.h" |
+#include "ui/gfx/compositor/layer_animation_element.h" |
+ |
+namespace ui { |
+ |
+LayerAnimationSequence::LayerAnimationSequence() |
+ : is_cyclic_(false), |
+ last_element_(0) { |
+} |
+ |
+LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element) |
+ : is_cyclic_(false), |
+ last_element_(0) { |
+ AddElement(element); |
+} |
+ |
+LayerAnimationSequence::~LayerAnimationSequence() { |
+} |
+ |
+void LayerAnimationSequence::Progress(base::TimeDelta elapsed, |
+ LayerAnimationDelegate* delegate) { |
+ while (last_element_ < elements_.size() && |
+ last_start_ + elements_[last_element_]->Duration() < elapsed) { |
+ // let the element we're passing finish. |
+ elements_[last_element_]->Progress(1.0, delegate); |
+ last_start_ += elements_[last_element_]->Duration(); |
+ ++last_element_; |
+ } |
+ |
+ if (last_element_ < elements_.size()) { |
+ // calculate t. |
+ double t = 1.0; |
+ if (elements_[last_element_]->Duration() > base::TimeDelta()) { |
+ t = (elapsed - last_start_).InMillisecondsF() / |
+ elements_[last_element_]->Duration().InMillisecondsF(); |
+ } |
+ elements_[last_element_]->Progress(t, delegate); |
+ } |
+ |
+ if (elapsed == duration_) { |
+ last_element_ = 0; |
+ last_start_ = base::TimeDelta::FromMilliseconds(0); |
+ } |
+} |
+ |
+void LayerAnimationSequence::Abort() { |
+ while (last_element_ < elements_.size()) { |
+ elements_[last_element_]->Abort(); |
+ ++last_element_; |
+ } |
+ last_element_ = 0; |
+ last_start_ = base::TimeDelta::FromMilliseconds(0); |
+} |
+ |
+void LayerAnimationSequence::AddElement(LayerAnimationElement* element) { |
+ // Update duration and properties. |
+ duration_ += element->Duration(); |
+ LayerAnimationElement::AnimatableProperties::const_iterator iter = |
+ element->Properties().begin(); |
+ while (iter != element->Properties().end()) { |
+ properties_.insert(*iter); |
+ ++iter; |
+ } |
+ |
+ elements_.push_back(make_scoped_refptr(element)); |
+} |
+ |
+bool LayerAnimationSequence::HasCommonProperty( |
+ const LayerAnimationSequence& other) const { |
+ LayerAnimationElement::AnimatableProperties intersection; |
+ std::insert_iterator<LayerAnimationElement::AnimatableProperties> ii( |
+ intersection, intersection.begin()); |
+ std::set_intersection(properties_.begin(), properties_.end(), |
+ other.properties().begin(), other.properties().end(), |
+ ii); |
+ return intersection.size() > 0; |
+} |
+ |
+} // namespace ui |