Chromium Code Reviews| Index: Source/core/platform/animation/TimingFunctionTestHelper.cpp |
| diff --git a/Source/core/platform/animation/TimingFunctionTestHelper.cpp b/Source/core/platform/animation/TimingFunctionTestHelper.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9fdf9e6212856c0f5d322ed98b023423bf1f7425 |
| --- /dev/null |
| +++ b/Source/core/platform/animation/TimingFunctionTestHelper.cpp |
| @@ -0,0 +1,151 @@ |
| +/* |
| + * Copyright (c) 2013, Google Inc. All rights reserved. |
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions are |
| + * met: |
| + * |
| + * * Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above |
| + * copyright notice, this list of conditions and the following disclaimer |
| + * in the documentation and/or other materials provided with the |
| + * distribution. |
| + * * Neither the name of Google Inc. nor the names of its |
| + * contributors may be used to endorse or promote products derived from |
| + * this software without specific prior written permission. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
| + |
| +#include "config.h" |
| + |
|
Steve Block
2013/11/04 23:05:02
Superfluous blank line
mithro-old
2013/11/05 01:53:09
Done.
|
| +#include "core/platform/animation/TimingFunctionTestHelper.h" |
| + |
| +#include <ostream> // NOLINT |
| + |
| +namespace WebCore { |
| + |
| +void PrintTo(const LinearTimingFunction& timefunction, ::std::ostream* os) |
|
Steve Block
2013/11/04 23:05:02
s/timeFunction/timingFunction
mithro-old
2013/11/05 01:53:09
Done.
|
| +{ |
| + *os << "LinearTimingFunction@" << &timefunction; |
| +} |
| + |
| +void PrintTo(const CubicBezierTimingFunction& timefunction, ::std::ostream* os) |
|
Steve Block
2013/11/04 23:05:02
Function and method names start with a lower case
mithro-old
2013/11/05 01:53:09
Don't get to control the name of this method. Set
|
| +{ |
| + *os << "CubicBezierTimingFunction@" << &timefunction << "("; |
| + switch (timefunction.subType()) { |
| + case CubicBezierTimingFunction::Ease: |
| + *os << "Ease"; |
| + break; |
| + case CubicBezierTimingFunction::EaseIn: |
| + *os << "EaseIn"; |
| + break; |
| + case CubicBezierTimingFunction::EaseOut: |
| + *os << "EaseOut"; |
| + break; |
| + case CubicBezierTimingFunction::EaseInOut: |
| + *os << "EaseInOut"; |
| + break; |
| + case CubicBezierTimingFunction::Custom: |
| + *os << "Custom"; |
| + break; |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + } |
| + *os << ", " << timefunction.x1(); |
| + *os << ", " << timefunction.y1(); |
| + *os << ", " << timefunction.x2(); |
| + *os << ", " << timefunction.y2(); |
| + *os << ")"; |
| +} |
| + |
| +void PrintTo(const StepsTimingFunction& timefunction, ::std::ostream* os) |
| +{ |
| + *os << "StepsTimingFunction@" << &timefunction << "("; |
| + switch (timefunction.subType()) { |
| + case StepsTimingFunction::Start: |
| + *os << "Start"; |
| + break; |
| + case StepsTimingFunction::End: |
| + *os << "End"; |
| + break; |
| + case StepsTimingFunction::Custom: |
| + *os << "Custom"; |
| + break; |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + } |
| + *os << ", " << timefunction.numberOfSteps(); |
| + *os << ", " << (timefunction.stepAtStart() ? "true" : "false"); |
| + *os << ")"; |
| +} |
| + |
| +class ChainedTimingFunctionPrintTo { |
|
Steve Block
2013/11/04 23:05:02
Is ChainedTimingFunctionPrinter a better name?
mithro-old
2013/11/05 01:53:09
Done.
|
| +private: |
| + static void PrintTo(const ChainedTimingFunction& timefunction, ::std::ostream* os) |
| + { |
| + // Forward declare the generic PrintTo function as ChainedTimingFunction needs to call it. |
| + void PrintTo(const TimingFunction&, ::std::ostream*); |
| + |
| + *os << "ChainedTimingFunction@" << &timefunction << "("; |
| + for (size_t i = 0; i < timefunction.m_segments.size(); i++) { |
| + ChainedTimingFunction::Segment segment = timefunction.m_segments[i]; |
| + PrintTo(*(segment.m_timingFunction.get()), os); |
| + *os << "[" << segment.m_min << " -> " << segment.m_max << "]"; |
| + if (i+1 != timefunction.m_segments.size()) { |
| + *os << ", "; |
| + } |
| + } |
| + *os << ")"; |
| + } |
| + |
| + friend void PrintTo(const ChainedTimingFunction&, ::std::ostream*); |
| +}; |
| + |
| +void PrintTo(const ChainedTimingFunction& timefunction, ::std::ostream* os) |
|
Steve Block
2013/11/04 23:05:02
Do we need this wrapper? Can the generic PrintTo()
mithro-old
2013/11/05 01:53:09
Yes, otherwise when you try and print a ChainedTim
|
| +{ |
| + ChainedTimingFunctionPrintTo::PrintTo(timefunction, os); |
| +} |
| + |
| +// The generic PrintTo *must* come after the non-generic PrintTo otherwise it |
| +// will end up calling itself. |
| +void PrintTo(const TimingFunction& timefunction, ::std::ostream* os) |
| +{ |
| + switch (timefunction.type()) { |
| + case TimingFunction::LinearFunction: { |
| + const LinearTimingFunction* linear = static_cast<const LinearTimingFunction*>(&timefunction); |
| + PrintTo(*linear, os); |
| + return; |
| + } |
| + case TimingFunction::CubicBezierFunction: { |
| + const CubicBezierTimingFunction* cubic = static_cast<const CubicBezierTimingFunction*>(&timefunction); |
| + PrintTo(*cubic, os); |
| + return; |
| + } |
| + case TimingFunction::StepsFunction: { |
| + const StepsTimingFunction* step = static_cast<const StepsTimingFunction*>(&timefunction); |
| + PrintTo(*step, os); |
| + return; |
| + } |
| + case TimingFunction::ChainedFunction: { |
| + const ChainedTimingFunction* chained = static_cast<const ChainedTimingFunction*>(&timefunction); |
| + PrintTo(*chained, os); |
| + return; |
| + } |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + } |
| +} |
| + |
| +} // namespace WebCore |