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

Side by Side 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, 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 unified diff | Download patch
« no previous file with comments | « Source/core/animation/InertAnimation.cpp ('k') | Source/core/animation/Interpolation.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef InterpolableValue_h
32 #define InterpolableValue_h
33
34 #include "wtf/OwnPtr.h"
35 #include "core/animation/AnimatableValue.h"
36
37 namespace WebCore {
38
39 class InterpolableValue {
40 public:
41 virtual PassOwnPtr<InterpolableValue> interpolate(InterpolableValue &other, double percentage) = 0;
42 virtual PassOwnPtr<InterpolableValue> clone() = 0;
43
44 virtual ~InterpolableValue() { }
45 };
46
47 class InterpolableNumber : public InterpolableValue {
48 public:
49 static PassOwnPtr<InterpolableNumber> create(double value)
50 {
51 return adoptPtr(new InterpolableNumber(value));
52 }
53
54 virtual PassOwnPtr<InterpolableValue> interpolate(InterpolableValue &other, double percentage)
55 {
56 InterpolableNumber *otherNumber = static_cast<InterpolableNumber *>(&oth er);
57 if (!percentage)
58 return create(m_value);
59 if (percentage == 1)
60 return create(otherNumber->m_value);
61 return create(m_value * (1 - percentage) + otherNumber->m_value * percen tage);
62 }
63
64 virtual PassOwnPtr<InterpolableValue> clone()
65 {
66 return create(m_value);
67 }
68
69 double value() { return m_value; }
70
71 private:
72 double m_value;
73
74 InterpolableNumber(double value)
75 : m_value(value)
76 { }
77
78 };
79
80 class InterpolableBool : public InterpolableValue {
81 public:
82 PassOwnPtr<InterpolableBool> create(bool value)
83 {
84 return adoptPtr(new InterpolableBool(value));
85 }
86
87 virtual PassOwnPtr<InterpolableValue> interpolate(InterpolableValue &other, double percentage)
88 {
89 if (percentage < 0.5) {
90 return clone();
91 }
92 return (other.clone());
93 }
94
95 virtual PassOwnPtr<InterpolableValue> clone()
96 {
97 return create(m_value);
98 }
99
100 bool value() { return m_value; }
101
102 private:
103 bool m_value;
104
105 InterpolableBool(bool value)
106 : m_value(value)
107 { }
108 };
109
110 class InterpolableList : public InterpolableValue {
111 public:
112 static PassOwnPtr<InterpolableList> create(InterpolableList &other)
113 {
114 return adoptPtr(new InterpolableList(other));
115 }
116
117 static PassOwnPtr<InterpolableList> create(size_t size)
118 {
119 return adoptPtr(new InterpolableList(size));
120 }
121
122 virtual PassOwnPtr<InterpolableValue> interpolate(InterpolableValue &other, double percentage)
123 {
124 InterpolableList *otherList = static_cast<InterpolableList *>(&other);
125 if (!percentage)
126 return create(*this);
127 if (percentage == 1)
128 return InterpolableList::create(*otherList);
129
130 OwnPtr<InterpolableList> result = create(m_size);
131 for (size_t i = 0; i < m_size; i++)
132 result->set(m_values.get()[i]->interpolate(*(otherList->m_values.get ()[i]), percentage), i);
133 return result.release();
134 }
135
136 virtual PassOwnPtr<InterpolableValue> clone()
137 {
138 return create(*this);
139 }
140
141 void set(PassOwnPtr<InterpolableValue> value, size_t position)
142 {
143 m_values.get()[position] = value;
144 }
145
146 private:
147 InterpolableList(size_t size)
148 : m_size(size)
149 {
150 m_values = adoptArrayPtr(new OwnPtr<InterpolableValue>[size]);
151 }
152
153 InterpolableList(InterpolableList& other)
154 : m_size(other.m_size)
155 {
156 m_values = adoptArrayPtr(new OwnPtr<InterpolableValue>[m_size]);
157 for (size_t i = 0; i < m_size; i++)
158 set(other.m_values.get()[i]->clone(), i);
159 }
160
161 size_t m_size;
162 OwnPtr<OwnPtr<InterpolableValue>[]> m_values;
163 };
164
165 // TODO: Kill this until it is dead.
166 class InterpolableAnimatableValue : public InterpolableValue
167 {
168 public:
169 static PassOwnPtr<InterpolableAnimatableValue> create(PassRefPtr<AnimatableV alue> value)
170 {
171 return adoptPtr(new InterpolableAnimatableValue(value));
172 }
173
174 virtual PassOwnPtr<InterpolableValue> interpolate(InterpolableValue &other, double percentage)
175 {
176 InterpolableAnimatableValue *otherValue = static_cast<InterpolableAnimat ableValue *>(&other);
177 if (!percentage)
178 return create(m_value);
179 if (percentage == 1)
180 return create(otherValue->m_value);
181 return create(AnimatableValue::interpolate(m_value.get(), otherValue->m_ value.get(), percentage));
182 }
183
184 AnimatableValue* value() { return m_value.get(); }
185
186 virtual PassOwnPtr<InterpolableValue> clone()
187 {
188 return create(m_value);
189 }
190
191 private:
192 InterpolableAnimatableValue(PassRefPtr<AnimatableValue> value)
193 : m_value(value)
194 { }
195
196 RefPtr<AnimatableValue> m_value;
197 };
198
199 }
200
201 #endif
OLDNEW
« 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