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 |
11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
12 * | 12 * |
13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 * Library General Public License for more details. | 16 * Library General Public License for more details. |
17 * | 17 * |
18 * You should have received a copy of the GNU Library General Public License | 18 * You should have received a copy of the GNU Library General Public License |
19 * along with this library; see the file COPYING.LIB. If not, write to | 19 * along with this library; see the file COPYING.LIB. If not, write to |
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #ifndef TimingFunction_h | 25 #ifndef TimingFunction_h |
26 #define TimingFunction_h | 26 #define TimingFunction_h |
27 | 27 |
28 #include "RuntimeEnabledFeatures.h" | 28 #include "RuntimeEnabledFeatures.h" |
| 29 #include "platform/PlatformExport.h" |
29 #include "platform/animation/AnimationUtilities.h" // For blend() | 30 #include "platform/animation/AnimationUtilities.h" // For blend() |
30 #include "platform/animation/UnitBezier.h" | 31 #include "platform/animation/UnitBezier.h" |
31 #include "wtf/OwnPtr.h" | 32 #include "wtf/OwnPtr.h" |
32 #include "wtf/PassOwnPtr.h" | 33 #include "wtf/PassOwnPtr.h" |
33 #include "wtf/PassRefPtr.h" | 34 #include "wtf/PassRefPtr.h" |
34 #include "wtf/RefCounted.h" | 35 #include "wtf/RefCounted.h" |
35 #include "wtf/StdLibExtras.h" | 36 #include "wtf/StdLibExtras.h" |
36 #include "wtf/Vector.h" | 37 #include "wtf/Vector.h" |
37 #include <algorithm> | 38 #include <algorithm> |
38 | 39 |
39 | 40 |
40 namespace WebCore { | 41 namespace WebCore { |
41 | 42 |
42 class TimingFunction : public RefCounted<TimingFunction> { | 43 class PLATFORM_EXPORT TimingFunction : public RefCounted<TimingFunction> { |
43 public: | 44 public: |
44 | 45 |
45 enum Type { | 46 enum Type { |
46 LinearFunction, CubicBezierFunction, StepsFunction, ChainedFunction | 47 LinearFunction, CubicBezierFunction, StepsFunction, ChainedFunction |
47 }; | 48 }; |
48 | 49 |
49 virtual ~TimingFunction() { } | 50 virtual ~TimingFunction() { } |
50 | 51 |
51 Type type() const { return m_type; } | 52 Type type() const { return m_type; } |
52 | 53 |
53 // Evaluates the timing function at the given fraction. The accuracy paramet
er provides a hint as to the required | 54 // Evaluates the timing function at the given fraction. The accuracy paramet
er provides a hint as to the required |
54 // accuracy and is not guaranteed. | 55 // accuracy and is not guaranteed. |
55 virtual double evaluate(double fraction, double accuracy) const = 0; | 56 virtual double evaluate(double fraction, double accuracy) const = 0; |
56 | 57 |
57 protected: | 58 protected: |
58 TimingFunction(Type type) | 59 TimingFunction(Type type) |
59 : m_type(type) | 60 : m_type(type) |
60 { | 61 { |
61 } | 62 } |
62 | 63 |
63 private: | 64 private: |
64 Type m_type; | 65 Type m_type; |
65 }; | 66 }; |
66 | 67 |
67 class LinearTimingFunction : public TimingFunction { | 68 class PLATFORM_EXPORT LinearTimingFunction : public TimingFunction { |
68 public: | 69 public: |
69 static PassRefPtr<LinearTimingFunction> create() | 70 static PassRefPtr<LinearTimingFunction> create() |
70 { | 71 { |
71 return adoptRef(new LinearTimingFunction); | 72 return adoptRef(new LinearTimingFunction); |
72 } | 73 } |
73 | 74 |
74 ~LinearTimingFunction() { } | 75 ~LinearTimingFunction() { } |
75 | 76 |
76 virtual double evaluate(double fraction, double) const | 77 virtual double evaluate(double fraction, double) const |
77 { | 78 { |
78 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled() || (fraction >=
0 && fraction <= 1)); | 79 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled() || (fraction >=
0 && fraction <= 1)); |
79 ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsCSSEnabled() |
| (fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Timing
function behavior outside the range [0, 1] is not yet specified"); | 80 ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsCSSEnabled() |
| (fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Timing
function behavior outside the range [0, 1] is not yet specified"); |
80 return fraction; | 81 return fraction; |
81 } | 82 } |
82 | 83 |
83 private: | 84 private: |
84 LinearTimingFunction() | 85 LinearTimingFunction() |
85 : TimingFunction(LinearFunction) | 86 : TimingFunction(LinearFunction) |
86 { | 87 { |
87 } | 88 } |
88 }; | 89 }; |
89 | 90 |
90 | 91 |
91 // Forward declare so we can friend it below. Don't use in production code! | 92 // Forward declare so we can friend it below. Don't use in production code! |
92 class ChainedTimingFunctionTestHelper; | 93 class ChainedTimingFunctionTestHelper; |
93 | 94 |
94 class CubicBezierTimingFunction : public TimingFunction { | 95 class PLATFORM_EXPORT CubicBezierTimingFunction : public TimingFunction { |
95 public: | 96 public: |
96 enum SubType { | 97 enum SubType { |
97 Ease, | 98 Ease, |
98 EaseIn, | 99 EaseIn, |
99 EaseOut, | 100 EaseOut, |
100 EaseInOut, | 101 EaseInOut, |
101 Custom | 102 Custom |
102 }; | 103 }; |
103 | 104 |
104 static PassRefPtr<CubicBezierTimingFunction> create(double x1, double y1, do
uble x2, double y2) | 105 static PassRefPtr<CubicBezierTimingFunction> create(double x1, double y1, do
uble x2, double y2) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 166 } |
166 | 167 |
167 double m_x1; | 168 double m_x1; |
168 double m_y1; | 169 double m_y1; |
169 double m_x2; | 170 double m_x2; |
170 double m_y2; | 171 double m_y2; |
171 SubType m_subType; | 172 SubType m_subType; |
172 mutable OwnPtr<UnitBezier> m_bezier; | 173 mutable OwnPtr<UnitBezier> m_bezier; |
173 }; | 174 }; |
174 | 175 |
175 class StepsTimingFunction : public TimingFunction { | 176 class PLATFORM_EXPORT StepsTimingFunction : public TimingFunction { |
176 public: | 177 public: |
177 enum SubType { | 178 enum SubType { |
178 Start, | 179 Start, |
179 End, | 180 End, |
180 Custom | 181 Custom |
181 }; | 182 }; |
182 | 183 |
183 static PassRefPtr<StepsTimingFunction> create(int steps, bool stepAtStart) | 184 static PassRefPtr<StepsTimingFunction> create(int steps, bool stepAtStart) |
184 { | 185 { |
185 return adoptRef(new StepsTimingFunction(Custom, steps, stepAtStart)); | 186 return adoptRef(new StepsTimingFunction(Custom, steps, stepAtStart)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 , m_stepAtStart(stepAtStart) | 227 , m_stepAtStart(stepAtStart) |
227 , m_subType(subType) | 228 , m_subType(subType) |
228 { | 229 { |
229 } | 230 } |
230 | 231 |
231 int m_steps; | 232 int m_steps; |
232 bool m_stepAtStart; | 233 bool m_stepAtStart; |
233 SubType m_subType; | 234 SubType m_subType; |
234 }; | 235 }; |
235 | 236 |
236 class ChainedTimingFunction : public TimingFunction { | 237 class PLATFORM_EXPORT ChainedTimingFunction : public TimingFunction { |
237 public: | 238 public: |
238 static PassRefPtr<ChainedTimingFunction> create() | 239 static PassRefPtr<ChainedTimingFunction> create() |
239 { | 240 { |
240 return adoptRef(new ChainedTimingFunction); | 241 return adoptRef(new ChainedTimingFunction); |
241 } | 242 } |
242 | 243 |
243 void appendSegment(double upperBound, TimingFunction* timingFunction) | 244 void appendSegment(double upperBound, TimingFunction* timingFunction) |
244 { | 245 { |
245 double max = m_segments.isEmpty() ? 0 : m_segments.last().max(); | 246 double max = m_segments.isEmpty() ? 0 : m_segments.last().max(); |
246 ASSERT(upperBound > max); | 247 ASSERT(upperBound > max); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 value.type() == TimingFunction::typeName##Function) | 322 value.type() == TimingFunction::typeName##Function) |
322 | 323 |
323 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Linear); | 324 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Linear); |
324 DEFINE_TIMING_FUNCTION_TYPE_CASTS(CubicBezier); | 325 DEFINE_TIMING_FUNCTION_TYPE_CASTS(CubicBezier); |
325 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Steps); | 326 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Steps); |
326 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Chained); | 327 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Chained); |
327 | 328 |
328 } // namespace WebCore | 329 } // namespace WebCore |
329 | 330 |
330 #endif // TimingFunction_h | 331 #endif // TimingFunction_h |
OLD | NEW |