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 LinearTimingFunction::toString() const |
| 11 { |
| 12 return "linear"; |
| 13 } |
| 14 |
| 15 double LinearTimingFunction::evaluate(double fraction, double) const |
| 16 { |
| 17 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"); |
| 18 return fraction; |
| 19 } |
| 20 |
| 21 String CubicBezierTimingFunction::toString() const |
| 22 { |
| 23 switch (this->subType()) { |
| 24 case CubicBezierTimingFunction::Ease: |
| 25 return "ease"; |
| 26 case CubicBezierTimingFunction::EaseIn: |
| 27 return "ease-in"; |
| 28 case CubicBezierTimingFunction::EaseOut: |
| 29 return "ease-out"; |
| 30 case CubicBezierTimingFunction::EaseInOut: |
| 31 return "ease-in-out"; |
| 32 case CubicBezierTimingFunction::Custom: |
| 33 return "cubic-bezier(" + String::numberToStringECMAScript(this->x1()) +
", " + |
| 34 String::numberToStringECMAScript(this->y1()) + ", " + String::number
ToStringECMAScript(this->x2()) + |
| 35 ", " + String::numberToStringECMAScript(this->y2()) + ")"; |
| 36 default: |
| 37 ASSERT_NOT_REACHED(); |
| 38 } |
| 39 return ""; |
| 40 } |
| 41 |
| 42 double CubicBezierTimingFunction::evaluate(double fraction, double accuracy) con
st |
| 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"); |
| 45 if (!m_bezier) |
| 46 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); |
| 47 return m_bezier->solve(fraction, accuracy); |
| 48 } |
| 49 |
| 50 String StepsTimingFunction::toString() const |
| 51 { |
| 52 StringBuilder builder; |
| 53 switch (this->subType()) { |
| 54 case StepsTimingFunction::Start: |
| 55 return "step-start"; |
| 56 case StepsTimingFunction::End: |
| 57 return "step-end"; |
| 58 case StepsTimingFunction::Custom: |
| 59 builder.append("steps(" + String::numberToStringECMAScript(this->numberO
fSteps()) + ", "); |
| 60 builder.append(this->stepAtStart() ? "start" : "end"); |
| 61 builder.append(")"); |
| 62 break; |
| 63 default: |
| 64 ASSERT_NOT_REACHED(); |
| 65 } |
| 66 return builder.toString(); |
| 67 } |
| 68 |
| 69 double StepsTimingFunction::evaluate(double fraction, double) const |
| 70 { |
| 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"); |
| 72 return std::min(1.0, (floor(m_steps * fraction) + m_stepAtStart) / m_steps); |
| 73 } |
| 74 |
| 75 String ChainedTimingFunction::toString() const |
| 76 { |
| 77 StringBuilder builder; |
| 78 builder.append("chained("); |
| 79 for (size_t i = 0; i < this->m_segments.size(); i++) { |
| 80 ChainedTimingFunction::Segment segment = this->m_segments[i]; |
| 81 builder.append(segment.m_timingFunction->toString()); |
| 82 builder.append("[" + String::numberToStringECMAScript(segment.m_min) + "
-> " + String::numberToStringECMAScript(segment.m_max) + "]"); |
| 83 if (i+1 != this->m_segments.size()) { |
| 84 builder.append(", "); |
| 85 } |
| 86 } |
| 87 builder.append(")"); |
| 88 return builder.toString(); |
| 89 } |
| 90 |
| 91 double ChainedTimingFunction::evaluate(double fraction, double accuracy) const |
| 92 { |
| 93 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"); |
| 94 ASSERT(!m_segments.isEmpty()); |
| 95 ASSERT(m_segments.last().max() == 1); |
| 96 size_t i = 0; |
| 97 const Segment* segment = &m_segments[i++]; |
| 98 while (fraction >= segment->max() && i < m_segments.size()) { |
| 99 segment = &m_segments[i++]; |
| 100 } |
| 101 return segment->evaluate(fraction, accuracy); |
| 102 } |
| 103 |
| 104 } // namespace WebCore |
OLD | NEW |