Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: Source/core/platform/animation/TimingFunction.h

Issue 54743002: Adding a reverse function to the TimingFunctions and tests to prove it works. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@timing-function-helper
Patch Set: Moved operator== stuff into own patch. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/core/platform/animation/TimingFunctionTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 virtual ~TimingFunction() { } 47 virtual ~TimingFunction() { }
48 48
49 Type type() const { return m_type; } 49 Type type() const { return m_type; }
50 50
51 // Evaluates the timing function at the given fraction. The accuracy paramet er provides a hint as to the required 51 // Evaluates the timing function at the given fraction. The accuracy paramet er provides a hint as to the required
52 // accuracy and is not guaranteed. 52 // accuracy and is not guaranteed.
53 virtual double evaluate(double fraction, double accuracy) const = 0; 53 virtual double evaluate(double fraction, double accuracy) const = 0;
54 virtual bool operator==(const TimingFunction& other) const = 0; 54 virtual bool operator==(const TimingFunction& other) const = 0;
55 virtual bool operator!=(const TimingFunction& other) const { return !operato r==(other); } 55 virtual bool operator!=(const TimingFunction& other) const { return !operato r==(other); }
56 56
57 virtual PassRefPtr<TimingFunction> reverse() const = 0;
58
57 protected: 59 protected:
58 TimingFunction(Type type) 60 TimingFunction(Type type)
59 : m_type(type) 61 : m_type(type)
60 { 62 {
61 } 63 }
62 64
63 private: 65 private:
64 Type m_type; 66 Type m_type;
65 }; 67 };
66 68
(...skipping 11 matching lines...) Expand all
78 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled() || (fraction >= 0 && fraction <= 1)); 80 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled() || (fraction >= 0 && fraction <= 1));
79 RELEASE_ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsEnable d() || (fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Ti ming function behavior outside the range [0, 1] is not yet specified"); 81 RELEASE_ASSERT_WITH_MESSAGE(!RuntimeEnabledFeatures::webAnimationsEnable d() || (fraction >= 0 && fraction <= 1), "Web Animations not yet implemented: Ti ming function behavior outside the range [0, 1] is not yet specified");
80 return fraction; 82 return fraction;
81 } 83 }
82 84
83 virtual bool operator==(const TimingFunction& other) const 85 virtual bool operator==(const TimingFunction& other) const
84 { 86 {
85 return other.type() == LinearFunction; 87 return other.type() == LinearFunction;
86 } 88 }
87 89
90 virtual PassRefPtr<TimingFunction> reverse() const
91 {
92 return const_cast<LinearTimingFunction*>(this);
93 }
94
88 private: 95 private:
89 LinearTimingFunction() 96 LinearTimingFunction()
90 : TimingFunction(LinearFunction) 97 : TimingFunction(LinearFunction)
91 { 98 {
92 } 99 }
93 }; 100 };
94 101
95 102
96 // Forward declare so we can friend it below. Don't used in production code! 103 // Forward declare so we can friend it below. Don't used in production code!
97 class ChainedTimingFunctionPrintTo; 104 class ChainedTimingFunctionPrintTo;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 return m_subType == ctf->m_subType; 184 return m_subType == ctf->m_subType;
178 } 185 }
179 186
180 double x1() const { return m_x1; } 187 double x1() const { return m_x1; }
181 double y1() const { return m_y1; } 188 double y1() const { return m_y1; }
182 double x2() const { return m_x2; } 189 double x2() const { return m_x2; }
183 double y2() const { return m_y2; } 190 double y2() const { return m_y2; }
184 191
185 SubType subType() const { return m_subType; } 192 SubType subType() const { return m_subType; }
186 193
194 virtual PassRefPtr<TimingFunction> reverse() const
195 {
196 switch (m_subType) {
197 case Ease:
198 return const_cast<CubicBezierTimingFunction*>(this);
199 case EaseIn:
200 return preset(EaseOut);
201 case EaseOut:
202 return preset(EaseIn);
203 case EaseInOut:
204 return const_cast<CubicBezierTimingFunction*>(this);
205 case Custom:
206 // Flip the timing function in x. We also have to flip it in y to
207 // maintain the invariant that it runs from (0, 0) to (1, 1).
208 return create(1 - m_x2, 1 - m_y2, 1 - m_x1, 1 - m_y1);
209 default:
210 ASSERT_NOT_REACHED();
211 }
212 }
213
187 private: 214 private:
188 explicit CubicBezierTimingFunction(SubType subType, double x1, double y1, do uble x2, double y2) 215 explicit CubicBezierTimingFunction(SubType subType, double x1, double y1, do uble x2, double y2)
189 : TimingFunction(CubicBezierFunction) 216 : TimingFunction(CubicBezierFunction)
190 , m_x1(x1) 217 , m_x1(x1)
191 , m_y1(y1) 218 , m_y1(y1)
192 , m_x2(x2) 219 , m_x2(x2)
193 , m_y2(y2) 220 , m_y2(y2)
194 , m_subType(subType) 221 , m_subType(subType)
195 { 222 {
196 } 223 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 if (m_subType != Custom) 289 if (m_subType != Custom)
263 return m_subType == stf->m_subType; 290 return m_subType == stf->m_subType;
264 return m_steps == stf->m_steps && m_stepAtStart == stf->m_stepAtStart; 291 return m_steps == stf->m_steps && m_stepAtStart == stf->m_stepAtStart;
265 } 292 }
266 293
267 int numberOfSteps() const { return m_steps; } 294 int numberOfSteps() const { return m_steps; }
268 bool stepAtStart() const { return m_stepAtStart; } 295 bool stepAtStart() const { return m_stepAtStart; }
269 296
270 SubType subType() const { return m_subType; } 297 SubType subType() const { return m_subType; }
271 298
299 virtual PassRefPtr<TimingFunction> reverse() const
300 {
301 switch (m_subType) {
302 case Start:
303 return preset(End);
304 case End:
305 return preset(Start);
306 case Custom:
307 return create(m_steps, !m_stepAtStart);
308 default:
309 ASSERT_NOT_REACHED();
310 return 0;
311 }
312 }
313
272 private: 314 private:
273 StepsTimingFunction(SubType subType, int steps, bool stepAtStart) 315 StepsTimingFunction(SubType subType, int steps, bool stepAtStart)
274 : TimingFunction(StepsFunction) 316 : TimingFunction(StepsFunction)
275 , m_steps(steps) 317 , m_steps(steps)
276 , m_stepAtStart(stepAtStart) 318 , m_stepAtStart(stepAtStart)
277 , m_subType(subType) 319 , m_subType(subType)
278 { 320 {
279 } 321 }
280 322
281 int m_steps; 323 int m_steps;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 if (ctf->m_segments.size() != m_segments.size()) 364 if (ctf->m_segments.size() != m_segments.size())
323 return false; 365 return false;
324 366
325 for (size_t i = 0; i < m_segments.size(); i++) { 367 for (size_t i = 0; i < m_segments.size(); i++) {
326 if (m_segments[i] != ctf->m_segments[i]) 368 if (m_segments[i] != ctf->m_segments[i])
327 return false; 369 return false;
328 } 370 }
329 return true; 371 return true;
330 } 372 }
331 373
374 virtual PassRefPtr<TimingFunction> reverse() const
375 {
376 RefPtr<ChainedTimingFunction> reversed = create();
377 for (size_t i = 0; i < m_segments.size(); i++) {
378 size_t index = m_segments.size() - i - 1;
379
380 reversed->appendSegment(1 - m_segments[index].m_min, m_segments[inde x].m_timingFunction->reverse().get());
381 }
382 return reversed;
383 }
384
332 private: 385 private:
333 class Segment { 386 class Segment {
334 public: 387 public:
335 Segment(double min, double max, TimingFunction* timingFunction) 388 Segment(double min, double max, TimingFunction* timingFunction)
336 : m_min(min) 389 : m_min(min)
337 , m_max(max) 390 , m_max(max)
338 , m_timingFunction(timingFunction) 391 , m_timingFunction(timingFunction)
339 { } 392 { }
340 393
341 double max() const { return m_max; } 394 double max() const { return m_max; }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 Vector<Segment> m_segments; 432 Vector<Segment> m_segments;
380 433
381 // Allow printing of our segments. Can be removed once 434 // Allow printing of our segments. Can be removed once
382 // ChainedTimingFunction has a public API for segments. 435 // ChainedTimingFunction has a public API for segments.
383 friend class ChainedTimingFunctionPrintTo; 436 friend class ChainedTimingFunctionPrintTo;
384 }; 437 };
385 438
386 } // namespace WebCore 439 } // namespace WebCore
387 440
388 #endif // TimingFunction_h 441 #endif // TimingFunction_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/platform/animation/TimingFunctionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698