OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "platform/animation/TimingFunction.h" | |
7 | |
8 namespace WebCore { | |
9 | |
10 String TimingFunction::toString() const | |
11 { | |
12 return ""; | |
13 } | |
14 | |
15 String LinearTimingFunction::toString() const | |
16 { | |
17 return "linear"; | |
18 } | |
19 | |
20 double LinearTimingFunction::evaluate(double fraction, double) const | |
21 { | |
22 ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animations not yet implemented: Timing function behavior outside the range [0, 1] is not yet specif ied"); | |
23 return fraction; | |
24 } | |
25 | |
26 String CubicBezierTimingFunction::toString() const | |
27 { | |
28 switch (this->subType()) { | |
29 case CubicBezierTimingFunction::Ease: | |
30 return "ease"; | |
31 break; | |
Mike Lawther (Google)
2014/02/13 23:03:01
These breaks after returns aren't needed.
| |
32 case CubicBezierTimingFunction::EaseIn: | |
33 return "ease-in"; | |
34 break; | |
35 case CubicBezierTimingFunction::EaseOut: | |
36 return "ease-out"; | |
37 break; | |
38 case CubicBezierTimingFunction::EaseInOut: | |
39 return "ease-in-out"; | |
40 break; | |
41 case CubicBezierTimingFunction::Custom: | |
42 return "cubic-bezier(" + String::numberToStringECMAScript(this->x1()) + ", " + | |
43 String::numberToStringECMAScript(this->y1()) + ", " + String::number ToStringECMAScript(this->x2()) + | |
44 ", " + String::numberToStringECMAScript(this->y2()) + ")"; | |
45 break; | |
46 default: | |
47 ASSERT_NOT_REACHED(); | |
48 } | |
49 return ""; | |
50 } | |
51 | |
52 double CubicBezierTimingFunction::evaluate(double fraction, double accuracy) con st | |
53 { | |
54 ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animations not yet implemented: Timing function behavior outside the range [0, 1] is not yet specif ied"); | |
55 if (!m_bezier) | |
56 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); | |
57 return m_bezier->solve(fraction, accuracy); | |
58 } | |
59 | |
60 String StepsTimingFunction::toString() const | |
61 { | |
62 StringBuilder builder; | |
63 switch (this->subType()) { | |
64 case StepsTimingFunction::Start: | |
65 return "step-start"; | |
66 break; | |
67 case StepsTimingFunction::End: | |
68 return "step-end"; | |
69 break; | |
70 case StepsTimingFunction::Custom: | |
71 builder.append("steps(" + String::numberToStringECMAScript(this->numberO fSteps()) + ", "); | |
72 builder.append(this->stepAtStart() ? "start" : "end"); | |
73 builder.append(")"); | |
74 break; | |
75 default: | |
76 ASSERT_NOT_REACHED(); | |
77 } | |
78 return builder.toString(); | |
79 } | |
80 | |
81 double StepsTimingFunction::evaluate(double fraction, double) const | |
82 { | |
83 ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animations not yet implemented: Timing function behavior outside the range [0, 1] is not yet specif ied"); | |
84 return std::min(1.0, (floor(m_steps * fraction) + m_stepAtStart) / m_steps); | |
85 } | |
86 | |
87 String ChainedTimingFunction::toString() const | |
88 { | |
89 StringBuilder builder; | |
90 builder.append("chained("); | |
91 for (size_t i = 0; i < this->m_segments.size(); i++) { | |
92 ChainedTimingFunction::Segment segment = this->m_segments[i]; | |
93 builder.append(segment.m_timingFunction->toString()); | |
94 builder.append("[" + String::numberToStringECMAScript(segment.m_min) + " -> " + String::numberToStringECMAScript(segment.m_max) + "]"); | |
95 if (i+1 != this->m_segments.size()) { | |
96 builder.append(", "); | |
97 } | |
98 } | |
99 builder.append(")"); | |
100 return builder.toString(); | |
101 } | |
102 | |
103 double ChainedTimingFunction::evaluate(double fraction, double accuracy) const | |
104 { | |
105 ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animations not yet implemented: Timing function behavior outside the range [0, 1] is not yet specif ied"); | |
106 ASSERT(!m_segments.isEmpty()); | |
107 ASSERT(m_segments.last().max() == 1); | |
108 size_t i = 0; | |
109 const Segment* segment = &m_segments[i++]; | |
110 while (fraction >= segment->max() && i < m_segments.size()) { | |
111 segment = &m_segments[i++]; | |
112 } | |
113 return segment->evaluate(fraction, accuracy); | |
114 } | |
115 | |
116 } // namespace WebCore | |
OLD | NEW |