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 22 matching lines...) Expand all Loading... | |
33 String::numberToStringECMAScript(this->y1()) + ", " + String::number ToStringECMAScript(this->x2()) + | 33 String::numberToStringECMAScript(this->y1()) + ", " + String::number ToStringECMAScript(this->x2()) + |
34 ", " + String::numberToStringECMAScript(this->y2()) + ")"; | 34 ", " + String::numberToStringECMAScript(this->y2()) + ")"; |
35 default: | 35 default: |
36 ASSERT_NOT_REACHED(); | 36 ASSERT_NOT_REACHED(); |
37 } | 37 } |
38 return ""; | 38 return ""; |
39 } | 39 } |
40 | 40 |
41 double CubicBezierTimingFunction::evaluate(double fraction, double accuracy) con st | 41 double CubicBezierTimingFunction::evaluate(double fraction, double accuracy) con st |
42 { | 42 { |
43 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 if (!m_bezier) | 43 if (!m_bezier) |
45 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); | 44 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); |
46 return m_bezier->solve(fraction, accuracy); | 45 return m_bezier->solve(fraction, accuracy); |
47 } | 46 } |
48 | 47 |
49 String StepsTimingFunction::toString() const | 48 String StepsTimingFunction::toString() const |
50 { | 49 { |
51 StringBuilder builder; | 50 StringBuilder builder; |
52 switch (this->subType()) { | 51 switch (this->subType()) { |
53 case StepsTimingFunction::Start: | 52 case StepsTimingFunction::Start: |
(...skipping 17 matching lines...) Expand all Loading... | |
71 builder.append(")"); | 70 builder.append(")"); |
72 break; | 71 break; |
73 default: | 72 default: |
74 ASSERT_NOT_REACHED(); | 73 ASSERT_NOT_REACHED(); |
75 } | 74 } |
76 return builder.toString(); | 75 return builder.toString(); |
77 } | 76 } |
78 | 77 |
79 double StepsTimingFunction::evaluate(double fraction, double) const | 78 double StepsTimingFunction::evaluate(double fraction, double) const |
80 { | 79 { |
81 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"); | |
82 double startOffset = 0; | 80 double startOffset = 0; |
83 switch (m_stepAtPosition) { | 81 switch (m_stepAtPosition) { |
84 case StepAtStart: | 82 case StepAtStart: |
85 startOffset = 1; | 83 startOffset = 1; |
86 break; | 84 break; |
87 case StepAtMiddle: | 85 case StepAtMiddle: |
88 startOffset = 0.5; | 86 startOffset = 0.5; |
89 break; | 87 break; |
90 case StepAtEnd: | 88 case StepAtEnd: |
91 startOffset = 0; | 89 startOffset = 0; |
92 break; | 90 break; |
93 default: | 91 default: |
94 ASSERT_NOT_REACHED(); | 92 ASSERT_NOT_REACHED(); |
95 break; | 93 break; |
96 } | 94 } |
97 return std::min(1.0, floor((m_steps * fraction) + startOffset) / m_steps); | 95 return std::min(std::max(floor((m_steps * fraction) + startOffset) / m_steps , 0.0), 1.0); |
alancutter (OOO until 2018)
2014/04/16 04:50:42
clampTo()?
shans
2014/04/17 06:04:18
Done.
| |
98 } | 96 } |
99 | 97 |
100 // Equals operators | 98 // Equals operators |
101 bool operator==(const LinearTimingFunction& lhs, const TimingFunction& rhs) | 99 bool operator==(const LinearTimingFunction& lhs, const TimingFunction& rhs) |
102 { | 100 { |
103 return rhs.type() == TimingFunction::LinearFunction; | 101 return rhs.type() == TimingFunction::LinearFunction; |
104 } | 102 } |
105 | 103 |
106 bool operator==(const CubicBezierTimingFunction& lhs, const TimingFunction& rhs) | 104 bool operator==(const CubicBezierTimingFunction& lhs, const TimingFunction& rhs) |
107 { | 105 { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 return false; | 148 return false; |
151 } | 149 } |
152 | 150 |
153 // No need to define specific operator!= as they can all come via this function. | 151 // No need to define specific operator!= as they can all come via this function. |
154 bool operator!=(const TimingFunction& lhs, const TimingFunction& rhs) | 152 bool operator!=(const TimingFunction& lhs, const TimingFunction& rhs) |
155 { | 153 { |
156 return !(lhs == rhs); | 154 return !(lhs == rhs); |
157 } | 155 } |
158 | 156 |
159 } // namespace WebCore | 157 } // namespace WebCore |
OLD | NEW |