Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGTransform.cpp

Issue 2068053002: Rename Blink constants generated from IDL files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 10 matching lines...) Expand all
21 #include "core/svg/SVGTransform.h" 21 #include "core/svg/SVGTransform.h"
22 22
23 #include "platform/FloatConversion.h" 23 #include "platform/FloatConversion.h"
24 #include "platform/geometry/FloatSize.h" 24 #include "platform/geometry/FloatSize.h"
25 #include "wtf/MathExtras.h" 25 #include "wtf/MathExtras.h"
26 #include "wtf/text/StringBuilder.h" 26 #include "wtf/text/StringBuilder.h"
27 27
28 namespace blink { 28 namespace blink {
29 29
30 SVGTransform::SVGTransform() 30 SVGTransform::SVGTransform()
31 : m_transformType(SVG_TRANSFORM_UNKNOWN) 31 : m_transformType(kSvgTransformUnknown)
32 , m_angle(0) 32 , m_angle(0)
33 { 33 {
34 } 34 }
35 35
36 SVGTransform::SVGTransform(SVGTransformType transformType, ConstructionMode mode ) 36 SVGTransform::SVGTransform(SVGTransformType transformType, ConstructionMode mode )
37 : m_transformType(transformType) 37 : m_transformType(transformType)
38 , m_angle(0) 38 , m_angle(0)
39 { 39 {
40 if (mode == ConstructZeroTransform) 40 if (mode == ConstructZeroTransform)
41 m_matrix = AffineTransform(0, 0, 0, 0, 0, 0); 41 m_matrix = AffineTransform(0, 0, 0, 0, 0, 0);
42 } 42 }
43 43
44 SVGTransform::SVGTransform(const AffineTransform& matrix) 44 SVGTransform::SVGTransform(const AffineTransform& matrix)
45 : m_transformType(SVG_TRANSFORM_MATRIX) 45 : m_transformType(kSvgTransformMatrix)
46 , m_angle(0) 46 , m_angle(0)
47 , m_matrix(matrix) 47 , m_matrix(matrix)
48 { 48 {
49 } 49 }
50 50
51 SVGTransform::SVGTransform(SVGTransformType transformType, float angle, const Fl oatPoint& center, const AffineTransform& matrix) 51 SVGTransform::SVGTransform(SVGTransformType transformType, float angle, const Fl oatPoint& center, const AffineTransform& matrix)
52 : m_transformType(transformType) 52 : m_transformType(transformType)
53 , m_angle(angle) 53 , m_angle(angle)
54 , m_center(center) 54 , m_center(center)
55 , m_matrix(matrix) 55 , m_matrix(matrix)
(...skipping 17 matching lines...) Expand all
73 } 73 }
74 74
75 void SVGTransform::setMatrix(const AffineTransform& matrix) 75 void SVGTransform::setMatrix(const AffineTransform& matrix)
76 { 76 {
77 onMatrixChange(); 77 onMatrixChange();
78 m_matrix = matrix; 78 m_matrix = matrix;
79 } 79 }
80 80
81 void SVGTransform::onMatrixChange() 81 void SVGTransform::onMatrixChange()
82 { 82 {
83 m_transformType = SVG_TRANSFORM_MATRIX; 83 m_transformType = kSvgTransformMatrix;
84 m_angle = 0; 84 m_angle = 0;
85 } 85 }
86 86
87 void SVGTransform::setTranslate(float tx, float ty) 87 void SVGTransform::setTranslate(float tx, float ty)
88 { 88 {
89 m_transformType = SVG_TRANSFORM_TRANSLATE; 89 m_transformType = kSvgTransformTranslate;
90 m_angle = 0; 90 m_angle = 0;
91 91
92 m_matrix.makeIdentity(); 92 m_matrix.makeIdentity();
93 m_matrix.translate(tx, ty); 93 m_matrix.translate(tx, ty);
94 } 94 }
95 95
96 FloatPoint SVGTransform::translate() const 96 FloatPoint SVGTransform::translate() const
97 { 97 {
98 return FloatPoint::narrowPrecision(m_matrix.e(), m_matrix.f()); 98 return FloatPoint::narrowPrecision(m_matrix.e(), m_matrix.f());
99 } 99 }
100 100
101 void SVGTransform::setScale(float sx, float sy) 101 void SVGTransform::setScale(float sx, float sy)
102 { 102 {
103 m_transformType = SVG_TRANSFORM_SCALE; 103 m_transformType = kSvgTransformScale;
104 m_angle = 0; 104 m_angle = 0;
105 m_center = FloatPoint(); 105 m_center = FloatPoint();
106 106
107 m_matrix.makeIdentity(); 107 m_matrix.makeIdentity();
108 m_matrix.scaleNonUniform(sx, sy); 108 m_matrix.scaleNonUniform(sx, sy);
109 } 109 }
110 110
111 FloatSize SVGTransform::scale() const 111 FloatSize SVGTransform::scale() const
112 { 112 {
113 return FloatSize::narrowPrecision(m_matrix.a(), m_matrix.d()); 113 return FloatSize::narrowPrecision(m_matrix.a(), m_matrix.d());
114 } 114 }
115 115
116 void SVGTransform::setRotate(float angle, float cx, float cy) 116 void SVGTransform::setRotate(float angle, float cx, float cy)
117 { 117 {
118 m_transformType = SVG_TRANSFORM_ROTATE; 118 m_transformType = kSvgTransformRotate;
119 m_angle = angle; 119 m_angle = angle;
120 m_center = FloatPoint(cx, cy); 120 m_center = FloatPoint(cx, cy);
121 121
122 // TODO: toString() implementation, which can show cx, cy (need to be stored ?) 122 // TODO: toString() implementation, which can show cx, cy (need to be stored ?)
123 m_matrix.makeIdentity(); 123 m_matrix.makeIdentity();
124 m_matrix.translate(cx, cy); 124 m_matrix.translate(cx, cy);
125 m_matrix.rotate(angle); 125 m_matrix.rotate(angle);
126 m_matrix.translate(-cx, -cy); 126 m_matrix.translate(-cx, -cy);
127 } 127 }
128 128
129 void SVGTransform::setSkewX(float angle) 129 void SVGTransform::setSkewX(float angle)
130 { 130 {
131 m_transformType = SVG_TRANSFORM_SKEWX; 131 m_transformType = kSvgTransformSkewx;
132 m_angle = angle; 132 m_angle = angle;
133 133
134 m_matrix.makeIdentity(); 134 m_matrix.makeIdentity();
135 m_matrix.skewX(angle); 135 m_matrix.skewX(angle);
136 } 136 }
137 137
138 void SVGTransform::setSkewY(float angle) 138 void SVGTransform::setSkewY(float angle)
139 { 139 {
140 m_transformType = SVG_TRANSFORM_SKEWY; 140 m_transformType = kSvgTransformSkewy;
141 m_angle = angle; 141 m_angle = angle;
142 142
143 m_matrix.makeIdentity(); 143 m_matrix.makeIdentity();
144 m_matrix.skewY(angle); 144 m_matrix.skewY(angle);
145 } 145 }
146 146
147 namespace { 147 namespace {
148 148
149 const char* transformTypePrefixForParsing(SVGTransformType type) 149 const char* transformTypePrefixForParsing(SVGTransformType type)
150 { 150 {
151 switch (type) { 151 switch (type) {
152 case SVG_TRANSFORM_UNKNOWN: 152 case kSvgTransformUnknown:
153 return ""; 153 return "";
154 case SVG_TRANSFORM_MATRIX: 154 case kSvgTransformMatrix:
155 return "matrix("; 155 return "matrix(";
156 case SVG_TRANSFORM_TRANSLATE: 156 case kSvgTransformTranslate:
157 return "translate("; 157 return "translate(";
158 case SVG_TRANSFORM_SCALE: 158 case kSvgTransformScale:
159 return "scale("; 159 return "scale(";
160 case SVG_TRANSFORM_ROTATE: 160 case kSvgTransformRotate:
161 return "rotate("; 161 return "rotate(";
162 case SVG_TRANSFORM_SKEWX: 162 case kSvgTransformSkewx:
163 return "skewX("; 163 return "skewX(";
164 case SVG_TRANSFORM_SKEWY: 164 case kSvgTransformSkewy:
165 return "skewY("; 165 return "skewY(";
166 } 166 }
167 ASSERT_NOT_REACHED(); 167 ASSERT_NOT_REACHED();
168 return ""; 168 return "";
169 } 169 }
170 170
171 } // namespace 171 } // namespace
172 172
173 String SVGTransform::valueAsString() const 173 String SVGTransform::valueAsString() const
174 { 174 {
175 double arguments[6]; 175 double arguments[6];
176 size_t argumentCount = 0; 176 size_t argumentCount = 0;
177 switch (m_transformType) { 177 switch (m_transformType) {
178 case SVG_TRANSFORM_UNKNOWN: 178 case kSvgTransformUnknown:
179 return emptyString(); 179 return emptyString();
180 case SVG_TRANSFORM_MATRIX: { 180 case kSvgTransformMatrix: {
181 arguments[argumentCount++] = m_matrix.a(); 181 arguments[argumentCount++] = m_matrix.a();
182 arguments[argumentCount++] = m_matrix.b(); 182 arguments[argumentCount++] = m_matrix.b();
183 arguments[argumentCount++] = m_matrix.c(); 183 arguments[argumentCount++] = m_matrix.c();
184 arguments[argumentCount++] = m_matrix.d(); 184 arguments[argumentCount++] = m_matrix.d();
185 arguments[argumentCount++] = m_matrix.e(); 185 arguments[argumentCount++] = m_matrix.e();
186 arguments[argumentCount++] = m_matrix.f(); 186 arguments[argumentCount++] = m_matrix.f();
187 break; 187 break;
188 } 188 }
189 case SVG_TRANSFORM_TRANSLATE: { 189 case kSvgTransformTranslate: {
190 arguments[argumentCount++] = m_matrix.e(); 190 arguments[argumentCount++] = m_matrix.e();
191 arguments[argumentCount++] = m_matrix.f(); 191 arguments[argumentCount++] = m_matrix.f();
192 break; 192 break;
193 } 193 }
194 case SVG_TRANSFORM_SCALE: { 194 case kSvgTransformScale: {
195 arguments[argumentCount++] = m_matrix.a(); 195 arguments[argumentCount++] = m_matrix.a();
196 arguments[argumentCount++] = m_matrix.d(); 196 arguments[argumentCount++] = m_matrix.d();
197 break; 197 break;
198 } 198 }
199 case SVG_TRANSFORM_ROTATE: { 199 case kSvgTransformRotate: {
200 arguments[argumentCount++] = m_angle; 200 arguments[argumentCount++] = m_angle;
201 201
202 double angleInRad = deg2rad(m_angle); 202 double angleInRad = deg2rad(m_angle);
203 double cosAngle = cos(angleInRad); 203 double cosAngle = cos(angleInRad);
204 double sinAngle = sin(angleInRad); 204 double sinAngle = sin(angleInRad);
205 float cx = narrowPrecisionToFloat(cosAngle != 1 ? (m_matrix.e() * (1 - c osAngle) - m_matrix.f() * sinAngle) / (1 - cosAngle) / 2 : 0); 205 float cx = narrowPrecisionToFloat(cosAngle != 1 ? (m_matrix.e() * (1 - c osAngle) - m_matrix.f() * sinAngle) / (1 - cosAngle) / 2 : 0);
206 float cy = narrowPrecisionToFloat(cosAngle != 1 ? (m_matrix.e() * sinAng le / (1 - cosAngle) + m_matrix.f()) / 2 : 0); 206 float cy = narrowPrecisionToFloat(cosAngle != 1 ? (m_matrix.e() * sinAng le / (1 - cosAngle) + m_matrix.f()) / 2 : 0);
207 if (cx || cy) { 207 if (cx || cy) {
208 arguments[argumentCount++] = cx; 208 arguments[argumentCount++] = cx;
209 arguments[argumentCount++] = cy; 209 arguments[argumentCount++] = cy;
210 } 210 }
211 break; 211 break;
212 } 212 }
213 case SVG_TRANSFORM_SKEWX: 213 case kSvgTransformSkewx:
214 arguments[argumentCount++] = m_angle; 214 arguments[argumentCount++] = m_angle;
215 break; 215 break;
216 case SVG_TRANSFORM_SKEWY: 216 case kSvgTransformSkewy:
217 arguments[argumentCount++] = m_angle; 217 arguments[argumentCount++] = m_angle;
218 break; 218 break;
219 } 219 }
220 ASSERT(argumentCount <= WTF_ARRAY_LENGTH(arguments)); 220 ASSERT(argumentCount <= WTF_ARRAY_LENGTH(arguments));
221 221
222 StringBuilder builder; 222 StringBuilder builder;
223 builder.append(transformTypePrefixForParsing(m_transformType)); 223 builder.append(transformTypePrefixForParsing(m_transformType));
224 224
225 for (size_t i = 0; i < argumentCount; ++i) { 225 for (size_t i = 0; i < argumentCount; ++i) {
226 if (i) 226 if (i)
(...skipping 18 matching lines...) Expand all
245 245
246 float SVGTransform::calculateDistance(SVGPropertyBase*, SVGElement*) 246 float SVGTransform::calculateDistance(SVGPropertyBase*, SVGElement*)
247 { 247 {
248 // SVGTransform is not animated by itself. 248 // SVGTransform is not animated by itself.
249 ASSERT_NOT_REACHED(); 249 ASSERT_NOT_REACHED();
250 250
251 return -1; 251 return -1;
252 } 252 }
253 253
254 } // namespace blink 254 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGTransform.h ('k') | third_party/WebKit/Source/core/svg/SVGTransformDistance.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698