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

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

Issue 153883003: [SVG] SVGAnimatedTransform{,List} migration to new SVG property impl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: haraken review Created 6 years, 10 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 | Annotate | Revision Log
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 11 matching lines...) Expand all
22 #include "core/svg/SVGTransform.h" 22 #include "core/svg/SVGTransform.h"
23 23
24 #include "platform/FloatConversion.h" 24 #include "platform/FloatConversion.h"
25 #include "platform/geometry/FloatSize.h" 25 #include "platform/geometry/FloatSize.h"
26 #include "wtf/MathExtras.h" 26 #include "wtf/MathExtras.h"
27 #include "wtf/text/StringBuilder.h" 27 #include "wtf/text/StringBuilder.h"
28 28
29 namespace WebCore { 29 namespace WebCore {
30 30
31 SVGTransform::SVGTransform() 31 SVGTransform::SVGTransform()
32 : m_type(SVG_TRANSFORM_UNKNOWN) 32 : NewSVGPropertyBase(classType())
33 , m_transformType(SVG_TRANSFORM_UNKNOWN)
33 , m_angle(0) 34 , m_angle(0)
34 { 35 {
35 } 36 }
36 37
37 SVGTransform::SVGTransform(SVGTransformType type, ConstructionMode mode) 38 SVGTransform::SVGTransform(SVGTransformType transformType, ConstructionMode mode )
38 : m_type(type) 39 : NewSVGPropertyBase(classType())
40 , m_transformType(transformType)
39 , m_angle(0) 41 , m_angle(0)
40 { 42 {
41 if (mode == ConstructZeroTransform) 43 if (mode == ConstructZeroTransform)
42 m_matrix = AffineTransform(0, 0, 0, 0, 0, 0); 44 m_matrix = AffineTransform(0, 0, 0, 0, 0, 0);
43 } 45 }
44 46
45 SVGTransform::SVGTransform(const AffineTransform& matrix) 47 SVGTransform::SVGTransform(const AffineTransform& matrix)
46 : m_type(SVG_TRANSFORM_MATRIX) 48 : NewSVGPropertyBase(classType())
49 , m_transformType(SVG_TRANSFORM_MATRIX)
47 , m_angle(0) 50 , m_angle(0)
48 , m_matrix(matrix) 51 , m_matrix(matrix)
49 { 52 {
50 } 53 }
51 54
55 SVGTransform::SVGTransform(SVGTransformType transformType, float angle, const Fl oatPoint& center, const AffineTransform& matrix)
56 : NewSVGPropertyBase(classType())
57 , m_transformType(transformType)
58 , m_angle(angle)
59 , m_center(center)
60 , m_matrix(matrix)
61 {
62 }
63
64 SVGTransform::~SVGTransform()
65 {
66 }
67
68 PassRefPtr<SVGTransform> SVGTransform::clone() const
69 {
70 return adoptRef(new SVGTransform(m_transformType, m_angle, m_center, m_matri x));
71 }
72
73 PassRefPtr<NewSVGPropertyBase> SVGTransform::cloneForAnimation(const String&) co nst
74 {
75 // SVGTransform is never animated.
76 ASSERT_NOT_REACHED();
77 }
78
52 void SVGTransform::setMatrix(const AffineTransform& matrix) 79 void SVGTransform::setMatrix(const AffineTransform& matrix)
53 { 80 {
54 m_type = SVG_TRANSFORM_MATRIX; 81 onMatrixChange();
55 m_angle = 0;
56 m_matrix = matrix; 82 m_matrix = matrix;
57 } 83 }
58 84
59 void SVGTransform::updateSVGMatrix() 85 void SVGTransform::onMatrixChange()
60 { 86 {
61 // The underlying matrix has been changed, alter the transformation type. 87 m_transformType = SVG_TRANSFORM_MATRIX;
62 // Spec: In case the matrix object is changed directly (i.e., without using the methods on the SVGTransform interface itself)
63 // then the type of the SVGTransform changes to SVG_TRANSFORM_MATRIX.
64 m_type = SVG_TRANSFORM_MATRIX;
65 m_angle = 0; 88 m_angle = 0;
66 } 89 }
67 90
68 void SVGTransform::setTranslate(float tx, float ty) 91 void SVGTransform::setTranslate(float tx, float ty)
69 { 92 {
70 m_type = SVG_TRANSFORM_TRANSLATE; 93 m_transformType = SVG_TRANSFORM_TRANSLATE;
71 m_angle = 0; 94 m_angle = 0;
72 95
73 m_matrix.makeIdentity(); 96 m_matrix.makeIdentity();
74 m_matrix.translate(tx, ty); 97 m_matrix.translate(tx, ty);
75 } 98 }
76 99
77 FloatPoint SVGTransform::translate() const 100 FloatPoint SVGTransform::translate() const
78 { 101 {
79 return FloatPoint::narrowPrecision(m_matrix.e(), m_matrix.f()); 102 return FloatPoint::narrowPrecision(m_matrix.e(), m_matrix.f());
80 } 103 }
81 104
82 void SVGTransform::setScale(float sx, float sy) 105 void SVGTransform::setScale(float sx, float sy)
83 { 106 {
84 m_type = SVG_TRANSFORM_SCALE; 107 m_transformType = SVG_TRANSFORM_SCALE;
85 m_angle = 0; 108 m_angle = 0;
86 m_center = FloatPoint(); 109 m_center = FloatPoint();
87 110
88 m_matrix.makeIdentity(); 111 m_matrix.makeIdentity();
89 m_matrix.scaleNonUniform(sx, sy); 112 m_matrix.scaleNonUniform(sx, sy);
90 } 113 }
91 114
92 FloatSize SVGTransform::scale() const 115 FloatSize SVGTransform::scale() const
93 { 116 {
94 return FloatSize::narrowPrecision(m_matrix.a(), m_matrix.d()); 117 return FloatSize::narrowPrecision(m_matrix.a(), m_matrix.d());
95 } 118 }
96 119
97 void SVGTransform::setRotate(float angle, float cx, float cy) 120 void SVGTransform::setRotate(float angle, float cx, float cy)
98 { 121 {
99 m_type = SVG_TRANSFORM_ROTATE; 122 m_transformType = SVG_TRANSFORM_ROTATE;
100 m_angle = angle; 123 m_angle = angle;
101 m_center = FloatPoint(cx, cy); 124 m_center = FloatPoint(cx, cy);
102 125
103 // TODO: toString() implementation, which can show cx, cy (need to be stored ?) 126 // TODO: toString() implementation, which can show cx, cy (need to be stored ?)
104 m_matrix.makeIdentity(); 127 m_matrix.makeIdentity();
105 m_matrix.translate(cx, cy); 128 m_matrix.translate(cx, cy);
106 m_matrix.rotate(angle); 129 m_matrix.rotate(angle);
107 m_matrix.translate(-cx, -cy); 130 m_matrix.translate(-cx, -cy);
108 } 131 }
109 132
110 void SVGTransform::setSkewX(float angle) 133 void SVGTransform::setSkewX(float angle)
111 { 134 {
112 m_type = SVG_TRANSFORM_SKEWX; 135 m_transformType = SVG_TRANSFORM_SKEWX;
113 m_angle = angle; 136 m_angle = angle;
114 137
115 m_matrix.makeIdentity(); 138 m_matrix.makeIdentity();
116 m_matrix.skewX(angle); 139 m_matrix.skewX(angle);
117 } 140 }
118 141
119 void SVGTransform::setSkewY(float angle) 142 void SVGTransform::setSkewY(float angle)
120 { 143 {
121 m_type = SVG_TRANSFORM_SKEWY; 144 m_transformType = SVG_TRANSFORM_SKEWY;
122 m_angle = angle; 145 m_angle = angle;
123 146
124 m_matrix.makeIdentity(); 147 m_matrix.makeIdentity();
125 m_matrix.skewY(angle); 148 m_matrix.skewY(angle);
126 } 149 }
127 150
128 const String& SVGTransform::transformTypePrefixForParsing(SVGTransformType type) 151 namespace {
152
153 const String& transformTypePrefixForParsing(SVGTransformType type)
129 { 154 {
130 switch (type) { 155 switch (type) {
131 case SVG_TRANSFORM_UNKNOWN: 156 case SVG_TRANSFORM_UNKNOWN:
132 return emptyString(); 157 return emptyString();
133 case SVG_TRANSFORM_MATRIX: { 158 case SVG_TRANSFORM_MATRIX: {
134 DEFINE_STATIC_LOCAL(String, matrixString, ("matrix(")); 159 DEFINE_STATIC_LOCAL(String, matrixString, ("matrix("));
135 return matrixString; 160 return matrixString;
136 } 161 }
137 case SVG_TRANSFORM_TRANSLATE: { 162 case SVG_TRANSFORM_TRANSLATE: {
138 DEFINE_STATIC_LOCAL(String, translateString, ("translate(")); 163 DEFINE_STATIC_LOCAL(String, translateString, ("translate("));
(...skipping 14 matching lines...) Expand all
153 case SVG_TRANSFORM_SKEWY: { 178 case SVG_TRANSFORM_SKEWY: {
154 DEFINE_STATIC_LOCAL(String, skewYString, ("skewY(")); 179 DEFINE_STATIC_LOCAL(String, skewYString, ("skewY("));
155 return skewYString; 180 return skewYString;
156 } 181 }
157 } 182 }
158 183
159 ASSERT_NOT_REACHED(); 184 ASSERT_NOT_REACHED();
160 return emptyString(); 185 return emptyString();
161 } 186 }
162 187
188 }
189
163 String SVGTransform::valueAsString() const 190 String SVGTransform::valueAsString() const
164 { 191 {
165 const String& prefix = transformTypePrefixForParsing(m_type); 192 const String& prefix = transformTypePrefixForParsing(m_transformType);
166 switch (m_type) { 193 switch (m_transformType) {
167 case SVG_TRANSFORM_UNKNOWN: 194 case SVG_TRANSFORM_UNKNOWN:
168 return prefix; 195 return prefix;
169 case SVG_TRANSFORM_MATRIX: { 196 case SVG_TRANSFORM_MATRIX: {
170 StringBuilder builder; 197 StringBuilder builder;
171 builder.append(prefix + String::number(m_matrix.a()) + ' ' + String::num ber(m_matrix.b()) + ' ' + String::number(m_matrix.c()) + ' ' + 198 builder.append(prefix + String::number(m_matrix.a()) + ' ' + String::num ber(m_matrix.b()) + ' ' + String::number(m_matrix.c()) + ' ' +
172 String::number(m_matrix.d()) + ' ' + String::number(m_mat rix.e()) + ' ' + String::number(m_matrix.f()) + ')'); 199 String::number(m_matrix.d()) + ' ' + String::number(m_mat rix.e()) + ' ' + String::number(m_matrix.f()) + ')');
173 return builder.toString(); 200 return builder.toString();
174 } 201 }
175 case SVG_TRANSFORM_TRANSLATE: 202 case SVG_TRANSFORM_TRANSLATE:
176 return prefix + String::number(m_matrix.e()) + ' ' + String::number(m_ma trix.f()) + ')'; 203 return prefix + String::number(m_matrix.e()) + ' ' + String::number(m_ma trix.f()) + ')';
(...skipping 12 matching lines...) Expand all
189 case SVG_TRANSFORM_SKEWX: 216 case SVG_TRANSFORM_SKEWX:
190 return prefix + String::number(m_angle) + ')'; 217 return prefix + String::number(m_angle) + ')';
191 case SVG_TRANSFORM_SKEWY: 218 case SVG_TRANSFORM_SKEWY:
192 return prefix + String::number(m_angle) + ')'; 219 return prefix + String::number(m_angle) + ')';
193 } 220 }
194 221
195 ASSERT_NOT_REACHED(); 222 ASSERT_NOT_REACHED();
196 return emptyString(); 223 return emptyString();
197 } 224 }
198 225
226 void SVGTransform::add(PassRefPtr<NewSVGPropertyBase>, SVGElement*)
227 {
228 // SVGTransform is not animated by itself.
229 ASSERT_NOT_REACHED();
230 }
231
232 void SVGTransform::calculateAnimatedValue(SVGAnimationElement*, float, unsigned, PassRefPtr<NewSVGPropertyBase>, PassRefPtr<NewSVGPropertyBase>, PassRefPtr<NewS VGPropertyBase>, SVGElement*)
233 {
234 // SVGTransform is not animated by itself.
235 ASSERT_NOT_REACHED();
236 }
237
238 float SVGTransform::calculateDistance(PassRefPtr<NewSVGPropertyBase>, SVGElement *)
239 {
240 // SVGTransform is not animated by itself.
241 ASSERT_NOT_REACHED();
242
243 return -1;
244 }
245
199 } // namespace WebCore 246 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698