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 |
| index 87825e4ee7f934c8cf336cf42da579063e9e9f3a..561d6717bb84f0a91a79427b5f82f4c4a0e1baef 100644 |
| --- a/Source/core/platform/animation/TimingFunctionTestHelper.cpp |
| +++ b/Source/core/platform/animation/TimingFunctionTestHelper.cpp |
| @@ -35,6 +35,68 @@ |
| namespace WebCore { |
| +// This class exists so that ChainedTimingFunction only needs to friend one thing. |
| +class ChainedTimingFunctionTestHelper { |
| + static void PrintTo(const ChainedTimingFunction& timingFunction, ::std::ostream* os) |
| + { |
| + // Forward declare the generic PrintTo function as ChainedTimingFunction needs to call it. |
| + void PrintTo(const TimingFunction&, ::std::ostream*); |
| + |
| + *os << "ChainedTimingFunction@" << &timingFunction << "("; |
| + for (size_t i = 0; i < timingFunction.m_segments.size(); i++) { |
| + ChainedTimingFunction::Segment segment = timingFunction.m_segments[i]; |
| + PrintTo(*(segment.m_timingFunction.get()), os); |
| + *os << "[" << segment.m_min << " -> " << segment.m_max << "]"; |
| + if (i+1 != timingFunction.m_segments.size()) { |
| + *os << ", "; |
| + } |
| + } |
| + *os << ")"; |
| + } |
| + |
| + static bool equals(const ChainedTimingFunction& lhs, const TimingFunction& rhs) |
| + { |
| + if (rhs.type() != TimingFunction::ChainedFunction) |
| + return false; |
| + |
| + if (&lhs == &rhs) |
| + return true; |
| + |
| + const ChainedTimingFunction* ctf = static_cast<const ChainedTimingFunction*>(&rhs); |
| + if (lhs.m_segments.size() != ctf->m_segments.size()) |
| + return false; |
| + |
| + for (size_t i = 0; i < lhs.m_segments.size(); i++) { |
| + if (!equals(lhs.m_segments[i], ctf->m_segments[i])) |
| + return false; |
| + } |
| + return true; |
| + } |
| + |
| + static bool equals(const ChainedTimingFunction::Segment& lhs, const ChainedTimingFunction::Segment& rhs) |
| + { |
| + if (&lhs == &rhs) |
| + return true; |
| + |
| + bool minMaxEq = (lhs.m_min == rhs.m_min) && (lhs.m_max == rhs.m_max); |
|
Steve Block
2013/11/06 05:47:19
Does this need a local?
mithro-old
2013/11/06 23:37:18
Done.
|
| + if (!minMaxEq) |
| + return false; |
| + |
| + if (lhs.m_timingFunction == rhs.m_timingFunction) |
| + return true; |
| + |
| + if (!lhs.m_timingFunction || !rhs.m_timingFunction) |
|
Steve Block
2013/11/06 05:47:19
m_timingFunction should always be non-null. You co
mithro-old
2013/11/06 23:37:18
Converted these to ASSERTs and added an ASSERT to
|
| + return false; |
| + |
| + return (*(lhs.m_timingFunction.get())) == (*(rhs.m_timingFunction.get())); |
| + } |
| + |
| + friend void PrintTo(const ChainedTimingFunction&, ::std::ostream*); |
| + friend bool operator==(const ChainedTimingFunction& lhs, const TimingFunction& rhs); |
| +}; |
| + |
| +// PrintTo functions |
|
Steve Block
2013/11/06 05:47:19
Again, this comment isn't really needed.
mithro-old
2013/11/06 23:37:18
Done.
|
| +// ----------------------------------------------------------------------- |
| void PrintTo(const LinearTimingFunction& timingFunction, ::std::ostream* os) |
| { |
| *os << "LinearTimingFunction@" << &timingFunction; |
| @@ -90,31 +152,9 @@ void PrintTo(const StepsTimingFunction& timingFunction, ::std::ostream* os) |
| *os << ")"; |
| } |
| -class ChainedTimingFunctionPrinter { |
| -private: |
| - static void PrintTo(const ChainedTimingFunction& timingFunction, ::std::ostream* os) |
| - { |
| - // Forward declare the generic PrintTo function as ChainedTimingFunction needs to call it. |
| - void PrintTo(const TimingFunction&, ::std::ostream*); |
| - |
| - *os << "ChainedTimingFunction@" << &timingFunction << "("; |
| - for (size_t i = 0; i < timingFunction.m_segments.size(); i++) { |
| - ChainedTimingFunction::Segment segment = timingFunction.m_segments[i]; |
| - PrintTo(*(segment.m_timingFunction.get()), os); |
| - *os << "[" << segment.m_min << " -> " << segment.m_max << "]"; |
| - if (i+1 != timingFunction.m_segments.size()) { |
| - *os << ", "; |
| - } |
| - } |
| - *os << ")"; |
| - } |
| - |
| - friend void PrintTo(const ChainedTimingFunction&, ::std::ostream*); |
| -}; |
| - |
| void PrintTo(const ChainedTimingFunction& timingFunction, ::std::ostream* os) |
| { |
| - ChainedTimingFunctionPrinter::PrintTo(timingFunction, os); |
| + ChainedTimingFunctionTestHelper::PrintTo(timingFunction, os); |
| } |
| // The generic PrintTo *must* come after the non-generic PrintTo otherwise it |
| @@ -147,4 +187,72 @@ void PrintTo(const TimingFunction& timingFunction, ::std::ostream* os) |
| } |
| } |
| +// operator== functions |
| +// ----------------------------------------------------------------------- |
| +bool operator==(const LinearTimingFunction& lhs, const TimingFunction& rhs) |
| +{ |
| + return rhs.type() == TimingFunction::LinearFunction; |
| +} |
| + |
| +bool operator==(const CubicBezierTimingFunction& lhs, const TimingFunction& rhs) |
| +{ |
| + if (rhs.type() != TimingFunction::CubicBezierFunction) |
| + return false; |
| + |
| + const CubicBezierTimingFunction* ctf = static_cast<const CubicBezierTimingFunction*>(&rhs); |
| + if ((lhs.subType() == CubicBezierTimingFunction::Custom) && (ctf->subType() == CubicBezierTimingFunction::Custom)) |
| + return (lhs.x1() == ctf->x1()) && (lhs.y1() == ctf->y1()) && (lhs.x2() == ctf->x2()) && (lhs.y2() == ctf->y2()); |
| + |
| + return lhs.subType() == ctf->subType(); |
| +} |
| + |
| +bool operator==(const StepsTimingFunction& lhs, const TimingFunction& rhs) |
| +{ |
| + if (rhs.type() != TimingFunction::StepsFunction) |
| + return false; |
| + |
| + const StepsTimingFunction* stf = static_cast<const StepsTimingFunction*>(&rhs); |
| + if ((lhs.subType() == StepsTimingFunction::Custom) && (stf->subType() == StepsTimingFunction::Custom)) |
| + return (lhs.numberOfSteps() == stf->numberOfSteps()) && (lhs.stepAtStart() == stf->stepAtStart()); |
| + |
| + return lhs.subType() == stf->subType(); |
| +} |
| + |
| +bool operator==(const ChainedTimingFunction& lhs, const TimingFunction& rhs) |
| +{ |
| + return ChainedTimingFunctionTestHelper::equals(lhs, rhs); |
| +} |
| + |
| +// Like in the PrintTo case, the generic operator== *must* come after the |
| +// non-generic operator== otherwise it will end up calling itself. |
| +bool operator==(const TimingFunction& lhs, const TimingFunction& rhs) |
| +{ |
| + switch (lhs.type()) { |
| + case TimingFunction::LinearFunction: { |
| + const LinearTimingFunction* linear = static_cast<const LinearTimingFunction*>(&lhs); |
| + return ((*linear) == rhs); |
|
Steve Block
2013/11/06 05:47:19
No need for these inner parens
mithro-old
2013/11/06 23:37:18
Done.
|
| + } |
| + case TimingFunction::CubicBezierFunction: { |
| + const CubicBezierTimingFunction* cubic = static_cast<const CubicBezierTimingFunction*>(&lhs); |
| + return ((*cubic) == rhs); |
| + } |
| + case TimingFunction::StepsFunction: { |
| + const StepsTimingFunction* step = static_cast<const StepsTimingFunction*>(&lhs); |
| + return ((*step) == rhs); |
| + } |
| + case TimingFunction::ChainedFunction: { |
| + const ChainedTimingFunction* chained = static_cast<const ChainedTimingFunction*>(&lhs); |
| + return ((*chained) == rhs); |
|
Steve Block
2013/11/06 05:47:19
Still don't see why we can't call ChainedTimingFun
mithro-old
2013/11/06 23:37:18
We could, but we'd still need the following operat
|
| + } |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + } |
| +} |
| + |
| +// No need to define specific operator!= as they can all come via this function. |
| +bool operator!=(const TimingFunction& lhs, const TimingFunction& rhs) |
| +{ |
| + return !(lhs == rhs); |
| +} |
| + |
| } // namespace WebCore |