Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / animation / AnimatableValueTestHelper.cpp
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
33 #include "core/animation/AnimatableValueTestHelper.h"
34
35
36
37 namespace WebCore {
38
39 bool operator==(const AnimatableValue& a, const AnimatableValue& b)
40 {
41     return a.equals(b);
42 }
43
44 void PrintTo(const AnimatableClipPathOperation& animValue, ::std::ostream* os)
45 {
46     *os << "AnimatableClipPathOperation@" << &animValue;
47 }
48
49 void PrintTo(const AnimatableColor& animColor, ::std::ostream* os)
50 {
51     *os << "AnimatableColor("
52         << animColor.color().serialized().utf8().data() << ", "
53         << animColor.visitedLinkColor().serialized().utf8().data() << ")";
54 }
55
56 void PrintTo(const AnimatableDouble& animDouble, ::std::ostream* os)
57 {
58     PrintTo(*(animDouble.toCSSValue().get()), os, "AnimatableDouble");
59 }
60
61 void PrintTo(const AnimatableImage& animImage, ::std::ostream* os)
62 {
63     PrintTo(*(animImage.toCSSValue().get()), os, "AnimatableImage");
64 }
65
66 void PrintTo(const AnimatableLength& animLength, ::std::ostream* os)
67 {
68     PrintTo(*(animLength.toCSSValue().get()), os, "AnimatableLength");
69 }
70
71 void PrintTo(const AnimatableLengthBox& animLengthBox, ::std::ostream* os)
72 {
73     *os << "AnimatableLengthBox(";
74     PrintTo(*(animLengthBox.left()), os);
75     *os << ", ";
76     PrintTo(*(animLengthBox.right()), os);
77     *os << ", ";
78     PrintTo(*(animLengthBox.top()), os);
79     *os << ", ";
80     PrintTo(*(animLengthBox.bottom()), os);
81     *os << ")";
82 }
83
84 void PrintTo(const AnimatableLengthPoint& animLengthPoint, ::std::ostream* os)
85 {
86     *os << "AnimatableLengthPoint(";
87     PrintTo(*(animLengthPoint.x()), os);
88     *os << ", ";
89     PrintTo(*(animLengthPoint.y()), os);
90     *os << ")";
91 }
92
93 void PrintTo(const AnimatableLengthSize& animLengthSize, ::std::ostream* os)
94 {
95     *os << "AnimatableLengthSize(";
96     PrintTo(*(animLengthSize.width()), os);
97     *os << ", ";
98     PrintTo(*(animLengthSize.height()), os);
99     *os << ")";
100 }
101
102 void PrintTo(const AnimatableNeutral& animValue, ::std::ostream* os)
103 {
104     *os << "AnimatableNeutral@" << &animValue;
105 }
106
107 void PrintTo(const AnimatableRepeatable& animValue, ::std::ostream* os)
108 {
109     *os << "AnimatableRepeatable(";
110
111     const Vector<RefPtr<AnimatableValue> > v = animValue.values();
112     for (Vector<RefPtr<AnimatableValue> >::const_iterator it = v.begin(); it != v.end(); ++it) {
113         PrintTo(*(it->get()), os);
114         if (it+1 != v.end())
115             *os << ", ";
116     }
117     *os << ")";
118 }
119
120 void PrintTo(const AnimatableSVGLength& animSVGLength, ::std::ostream* os)
121 {
122     *os << "AnimatableSVGLength("
123         << animSVGLength.toSVGLength()->valueAsString().utf8().data() << ")";
124 }
125
126 void PrintTo(const AnimatableSVGPaint& animSVGPaint, ::std::ostream* os)
127 {
128     *os << "AnimatableSVGPaint(";
129     if (animSVGPaint.paintType() == SVGPaint::SVG_PAINTTYPE_RGBCOLOR)
130         *os << animSVGPaint.color().serialized().utf8().data();
131     else if (animSVGPaint.paintType() == SVGPaint::SVG_PAINTTYPE_URI)
132         *os << "url(" << animSVGPaint.uri().utf8().data() << ")";
133     else
134         *os << animSVGPaint.paintType();
135     *os << ")";
136 }
137
138 void PrintTo(const AnimatableShapeValue& animValue, ::std::ostream* os)
139 {
140     *os << "AnimatableShapeValue@" << &animValue;
141 }
142
143 void PrintTo(const AnimatableStrokeDasharrayList& animValue, ::std::ostream* os)
144 {
145     *os << "AnimatableStrokeDasharrayList(";
146     RefPtr<SVGLengthList> list = animValue.toSVGLengthList();
147     size_t length = list->numberOfItems();
148     for (size_t i = 0; i < length; ++i) {
149         *os << list->at(i)->valueAsString().utf8().data();
150         if (i != length-1)
151             *os << ", ";
152     }
153     *os << ")";
154 }
155
156 void PrintTo(const AnimatableTransform& animTransform, ::std::ostream* os)
157 {
158     TransformOperations ops = animTransform.transformOperations();
159
160     *os << "AnimatableTransform(";
161     // FIXME: TransformOperations should really have it's own pretty-printer
162     // then we could just call that.
163     // FIXME: Output useful names not just the raw matrixes.
164     for (unsigned i = 0; i < ops.size(); i++) {
165         const TransformOperation* op = ops.at(i);
166
167         TransformationMatrix matrix;
168         op->apply(matrix, FloatSize(1.0, 1.0));
169
170         *os << "[";
171         if (matrix.isAffine()) {
172             *os << matrix.a();
173             *os << " " << matrix.b();
174             *os << " " << matrix.c();
175             *os << " " << matrix.d();
176             *os << " " << matrix.e();
177             *os << " " << matrix.f();
178         } else {
179             *os << matrix.m11();
180             *os << " " << matrix.m12();
181             *os << " " << matrix.m13();
182             *os << " " << matrix.m14();
183             *os << " ";
184             *os << " " << matrix.m21();
185             *os << " " << matrix.m22();
186             *os << " " << matrix.m23();
187             *os << " " << matrix.m24();
188             *os << " ";
189             *os << " " << matrix.m31();
190             *os << " " << matrix.m32();
191             *os << " " << matrix.m33();
192             *os << " " << matrix.m34();
193             *os << " ";
194             *os << " " << matrix.m41();
195             *os << " " << matrix.m42();
196             *os << " " << matrix.m43();
197             *os << " " << matrix.m44();
198         }
199         *os << "]";
200         if (i < ops.size() - 1)
201             *os << ", ";
202     }
203     *os << ")";
204 }
205
206 void PrintTo(const AnimatableUnknown& animUnknown, ::std::ostream* os)
207 {
208     PrintTo(*(animUnknown.toCSSValue().get()), os, "AnimatableUnknown");
209 }
210
211 void PrintTo(const AnimatableVisibility& animVisibility, ::std::ostream* os)
212 {
213     *os << "AnimatableVisibility(";
214     switch (animVisibility.visibility()) {
215     case VISIBLE:
216         *os << "VISIBLE";
217         break;
218     case HIDDEN:
219         *os << "HIDDEN";
220         break;
221     case COLLAPSE:
222         *os << "COLLAPSE";
223         break;
224     default:
225         *os << "Unknown Visbilility - update switch in AnimatableValueTestHelper.h";
226     }
227     *os << ")";
228 }
229
230 void PrintTo(const AnimatableValue& animValue, ::std::ostream* os)
231 {
232     if (animValue.isClipPathOperation())
233         PrintTo(*(toAnimatableClipPathOperation(&animValue)), os);
234     else if (animValue.isColor())
235         PrintTo(*(toAnimatableColor(&animValue)), os);
236     else if (animValue.isDouble())
237         PrintTo(*(toAnimatableDouble(&animValue)), os);
238     else if (animValue.isImage())
239         PrintTo(*(toAnimatableImage(&animValue)), os);
240     else if (animValue.isLength())
241         PrintTo(*(toAnimatableLength(&animValue)), os);
242     else if (animValue.isLengthBox())
243         PrintTo(*(toAnimatableLengthBox(&animValue)), os);
244     else if (animValue.isLengthPoint())
245         PrintTo(*(toAnimatableLengthPoint(&animValue)), os);
246     else if (animValue.isLengthSize())
247         PrintTo(*(toAnimatableLengthSize(&animValue)), os);
248     else if (animValue.isNeutral())
249         PrintTo(*(static_cast<const AnimatableNeutral*>(&animValue)), os);
250     else if (animValue.isRepeatable())
251         PrintTo(*(toAnimatableRepeatable(&animValue)), os);
252     else if (animValue.isSVGLength())
253         PrintTo(*(toAnimatableSVGLength(&animValue)), os);
254     else if (animValue.isSVGPaint())
255         PrintTo(*(toAnimatableSVGPaint(&animValue)), os);
256     else if (animValue.isShapeValue())
257         PrintTo(*(toAnimatableShapeValue(&animValue)), os);
258     else if (animValue.isStrokeDasharrayList())
259         PrintTo(*(toAnimatableStrokeDasharrayList(&animValue)), os);
260     else if (animValue.isTransform())
261         PrintTo(*(toAnimatableTransform(&animValue)), os);
262     else if (animValue.isUnknown())
263         PrintTo(*(toAnimatableUnknown(&animValue)), os);
264     else if (animValue.isVisibility())
265         PrintTo(*(toAnimatableVisibility(&animValue)), os);
266     else
267         *os << "Unknown AnimatableValue - update ifelse chain in AnimatableValueTestHelper.h";
268 }
269
270 } // namespace WebCore