OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "platform/animation/TimingFunction.h" | 6 #include "platform/animation/TimingFunction.h" |
7 | 7 |
8 namespace WebCore { | 8 namespace WebCore { |
9 | 9 |
10 String LinearTimingFunction::toString() const | 10 String LinearTimingFunction::toString() const |
(...skipping 29 matching lines...) Expand all Loading... | |
40 } | 40 } |
41 | 41 |
42 double CubicBezierTimingFunction::evaluate(double fraction, double accuracy) con st | 42 double CubicBezierTimingFunction::evaluate(double fraction, double accuracy) con st |
43 { | 43 { |
44 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"); | 44 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"); |
45 if (!m_bezier) | 45 if (!m_bezier) |
46 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); | 46 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); |
47 return m_bezier->solve(fraction, accuracy); | 47 return m_bezier->solve(fraction, accuracy); |
48 } | 48 } |
49 | 49 |
50 // FIXME: Unit test this thoroughly | |
dstockwell
2014/02/24 04:58:40
Not a good fixme.
rjwright
2014/02/24 11:17:46
Done.
| |
50 String StepsTimingFunction::toString() const | 51 String StepsTimingFunction::toString() const |
51 { | 52 { |
52 StringBuilder builder; | 53 StringBuilder builder; |
53 switch (this->subType()) { | 54 switch (this->subType()) { |
54 case StepsTimingFunction::Start: | 55 case StepsTimingFunction::Start: |
55 return "step-start"; | 56 return "step-start"; |
57 case StepsTimingFunction::Middle: | |
58 return "step-middle"; | |
56 case StepsTimingFunction::End: | 59 case StepsTimingFunction::End: |
57 return "step-end"; | 60 return "step-end"; |
58 case StepsTimingFunction::Custom: | 61 case StepsTimingFunction::Custom: |
59 builder.append("steps(" + String::numberToStringECMAScript(this->numberO fSteps()) + ", "); | 62 builder.append("steps(" + String::numberToStringECMAScript(this->numberO fSteps()) + ", "); |
60 builder.append(this->stepAtStart() ? "start" : "end"); | 63 |
64 if (this->stepAtPosition() == StepsTimingFunction::StepAtStart) | |
65 builder.append("start"); | |
66 else if (this->stepAtPosition() == StepsTimingFunction::StepAtMiddle) | |
67 builder.append("middle"); | |
68 else if (this->stepAtPosition() == StepsTimingFunction::StepAtEnd) | |
69 builder.append("end"); | |
70 else | |
71 ASSERT_NOT_REACHED(); | |
72 | |
61 builder.append(")"); | 73 builder.append(")"); |
62 break; | 74 break; |
63 default: | 75 default: |
64 ASSERT_NOT_REACHED(); | 76 ASSERT_NOT_REACHED(); |
65 } | 77 } |
66 return builder.toString(); | 78 return builder.toString(); |
67 } | 79 } |
68 | 80 |
69 double StepsTimingFunction::evaluate(double fraction, double) const | 81 double StepsTimingFunction::evaluate(double fraction, double) const |
70 { | 82 { |
71 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"); | 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"); |
72 return std::min(1.0, (floor(m_steps * fraction) + m_stepAtStart) / m_steps); | 84 double startOffset = 0; |
85 switch (m_stepAtPosition) { | |
86 case StepAtStart: | |
87 startOffset = 1; | |
88 break; | |
89 case StepAtMiddle: | |
90 startOffset = 0.5; | |
91 break; | |
92 case StepAtEnd: | |
93 startOffset = 0; | |
94 break; | |
95 default: | |
96 ASSERT_NOT_REACHED(); | |
97 break; | |
98 } | |
99 return std::min(1.0, floor((m_steps * fraction) + startOffset) / m_steps); | |
73 } | 100 } |
74 | 101 |
75 String ChainedTimingFunction::toString() const | 102 String ChainedTimingFunction::toString() const |
76 { | 103 { |
77 StringBuilder builder; | 104 StringBuilder builder; |
78 builder.append("chained("); | 105 builder.append("chained("); |
79 for (size_t i = 0; i < this->m_segments.size(); i++) { | 106 for (size_t i = 0; i < this->m_segments.size(); i++) { |
80 ChainedTimingFunction::Segment segment = this->m_segments[i]; | 107 ChainedTimingFunction::Segment segment = this->m_segments[i]; |
81 builder.append(segment.m_timingFunction->toString()); | 108 builder.append(segment.m_timingFunction->toString()); |
82 builder.append("[" + String::numberToStringECMAScript(segment.m_min) + " -> " + String::numberToStringECMAScript(segment.m_max) + "]"); | 109 builder.append("[" + String::numberToStringECMAScript(segment.m_min) + " -> " + String::numberToStringECMAScript(segment.m_max) + "]"); |
(...skipping 12 matching lines...) Expand all Loading... | |
95 ASSERT(m_segments.last().max() == 1); | 122 ASSERT(m_segments.last().max() == 1); |
96 size_t i = 0; | 123 size_t i = 0; |
97 const Segment* segment = &m_segments[i++]; | 124 const Segment* segment = &m_segments[i++]; |
98 while (fraction >= segment->max() && i < m_segments.size()) { | 125 while (fraction >= segment->max() && i < m_segments.size()) { |
99 segment = &m_segments[i++]; | 126 segment = &m_segments[i++]; |
100 } | 127 } |
101 return segment->evaluate(fraction, accuracy); | 128 return segment->evaluate(fraction, accuracy); |
102 } | 129 } |
103 | 130 |
104 } // namespace WebCore | 131 } // namespace WebCore |
OLD | NEW |