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