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

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

Issue 143573004: [wip] interpolable value refactor. NOT FOR LANDING. Base URL: https://chromium.googlesource.com/chromium/blink.git@interpolationWrap
Patch Set: Created 6 years, 11 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/InertAnimation.cpp ('k') | Source/core/animation/Interpolation.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/animation/InterpolableValue.h
diff --git a/Source/core/animation/InterpolableValue.h b/Source/core/animation/InterpolableValue.h
new file mode 100644
index 0000000000000000000000000000000000000000..f6059968aa383bd00949342c74ba330bc9209a6b
--- /dev/null
+++ b/Source/core/animation/InterpolableValue.h
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2014 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef InterpolableValue_h
+#define InterpolableValue_h
+
+#include "wtf/OwnPtr.h"
+#include "core/animation/AnimatableValue.h"
+
+namespace WebCore {
+
+class InterpolableValue {
+public:
+ virtual PassOwnPtr<InterpolableValue> interpolate(InterpolableValue &other, double percentage) = 0;
+ virtual PassOwnPtr<InterpolableValue> clone() = 0;
+
+ virtual ~InterpolableValue() { }
+};
+
+class InterpolableNumber : public InterpolableValue {
+public:
+ static PassOwnPtr<InterpolableNumber> create(double value)
+ {
+ return adoptPtr(new InterpolableNumber(value));
+ }
+
+ virtual PassOwnPtr<InterpolableValue> interpolate(InterpolableValue &other, double percentage)
+ {
+ InterpolableNumber *otherNumber = static_cast<InterpolableNumber *>(&other);
+ if (!percentage)
+ return create(m_value);
+ if (percentage == 1)
+ return create(otherNumber->m_value);
+ return create(m_value * (1 - percentage) + otherNumber->m_value * percentage);
+ }
+
+ virtual PassOwnPtr<InterpolableValue> clone()
+ {
+ return create(m_value);
+ }
+
+ double value() { return m_value; }
+
+private:
+ double m_value;
+
+ InterpolableNumber(double value)
+ : m_value(value)
+ { }
+
+};
+
+class InterpolableBool : public InterpolableValue {
+public:
+ PassOwnPtr<InterpolableBool> create(bool value)
+ {
+ return adoptPtr(new InterpolableBool(value));
+ }
+
+ virtual PassOwnPtr<InterpolableValue> interpolate(InterpolableValue &other, double percentage)
+ {
+ if (percentage < 0.5) {
+ return clone();
+ }
+ return (other.clone());
+ }
+
+ virtual PassOwnPtr<InterpolableValue> clone()
+ {
+ return create(m_value);
+ }
+
+ bool value() { return m_value; }
+
+private:
+ bool m_value;
+
+ InterpolableBool(bool value)
+ : m_value(value)
+ { }
+};
+
+class InterpolableList : public InterpolableValue {
+public:
+ static PassOwnPtr<InterpolableList> create(InterpolableList &other)
+ {
+ return adoptPtr(new InterpolableList(other));
+ }
+
+ static PassOwnPtr<InterpolableList> create(size_t size)
+ {
+ return adoptPtr(new InterpolableList(size));
+ }
+
+ virtual PassOwnPtr<InterpolableValue> interpolate(InterpolableValue &other, double percentage)
+ {
+ InterpolableList *otherList = static_cast<InterpolableList *>(&other);
+ if (!percentage)
+ return create(*this);
+ if (percentage == 1)
+ return InterpolableList::create(*otherList);
+
+ OwnPtr<InterpolableList> result = create(m_size);
+ for (size_t i = 0; i < m_size; i++)
+ result->set(m_values.get()[i]->interpolate(*(otherList->m_values.get()[i]), percentage), i);
+ return result.release();
+ }
+
+ virtual PassOwnPtr<InterpolableValue> clone()
+ {
+ return create(*this);
+ }
+
+ void set(PassOwnPtr<InterpolableValue> value, size_t position)
+ {
+ m_values.get()[position] = value;
+ }
+
+private:
+ InterpolableList(size_t size)
+ : m_size(size)
+ {
+ m_values = adoptArrayPtr(new OwnPtr<InterpolableValue>[size]);
+ }
+
+ InterpolableList(InterpolableList& other)
+ : m_size(other.m_size)
+ {
+ m_values = adoptArrayPtr(new OwnPtr<InterpolableValue>[m_size]);
+ for (size_t i = 0; i < m_size; i++)
+ set(other.m_values.get()[i]->clone(), i);
+ }
+
+ size_t m_size;
+ OwnPtr<OwnPtr<InterpolableValue>[]> m_values;
+};
+
+// TODO: Kill this until it is dead.
+class InterpolableAnimatableValue : public InterpolableValue
+{
+public:
+ static PassOwnPtr<InterpolableAnimatableValue> create(PassRefPtr<AnimatableValue> value)
+ {
+ return adoptPtr(new InterpolableAnimatableValue(value));
+ }
+
+ virtual PassOwnPtr<InterpolableValue> interpolate(InterpolableValue &other, double percentage)
+ {
+ InterpolableAnimatableValue *otherValue = static_cast<InterpolableAnimatableValue *>(&other);
+ if (!percentage)
+ return create(m_value);
+ if (percentage == 1)
+ return create(otherValue->m_value);
+ return create(AnimatableValue::interpolate(m_value.get(), otherValue->m_value.get(), percentage));
+ }
+
+ AnimatableValue* value() { return m_value.get(); }
+
+ virtual PassOwnPtr<InterpolableValue> clone()
+ {
+ return create(m_value);
+ }
+
+private:
+ InterpolableAnimatableValue(PassRefPtr<AnimatableValue> value)
+ : m_value(value)
+ { }
+
+ RefPtr<AnimatableValue> m_value;
+};
+
+}
+
+#endif
« no previous file with comments | « Source/core/animation/InertAnimation.cpp ('k') | Source/core/animation/Interpolation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698