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

Unified Diff: Source/core/animation/Interpolation.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/InterpolableValue.h ('k') | Source/core/animation/InterpolationEffect.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/animation/Interpolation.h
diff --git a/Source/core/animation/Interpolation.h b/Source/core/animation/Interpolation.h
new file mode 100644
index 0000000000000000000000000000000000000000..71db218e72bc1a4add9f080ce3487b139bb7582b
--- /dev/null
+++ b/Source/core/animation/Interpolation.h
@@ -0,0 +1,116 @@
+/*
+ * 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 Interpolation_h
+#define Interpolation_h
+
+#include "core/animation/InterpolableValue.h"
+#include "wtf/RefCounted.h"
+
+namespace WebCore {
+
+class StyleResolverState;
+
+class Interpolation : public RefCounted<Interpolation> {
+public:
+ static PassRefPtr<Interpolation> create(PassOwnPtr<InterpolableValue> start, PassOwnPtr<InterpolableValue> end)
+ {
+ return adoptRef(new Interpolation(start, end));
+ }
+
+ void interpolate(int iteration, double fraction) const
+ {
+ if (m_cachedFraction != fraction || m_cachedIteration != iteration)
+ {
+ m_cachedValue = m_start->interpolate(*m_end, fraction);
+ m_cachedIteration = iteration;
+ m_cachedFraction = fraction;
+ }
+ }
+
+protected:
+ const OwnPtr<InterpolableValue> m_start;
+ const OwnPtr<InterpolableValue> m_end;
+
+ mutable double m_cachedFraction;
+ mutable int m_cachedIteration;
+ mutable OwnPtr<InterpolableValue> m_cachedValue;
+
+ Interpolation(PassOwnPtr<InterpolableValue> start, PassOwnPtr<InterpolableValue> end)
+ : m_start(start)
+ , m_end(end)
+ , m_cachedFraction(0)
+ , m_cachedValue(m_start->clone())
+ { }
+};
+
+class StyleInterpolation : public Interpolation {
+public:
+ // 1) convert m_cachedValue into an X
+ // 2) shove X into StyleResolverState
+ // X can be:
+ // (1) a CSSValue (and applied via StyleBuilder::applyProperty)
+ // (2) an AnimatableValue (and applied via // AnimatedStyleBuilder::applyProperty)
+ // (3) a custom value that is inserted directly into the StyleResolverState.
+ virtual void apply(StyleResolverState& state) const = 0;
+
+ CSSPropertyID id() const { return m_id; }
+
+protected:
+ CSSPropertyID m_id;
+
+ StyleInterpolation(PassOwnPtr<InterpolableValue> start, PassOwnPtr<InterpolableValue> end, CSSPropertyID id)
+ : Interpolation(start, end)
+ , m_id(id)
+ { }
+};
+
+class LegacyStyleInterpolation : public StyleInterpolation {
+public:
+ static PassRefPtr<LegacyStyleInterpolation> create(PassRefPtr<AnimatableValue> start, PassRefPtr<AnimatableValue> end, CSSPropertyID id)
+ {
+ return adoptRef(new LegacyStyleInterpolation(InterpolableAnimatableValue::create(start), InterpolableAnimatableValue::create(end), id));
+ }
+
+ virtual void apply(StyleResolverState& state) const;
+
+ AnimatableValue* currentValue() const {
+ InterpolableAnimatableValue *value = static_cast<InterpolableAnimatableValue *>(m_cachedValue.get());
+ return value->value();
+ }
+
+private:
+ LegacyStyleInterpolation(PassOwnPtr<InterpolableValue> start, PassOwnPtr<InterpolableValue> end, CSSPropertyID id)
+ : StyleInterpolation(start, end, id)
+ { }
+};
+
+}
+#endif
« no previous file with comments | « Source/core/animation/InterpolableValue.h ('k') | Source/core/animation/InterpolationEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698