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