| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 LinearFunction, CubicBezierFunction, StepsFunction, ChainedFunction | 45 LinearFunction, CubicBezierFunction, StepsFunction, ChainedFunction |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 virtual ~TimingFunction() { } | 48 virtual ~TimingFunction() { } |
| 49 | 49 |
| 50 Type type() const { return m_type; } | 50 Type type() const { return m_type; } |
| 51 | 51 |
| 52 // Evaluates the timing function at the given fraction. The accuracy paramet
er provides a hint as to the required | 52 // 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. | 53 // accuracy and is not guaranteed. |
| 54 virtual double evaluate(double fraction, double accuracy) const = 0; | 54 virtual double evaluate(double fraction, double accuracy) const = 0; |
| 55 virtual bool operator==(const TimingFunction& other) const = 0; | |
| 56 | 55 |
| 57 protected: | 56 protected: |
| 58 TimingFunction(Type type) | 57 TimingFunction(Type type) |
| 59 : m_type(type) | 58 : m_type(type) |
| 60 { | 59 { |
| 61 } | 60 } |
| 62 | 61 |
| 63 private: | 62 private: |
| 64 Type m_type; | 63 Type m_type; |
| 65 }; | 64 }; |
| 66 | 65 |
| 67 class LinearTimingFunction : public TimingFunction { | 66 class LinearTimingFunction : public TimingFunction { |
| 68 public: | 67 public: |
| 69 static PassRefPtr<LinearTimingFunction> create() | 68 static PassRefPtr<LinearTimingFunction> create() |
| 70 { | 69 { |
| 71 return adoptRef(new LinearTimingFunction); | 70 return adoptRef(new LinearTimingFunction); |
| 72 } | 71 } |
| 73 | 72 |
| 74 ~LinearTimingFunction() { } | 73 ~LinearTimingFunction() { } |
| 75 | 74 |
| 76 virtual double evaluate(double fraction, double) const | 75 virtual double evaluate(double fraction, double) const |
| 77 { | 76 { |
| 78 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled() || (fraction >= 0
&& fraction <= 1)); | 77 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled() || (fraction >= 0
&& fraction <= 1)); |
| 79 ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsEnabled() || (
fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Timing fun
ction behavior outside the range [0, 1] is not yet specified"); | 78 ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsEnabled() || (
fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Timing fun
ction behavior outside the range [0, 1] is not yet specified"); |
| 80 return fraction; | 79 return fraction; |
| 81 } | 80 } |
| 82 | 81 |
| 83 virtual bool operator==(const TimingFunction& other) const | |
| 84 { | |
| 85 return other.type() == LinearFunction; | |
| 86 } | |
| 87 | |
| 88 private: | 82 private: |
| 89 LinearTimingFunction() | 83 LinearTimingFunction() |
| 90 : TimingFunction(LinearFunction) | 84 : TimingFunction(LinearFunction) |
| 91 { | 85 { |
| 92 } | 86 } |
| 93 }; | 87 }; |
| 94 | 88 |
| 95 | 89 |
| 96 // Forward declare so we can friend it below. Don't use in production code! | 90 // Forward declare so we can friend it below. Don't use in production code! |
| 97 class ChainedTimingFunctionPrinter; | 91 class ChainedTimingFunctionPrinter; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 138 |
| 145 virtual double evaluate(double fraction, double accuracy) const | 139 virtual double evaluate(double fraction, double accuracy) const |
| 146 { | 140 { |
| 147 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled() || (fraction >= 0
&& fraction <= 1)); | 141 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled() || (fraction >= 0
&& fraction <= 1)); |
| 148 ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsEnabled() || (
fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Timing fun
ction behavior outside the range [0, 1] is not yet specified"); | 142 ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsEnabled() || (
fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Timing fun
ction behavior outside the range [0, 1] is not yet specified"); |
| 149 if (!m_bezier) | 143 if (!m_bezier) |
| 150 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); | 144 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); |
| 151 return m_bezier->solve(fraction, accuracy); | 145 return m_bezier->solve(fraction, accuracy); |
| 152 } | 146 } |
| 153 | 147 |
| 154 virtual bool operator==(const TimingFunction& other) const | |
| 155 { | |
| 156 if (other.type() == CubicBezierFunction) { | |
| 157 const CubicBezierTimingFunction* ctf = static_cast<const CubicBezier
TimingFunction*>(&other); | |
| 158 if (m_subType != Custom) | |
| 159 return m_subType == ctf->m_subType; | |
| 160 | |
| 161 return m_x1 == ctf->m_x1 && m_y1 == ctf->m_y1 && m_x2 == ctf->m_x2 &
& m_y2 == ctf->m_y2; | |
| 162 } | |
| 163 return false; | |
| 164 } | |
| 165 | |
| 166 double x1() const { return m_x1; } | 148 double x1() const { return m_x1; } |
| 167 double y1() const { return m_y1; } | 149 double y1() const { return m_y1; } |
| 168 double x2() const { return m_x2; } | 150 double x2() const { return m_x2; } |
| 169 double y2() const { return m_y2; } | 151 double y2() const { return m_y2; } |
| 170 | 152 |
| 171 SubType subType() const { return m_subType; } | 153 SubType subType() const { return m_subType; } |
| 172 | 154 |
| 173 private: | 155 private: |
| 174 explicit CubicBezierTimingFunction(SubType subType, double x1, double y1, do
uble x2, double y2) | 156 explicit CubicBezierTimingFunction(SubType subType, double x1, double y1, do
uble x2, double y2) |
| 175 : TimingFunction(CubicBezierFunction) | 157 : TimingFunction(CubicBezierFunction) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 206 |
| 225 ~StepsTimingFunction() { } | 207 ~StepsTimingFunction() { } |
| 226 | 208 |
| 227 virtual double evaluate(double fraction, double) const | 209 virtual double evaluate(double fraction, double) const |
| 228 { | 210 { |
| 229 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled() || (fraction >= 0
&& fraction <= 1)); | 211 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled() || (fraction >= 0
&& fraction <= 1)); |
| 230 ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsEnabled() || (
fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Timing fun
ction behavior outside the range [0, 1] is not yet specified"); | 212 ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsEnabled() || (
fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Timing fun
ction 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); | 213 return std::min(1.0, (floor(m_steps * fraction) + m_stepAtStart) / m_ste
ps); |
| 232 } | 214 } |
| 233 | 215 |
| 234 virtual bool operator==(const TimingFunction& other) const | |
| 235 { | |
| 236 if (other.type() == StepsFunction) { | |
| 237 const StepsTimingFunction* stf = static_cast<const StepsTimingFuncti
on*>(&other); | |
| 238 if (m_subType != Custom) | |
| 239 return m_subType == stf->m_subType; | |
| 240 return m_steps == stf->m_steps && m_stepAtStart == stf->m_stepAtStar
t; | |
| 241 } | |
| 242 return false; | |
| 243 } | |
| 244 | |
| 245 int numberOfSteps() const { return m_steps; } | 216 int numberOfSteps() const { return m_steps; } |
| 246 bool stepAtStart() const { return m_stepAtStart; } | 217 bool stepAtStart() const { return m_stepAtStart; } |
| 247 | 218 |
| 248 SubType subType() const { return m_subType; } | 219 SubType subType() const { return m_subType; } |
| 249 | 220 |
| 250 private: | 221 private: |
| 251 StepsTimingFunction(SubType subType, int steps, bool stepAtStart) | 222 StepsTimingFunction(SubType subType, int steps, bool stepAtStart) |
| 252 : TimingFunction(StepsFunction) | 223 : TimingFunction(StepsFunction) |
| 253 , m_steps(steps) | 224 , m_steps(steps) |
| 254 , m_stepAtStart(stepAtStart) | 225 , m_stepAtStart(stepAtStart) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 280 ASSERT(!m_segments.isEmpty()); | 251 ASSERT(!m_segments.isEmpty()); |
| 281 ASSERT(m_segments.last().max() == 1); | 252 ASSERT(m_segments.last().max() == 1); |
| 282 size_t i = 0; | 253 size_t i = 0; |
| 283 const Segment* segment = &m_segments[i++]; | 254 const Segment* segment = &m_segments[i++]; |
| 284 while (fraction >= segment->max() && i < m_segments.size()) { | 255 while (fraction >= segment->max() && i < m_segments.size()) { |
| 285 segment = &m_segments[i++]; | 256 segment = &m_segments[i++]; |
| 286 } | 257 } |
| 287 return segment->evaluate(fraction, accuracy); | 258 return segment->evaluate(fraction, accuracy); |
| 288 } | 259 } |
| 289 | 260 |
| 290 virtual bool operator==(const TimingFunction& other) const | |
| 291 { | |
| 292 // This class is not exposed to CSS, so this method is not required. | |
| 293 ASSERT_NOT_REACHED(); | |
| 294 return false; | |
| 295 } | |
| 296 | |
| 297 private: | 261 private: |
| 298 class Segment { | 262 class Segment { |
| 299 public: | 263 public: |
| 300 Segment(double min, double max, TimingFunction* timingFunction) | 264 Segment(double min, double max, TimingFunction* timingFunction) |
| 301 : m_min(min) | 265 : m_min(min) |
| 302 , m_max(max) | 266 , m_max(max) |
| 303 , m_timingFunction(timingFunction) | 267 , m_timingFunction(timingFunction) |
| 304 { } | 268 { } |
| 305 | 269 |
| 306 double max() const { return m_max; } | 270 double max() const { return m_max; } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 331 Vector<Segment> m_segments; | 295 Vector<Segment> m_segments; |
| 332 | 296 |
| 333 // Allow printing of our segments. Can be removed once | 297 // Allow printing of our segments. Can be removed once |
| 334 // ChainedTimingFunction has a public API for segments. | 298 // ChainedTimingFunction has a public API for segments. |
| 335 friend class ChainedTimingFunctionPrinter; | 299 friend class ChainedTimingFunctionPrinter; |
| 336 }; | 300 }; |
| 337 | 301 |
| 338 } // namespace WebCore | 302 } // namespace WebCore |
| 339 | 303 |
| 340 #endif // TimingFunction_h | 304 #endif // TimingFunction_h |
| OLD | NEW |