| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "platform/animation/TimingFunctionTestHelper.h" | |
| 33 | |
| 34 | |
| 35 namespace WebCore { | |
| 36 | |
| 37 // This class exists so that ChainedTimingFunction only needs to friend one thin
g. | |
| 38 class ChainedTimingFunctionTestHelper { | |
| 39 static bool equals(const ChainedTimingFunction& lhs, const TimingFunction& r
hs) | |
| 40 { | |
| 41 if (rhs.type() != TimingFunction::ChainedFunction) | |
| 42 return false; | |
| 43 | |
| 44 if (&lhs == &rhs) | |
| 45 return true; | |
| 46 | |
| 47 const ChainedTimingFunction& ctf = toChainedTimingFunction(rhs); | |
| 48 if (lhs.m_segments.size() != ctf.m_segments.size()) | |
| 49 return false; | |
| 50 | |
| 51 for (size_t i = 0; i < lhs.m_segments.size(); i++) { | |
| 52 if (!equals(lhs.m_segments[i], ctf.m_segments[i])) | |
| 53 return false; | |
| 54 } | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 static bool equals(const ChainedTimingFunction::Segment& lhs, const ChainedT
imingFunction::Segment& rhs) | |
| 59 { | |
| 60 if (&lhs == &rhs) | |
| 61 return true; | |
| 62 | |
| 63 if ((lhs.m_min != rhs.m_min) || (lhs.m_max != rhs.m_max)) | |
| 64 return false; | |
| 65 | |
| 66 if (lhs.m_timingFunction == rhs.m_timingFunction) | |
| 67 return true; | |
| 68 | |
| 69 ASSERT(lhs.m_timingFunction); | |
| 70 ASSERT(rhs.m_timingFunction); | |
| 71 | |
| 72 return (*(lhs.m_timingFunction.get())) == (*(rhs.m_timingFunction.get())
); | |
| 73 } | |
| 74 | |
| 75 friend bool operator==(const ChainedTimingFunction& lhs, const TimingFunctio
n& rhs); | |
| 76 }; | |
| 77 | |
| 78 void PrintTo(const TimingFunction& timingFunction, ::std::ostream* os) | |
| 79 { | |
| 80 *os << timingFunction.toString().latin1().data(); | |
| 81 } | |
| 82 | |
| 83 bool operator==(const LinearTimingFunction& lhs, const TimingFunction& rhs) | |
| 84 { | |
| 85 return rhs.type() == TimingFunction::LinearFunction; | |
| 86 } | |
| 87 | |
| 88 bool operator==(const CubicBezierTimingFunction& lhs, const TimingFunction& rhs) | |
| 89 { | |
| 90 if (rhs.type() != TimingFunction::CubicBezierFunction) | |
| 91 return false; | |
| 92 | |
| 93 const CubicBezierTimingFunction& ctf = toCubicBezierTimingFunction(rhs); | |
| 94 if ((lhs.subType() == CubicBezierTimingFunction::Custom) && (ctf.subType() =
= CubicBezierTimingFunction::Custom)) | |
| 95 return (lhs.x1() == ctf.x1()) && (lhs.y1() == ctf.y1()) && (lhs.x2() ==
ctf.x2()) && (lhs.y2() == ctf.y2()); | |
| 96 | |
| 97 return lhs.subType() == ctf.subType(); | |
| 98 } | |
| 99 | |
| 100 bool operator==(const StepsTimingFunction& lhs, const TimingFunction& rhs) | |
| 101 { | |
| 102 if (rhs.type() != TimingFunction::StepsFunction) | |
| 103 return false; | |
| 104 | |
| 105 const StepsTimingFunction& stf = toStepsTimingFunction(rhs); | |
| 106 if ((lhs.subType() == StepsTimingFunction::Custom) && (stf.subType() == Step
sTimingFunction::Custom)) | |
| 107 return (lhs.numberOfSteps() == stf.numberOfSteps()) && (lhs.stepAtStart(
) == stf.stepAtStart()); | |
| 108 | |
| 109 return lhs.subType() == stf.subType(); | |
| 110 } | |
| 111 | |
| 112 bool operator==(const ChainedTimingFunction& lhs, const TimingFunction& rhs) | |
| 113 { | |
| 114 return ChainedTimingFunctionTestHelper::equals(lhs, rhs); | |
| 115 } | |
| 116 | |
| 117 // Like in the PrintTo case, the generic operator== *must* come after the | |
| 118 // non-generic operator== otherwise it will end up calling itself. | |
| 119 bool operator==(const TimingFunction& lhs, const TimingFunction& rhs) | |
| 120 { | |
| 121 switch (lhs.type()) { | |
| 122 case TimingFunction::LinearFunction: { | |
| 123 const LinearTimingFunction& linear = toLinearTimingFunction(lhs); | |
| 124 return (linear == rhs); | |
| 125 } | |
| 126 case TimingFunction::CubicBezierFunction: { | |
| 127 const CubicBezierTimingFunction& cubic = toCubicBezierTimingFunction(lhs
); | |
| 128 return (cubic == rhs); | |
| 129 } | |
| 130 case TimingFunction::StepsFunction: { | |
| 131 const StepsTimingFunction& step = toStepsTimingFunction(lhs); | |
| 132 return (step == rhs); | |
| 133 } | |
| 134 case TimingFunction::ChainedFunction: { | |
| 135 const ChainedTimingFunction& chained = toChainedTimingFunction(lhs); | |
| 136 return (chained == rhs); | |
| 137 } | |
| 138 default: | |
| 139 ASSERT_NOT_REACHED(); | |
| 140 } | |
| 141 return false; | |
| 142 } | |
| 143 | |
| 144 // No need to define specific operator!= as they can all come via this function. | |
| 145 bool operator!=(const TimingFunction& lhs, const TimingFunction& rhs) | |
| 146 { | |
| 147 return !(lhs == rhs); | |
| 148 } | |
| 149 | |
| 150 } // namespace WebCore | |
| OLD | NEW |