| 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 24 matching lines...) Expand all Loading... |
| 35 #include "wtf/RefCounted.h" | 35 #include "wtf/RefCounted.h" |
| 36 #include "wtf/StdLibExtras.h" | 36 #include "wtf/StdLibExtras.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 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 class PLATFORM_EXPORT TimingFunction : public RefCounted<TimingFunction> { | 42 class PLATFORM_EXPORT TimingFunction : public RefCounted<TimingFunction> { |
| 43 public: | 43 public: |
| 44 | 44 |
| 45 enum Type { | 45 enum FunctionType { |
| 46 LinearFunction, CubicBezierFunction, StepsFunction | 46 LinearFunction, CubicBezierFunction, StepsFunction |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 virtual ~TimingFunction() { } | 49 virtual ~TimingFunction() { } |
| 50 | 50 |
| 51 Type type() const { return m_type; } | 51 FunctionType type() const { return m_type; } |
| 52 | 52 |
| 53 virtual String toString() const = 0; | 53 virtual String toString() const = 0; |
| 54 | 54 |
| 55 // Evaluates the timing function at the given fraction. The accuracy paramet
er provides a hint as to the required | 55 // Evaluates the timing function at the given fraction. The accuracy paramet
er provides a hint as to the required |
| 56 // accuracy and is not guaranteed. | 56 // accuracy and is not guaranteed. |
| 57 virtual double evaluate(double fraction, double accuracy) const = 0; | 57 virtual double evaluate(double fraction, double accuracy) const = 0; |
| 58 | 58 |
| 59 // This function returns the minimum and maximum values obtainable when | 59 // This function returns the minimum and maximum values obtainable when |
| 60 // calling evaluate(); | 60 // calling evaluate(); |
| 61 virtual void range(double* minValue, double* maxValue) const = 0; | 61 virtual void range(double* minValue, double* maxValue) const = 0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 77 { } | 77 { } |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 // Partitions the timing function into a number of regions, | 80 // Partitions the timing function into a number of regions, |
| 81 // representing the ranges in which the function's value is < 0.5 | 81 // representing the ranges in which the function's value is < 0.5 |
| 82 // and >= 0.5, and hence whether interpolation 0 or 1 should be | 82 // and >= 0.5, and hence whether interpolation 0 or 1 should be |
| 83 // used. | 83 // used. |
| 84 virtual void partition(Vector<PartitionRegion>& regions) const = 0; | 84 virtual void partition(Vector<PartitionRegion>& regions) const = 0; |
| 85 | 85 |
| 86 protected: | 86 protected: |
| 87 TimingFunction(Type type) | 87 TimingFunction(FunctionType type) |
| 88 : m_type(type) | 88 : m_type(type) |
| 89 { | 89 { |
| 90 } | 90 } |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 Type m_type; | 93 FunctionType m_type; |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 class PLATFORM_EXPORT LinearTimingFunction final : public TimingFunction { | 96 class PLATFORM_EXPORT LinearTimingFunction final : public TimingFunction { |
| 97 public: | 97 public: |
| 98 static LinearTimingFunction* shared() | 98 static LinearTimingFunction* shared() |
| 99 { | 99 { |
| 100 DEFINE_STATIC_REF(LinearTimingFunction, linear, (adoptRef(new LinearTimi
ngFunction()))); | 100 DEFINE_STATIC_REF(LinearTimingFunction, linear, (adoptRef(new LinearTimi
ngFunction()))); |
| 101 return linear; | 101 return linear; |
| 102 } | 102 } |
| 103 | 103 |
| 104 ~LinearTimingFunction() override { } | 104 ~LinearTimingFunction() override { } |
| 105 | 105 |
| 106 String toString() const override; | 106 String toString() const override; |
| 107 | 107 |
| 108 double evaluate(double fraction, double) const override; | 108 double evaluate(double fraction, double) const override; |
| 109 void range(double* minValue, double* maxValue) const override; | 109 void range(double* minValue, double* maxValue) const override; |
| 110 void partition(Vector<PartitionRegion>& regions) const override; | 110 void partition(Vector<PartitionRegion>& regions) const override; |
| 111 private: | 111 private: |
| 112 LinearTimingFunction() | 112 LinearTimingFunction() |
| 113 : TimingFunction(LinearFunction) | 113 : TimingFunction(LinearFunction) |
| 114 { | 114 { |
| 115 } | 115 } |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 class PLATFORM_EXPORT CubicBezierTimingFunction final : public TimingFunction { | 118 class PLATFORM_EXPORT CubicBezierTimingFunction final : public TimingFunction { |
| 119 public: | 119 public: |
| 120 enum SubType { | 120 enum FunctionSubType { |
| 121 Ease, | 121 Ease, |
| 122 EaseIn, | 122 EaseIn, |
| 123 EaseOut, | 123 EaseOut, |
| 124 EaseInOut, | 124 EaseInOut, |
| 125 Custom | 125 Custom |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 static PassRefPtr<CubicBezierTimingFunction> create(double x1, double y1, do
uble x2, double y2) | 128 static PassRefPtr<CubicBezierTimingFunction> create(double x1, double y1, do
uble x2, double y2) |
| 129 { | 129 { |
| 130 return adoptRef(new CubicBezierTimingFunction(Custom, x1, y1, x2, y2)); | 130 return adoptRef(new CubicBezierTimingFunction(Custom, x1, y1, x2, y2)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 static CubicBezierTimingFunction* preset(SubType subType) | 133 static CubicBezierTimingFunction* preset(FunctionSubType subType) |
| 134 { | 134 { |
| 135 switch (subType) { | 135 switch (subType) { |
| 136 case Ease: | 136 case Ease: |
| 137 { | 137 { |
| 138 DEFINE_STATIC_REF(CubicBezierTimingFunction, ease, (adoptRef(new
CubicBezierTimingFunction(Ease, 0.25, 0.1, 0.25, 1.0)))); | 138 DEFINE_STATIC_REF(CubicBezierTimingFunction, ease, (adoptRef(new
CubicBezierTimingFunction(Ease, 0.25, 0.1, 0.25, 1.0)))); |
| 139 return ease; | 139 return ease; |
| 140 } | 140 } |
| 141 case EaseIn: | 141 case EaseIn: |
| 142 { | 142 { |
| 143 DEFINE_STATIC_REF(CubicBezierTimingFunction, easeIn, (adoptRef(n
ew CubicBezierTimingFunction(EaseIn, 0.42, 0.0, 1.0, 1.0)))); | 143 DEFINE_STATIC_REF(CubicBezierTimingFunction, easeIn, (adoptRef(n
ew CubicBezierTimingFunction(EaseIn, 0.42, 0.0, 1.0, 1.0)))); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 165 | 165 |
| 166 double evaluate(double fraction, double accuracy) const override; | 166 double evaluate(double fraction, double accuracy) const override; |
| 167 void range(double* minValue, double* maxValue) const override; | 167 void range(double* minValue, double* maxValue) const override; |
| 168 void partition(Vector<PartitionRegion>& regions) const override; | 168 void partition(Vector<PartitionRegion>& regions) const override; |
| 169 | 169 |
| 170 double x1() const { return m_x1; } | 170 double x1() const { return m_x1; } |
| 171 double y1() const { return m_y1; } | 171 double y1() const { return m_y1; } |
| 172 double x2() const { return m_x2; } | 172 double x2() const { return m_x2; } |
| 173 double y2() const { return m_y2; } | 173 double y2() const { return m_y2; } |
| 174 | 174 |
| 175 SubType subType() const { return m_subType; } | 175 FunctionSubType subType() const { return m_subType; } |
| 176 | 176 |
| 177 private: | 177 private: |
| 178 explicit CubicBezierTimingFunction(SubType subType, double x1, double y1, do
uble x2, double y2) | 178 explicit CubicBezierTimingFunction(FunctionSubType subType, double x1, doubl
e y1, double x2, double y2) |
| 179 : TimingFunction(CubicBezierFunction) | 179 : TimingFunction(CubicBezierFunction) |
| 180 , m_x1(x1) | 180 , m_x1(x1) |
| 181 , m_y1(y1) | 181 , m_y1(y1) |
| 182 , m_x2(x2) | 182 , m_x2(x2) |
| 183 , m_y2(y2) | 183 , m_y2(y2) |
| 184 , m_subType(subType) | 184 , m_subType(subType) |
| 185 { | 185 { |
| 186 } | 186 } |
| 187 | 187 |
| 188 // Finds points on the cubic bezier that cross the given horizontal | 188 // Finds points on the cubic bezier that cross the given horizontal |
| 189 // line, storing their x values in solution1-3 and returning the | 189 // line, storing their x values in solution1-3 and returning the |
| 190 // number of solutions found. | 190 // number of solutions found. |
| 191 size_t findIntersections(double intersectionY, double& solution1, double& so
lution2, double& solution3) const; | 191 size_t findIntersections(double intersectionY, double& solution1, double& so
lution2, double& solution3) const; |
| 192 | 192 |
| 193 double m_x1; | 193 double m_x1; |
| 194 double m_y1; | 194 double m_y1; |
| 195 double m_x2; | 195 double m_x2; |
| 196 double m_y2; | 196 double m_y2; |
| 197 SubType m_subType; | 197 FunctionSubType m_subType; |
| 198 mutable OwnPtr<UnitBezier> m_bezier; | 198 mutable OwnPtr<UnitBezier> m_bezier; |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 class PLATFORM_EXPORT StepsTimingFunction final : public TimingFunction { | 201 class PLATFORM_EXPORT StepsTimingFunction final : public TimingFunction { |
| 202 public: | 202 public: |
| 203 enum StepAtPosition { | 203 enum StepAtPosition { |
| 204 Start, | 204 Start, |
| 205 Middle, | 205 Middle, |
| 206 End | 206 End |
| 207 }; | 207 }; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 232 | 232 |
| 233 ~StepsTimingFunction() override { } | 233 ~StepsTimingFunction() override { } |
| 234 | 234 |
| 235 String toString() const override; | 235 String toString() const override; |
| 236 | 236 |
| 237 double evaluate(double fraction, double) const override; | 237 double evaluate(double fraction, double) const override; |
| 238 void range(double* minValue, double* maxValue) const override; | 238 void range(double* minValue, double* maxValue) const override; |
| 239 void partition(Vector<PartitionRegion>& regions) const override; | 239 void partition(Vector<PartitionRegion>& regions) const override; |
| 240 | 240 |
| 241 int numberOfSteps() const { return m_steps; } | 241 int numberOfSteps() const { return m_steps; } |
| 242 StepAtPosition stepAtPosition() const { return m_stepAtPosition; } | 242 StepAtPosition getStepAtPosition() const { return m_stepAtPosition; } |
| 243 | 243 |
| 244 private: | 244 private: |
| 245 StepsTimingFunction(int steps, StepAtPosition stepAtPosition) | 245 StepsTimingFunction(int steps, StepAtPosition stepAtPosition) |
| 246 : TimingFunction(StepsFunction) | 246 : TimingFunction(StepsFunction) |
| 247 , m_steps(steps) | 247 , m_steps(steps) |
| 248 , m_stepAtPosition(stepAtPosition) | 248 , m_stepAtPosition(stepAtPosition) |
| 249 { | 249 { |
| 250 } | 250 } |
| 251 | 251 |
| 252 int m_steps; | 252 int m_steps; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 266 value->type() == TimingFunction::typeName##Function, \ | 266 value->type() == TimingFunction::typeName##Function, \ |
| 267 value.type() == TimingFunction::typeName##Function) | 267 value.type() == TimingFunction::typeName##Function) |
| 268 | 268 |
| 269 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Linear); | 269 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Linear); |
| 270 DEFINE_TIMING_FUNCTION_TYPE_CASTS(CubicBezier); | 270 DEFINE_TIMING_FUNCTION_TYPE_CASTS(CubicBezier); |
| 271 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Steps); | 271 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Steps); |
| 272 | 272 |
| 273 } // namespace blink | 273 } // namespace blink |
| 274 | 274 |
| 275 #endif // TimingFunction_h | 275 #endif // TimingFunction_h |
| OLD | NEW |