OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
3 * (C) 2000 Antti Koivisto (koivisto@kde.org) | 3 * (C) 2000 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2000 Dirk Mueller (mueller@kde.org) | 4 * (C) 2000 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) | 6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "RuntimeEnabledFeatures.h" | 28 #include "RuntimeEnabledFeatures.h" |
29 #include "platform/animation/AnimationUtilities.h" // For blend() | 29 #include "platform/animation/AnimationUtilities.h" // For blend() |
30 #include "platform/animation/UnitBezier.h" | 30 #include "platform/animation/UnitBezier.h" |
31 #include "wtf/OwnPtr.h" | 31 #include "wtf/OwnPtr.h" |
32 #include "wtf/PassOwnPtr.h" | 32 #include "wtf/PassOwnPtr.h" |
33 #include "wtf/PassRefPtr.h" | 33 #include "wtf/PassRefPtr.h" |
34 #include "wtf/RefCounted.h" | 34 #include "wtf/RefCounted.h" |
35 #include "wtf/Vector.h" | 35 #include "wtf/Vector.h" |
36 #include <algorithm> | 36 #include <algorithm> |
37 | 37 |
38 | |
39 namespace WebCore { | 38 namespace WebCore { |
40 | 39 |
41 class TimingFunction : public RefCounted<TimingFunction> { | 40 class TimingFunction : public RefCounted<TimingFunction> { |
42 public: | 41 public: |
43 | 42 |
44 enum Type { | 43 enum Type { |
45 LinearFunction, CubicBezierFunction, StepsFunction, ChainedFunction | 44 LinearFunction, CubicBezierFunction, StepsFunction, ChainedFunction |
46 }; | 45 }; |
47 | 46 |
48 virtual ~TimingFunction() { } | 47 virtual ~TimingFunction() { } |
49 | 48 |
50 Type type() const { return m_type; } | 49 Type type() const { return m_type; } |
51 | 50 |
52 // Evaluates the timing function at the given fraction. The accuracy paramet
er provides a hint as to the required | 51 // Evaluates the timing function at the given fraction. The accuracy paramet
er provides a hint as to the required |
53 // accuracy and is not guaranteed. | 52 // accuracy and is not guaranteed. |
54 virtual double evaluate(double fraction, double accuracy) const = 0; | 53 virtual double evaluate(double fraction, double accuracy) const = 0; |
55 virtual bool operator==(const TimingFunction& other) const = 0; | 54 virtual bool operator==(const TimingFunction& other) const = 0; |
| 55 virtual bool operator!=(const TimingFunction& other) const { return !operato
r==(other); } |
56 | 56 |
57 protected: | 57 protected: |
58 TimingFunction(Type type) | 58 TimingFunction(Type type) |
59 : m_type(type) | 59 : m_type(type) |
60 { | 60 { |
61 } | 61 } |
62 | 62 |
63 private: | 63 private: |
64 Type m_type; | 64 Type m_type; |
65 }; | 65 }; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 { | 146 { |
147 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled() || (fraction >= 0
&& fraction <= 1)); | 147 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled() || (fraction >= 0
&& fraction <= 1)); |
148 RELEASE_ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsEnable
d() || (fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Ti
ming function behavior outside the range [0, 1] is not yet specified"); | 148 RELEASE_ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsEnable
d() || (fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Ti
ming function behavior outside the range [0, 1] is not yet specified"); |
149 if (!m_bezier) | 149 if (!m_bezier) |
150 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); | 150 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); |
151 return m_bezier->solve(fraction, accuracy); | 151 return m_bezier->solve(fraction, accuracy); |
152 } | 152 } |
153 | 153 |
154 virtual bool operator==(const TimingFunction& other) const | 154 virtual bool operator==(const TimingFunction& other) const |
155 { | 155 { |
156 if (other.type() == CubicBezierFunction) { | 156 if (other.type() != CubicBezierFunction) |
157 const CubicBezierTimingFunction* ctf = static_cast<const CubicBezier
TimingFunction*>(&other); | 157 return false; |
158 if (m_subType != Custom) | |
159 return m_subType == ctf->m_subType; | |
160 | 158 |
| 159 const CubicBezierTimingFunction* ctf = static_cast<const CubicBezierTimi
ngFunction*>(&other); |
| 160 if (m_subType == Custom && ctf->m_subType == Custom) |
161 return m_x1 == ctf->m_x1 && m_y1 == ctf->m_y1 && m_x2 == ctf->m_x2 &
& m_y2 == ctf->m_y2; | 161 return m_x1 == ctf->m_x1 && m_y1 == ctf->m_y1 && m_x2 == ctf->m_x2 &
& m_y2 == ctf->m_y2; |
162 } | 162 |
163 return false; | 163 return m_subType == ctf->m_subType; |
164 } | 164 } |
165 | 165 |
166 double x1() const { return m_x1; } | 166 double x1() const { return m_x1; } |
167 double y1() const { return m_y1; } | 167 double y1() const { return m_y1; } |
168 double x2() const { return m_x2; } | 168 double x2() const { return m_x2; } |
169 double y2() const { return m_y2; } | 169 double y2() const { return m_y2; } |
170 | 170 |
171 SubType subType() const { return m_subType; } | 171 SubType subType() const { return m_subType; } |
172 | 172 |
173 private: | 173 private: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 226 |
227 virtual double evaluate(double fraction, double) const | 227 virtual double evaluate(double fraction, double) const |
228 { | 228 { |
229 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled() || (fraction >= 0
&& fraction <= 1)); | 229 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled() || (fraction >= 0
&& fraction <= 1)); |
230 RELEASE_ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsEnable
d() || (fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Ti
ming function behavior outside the range [0, 1] is not yet specified"); | 230 RELEASE_ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsEnable
d() || (fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Ti
ming function behavior outside the range [0, 1] is not yet specified"); |
231 return std::min(1.0, (floor(m_steps * fraction) + m_stepAtStart) / m_ste
ps); | 231 return std::min(1.0, (floor(m_steps * fraction) + m_stepAtStart) / m_ste
ps); |
232 } | 232 } |
233 | 233 |
234 virtual bool operator==(const TimingFunction& other) const | 234 virtual bool operator==(const TimingFunction& other) const |
235 { | 235 { |
236 if (other.type() == StepsFunction) { | 236 if (other.type() != StepsFunction) |
237 const StepsTimingFunction* stf = static_cast<const StepsTimingFuncti
on*>(&other); | 237 return false; |
238 if (m_subType != Custom) | 238 |
239 return m_subType == stf->m_subType; | 239 const StepsTimingFunction* stf = static_cast<const StepsTimingFunction*>
(&other); |
| 240 if (m_subType == Custom && stf->m_subType == Custom) |
240 return m_steps == stf->m_steps && m_stepAtStart == stf->m_stepAtStar
t; | 241 return m_steps == stf->m_steps && m_stepAtStart == stf->m_stepAtStar
t; |
241 } | 242 |
242 return false; | 243 return m_subType == stf->m_subType; |
243 } | 244 } |
244 | 245 |
245 int numberOfSteps() const { return m_steps; } | 246 int numberOfSteps() const { return m_steps; } |
246 bool stepAtStart() const { return m_stepAtStart; } | 247 bool stepAtStart() const { return m_stepAtStart; } |
247 | 248 |
248 SubType subType() const { return m_subType; } | 249 SubType subType() const { return m_subType; } |
249 | 250 |
250 private: | 251 private: |
251 StepsTimingFunction(SubType subType, int steps, bool stepAtStart) | 252 StepsTimingFunction(SubType subType, int steps, bool stepAtStart) |
252 : TimingFunction(StepsFunction) | 253 : TimingFunction(StepsFunction) |
(...skipping 14 matching lines...) Expand all Loading... |
267 { | 268 { |
268 return adoptRef(new ChainedTimingFunction); | 269 return adoptRef(new ChainedTimingFunction); |
269 } | 270 } |
270 | 271 |
271 void appendSegment(double upperBound, TimingFunction* timingFunction) | 272 void appendSegment(double upperBound, TimingFunction* timingFunction) |
272 { | 273 { |
273 double max = m_segments.isEmpty() ? 0 : m_segments.last().max(); | 274 double max = m_segments.isEmpty() ? 0 : m_segments.last().max(); |
274 ASSERT(upperBound > max); | 275 ASSERT(upperBound > max); |
275 m_segments.append(Segment(max, upperBound, timingFunction)); | 276 m_segments.append(Segment(max, upperBound, timingFunction)); |
276 } | 277 } |
| 278 |
277 virtual double evaluate(double fraction, double accuracy) const | 279 virtual double evaluate(double fraction, double accuracy) const |
278 { | 280 { |
279 RELEASE_ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animati
ons not yet implemented: Timing function behavior outside the range [0, 1] is no
t yet specified"); | 281 RELEASE_ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animati
ons not yet implemented: Timing function behavior outside the range [0, 1] is no
t yet specified"); |
280 ASSERT(!m_segments.isEmpty()); | 282 ASSERT(!m_segments.isEmpty()); |
281 ASSERT(m_segments.last().max() == 1); | 283 ASSERT(m_segments.last().max() == 1); |
282 size_t i = 0; | 284 size_t i = 0; |
283 const Segment* segment = &m_segments[i++]; | 285 const Segment* segment = &m_segments[i++]; |
284 while (fraction >= segment->max() && i < m_segments.size()) { | 286 while (fraction >= segment->max() && i < m_segments.size()) { |
285 segment = &m_segments[i++]; | 287 segment = &m_segments[i++]; |
286 } | 288 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 Vector<Segment> m_segments; | 333 Vector<Segment> m_segments; |
332 | 334 |
333 // Allow printing of our segments. Can be removed once | 335 // Allow printing of our segments. Can be removed once |
334 // ChainedTimingFunction has a public API for segments. | 336 // ChainedTimingFunction has a public API for segments. |
335 friend class ChainedTimingFunctionPrintTo; | 337 friend class ChainedTimingFunctionPrintTo; |
336 }; | 338 }; |
337 | 339 |
338 } // namespace WebCore | 340 } // namespace WebCore |
339 | 341 |
340 #endif // TimingFunction_h | 342 #endif // TimingFunction_h |
OLD | NEW |