Index: Source/core/animation/InterpolableValue.cpp |
diff --git a/Source/core/animation/InterpolableValue.cpp b/Source/core/animation/InterpolableValue.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6e1f0b29e010d179ef72f1e7720112655168433c |
--- /dev/null |
+++ b/Source/core/animation/InterpolableValue.cpp |
@@ -0,0 +1,49 @@ |
+// Copyright 2014 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 "config.h" |
+#include "core/animation/InterpolableValue.h" |
+ |
+namespace WebCore { |
+ |
+PassOwnPtr<InterpolableValue> InterpolableNumber::interpolate(const InterpolableValue &other, double progress) const |
+{ |
+ const InterpolableNumber* otherNumber = toInterpolableNumber(&other); |
+ if (!progress) |
+ return create(m_value); |
+ if (progress == 1) |
+ return create(otherNumber->m_value); |
+ return create(m_value * (1 - progress) + otherNumber->m_value * progress); |
+} |
+ |
+PassOwnPtr<InterpolableValue> InterpolableBool::interpolate(const InterpolableValue &other, double progress) const |
+{ |
+ if (progress < 0.5) { |
+ return clone(); |
+ } |
+ return other.clone(); |
+} |
+ |
+PassOwnPtr<InterpolableValue> InterpolableList::interpolate(const InterpolableValue &other, double progress) const |
+{ |
+ const InterpolableList* otherList = toInterpolableList(&other); |
+ ASSERT(otherList->m_size == m_size); |
+ |
+ if (!progress) { |
+ return create(*this); |
+ } |
+ if (progress == 1) { |
+ return InterpolableList::create(*otherList); |
+ } |
+ |
+ OwnPtr<InterpolableList> result = create(m_size); |
+ for (size_t i = 0; i < m_size; i++) { |
+ ASSERT(m_values.get()[i]); |
+ ASSERT(otherList->m_values.get()[i]); |
+ result->set(i, m_values.get()[i]->interpolate(*(otherList->m_values.get()[i]), progress)); |
+ } |
+ return result.release(); |
+} |
+ |
+} |