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 20 matching lines...) Expand all Loading... |
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/StdLibExtras.h" | 35 #include "wtf/StdLibExtras.h" |
36 #include "wtf/Vector.h" | 36 #include "wtf/Vector.h" |
37 #include "wtf/text/StringBuilder.h" | 37 #include "wtf/text/StringBuilder.h" |
38 #include "wtf/text/WTFString.h" | 38 #include "wtf/text/WTFString.h" |
39 #include <algorithm> | 39 #include <algorithm> |
40 | 40 |
41 | |
42 namespace WebCore { | 41 namespace WebCore { |
43 | 42 |
44 class PLATFORM_EXPORT TimingFunction : public RefCounted<TimingFunction> { | 43 class PLATFORM_EXPORT TimingFunction : public RefCounted<TimingFunction> { |
45 public: | 44 public: |
46 | 45 |
47 enum Type { | 46 enum Type { |
48 LinearFunction, CubicBezierFunction, StepsFunction, ChainedFunction | 47 LinearFunction, CubicBezierFunction, StepsFunction, ChainedFunction |
49 }; | 48 }; |
50 | 49 |
51 virtual ~TimingFunction() { } | 50 virtual ~TimingFunction() { } |
52 | 51 |
53 Type type() const { return m_type; } | 52 Type type() const { return m_type; } |
54 | 53 |
55 virtual String toString() const = 0; | 54 virtual String toString() const = 0; |
56 | 55 |
57 // Evaluates the timing function at the given fraction. The accuracy paramet
er provides a hint as to the required | 56 // Evaluates the timing function at the given fraction. The accuracy paramet
er provides a hint as to the required |
58 // accuracy and is not guaranteed. | 57 // accuracy and is not guaranteed. |
59 virtual double evaluate(double fraction, double accuracy) const =0; | 58 virtual double evaluate(double fraction, double accuracy) const = 0; |
60 | 59 |
61 protected: | 60 protected: |
62 TimingFunction(Type type) | 61 TimingFunction(Type type) |
63 : m_type(type) | 62 : m_type(type) |
64 { | 63 { |
65 } | 64 } |
66 | 65 |
67 private: | 66 private: |
68 Type m_type; | 67 Type m_type; |
69 }; | 68 }; |
(...skipping 11 matching lines...) Expand all Loading... |
81 | 80 |
82 virtual double evaluate(double fraction, double) const OVERRIDE; | 81 virtual double evaluate(double fraction, double) const OVERRIDE; |
83 | 82 |
84 private: | 83 private: |
85 LinearTimingFunction() | 84 LinearTimingFunction() |
86 : TimingFunction(LinearFunction) | 85 : TimingFunction(LinearFunction) |
87 { | 86 { |
88 } | 87 } |
89 }; | 88 }; |
90 | 89 |
91 // Forward declare so we can friend it below. Don't use in production code! | |
92 class ChainedTimingFunctionTestHelper; | |
93 | |
94 class PLATFORM_EXPORT CubicBezierTimingFunction FINAL : public TimingFunction { | 90 class PLATFORM_EXPORT CubicBezierTimingFunction FINAL : public TimingFunction { |
95 public: | 91 public: |
96 enum SubType { | 92 enum SubType { |
97 Ease, | 93 Ease, |
98 EaseIn, | 94 EaseIn, |
99 EaseOut, | 95 EaseOut, |
100 EaseInOut, | 96 EaseInOut, |
101 Custom | 97 Custom |
102 }; | 98 }; |
103 | 99 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 double m_y2; | 161 double m_y2; |
166 SubType m_subType; | 162 SubType m_subType; |
167 mutable OwnPtr<UnitBezier> m_bezier; | 163 mutable OwnPtr<UnitBezier> m_bezier; |
168 }; | 164 }; |
169 | 165 |
170 class PLATFORM_EXPORT StepsTimingFunction FINAL : public TimingFunction { | 166 class PLATFORM_EXPORT StepsTimingFunction FINAL : public TimingFunction { |
171 public: | 167 public: |
172 enum SubType { | 168 enum SubType { |
173 Start, | 169 Start, |
174 End, | 170 End, |
| 171 Middle, |
175 Custom | 172 Custom |
176 }; | 173 }; |
177 | 174 |
178 static PassRefPtr<StepsTimingFunction> create(int steps, bool stepAtStart) | 175 enum StepAtPosition { |
| 176 StepAtStart, |
| 177 StepAtMiddle, |
| 178 StepAtEnd |
| 179 }; |
| 180 |
| 181 static PassRefPtr<StepsTimingFunction> create(int steps, StepAtPosition step
AtPosition) |
179 { | 182 { |
180 return adoptRef(new StepsTimingFunction(Custom, steps, stepAtStart)); | 183 return adoptRef(new StepsTimingFunction(Custom, steps, stepAtPosition)); |
181 } | 184 } |
182 | 185 |
183 static StepsTimingFunction* preset(SubType subType) | 186 static StepsTimingFunction* preset(SubType subType) |
184 { | 187 { |
185 switch (subType) { | 188 switch (subType) { |
186 case Start: | 189 case Start: |
187 { | 190 { |
188 DEFINE_STATIC_REF(StepsTimingFunction, start, (adoptRef(new Step
sTimingFunction(Start, 1, true)))); | 191 DEFINE_STATIC_REF(StepsTimingFunction, start, (adoptRef(new Step
sTimingFunction(Start, 1, StepAtStart)))); |
189 return start; | 192 return start; |
190 } | 193 } |
| 194 case Middle: |
| 195 { |
| 196 DEFINE_STATIC_REF(StepsTimingFunction, middle, (adoptRef(new Ste
psTimingFunction(Middle, 1, StepAtMiddle)))); |
| 197 return middle; |
| 198 } |
191 case End: | 199 case End: |
192 { | 200 { |
193 DEFINE_STATIC_REF(StepsTimingFunction, end, (adoptRef(new StepsT
imingFunction(End, 1, false)))); | 201 DEFINE_STATIC_REF(StepsTimingFunction, end, (adoptRef(new StepsT
imingFunction(End, 1, StepAtEnd)))); |
194 return end; | 202 return end; |
195 } | 203 } |
196 default: | 204 default: |
197 ASSERT_NOT_REACHED(); | 205 ASSERT_NOT_REACHED(); |
198 return 0; | 206 return 0; |
199 } | 207 } |
200 } | 208 } |
201 | 209 |
202 | 210 |
203 virtual ~StepsTimingFunction() { } | 211 virtual ~StepsTimingFunction() { } |
204 | 212 |
205 virtual String toString() const OVERRIDE; | 213 virtual String toString() const OVERRIDE; |
206 | 214 |
207 virtual double evaluate(double fraction, double) const OVERRIDE; | 215 virtual double evaluate(double fraction, double) const OVERRIDE; |
208 | 216 |
209 int numberOfSteps() const { return m_steps; } | 217 int numberOfSteps() const { return m_steps; } |
210 bool stepAtStart() const { return m_stepAtStart; } | 218 StepAtPosition stepAtPosition() const { return m_stepAtPosition; } |
211 | 219 |
212 SubType subType() const { return m_subType; } | 220 SubType subType() const { return m_subType; } |
213 | 221 |
214 private: | 222 private: |
215 StepsTimingFunction(SubType subType, int steps, bool stepAtStart) | 223 StepsTimingFunction(SubType subType, int steps, StepAtPosition stepAtPositio
n) |
216 : TimingFunction(StepsFunction) | 224 : TimingFunction(StepsFunction) |
217 , m_steps(steps) | 225 , m_steps(steps) |
218 , m_stepAtStart(stepAtStart) | 226 , m_stepAtPosition(stepAtPosition) |
219 , m_subType(subType) | 227 , m_subType(subType) |
220 { | 228 { |
221 } | 229 } |
222 | 230 |
223 int m_steps; | 231 int m_steps; |
224 bool m_stepAtStart; | 232 StepAtPosition m_stepAtPosition; |
225 SubType m_subType; | 233 SubType m_subType; |
226 }; | 234 }; |
227 | 235 |
228 class PLATFORM_EXPORT ChainedTimingFunction FINAL : public TimingFunction { | 236 class PLATFORM_EXPORT ChainedTimingFunction FINAL : public TimingFunction { |
229 public: | 237 public: |
230 static PassRefPtr<ChainedTimingFunction> create() | 238 static PassRefPtr<ChainedTimingFunction> create() |
231 { | 239 { |
232 return adoptRef(new ChainedTimingFunction); | 240 return adoptRef(new ChainedTimingFunction); |
233 } | 241 } |
234 | 242 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 276 |
269 // FIXME: Come up with a public API for the segments and remove this. | 277 // FIXME: Come up with a public API for the segments and remove this. |
270 friend class CompositorAnimationsImpl; | 278 friend class CompositorAnimationsImpl; |
271 friend class CompositorAnimations; | 279 friend class CompositorAnimations; |
272 | 280 |
273 // Allow the compositor to reverse the timing function. | 281 // Allow the compositor to reverse the timing function. |
274 friend class CompositorAnimationsTimingFunctionReverser; | 282 friend class CompositorAnimationsTimingFunctionReverser; |
275 | 283 |
276 // Allow PrintTo/operator== of the segments. Can be removed once | 284 // Allow PrintTo/operator== of the segments. Can be removed once |
277 // ChainedTimingFunction has a public API for segments. | 285 // ChainedTimingFunction has a public API for segments. |
278 friend class ChainedTimingFunctionTestHelper; | |
279 friend class ChainedTimingFunction; | 286 friend class ChainedTimingFunction; |
280 }; | 287 }; |
281 | 288 |
282 ChainedTimingFunction() | 289 ChainedTimingFunction() |
283 : TimingFunction(ChainedFunction) | 290 : TimingFunction(ChainedFunction) |
284 { | 291 { |
285 } | 292 } |
286 | 293 |
287 Vector<Segment> m_segments; | 294 Vector<Segment> m_segments; |
288 | 295 |
289 // FIXME: Come up with a public API for the segments and remove this. | 296 // FIXME: Come up with a public API for the segments and remove this. |
290 friend class CompositorAnimationsImpl; | 297 friend class CompositorAnimationsImpl; |
291 friend class CompositorAnimations; | 298 friend class CompositorAnimations; |
292 | 299 |
293 // Allow the compositor to reverse the timing function. | 300 // Allow the compositor to reverse the timing function. |
294 friend class CompositorAnimationsTimingFunctionReverser; | 301 friend class CompositorAnimationsTimingFunctionReverser; |
295 | 302 |
296 // Allow PrintTo/operator== of the segments. Can be removed once | 303 // Allow PrintTo/operator== of the segments. Can be removed once |
297 // ChainedTimingFunction has a public API for segments. | 304 // ChainedTimingFunction has a public API for segments. |
298 friend class ChainedTimingFunctionTestHelper; | 305 friend class ChainedTimingFunctionTestHelper; |
299 }; | 306 }; |
300 | 307 |
| 308 PLATFORM_EXPORT bool operator==(const LinearTimingFunction&, const TimingFunctio
n&); |
| 309 PLATFORM_EXPORT bool operator==(const CubicBezierTimingFunction&, const TimingFu
nction&); |
| 310 PLATFORM_EXPORT bool operator==(const StepsTimingFunction&, const TimingFunction
&); |
| 311 |
| 312 PLATFORM_EXPORT bool operator==(const TimingFunction&, const TimingFunction&); |
| 313 PLATFORM_EXPORT bool operator!=(const TimingFunction&, const TimingFunction&); |
| 314 |
301 #define DEFINE_TIMING_FUNCTION_TYPE_CASTS(typeName) \ | 315 #define DEFINE_TIMING_FUNCTION_TYPE_CASTS(typeName) \ |
302 DEFINE_TYPE_CASTS( \ | 316 DEFINE_TYPE_CASTS( \ |
303 typeName##TimingFunction, TimingFunction, value, \ | 317 typeName##TimingFunction, TimingFunction, value, \ |
304 value->type() == TimingFunction::typeName##Function, \ | 318 value->type() == TimingFunction::typeName##Function, \ |
305 value.type() == TimingFunction::typeName##Function) | 319 value.type() == TimingFunction::typeName##Function) |
306 | 320 |
307 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Linear); | 321 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Linear); |
308 DEFINE_TIMING_FUNCTION_TYPE_CASTS(CubicBezier); | 322 DEFINE_TIMING_FUNCTION_TYPE_CASTS(CubicBezier); |
309 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Steps); | 323 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Steps); |
310 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Chained); | 324 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Chained); |
311 | 325 |
312 } // namespace WebCore | 326 } // namespace WebCore |
313 | 327 |
314 #endif // TimingFunction_h | 328 #endif // TimingFunction_h |
OLD | NEW |