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

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

Issue 152853003: Web Animations API: Bindings for TimedItem.specified with readonly attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Change TimedItemTiming m_parent to RefPtr<TimedItem> Created 6 years, 10 months 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 | « Source/core/core.gypi ('k') | Source/platform/animation/TimingFunctionTestHelper.h » ('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 16 matching lines...) Expand all
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 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 { return ""; }
abarth-chromium 2014/02/13 03:09:38 Please move virtual functions out of line.
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 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
80 virtual String toString() const OVERRIDE { return "linear"; }
abarth-chromium 2014/02/13 03:09:38 ditto
81
76 virtual double evaluate(double fraction, double) const OVERRIDE 82 virtual double evaluate(double fraction, double) const OVERRIDE
77 { 83 {
78 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled() || (fraction >= 0 && fraction <= 1)); 84 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled() || (fraction >= 0 && fraction <= 1));
79 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"); 85 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");
80 return fraction; 86 return fraction;
81 } 87 }
82 88
83 private: 89 private:
84 LinearTimingFunction() 90 LinearTimingFunction()
85 : TimingFunction(LinearFunction) 91 : TimingFunction(LinearFunction)
86 { 92 {
87 } 93 }
88 }; 94 };
89 95
90
91 // Forward declare so we can friend it below. Don't use in production code! 96 // Forward declare so we can friend it below. Don't use in production code!
92 class ChainedTimingFunctionTestHelper; 97 class ChainedTimingFunctionTestHelper;
93 98
94 class CubicBezierTimingFunction FINAL : public TimingFunction { 99 class CubicBezierTimingFunction FINAL : public TimingFunction {
95 public: 100 public:
96 enum SubType { 101 enum SubType {
97 Ease, 102 Ease,
98 EaseIn, 103 EaseIn,
99 EaseOut, 104 EaseOut,
100 EaseInOut, 105 EaseInOut,
(...skipping 29 matching lines...) Expand all
130 return easeInOut; 135 return easeInOut;
131 } 136 }
132 default: 137 default:
133 ASSERT_NOT_REACHED(); 138 ASSERT_NOT_REACHED();
134 return 0; 139 return 0;
135 } 140 }
136 } 141 }
137 142
138 virtual ~CubicBezierTimingFunction() { } 143 virtual ~CubicBezierTimingFunction() { }
139 144
145 virtual String toString() const OVERRIDE
146 {
147 switch (this->subType()) {
148 case CubicBezierTimingFunction::Ease:
149 return "ease";
150 break;
151 case CubicBezierTimingFunction::EaseIn:
152 return "ease-in";
153 break;
154 case CubicBezierTimingFunction::EaseOut:
155 return "ease-out";
156 break;
157 case CubicBezierTimingFunction::EaseInOut:
158 return "ease-in-out";
159 break;
160 case CubicBezierTimingFunction::Custom:
161 return "cubic-bezier(" + String::numberToStringECMAScript(this->x1() ) + ", " +
162 String::numberToStringECMAScript(this->y1()) + ", " + String::nu mberToStringECMAScript(this->x2()) +
163 ", " + String::numberToStringECMAScript(this->y2()) + ")";
164 break;
165 default:
166 ASSERT_NOT_REACHED();
167 }
168 return "";
169 }
170
140 virtual double evaluate(double fraction, double accuracy) const OVERRIDE 171 virtual double evaluate(double fraction, double accuracy) const OVERRIDE
141 { 172 {
142 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled() || (fraction >= 0 && fraction <= 1)); 173 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled() || (fraction >= 0 && fraction <= 1));
143 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"); 174 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");
144 if (!m_bezier) 175 if (!m_bezier)
145 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); 176 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2));
146 return m_bezier->solve(fraction, accuracy); 177 return m_bezier->solve(fraction, accuracy);
147 } 178 }
148 179
149 double x1() const { return m_x1; } 180 double x1() const { return m_x1; }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 231 }
201 default: 232 default:
202 ASSERT_NOT_REACHED(); 233 ASSERT_NOT_REACHED();
203 return 0; 234 return 0;
204 } 235 }
205 } 236 }
206 237
207 238
208 virtual ~StepsTimingFunction() { } 239 virtual ~StepsTimingFunction() { }
209 240
241 virtual String toString() const OVERRIDE
242 {
243 StringBuilder builder;
244 switch (this->subType()) {
245 case StepsTimingFunction::Start:
246 return "step-start";
247 break;
248 case StepsTimingFunction::End:
249 return "step-end";
250 break;
251 case StepsTimingFunction::Custom:
252 builder.append("steps(" + String::numberToStringECMAScript(this->num berOfSteps()) + ", ");
253 builder.append(this->stepAtStart() ? "start" : "end");
254 builder.append(")");
255 break;
256 default:
257 ASSERT_NOT_REACHED();
258 }
259 return builder.toString();
260 }
261
210 virtual double evaluate(double fraction, double) const OVERRIDE 262 virtual double evaluate(double fraction, double) const OVERRIDE
211 { 263 {
212 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled() || (fraction >= 0 && fraction <= 1)); 264 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"); 265 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); 266 return std::min(1.0, (floor(m_steps * fraction) + m_stepAtStart) / m_ste ps);
215 } 267 }
216 268
217 int numberOfSteps() const { return m_steps; } 269 int numberOfSteps() const { return m_steps; }
218 bool stepAtStart() const { return m_stepAtStart; } 270 bool stepAtStart() const { return m_stepAtStart; }
219 271
(...skipping 19 matching lines...) Expand all
239 { 291 {
240 return adoptRef(new ChainedTimingFunction); 292 return adoptRef(new ChainedTimingFunction);
241 } 293 }
242 294
243 void appendSegment(double upperBound, TimingFunction* timingFunction) 295 void appendSegment(double upperBound, TimingFunction* timingFunction)
244 { 296 {
245 double max = m_segments.isEmpty() ? 0 : m_segments.last().max(); 297 double max = m_segments.isEmpty() ? 0 : m_segments.last().max();
246 ASSERT(upperBound > max); 298 ASSERT(upperBound > max);
247 m_segments.append(Segment(max, upperBound, timingFunction)); 299 m_segments.append(Segment(max, upperBound, timingFunction));
248 } 300 }
301
302 virtual String toString() const OVERRIDE
303 {
304 StringBuilder builder;
305 builder.append("chained(");
306 for (size_t i = 0; i < this->m_segments.size(); i++) {
307 ChainedTimingFunction::Segment segment = this->m_segments[i];
308 builder.append(segment.m_timingFunction->toString());
309 builder.append("[" + String::numberToStringECMAScript(segment.m_min) + " -> " + String::numberToStringECMAScript(segment.m_max) + "]");
310 if (i+1 != this->m_segments.size()) {
311 builder.append(", ");
312 }
313 }
314 builder.append(")");
315 return builder.toString();
316 }
317
249 virtual double evaluate(double fraction, double accuracy) const OVERRIDE 318 virtual double evaluate(double fraction, double accuracy) const OVERRIDE
250 { 319 {
251 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"); 320 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");
252 ASSERT(!m_segments.isEmpty()); 321 ASSERT(!m_segments.isEmpty());
253 ASSERT(m_segments.last().max() == 1); 322 ASSERT(m_segments.last().max() == 1);
254 size_t i = 0; 323 size_t i = 0;
255 const Segment* segment = &m_segments[i++]; 324 const Segment* segment = &m_segments[i++];
256 while (fraction >= segment->max() && i < m_segments.size()) { 325 while (fraction >= segment->max() && i < m_segments.size()) {
257 segment = &m_segments[i++]; 326 segment = &m_segments[i++];
258 } 327 }
(...skipping 26 matching lines...) Expand all
285 // FIXME: Come up with a public API for the segments and remove this. 354 // FIXME: Come up with a public API for the segments and remove this.
286 friend class CompositorAnimationsImpl; 355 friend class CompositorAnimationsImpl;
287 friend class CompositorAnimations; 356 friend class CompositorAnimations;
288 357
289 // Allow the compositor to reverse the timing function. 358 // Allow the compositor to reverse the timing function.
290 friend class CompositorAnimationsTimingFunctionReverser; 359 friend class CompositorAnimationsTimingFunctionReverser;
291 360
292 // Allow PrintTo/operator== of the segments. Can be removed once 361 // Allow PrintTo/operator== of the segments. Can be removed once
293 // ChainedTimingFunction has a public API for segments. 362 // ChainedTimingFunction has a public API for segments.
294 friend class ChainedTimingFunctionTestHelper; 363 friend class ChainedTimingFunctionTestHelper;
364 friend class ChainedTimingFunction;
295 }; 365 };
296 366
297 ChainedTimingFunction() 367 ChainedTimingFunction()
298 : TimingFunction(ChainedFunction) 368 : TimingFunction(ChainedFunction)
299 { 369 {
300 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled()); 370 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled());
301 } 371 }
302 372
303 Vector<Segment> m_segments; 373 Vector<Segment> m_segments;
304 374
(...skipping 16 matching lines...) Expand all
321 value.type() == TimingFunction::typeName##Function) 391 value.type() == TimingFunction::typeName##Function)
322 392
323 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Linear); 393 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Linear);
324 DEFINE_TIMING_FUNCTION_TYPE_CASTS(CubicBezier); 394 DEFINE_TIMING_FUNCTION_TYPE_CASTS(CubicBezier);
325 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Steps); 395 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Steps);
326 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Chained); 396 DEFINE_TIMING_FUNCTION_TYPE_CASTS(Chained);
327 397
328 } // namespace WebCore 398 } // namespace WebCore
329 399
330 #endif // TimingFunction_h 400 #endif // TimingFunction_h
OLDNEW
« no previous file with comments | « Source/core/core.gypi ('k') | Source/platform/animation/TimingFunctionTestHelper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698