Chromium Code Reviews| Index: Source/platform/animation/TimingFunction.cpp |
| diff --git a/Source/platform/animation/TimingFunction.cpp b/Source/platform/animation/TimingFunction.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a743c4cdecd4e3667e8a65c381c461400bf2a7d3 |
| --- /dev/null |
| +++ b/Source/platform/animation/TimingFunction.cpp |
| @@ -0,0 +1,116 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "platform/animation/TimingFunction.h" |
| + |
| +namespace WebCore { |
| + |
| +String TimingFunction::toString() const |
| +{ |
| + return ""; |
| +} |
| + |
| +String LinearTimingFunction::toString() const |
| +{ |
| + return "linear"; |
| +} |
| + |
| +double LinearTimingFunction::evaluate(double fraction, double) const |
| +{ |
| + ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animations not yet implemented: Timing function behavior outside the range [0, 1] is not yet specified"); |
| + return fraction; |
| +} |
| + |
| +String CubicBezierTimingFunction::toString() const |
| +{ |
| + switch (this->subType()) { |
| + case CubicBezierTimingFunction::Ease: |
| + return "ease"; |
| + break; |
|
Mike Lawther (Google)
2014/02/13 23:03:01
These breaks after returns aren't needed.
|
| + case CubicBezierTimingFunction::EaseIn: |
| + return "ease-in"; |
| + break; |
| + case CubicBezierTimingFunction::EaseOut: |
| + return "ease-out"; |
| + break; |
| + case CubicBezierTimingFunction::EaseInOut: |
| + return "ease-in-out"; |
| + break; |
| + case CubicBezierTimingFunction::Custom: |
| + return "cubic-bezier(" + String::numberToStringECMAScript(this->x1()) + ", " + |
| + String::numberToStringECMAScript(this->y1()) + ", " + String::numberToStringECMAScript(this->x2()) + |
| + ", " + String::numberToStringECMAScript(this->y2()) + ")"; |
| + break; |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + } |
| + return ""; |
| +} |
| + |
| +double CubicBezierTimingFunction::evaluate(double fraction, double accuracy) const |
| +{ |
| + ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animations not yet implemented: Timing function behavior outside the range [0, 1] is not yet specified"); |
| + if (!m_bezier) |
| + m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); |
| + return m_bezier->solve(fraction, accuracy); |
| +} |
| + |
| +String StepsTimingFunction::toString() const |
| +{ |
| + StringBuilder builder; |
| + switch (this->subType()) { |
| + case StepsTimingFunction::Start: |
| + return "step-start"; |
| + break; |
| + case StepsTimingFunction::End: |
| + return "step-end"; |
| + break; |
| + case StepsTimingFunction::Custom: |
| + builder.append("steps(" + String::numberToStringECMAScript(this->numberOfSteps()) + ", "); |
| + builder.append(this->stepAtStart() ? "start" : "end"); |
| + builder.append(")"); |
| + break; |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + } |
| + return builder.toString(); |
| +} |
| + |
| +double StepsTimingFunction::evaluate(double fraction, double) const |
| +{ |
| + ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animations not yet implemented: Timing function behavior outside the range [0, 1] is not yet specified"); |
| + return std::min(1.0, (floor(m_steps * fraction) + m_stepAtStart) / m_steps); |
| +} |
| + |
| +String ChainedTimingFunction::toString() const |
| +{ |
| + StringBuilder builder; |
| + builder.append("chained("); |
| + for (size_t i = 0; i < this->m_segments.size(); i++) { |
| + ChainedTimingFunction::Segment segment = this->m_segments[i]; |
| + builder.append(segment.m_timingFunction->toString()); |
| + builder.append("[" + String::numberToStringECMAScript(segment.m_min) + " -> " + String::numberToStringECMAScript(segment.m_max) + "]"); |
| + if (i+1 != this->m_segments.size()) { |
| + builder.append(", "); |
| + } |
| + } |
| + builder.append(")"); |
| + return builder.toString(); |
| +} |
| + |
| +double ChainedTimingFunction::evaluate(double fraction, double accuracy) const |
| +{ |
| + ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animations not yet implemented: Timing function behavior outside the range [0, 1] is not yet specified"); |
| + ASSERT(!m_segments.isEmpty()); |
| + ASSERT(m_segments.last().max() == 1); |
| + size_t i = 0; |
| + const Segment* segment = &m_segments[i++]; |
| + while (fraction >= segment->max() && i < m_segments.size()) { |
| + segment = &m_segments[i++]; |
| + } |
| + return segment->evaluate(fraction, accuracy); |
| +} |
| + |
| +} // namespace WebCore |