| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 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/StdLibExtras.h" | 35 #include "wtf/StdLibExtras.h" |
| 36 #include "wtf/Vector.h" | 36 #include "wtf/Vector.h" |
| 37 #include "wtf/text/StringBuilder.h" |
| 38 #include "wtf/text/WTFString.h" |
| 37 #include <algorithm> | 39 #include <algorithm> |
| 38 | 40 |
| 39 | 41 |
| 40 namespace WebCore { | 42 namespace WebCore { |
| 41 | 43 |
| 42 class TimingFunction : public RefCounted<TimingFunction> { | 44 class PLATFORM_EXPORT TimingFunction : public RefCounted<TimingFunction> { |
| 43 public: | 45 public: |
| 44 | 46 |
| 45 enum Type { | 47 enum Type { |
| 46 LinearFunction, CubicBezierFunction, StepsFunction, ChainedFunction | 48 LinearFunction, CubicBezierFunction, StepsFunction, ChainedFunction |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 virtual ~TimingFunction() { } | 51 virtual ~TimingFunction() { } |
| 50 | 52 |
| 51 Type type() const { return m_type; } | 53 Type type() const { return m_type; } |
| 52 | 54 |
| 55 virtual String toString() const = 0; |
| 56 |
| 53 // Evaluates the timing function at the given fraction. The accuracy paramet
er provides a hint as to the required | 57 // 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. | 58 // accuracy and is not guaranteed. |
| 55 virtual double evaluate(double fraction, double accuracy) const = 0; | 59 virtual double evaluate(double fraction, double accuracy) const =0; |
| 56 | 60 |
| 57 protected: | 61 protected: |
| 58 TimingFunction(Type type) | 62 TimingFunction(Type type) |
| 59 : m_type(type) | 63 : m_type(type) |
| 60 { | 64 { |
| 61 } | 65 } |
| 62 | 66 |
| 63 private: | 67 private: |
| 64 Type m_type; | 68 Type m_type; |
| 65 }; | 69 }; |
| 66 | 70 |
| 67 class LinearTimingFunction FINAL : public TimingFunction { | 71 class PLATFORM_EXPORT LinearTimingFunction FINAL : public TimingFunction { |
| 68 public: | 72 public: |
| 69 static PassRefPtr<LinearTimingFunction> create() | 73 static PassRefPtr<LinearTimingFunction> create() |
| 70 { | 74 { |
| 71 return adoptRef(new LinearTimingFunction); | 75 return adoptRef(new LinearTimingFunction); |
| 72 } | 76 } |
| 73 | 77 |
| 74 virtual ~LinearTimingFunction() { } | 78 virtual ~LinearTimingFunction() { } |
| 75 | 79 |
| 76 virtual double evaluate(double fraction, double) const OVERRIDE | 80 virtual String toString() const OVERRIDE; |
| 77 { | 81 |
| 78 ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animations not
yet implemented: Timing function behavior outside the range [0, 1] is not yet sp
ecified"); | 82 virtual double evaluate(double fraction, double) const OVERRIDE; |
| 79 return fraction; | |
| 80 } | |
| 81 | 83 |
| 82 private: | 84 private: |
| 83 LinearTimingFunction() | 85 LinearTimingFunction() |
| 84 : TimingFunction(LinearFunction) | 86 : TimingFunction(LinearFunction) |
| 85 { | 87 { |
| 86 } | 88 } |
| 87 }; | 89 }; |
| 88 | 90 |
| 89 | |
| 90 // Forward declare so we can friend it below. Don't use in production code! | 91 // Forward declare so we can friend it below. Don't use in production code! |
| 91 class ChainedTimingFunctionTestHelper; | 92 class ChainedTimingFunctionTestHelper; |
| 92 | 93 |
| 93 class CubicBezierTimingFunction FINAL : public TimingFunction { | 94 class PLATFORM_EXPORT CubicBezierTimingFunction FINAL : public TimingFunction { |
| 94 public: | 95 public: |
| 95 enum SubType { | 96 enum SubType { |
| 96 Ease, | 97 Ease, |
| 97 EaseIn, | 98 EaseIn, |
| 98 EaseOut, | 99 EaseOut, |
| 99 EaseInOut, | 100 EaseInOut, |
| 100 Custom | 101 Custom |
| 101 }; | 102 }; |
| 102 | 103 |
| 103 static PassRefPtr<CubicBezierTimingFunction> create(double x1, double y1, do
uble x2, double y2) | 104 static PassRefPtr<CubicBezierTimingFunction> create(double x1, double y1, do
uble x2, double y2) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 129 return easeInOut; | 130 return easeInOut; |
| 130 } | 131 } |
| 131 default: | 132 default: |
| 132 ASSERT_NOT_REACHED(); | 133 ASSERT_NOT_REACHED(); |
| 133 return 0; | 134 return 0; |
| 134 } | 135 } |
| 135 } | 136 } |
| 136 | 137 |
| 137 virtual ~CubicBezierTimingFunction() { } | 138 virtual ~CubicBezierTimingFunction() { } |
| 138 | 139 |
| 139 virtual double evaluate(double fraction, double accuracy) const OVERRIDE | 140 virtual String toString() const OVERRIDE; |
| 140 { | 141 |
| 141 ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animations not
yet implemented: Timing function behavior outside the range [0, 1] is not yet sp
ecified"); | 142 virtual double evaluate(double fraction, double accuracy) const OVERRIDE; |
| 142 if (!m_bezier) | |
| 143 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); | |
| 144 return m_bezier->solve(fraction, accuracy); | |
| 145 } | |
| 146 | 143 |
| 147 double x1() const { return m_x1; } | 144 double x1() const { return m_x1; } |
| 148 double y1() const { return m_y1; } | 145 double y1() const { return m_y1; } |
| 149 double x2() const { return m_x2; } | 146 double x2() const { return m_x2; } |
| 150 double y2() const { return m_y2; } | 147 double y2() const { return m_y2; } |
| 151 | 148 |
| 152 SubType subType() const { return m_subType; } | 149 SubType subType() const { return m_subType; } |
| 153 | 150 |
| 154 private: | 151 private: |
| 155 explicit CubicBezierTimingFunction(SubType subType, double x1, double y1, do
uble x2, double y2) | 152 explicit CubicBezierTimingFunction(SubType subType, double x1, double y1, do
uble x2, double y2) |
| 156 : TimingFunction(CubicBezierFunction) | 153 : TimingFunction(CubicBezierFunction) |
| 157 , m_x1(x1) | 154 , m_x1(x1) |
| 158 , m_y1(y1) | 155 , m_y1(y1) |
| 159 , m_x2(x2) | 156 , m_x2(x2) |
| 160 , m_y2(y2) | 157 , m_y2(y2) |
| 161 , m_subType(subType) | 158 , m_subType(subType) |
| 162 { | 159 { |
| 163 } | 160 } |
| 164 | 161 |
| 165 double m_x1; | 162 double m_x1; |
| 166 double m_y1; | 163 double m_y1; |
| 167 double m_x2; | 164 double m_x2; |
| 168 double m_y2; | 165 double m_y2; |
| 169 SubType m_subType; | 166 SubType m_subType; |
| 170 mutable OwnPtr<UnitBezier> m_bezier; | 167 mutable OwnPtr<UnitBezier> m_bezier; |
| 171 }; | 168 }; |
| 172 | 169 |
| 173 class StepsTimingFunction FINAL : public TimingFunction { | 170 class PLATFORM_EXPORT StepsTimingFunction FINAL : public TimingFunction { |
| 174 public: | 171 public: |
| 175 enum SubType { | 172 enum SubType { |
| 176 Start, | 173 Start, |
| 177 End, | 174 End, |
| 178 Custom | 175 Custom |
| 179 }; | 176 }; |
| 180 | 177 |
| 181 static PassRefPtr<StepsTimingFunction> create(int steps, bool stepAtStart) | 178 static PassRefPtr<StepsTimingFunction> create(int steps, bool stepAtStart) |
| 182 { | 179 { |
| 183 return adoptRef(new StepsTimingFunction(Custom, steps, stepAtStart)); | 180 return adoptRef(new StepsTimingFunction(Custom, steps, stepAtStart)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 198 } | 195 } |
| 199 default: | 196 default: |
| 200 ASSERT_NOT_REACHED(); | 197 ASSERT_NOT_REACHED(); |
| 201 return 0; | 198 return 0; |
| 202 } | 199 } |
| 203 } | 200 } |
| 204 | 201 |
| 205 | 202 |
| 206 virtual ~StepsTimingFunction() { } | 203 virtual ~StepsTimingFunction() { } |
| 207 | 204 |
| 208 virtual double evaluate(double fraction, double) const OVERRIDE | 205 virtual String toString() const OVERRIDE; |
| 209 { | 206 |
| 210 ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animations not
yet implemented: Timing function behavior outside the range [0, 1] is not yet sp
ecified"); | 207 virtual double evaluate(double fraction, double) const OVERRIDE; |
| 211 return std::min(1.0, (floor(m_steps * fraction) + m_stepAtStart) / m_ste
ps); | |
| 212 } | |
| 213 | 208 |
| 214 int numberOfSteps() const { return m_steps; } | 209 int numberOfSteps() const { return m_steps; } |
| 215 bool stepAtStart() const { return m_stepAtStart; } | 210 bool stepAtStart() const { return m_stepAtStart; } |
| 216 | 211 |
| 217 SubType subType() const { return m_subType; } | 212 SubType subType() const { return m_subType; } |
| 218 | 213 |
| 219 private: | 214 private: |
| 220 StepsTimingFunction(SubType subType, int steps, bool stepAtStart) | 215 StepsTimingFunction(SubType subType, int steps, bool stepAtStart) |
| 221 : TimingFunction(StepsFunction) | 216 : TimingFunction(StepsFunction) |
| 222 , m_steps(steps) | 217 , m_steps(steps) |
| 223 , m_stepAtStart(stepAtStart) | 218 , m_stepAtStart(stepAtStart) |
| 224 , m_subType(subType) | 219 , m_subType(subType) |
| 225 { | 220 { |
| 226 } | 221 } |
| 227 | 222 |
| 228 int m_steps; | 223 int m_steps; |
| 229 bool m_stepAtStart; | 224 bool m_stepAtStart; |
| 230 SubType m_subType; | 225 SubType m_subType; |
| 231 }; | 226 }; |
| 232 | 227 |
| 233 class ChainedTimingFunction FINAL : public TimingFunction { | 228 class PLATFORM_EXPORT ChainedTimingFunction FINAL : public TimingFunction { |
| 234 public: | 229 public: |
| 235 static PassRefPtr<ChainedTimingFunction> create() | 230 static PassRefPtr<ChainedTimingFunction> create() |
| 236 { | 231 { |
| 237 return adoptRef(new ChainedTimingFunction); | 232 return adoptRef(new ChainedTimingFunction); |
| 238 } | 233 } |
| 239 | 234 |
| 240 void appendSegment(double upperBound, TimingFunction* timingFunction) | 235 void appendSegment(double upperBound, TimingFunction* timingFunction) |
| 241 { | 236 { |
| 242 double max = m_segments.isEmpty() ? 0 : m_segments.last().max(); | 237 double max = m_segments.isEmpty() ? 0 : m_segments.last().max(); |
| 243 ASSERT(upperBound > max); | 238 ASSERT(upperBound > max); |
| 244 m_segments.append(Segment(max, upperBound, timingFunction)); | 239 m_segments.append(Segment(max, upperBound, timingFunction)); |
| 245 } | 240 } |
| 246 virtual double evaluate(double fraction, double accuracy) const OVERRIDE | 241 |
| 247 { | 242 virtual String toString() const OVERRIDE; |
| 248 ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animations not
yet implemented: Timing function behavior outside the range [0, 1] is not yet sp
ecified"); | 243 |
| 249 ASSERT(!m_segments.isEmpty()); | 244 virtual double evaluate(double fraction, double accuracy) const OVERRIDE; |
| 250 ASSERT(m_segments.last().max() == 1); | |
| 251 size_t i = 0; | |
| 252 const Segment* segment = &m_segments[i++]; | |
| 253 while (fraction >= segment->max() && i < m_segments.size()) { | |
| 254 segment = &m_segments[i++]; | |
| 255 } | |
| 256 return segment->evaluate(fraction, accuracy); | |
| 257 } | |
| 258 | 245 |
| 259 private: | 246 private: |
| 260 class Segment { | 247 class Segment { |
| 261 public: | 248 public: |
| 262 Segment(double min, double max, TimingFunction* timingFunction) | 249 Segment(double min, double max, TimingFunction* timingFunction) |
| 263 : m_min(min) | 250 : m_min(min) |
| 264 , m_max(max) | 251 , m_max(max) |
| 265 , m_timingFunction(timingFunction) | 252 , m_timingFunction(timingFunction) |
| 266 { ASSERT(timingFunction); } | 253 { ASSERT(timingFunction); } |
| 267 | 254 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 282 // FIXME: Come up with a public API for the segments and remove this. | 269 // FIXME: Come up with a public API for the segments and remove this. |
| 283 friend class CompositorAnimationsImpl; | 270 friend class CompositorAnimationsImpl; |
| 284 friend class CompositorAnimations; | 271 friend class CompositorAnimations; |
| 285 | 272 |
| 286 // Allow the compositor to reverse the timing function. | 273 // Allow the compositor to reverse the timing function. |
| 287 friend class CompositorAnimationsTimingFunctionReverser; | 274 friend class CompositorAnimationsTimingFunctionReverser; |
| 288 | 275 |
| 289 // Allow PrintTo/operator== of the segments. Can be removed once | 276 // Allow PrintTo/operator== of the segments. Can be removed once |
| 290 // ChainedTimingFunction has a public API for segments. | 277 // ChainedTimingFunction has a public API for segments. |
| 291 friend class ChainedTimingFunctionTestHelper; | 278 friend class ChainedTimingFunctionTestHelper; |
| 279 friend class ChainedTimingFunction; |
| 292 }; | 280 }; |
| 293 | 281 |
| 294 ChainedTimingFunction() | 282 ChainedTimingFunction() |
| 295 : TimingFunction(ChainedFunction) | 283 : TimingFunction(ChainedFunction) |
| 296 { | 284 { |
| 297 } | 285 } |
| 298 | 286 |
| 299 Vector<Segment> m_segments; | 287 Vector<Segment> m_segments; |
| 300 | 288 |
| 301 // FIXME: Come up with a public API for the segments and remove this. | 289 // FIXME: Come up with a public API for the segments and remove this. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 317 value.type() == TimingFunction::typeName##Function) | 305 value.type() == TimingFunction::typeName##Function) |
| 318 | 306 |
| 319 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Linear); | 307 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Linear); |
| 320 DEFINE_TIMING_FUNCTION_TYPE_CASTS(CubicBezier); | 308 DEFINE_TIMING_FUNCTION_TYPE_CASTS(CubicBezier); |
| 321 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Steps); | 309 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Steps); |
| 322 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Chained); | 310 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Chained); |
| 323 | 311 |
| 324 } // namespace WebCore | 312 } // namespace WebCore |
| 325 | 313 |
| 326 #endif // TimingFunction_h | 314 #endif // TimingFunction_h |
| OLD | NEW |