Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(483)

Unified Diff: Source/core/animation/InterpolableValue.cpp

Issue 177183007: Web Animations: Add InterpolableValue hierarchy. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/animation/InterpolableValue.h ('k') | Source/core/animation/InterpolableValueTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ff6e6e7dd18d4a6e5750e7b0587e300c3e1d627f
--- /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 &to, const double progress) const
+{
+ const InterpolableNumber* toNumber = toInterpolableNumber(&to);
+ if (!progress)
+ return create(m_value);
+ if (progress == 1)
+ return create(toNumber->m_value);
+ return create(m_value * (1 - progress) + toNumber->m_value * progress);
+}
+
+PassOwnPtr<InterpolableValue> InterpolableBool::interpolate(const InterpolableValue &to, const double progress) const
+{
+ if (progress < 0.5) {
+ return clone();
+ }
+ return to.clone();
+}
+
+PassOwnPtr<InterpolableValue> InterpolableList::interpolate(const InterpolableValue &to, const double progress) const
+{
+ const InterpolableList* toList = toInterpolableList(&to);
+ ASSERT(toList->m_size == m_size);
+
+ if (!progress) {
+ return create(*this);
+ }
+ if (progress == 1) {
+ return InterpolableList::create(*toList);
+ }
+
+ OwnPtr<InterpolableList> result = create(m_size);
+ for (size_t i = 0; i < m_size; i++) {
+ ASSERT(m_values.get()[i]);
+ ASSERT(toList->m_values.get()[i]);
+ result->set(i, m_values.get()[i]->interpolate(*(toList->m_values.get()[i]), progress));
+ }
+ return result.release();
+}
+
+}
« no previous file with comments | « Source/core/animation/InterpolableValue.h ('k') | Source/core/animation/InterpolableValueTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698