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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 double m_y2; | 170 double m_y2; |
171 SubType m_subType; | 171 SubType m_subType; |
172 mutable OwnPtr<UnitBezier> m_bezier; | 172 mutable OwnPtr<UnitBezier> m_bezier; |
173 }; | 173 }; |
174 | 174 |
175 class StepsTimingFunction FINAL : public TimingFunction { | 175 class StepsTimingFunction FINAL : public TimingFunction { |
176 public: | 176 public: |
177 enum SubType { | 177 enum SubType { |
178 Start, | 178 Start, |
179 End, | 179 End, |
| 180 Middle, |
180 Custom | 181 Custom |
181 }; | 182 }; |
182 | 183 |
183 static PassRefPtr<StepsTimingFunction> create(int steps, bool stepAtStart) | 184 enum StepAtPosition { |
| 185 StepAtStart, |
| 186 StepAtMiddle, |
| 187 StepAtEnd |
| 188 }; |
| 189 |
| 190 static PassRefPtr<StepsTimingFunction> create(int steps, StepAtPosition step
AtPosition) |
184 { | 191 { |
185 return adoptRef(new StepsTimingFunction(Custom, steps, stepAtStart)); | 192 return adoptRef(new StepsTimingFunction(Custom, steps, stepAtPosition)); |
186 } | 193 } |
187 | 194 |
188 static StepsTimingFunction* preset(SubType subType) | 195 static StepsTimingFunction* preset(SubType subType) |
189 { | 196 { |
190 switch (subType) { | 197 switch (subType) { |
191 case Start: | 198 case Start: |
192 { | 199 { |
193 DEFINE_STATIC_REF(StepsTimingFunction, start, (adoptRef(new Step
sTimingFunction(Start, 1, true)))); | 200 DEFINE_STATIC_REF(StepsTimingFunction, start, (adoptRef(new Step
sTimingFunction(Start, 1, StepAtStart)))); |
194 return start; | 201 return start; |
195 } | 202 } |
| 203 case Middle: |
| 204 { |
| 205 DEFINE_STATIC_REF(StepsTimingFunction, middle, (adoptRef(new Ste
psTimingFunction(Middle, 1, StepAtMiddle)))); |
| 206 return middle; |
| 207 } |
196 case End: | 208 case End: |
197 { | 209 { |
198 DEFINE_STATIC_REF(StepsTimingFunction, end, (adoptRef(new StepsT
imingFunction(End, 1, false)))); | 210 DEFINE_STATIC_REF(StepsTimingFunction, end, (adoptRef(new StepsT
imingFunction(End, 1, StepAtEnd)))); |
199 return end; | 211 return end; |
200 } | 212 } |
201 default: | 213 default: |
202 ASSERT_NOT_REACHED(); | 214 ASSERT_NOT_REACHED(); |
203 return 0; | 215 return 0; |
204 } | 216 } |
205 } | 217 } |
206 | 218 |
207 | 219 |
208 virtual ~StepsTimingFunction() { } | 220 virtual ~StepsTimingFunction() { } |
209 | 221 |
210 virtual double evaluate(double fraction, double) const OVERRIDE | 222 virtual double evaluate(double fraction, double) const OVERRIDE |
211 { | 223 { |
212 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled() || (fraction >=
0 && fraction <= 1)); | 224 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled() || (fraction >=
0 && fraction <= 1)); |
213 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"); | 225 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"); |
214 return std::min(1.0, (floor(m_steps * fraction) + m_stepAtStart) / m_ste
ps); | 226 double startOffset = 0; |
| 227 switch (m_stepAtPosition) { |
| 228 case StepAtStart: |
| 229 { |
| 230 startOffset = 1; |
| 231 break; |
| 232 } |
| 233 case StepAtMiddle: |
| 234 { |
| 235 startOffset = 0.5; |
| 236 break; |
| 237 } |
| 238 case StepAtEnd: |
| 239 { |
| 240 startOffset = 0; |
| 241 break; |
| 242 } |
| 243 default: |
| 244 { |
| 245 ASSERT_NOT_REACHED(); |
| 246 break; |
| 247 } |
| 248 } |
| 249 return std::min(1.0, floor((m_steps * fraction) + startOffset) / m_steps
); |
215 } | 250 } |
216 | 251 |
217 int numberOfSteps() const { return m_steps; } | 252 int numberOfSteps() const { return m_steps; } |
218 bool stepAtStart() const { return m_stepAtStart; } | 253 StepAtPosition stepAtPosition() const { return m_stepAtPosition; } |
219 | 254 |
220 SubType subType() const { return m_subType; } | 255 SubType subType() const { return m_subType; } |
221 | 256 |
222 private: | 257 private: |
223 StepsTimingFunction(SubType subType, int steps, bool stepAtStart) | 258 StepsTimingFunction(SubType subType, int steps, StepAtPosition stepAtPositio
n) |
224 : TimingFunction(StepsFunction) | 259 : TimingFunction(StepsFunction) |
225 , m_steps(steps) | 260 , m_steps(steps) |
226 , m_stepAtStart(stepAtStart) | 261 , m_stepAtPosition(stepAtPosition) |
227 , m_subType(subType) | 262 , m_subType(subType) |
228 { | 263 { |
229 } | 264 } |
230 | 265 |
231 int m_steps; | 266 int m_steps; |
232 bool m_stepAtStart; | 267 StepAtPosition m_stepAtPosition; |
233 SubType m_subType; | 268 SubType m_subType; |
234 }; | 269 }; |
235 | 270 |
236 class ChainedTimingFunction FINAL : public TimingFunction { | 271 class ChainedTimingFunction FINAL : public TimingFunction { |
237 public: | 272 public: |
238 static PassRefPtr<ChainedTimingFunction> create() | 273 static PassRefPtr<ChainedTimingFunction> create() |
239 { | 274 { |
240 return adoptRef(new ChainedTimingFunction); | 275 return adoptRef(new ChainedTimingFunction); |
241 } | 276 } |
242 | 277 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 value.type() == TimingFunction::typeName##Function) | 356 value.type() == TimingFunction::typeName##Function) |
322 | 357 |
323 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Linear); | 358 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Linear); |
324 DEFINE_TIMING_FUNCTION_TYPE_CASTS(CubicBezier); | 359 DEFINE_TIMING_FUNCTION_TYPE_CASTS(CubicBezier); |
325 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Steps); | 360 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Steps); |
326 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Chained); | 361 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Chained); |
327 | 362 |
328 } // namespace WebCore | 363 } // namespace WebCore |
329 | 364 |
330 #endif // TimingFunction_h | 365 #endif // TimingFunction_h |
OLD | NEW |