OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 17 matching lines...) Expand all Loading... | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/platform/animation/TimingFunctionTestHelper.h" | 32 #include "core/platform/animation/TimingFunctionTestHelper.h" |
33 | 33 |
34 #include <ostream> // NOLINT | 34 #include <ostream> // NOLINT |
35 | 35 |
36 namespace WebCore { | 36 namespace WebCore { |
37 | 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 = static_cast<const ChainedTimingFuncti on*>(&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 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.
| |
82 if (!minMaxEq) | |
83 return false; | |
84 | |
85 if (lhs.m_timingFunction == rhs.m_timingFunction) | |
86 return true; | |
87 | |
88 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
| |
89 return false; | |
90 | |
91 return (*(lhs.m_timingFunction.get())) == (*(rhs.m_timingFunction.get()) ); | |
92 } | |
93 | |
94 friend void PrintTo(const ChainedTimingFunction&, ::std::ostream*); | |
95 friend bool operator==(const ChainedTimingFunction& lhs, const TimingFunctio n& rhs); | |
96 }; | |
97 | |
98 // 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.
| |
99 // ----------------------------------------------------------------------- | |
38 void PrintTo(const LinearTimingFunction& timingFunction, ::std::ostream* os) | 100 void PrintTo(const LinearTimingFunction& timingFunction, ::std::ostream* os) |
39 { | 101 { |
40 *os << "LinearTimingFunction@" << &timingFunction; | 102 *os << "LinearTimingFunction@" << &timingFunction; |
41 } | 103 } |
42 | 104 |
43 void PrintTo(const CubicBezierTimingFunction& timingFunction, ::std::ostream* os ) | 105 void PrintTo(const CubicBezierTimingFunction& timingFunction, ::std::ostream* os ) |
44 { | 106 { |
45 *os << "CubicBezierTimingFunction@" << &timingFunction << "("; | 107 *os << "CubicBezierTimingFunction@" << &timingFunction << "("; |
46 switch (timingFunction.subType()) { | 108 switch (timingFunction.subType()) { |
47 case CubicBezierTimingFunction::Ease: | 109 case CubicBezierTimingFunction::Ease: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 *os << "Custom"; | 145 *os << "Custom"; |
84 break; | 146 break; |
85 default: | 147 default: |
86 ASSERT_NOT_REACHED(); | 148 ASSERT_NOT_REACHED(); |
87 } | 149 } |
88 *os << ", " << timingFunction.numberOfSteps(); | 150 *os << ", " << timingFunction.numberOfSteps(); |
89 *os << ", " << (timingFunction.stepAtStart() ? "true" : "false"); | 151 *os << ", " << (timingFunction.stepAtStart() ? "true" : "false"); |
90 *os << ")"; | 152 *os << ")"; |
91 } | 153 } |
92 | 154 |
93 class ChainedTimingFunctionPrinter { | |
94 private: | |
95 static void PrintTo(const ChainedTimingFunction& timingFunction, ::std::ostr eam* os) | |
96 { | |
97 // Forward declare the generic PrintTo function as ChainedTimingFunction needs to call it. | |
98 void PrintTo(const TimingFunction&, ::std::ostream*); | |
99 | |
100 *os << "ChainedTimingFunction@" << &timingFunction << "("; | |
101 for (size_t i = 0; i < timingFunction.m_segments.size(); i++) { | |
102 ChainedTimingFunction::Segment segment = timingFunction.m_segments[i ]; | |
103 PrintTo(*(segment.m_timingFunction.get()), os); | |
104 *os << "[" << segment.m_min << " -> " << segment.m_max << "]"; | |
105 if (i+1 != timingFunction.m_segments.size()) { | |
106 *os << ", "; | |
107 } | |
108 } | |
109 *os << ")"; | |
110 } | |
111 | |
112 friend void PrintTo(const ChainedTimingFunction&, ::std::ostream*); | |
113 }; | |
114 | |
115 void PrintTo(const ChainedTimingFunction& timingFunction, ::std::ostream* os) | 155 void PrintTo(const ChainedTimingFunction& timingFunction, ::std::ostream* os) |
116 { | 156 { |
117 ChainedTimingFunctionPrinter::PrintTo(timingFunction, os); | 157 ChainedTimingFunctionTestHelper::PrintTo(timingFunction, os); |
118 } | 158 } |
119 | 159 |
120 // The generic PrintTo *must* come after the non-generic PrintTo otherwise it | 160 // The generic PrintTo *must* come after the non-generic PrintTo otherwise it |
121 // will end up calling itself. | 161 // will end up calling itself. |
122 void PrintTo(const TimingFunction& timingFunction, ::std::ostream* os) | 162 void PrintTo(const TimingFunction& timingFunction, ::std::ostream* os) |
123 { | 163 { |
124 switch (timingFunction.type()) { | 164 switch (timingFunction.type()) { |
125 case TimingFunction::LinearFunction: { | 165 case TimingFunction::LinearFunction: { |
126 const LinearTimingFunction* linear = static_cast<const LinearTimingFunct ion*>(&timingFunction); | 166 const LinearTimingFunction* linear = static_cast<const LinearTimingFunct ion*>(&timingFunction); |
127 PrintTo(*linear, os); | 167 PrintTo(*linear, os); |
(...skipping 12 matching lines...) Expand all Loading... | |
140 case TimingFunction::ChainedFunction: { | 180 case TimingFunction::ChainedFunction: { |
141 const ChainedTimingFunction* chained = static_cast<const ChainedTimingFu nction*>(&timingFunction); | 181 const ChainedTimingFunction* chained = static_cast<const ChainedTimingFu nction*>(&timingFunction); |
142 PrintTo(*chained, os); | 182 PrintTo(*chained, os); |
143 return; | 183 return; |
144 } | 184 } |
145 default: | 185 default: |
146 ASSERT_NOT_REACHED(); | 186 ASSERT_NOT_REACHED(); |
147 } | 187 } |
148 } | 188 } |
149 | 189 |
190 // operator== functions | |
191 // ----------------------------------------------------------------------- | |
192 bool operator==(const LinearTimingFunction& lhs, const TimingFunction& rhs) | |
193 { | |
194 return rhs.type() == TimingFunction::LinearFunction; | |
195 } | |
196 | |
197 bool operator==(const CubicBezierTimingFunction& lhs, const TimingFunction& rhs) | |
198 { | |
199 if (rhs.type() != TimingFunction::CubicBezierFunction) | |
200 return false; | |
201 | |
202 const CubicBezierTimingFunction* ctf = static_cast<const CubicBezierTimingFu nction*>(&rhs); | |
203 if ((lhs.subType() == CubicBezierTimingFunction::Custom) && (ctf->subType() == CubicBezierTimingFunction::Custom)) | |
204 return (lhs.x1() == ctf->x1()) && (lhs.y1() == ctf->y1()) && (lhs.x2() = = ctf->x2()) && (lhs.y2() == ctf->y2()); | |
205 | |
206 return lhs.subType() == ctf->subType(); | |
207 } | |
208 | |
209 bool operator==(const StepsTimingFunction& lhs, const TimingFunction& rhs) | |
210 { | |
211 if (rhs.type() != TimingFunction::StepsFunction) | |
212 return false; | |
213 | |
214 const StepsTimingFunction* stf = static_cast<const StepsTimingFunction*>(&rh s); | |
215 if ((lhs.subType() == StepsTimingFunction::Custom) && (stf->subType() == Ste psTimingFunction::Custom)) | |
216 return (lhs.numberOfSteps() == stf->numberOfSteps()) && (lhs.stepAtStart () == stf->stepAtStart()); | |
217 | |
218 return lhs.subType() == stf->subType(); | |
219 } | |
220 | |
221 bool operator==(const ChainedTimingFunction& lhs, const TimingFunction& rhs) | |
222 { | |
223 return ChainedTimingFunctionTestHelper::equals(lhs, rhs); | |
224 } | |
225 | |
226 // Like in the PrintTo case, the generic operator== *must* come after the | |
227 // non-generic operator== otherwise it will end up calling itself. | |
228 bool operator==(const TimingFunction& lhs, const TimingFunction& rhs) | |
229 { | |
230 switch (lhs.type()) { | |
231 case TimingFunction::LinearFunction: { | |
232 const LinearTimingFunction* linear = static_cast<const LinearTimingFunct ion*>(&lhs); | |
233 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.
| |
234 } | |
235 case TimingFunction::CubicBezierFunction: { | |
236 const CubicBezierTimingFunction* cubic = static_cast<const CubicBezierTi mingFunction*>(&lhs); | |
237 return ((*cubic) == rhs); | |
238 } | |
239 case TimingFunction::StepsFunction: { | |
240 const StepsTimingFunction* step = static_cast<const StepsTimingFunction* >(&lhs); | |
241 return ((*step) == rhs); | |
242 } | |
243 case TimingFunction::ChainedFunction: { | |
244 const ChainedTimingFunction* chained = static_cast<const ChainedTimingFu nction*>(&lhs); | |
245 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
| |
246 } | |
247 default: | |
248 ASSERT_NOT_REACHED(); | |
249 } | |
250 } | |
251 | |
252 // No need to define specific operator!= as they can all come via this function. | |
253 bool operator!=(const TimingFunction& lhs, const TimingFunction& rhs) | |
254 { | |
255 return !(lhs == rhs); | |
256 } | |
257 | |
150 } // namespace WebCore | 258 } // namespace WebCore |
OLD | NEW |