| 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 "core/platform/animation/TimingFunctionTestHelper.h" | |
| 33 | |
| 34 #include <ostream> // NOLINT | |
| 35 | |
| 36 namespace WebCore { | |
| 37 | |
| 38 // This class exists so that ChainedTimingFunction only needs to friend one thin
g. | |
| 39 class ChainedTimingFunctionTestHelper { | |
| 40 static void PrintTo(const ChainedTimingFunction& timingFunction, ::std::ostr
eam* os) | |
| 41 { | |
| 42 // Forward declare the generic PrintTo function as ChainedTimingFunction
needs to call it. | |
| 43 void PrintTo(const TimingFunction&, ::std::ostream*); | |
| 44 | |
| 45 *os << "ChainedTimingFunction@" << &timingFunction << "("; | |
| 46 for (size_t i = 0; i < timingFunction.m_segments.size(); i++) { | |
| 47 ChainedTimingFunction::Segment segment = timingFunction.m_segments[i
]; | |
| 48 PrintTo(*(segment.m_timingFunction.get()), os); | |
| 49 *os << "[" << segment.m_min << " -> " << segment.m_max << "]"; | |
| 50 if (i+1 != timingFunction.m_segments.size()) { | |
| 51 *os << ", "; | |
| 52 } | |
| 53 } | |
| 54 *os << ")"; | |
| 55 } | |
| 56 | |
| 57 static bool equals(const ChainedTimingFunction& lhs, const TimingFunction& r
hs) | |
| 58 { | |
| 59 if (rhs.type() != TimingFunction::ChainedFunction) | |
| 60 return false; | |
| 61 | |
| 62 if (&lhs == &rhs) | |
| 63 return true; | |
| 64 | |
| 65 const ChainedTimingFunction& ctf = toChainedTimingFunction(rhs); | |
| 66 if (lhs.m_segments.size() != ctf.m_segments.size()) | |
| 67 return false; | |
| 68 | |
| 69 for (size_t i = 0; i < lhs.m_segments.size(); i++) { | |
| 70 if (!equals(lhs.m_segments[i], ctf.m_segments[i])) | |
| 71 return false; | |
| 72 } | |
| 73 return true; | |
| 74 } | |
| 75 | |
| 76 static bool equals(const ChainedTimingFunction::Segment& lhs, const ChainedT
imingFunction::Segment& rhs) | |
| 77 { | |
| 78 if (&lhs == &rhs) | |
| 79 return true; | |
| 80 | |
| 81 if ((lhs.m_min != rhs.m_min) || (lhs.m_max != rhs.m_max)) | |
| 82 return false; | |
| 83 | |
| 84 if (lhs.m_timingFunction == rhs.m_timingFunction) | |
| 85 return true; | |
| 86 | |
| 87 ASSERT(lhs.m_timingFunction); | |
| 88 ASSERT(rhs.m_timingFunction); | |
| 89 | |
| 90 return (*(lhs.m_timingFunction.get())) == (*(rhs.m_timingFunction.get())
); | |
| 91 } | |
| 92 | |
| 93 friend void PrintTo(const ChainedTimingFunction&, ::std::ostream*); | |
| 94 friend bool operator==(const ChainedTimingFunction& lhs, const TimingFunctio
n& rhs); | |
| 95 }; | |
| 96 | |
| 97 void PrintTo(const LinearTimingFunction& timingFunction, ::std::ostream* os) | |
| 98 { | |
| 99 *os << "LinearTimingFunction@" << &timingFunction; | |
| 100 } | |
| 101 | |
| 102 void PrintTo(const CubicBezierTimingFunction& timingFunction, ::std::ostream* os
) | |
| 103 { | |
| 104 *os << "CubicBezierTimingFunction@" << &timingFunction << "("; | |
| 105 switch (timingFunction.subType()) { | |
| 106 case CubicBezierTimingFunction::Ease: | |
| 107 *os << "Ease"; | |
| 108 break; | |
| 109 case CubicBezierTimingFunction::EaseIn: | |
| 110 *os << "EaseIn"; | |
| 111 break; | |
| 112 case CubicBezierTimingFunction::EaseOut: | |
| 113 *os << "EaseOut"; | |
| 114 break; | |
| 115 case CubicBezierTimingFunction::EaseInOut: | |
| 116 *os << "EaseInOut"; | |
| 117 break; | |
| 118 case CubicBezierTimingFunction::Custom: | |
| 119 *os << "Custom"; | |
| 120 break; | |
| 121 default: | |
| 122 ASSERT_NOT_REACHED(); | |
| 123 } | |
| 124 *os << ", " << timingFunction.x1(); | |
| 125 *os << ", " << timingFunction.y1(); | |
| 126 *os << ", " << timingFunction.x2(); | |
| 127 *os << ", " << timingFunction.y2(); | |
| 128 *os << ")"; | |
| 129 } | |
| 130 | |
| 131 void PrintTo(const StepsTimingFunction& timingFunction, ::std::ostream* os) | |
| 132 { | |
| 133 *os << "StepsTimingFunction@" << &timingFunction << "("; | |
| 134 switch (timingFunction.subType()) { | |
| 135 case StepsTimingFunction::Start: | |
| 136 *os << "Start"; | |
| 137 break; | |
| 138 case StepsTimingFunction::End: | |
| 139 *os << "End"; | |
| 140 break; | |
| 141 case StepsTimingFunction::Custom: | |
| 142 *os << "Custom"; | |
| 143 break; | |
| 144 default: | |
| 145 ASSERT_NOT_REACHED(); | |
| 146 } | |
| 147 *os << ", " << timingFunction.numberOfSteps(); | |
| 148 *os << ", " << (timingFunction.stepAtStart() ? "true" : "false"); | |
| 149 *os << ")"; | |
| 150 } | |
| 151 | |
| 152 void PrintTo(const ChainedTimingFunction& timingFunction, ::std::ostream* os) | |
| 153 { | |
| 154 ChainedTimingFunctionTestHelper::PrintTo(timingFunction, os); | |
| 155 } | |
| 156 | |
| 157 // The generic PrintTo *must* come after the non-generic PrintTo otherwise it | |
| 158 // will end up calling itself. | |
| 159 void PrintTo(const TimingFunction& timingFunction, ::std::ostream* os) | |
| 160 { | |
| 161 switch (timingFunction.type()) { | |
| 162 case TimingFunction::LinearFunction: { | |
| 163 const LinearTimingFunction& linear = toLinearTimingFunction(timingFuncti
on); | |
| 164 PrintTo(linear, os); | |
| 165 return; | |
| 166 } | |
| 167 case TimingFunction::CubicBezierFunction: { | |
| 168 const CubicBezierTimingFunction& cubic = toCubicBezierTimingFunction(tim
ingFunction); | |
| 169 PrintTo(cubic, os); | |
| 170 return; | |
| 171 } | |
| 172 case TimingFunction::StepsFunction: { | |
| 173 const StepsTimingFunction& step = toStepsTimingFunction(timingFunction); | |
| 174 PrintTo(step, os); | |
| 175 return; | |
| 176 } | |
| 177 case TimingFunction::ChainedFunction: { | |
| 178 const ChainedTimingFunction& chained = toChainedTimingFunction(timingFun
ction); | |
| 179 PrintTo(chained, os); | |
| 180 return; | |
| 181 } | |
| 182 default: | |
| 183 ASSERT_NOT_REACHED(); | |
| 184 } | |
| 185 } | |
| 186 | |
| 187 bool operator==(const LinearTimingFunction& lhs, const TimingFunction& rhs) | |
| 188 { | |
| 189 return rhs.type() == TimingFunction::LinearFunction; | |
| 190 } | |
| 191 | |
| 192 bool operator==(const CubicBezierTimingFunction& lhs, const TimingFunction& rhs) | |
| 193 { | |
| 194 if (rhs.type() != TimingFunction::CubicBezierFunction) | |
| 195 return false; | |
| 196 | |
| 197 const CubicBezierTimingFunction& ctf = toCubicBezierTimingFunction(rhs); | |
| 198 if ((lhs.subType() == CubicBezierTimingFunction::Custom) && (ctf.subType() =
= CubicBezierTimingFunction::Custom)) | |
| 199 return (lhs.x1() == ctf.x1()) && (lhs.y1() == ctf.y1()) && (lhs.x2() ==
ctf.x2()) && (lhs.y2() == ctf.y2()); | |
| 200 | |
| 201 return lhs.subType() == ctf.subType(); | |
| 202 } | |
| 203 | |
| 204 bool operator==(const StepsTimingFunction& lhs, const TimingFunction& rhs) | |
| 205 { | |
| 206 if (rhs.type() != TimingFunction::StepsFunction) | |
| 207 return false; | |
| 208 | |
| 209 const StepsTimingFunction& stf = toStepsTimingFunction(rhs); | |
| 210 if ((lhs.subType() == StepsTimingFunction::Custom) && (stf.subType() == Step
sTimingFunction::Custom)) | |
| 211 return (lhs.numberOfSteps() == stf.numberOfSteps()) && (lhs.stepAtStart(
) == stf.stepAtStart()); | |
| 212 | |
| 213 return lhs.subType() == stf.subType(); | |
| 214 } | |
| 215 | |
| 216 bool operator==(const ChainedTimingFunction& lhs, const TimingFunction& rhs) | |
| 217 { | |
| 218 return ChainedTimingFunctionTestHelper::equals(lhs, rhs); | |
| 219 } | |
| 220 | |
| 221 // Like in the PrintTo case, the generic operator== *must* come after the | |
| 222 // non-generic operator== otherwise it will end up calling itself. | |
| 223 bool operator==(const TimingFunction& lhs, const TimingFunction& rhs) | |
| 224 { | |
| 225 switch (lhs.type()) { | |
| 226 case TimingFunction::LinearFunction: { | |
| 227 const LinearTimingFunction& linear = toLinearTimingFunction(lhs); | |
| 228 return (linear == rhs); | |
| 229 } | |
| 230 case TimingFunction::CubicBezierFunction: { | |
| 231 const CubicBezierTimingFunction& cubic = toCubicBezierTimingFunction(lhs
); | |
| 232 return (cubic == rhs); | |
| 233 } | |
| 234 case TimingFunction::StepsFunction: { | |
| 235 const StepsTimingFunction& step = toStepsTimingFunction(lhs); | |
| 236 return (step == rhs); | |
| 237 } | |
| 238 case TimingFunction::ChainedFunction: { | |
| 239 const ChainedTimingFunction& chained = toChainedTimingFunction(lhs); | |
| 240 return (chained == rhs); | |
| 241 } | |
| 242 default: | |
| 243 ASSERT_NOT_REACHED(); | |
| 244 } | |
| 245 return false; | |
| 246 } | |
| 247 | |
| 248 // No need to define specific operator!= as they can all come via this function. | |
| 249 bool operator!=(const TimingFunction& lhs, const TimingFunction& rhs) | |
| 250 { | |
| 251 return !(lhs == rhs); | |
| 252 } | |
| 253 | |
| 254 } // namespace WebCore | |
| OLD | NEW |