OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2008 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, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 */ | 19 */ |
20 | 20 |
21 #ifndef SVGTransform_h | 21 #ifndef SVGTransform_h |
22 #define SVGTransform_h | 22 #define SVGTransform_h |
23 | 23 |
24 #include "core/svg/properties/NewSVGProperty.h" | 24 #include "core/svg/properties/SVGProperty.h" |
25 #include "platform/geometry/FloatPoint.h" | 25 #include "platform/geometry/FloatPoint.h" |
26 #include "platform/transforms/AffineTransform.h" | 26 #include "platform/transforms/AffineTransform.h" |
27 #include "wtf/text/WTFString.h" | 27 #include "wtf/text/WTFString.h" |
28 | 28 |
29 namespace WebCore { | 29 namespace WebCore { |
30 | 30 |
31 class FloatSize; | 31 class FloatSize; |
32 class SVGTransformTearOff; | 32 class SVGTransformTearOff; |
33 | 33 |
34 enum SVGTransformType { | 34 enum SVGTransformType { |
35 SVG_TRANSFORM_UNKNOWN = 0, | 35 SVG_TRANSFORM_UNKNOWN = 0, |
36 SVG_TRANSFORM_MATRIX = 1, | 36 SVG_TRANSFORM_MATRIX = 1, |
37 SVG_TRANSFORM_TRANSLATE = 2, | 37 SVG_TRANSFORM_TRANSLATE = 2, |
38 SVG_TRANSFORM_SCALE = 3, | 38 SVG_TRANSFORM_SCALE = 3, |
39 SVG_TRANSFORM_ROTATE = 4, | 39 SVG_TRANSFORM_ROTATE = 4, |
40 SVG_TRANSFORM_SKEWX = 5, | 40 SVG_TRANSFORM_SKEWX = 5, |
41 SVG_TRANSFORM_SKEWY = 6 | 41 SVG_TRANSFORM_SKEWY = 6 |
42 }; | 42 }; |
43 | 43 |
44 class SVGTransform : public NewSVGPropertyBase { | 44 class SVGTransform : public SVGPropertyBase { |
45 public: | 45 public: |
46 typedef SVGTransformTearOff TearOffType; | 46 typedef SVGTransformTearOff TearOffType; |
47 | 47 |
48 enum ConstructionMode { | 48 enum ConstructionMode { |
49 ConstructIdentityTransform, | 49 ConstructIdentityTransform, |
50 ConstructZeroTransform | 50 ConstructZeroTransform |
51 }; | 51 }; |
52 | 52 |
53 static PassRefPtr<SVGTransform> create() | 53 static PassRefPtr<SVGTransform> create() |
54 { | 54 { |
55 return adoptRef(new SVGTransform()); | 55 return adoptRef(new SVGTransform()); |
56 } | 56 } |
57 | 57 |
58 static PassRefPtr<SVGTransform> create(SVGTransformType type, ConstructionMo
de mode = ConstructIdentityTransform) | 58 static PassRefPtr<SVGTransform> create(SVGTransformType type, ConstructionMo
de mode = ConstructIdentityTransform) |
59 { | 59 { |
60 return adoptRef(new SVGTransform(type, mode)); | 60 return adoptRef(new SVGTransform(type, mode)); |
61 } | 61 } |
62 | 62 |
63 static PassRefPtr<SVGTransform> create(const AffineTransform& affineTransfor
m) | 63 static PassRefPtr<SVGTransform> create(const AffineTransform& affineTransfor
m) |
64 { | 64 { |
65 return adoptRef(new SVGTransform(affineTransform)); | 65 return adoptRef(new SVGTransform(affineTransform)); |
66 } | 66 } |
67 | 67 |
68 virtual ~SVGTransform(); | 68 virtual ~SVGTransform(); |
69 | 69 |
70 PassRefPtr<SVGTransform> clone() const; | 70 PassRefPtr<SVGTransform> clone() const; |
71 virtual PassRefPtr<NewSVGPropertyBase> cloneForAnimation(const String&) cons
t OVERRIDE; | 71 virtual PassRefPtr<SVGPropertyBase> cloneForAnimation(const String&) const O
VERRIDE; |
72 | 72 |
73 SVGTransformType transformType() const { return m_transformType; } | 73 SVGTransformType transformType() const { return m_transformType; } |
74 | 74 |
75 const AffineTransform& matrix() const { return m_matrix; } | 75 const AffineTransform& matrix() const { return m_matrix; } |
76 | 76 |
77 // |onMatrixChange| must be called after modifications via |mutableMatrix|. | 77 // |onMatrixChange| must be called after modifications via |mutableMatrix|. |
78 AffineTransform* mutableMatrix() { return &m_matrix; } | 78 AffineTransform* mutableMatrix() { return &m_matrix; } |
79 void onMatrixChange(); | 79 void onMatrixChange(); |
80 | 80 |
81 float angle() const { return m_angle; } | 81 float angle() const { return m_angle; } |
82 FloatPoint rotationCenter() const { return m_center; } | 82 FloatPoint rotationCenter() const { return m_center; } |
83 | 83 |
84 void setMatrix(const AffineTransform&); | 84 void setMatrix(const AffineTransform&); |
85 void setTranslate(float tx, float ty); | 85 void setTranslate(float tx, float ty); |
86 void setScale(float sx, float sy); | 86 void setScale(float sx, float sy); |
87 void setRotate(float angle, float cx, float cy); | 87 void setRotate(float angle, float cx, float cy); |
88 void setSkewX(float angle); | 88 void setSkewX(float angle); |
89 void setSkewY(float angle); | 89 void setSkewY(float angle); |
90 | 90 |
91 // Internal use only (animation system) | 91 // Internal use only (animation system) |
92 FloatPoint translate() const; | 92 FloatPoint translate() const; |
93 FloatSize scale() const; | 93 FloatSize scale() const; |
94 | 94 |
95 bool isValid() const { return m_transformType != SVG_TRANSFORM_UNKNOWN; } | 95 bool isValid() const { return m_transformType != SVG_TRANSFORM_UNKNOWN; } |
96 | 96 |
97 virtual String valueAsString() const OVERRIDE; | 97 virtual String valueAsString() const OVERRIDE; |
98 | 98 |
99 virtual void add(PassRefPtr<NewSVGPropertyBase>, SVGElement*) OVERRIDE; | 99 virtual void add(PassRefPtr<SVGPropertyBase>, SVGElement*) OVERRIDE; |
100 virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage,
unsigned repeatCount, PassRefPtr<NewSVGPropertyBase> from, PassRefPtr<NewSVGProp
ertyBase> to, PassRefPtr<NewSVGPropertyBase> toAtEndOfDurationValue, SVGElement*
contextElement) OVERRIDE; | 100 virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage,
unsigned repeatCount, PassRefPtr<SVGPropertyBase> from, PassRefPtr<SVGPropertyBa
se> to, PassRefPtr<SVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextE
lement) OVERRIDE; |
101 virtual float calculateDistance(PassRefPtr<NewSVGPropertyBase> to, SVGElemen
t* contextElement) OVERRIDE; | 101 virtual float calculateDistance(PassRefPtr<SVGPropertyBase> to, SVGElement*
contextElement) OVERRIDE; |
102 | 102 |
103 static AnimatedPropertyType classType() { return AnimatedTransform; } | 103 static AnimatedPropertyType classType() { return AnimatedTransform; } |
104 | 104 |
105 private: | 105 private: |
106 SVGTransform(); | 106 SVGTransform(); |
107 SVGTransform(SVGTransformType, ConstructionMode); | 107 SVGTransform(SVGTransformType, ConstructionMode); |
108 explicit SVGTransform(const AffineTransform&); | 108 explicit SVGTransform(const AffineTransform&); |
109 SVGTransform(SVGTransformType, float, const FloatPoint&, const AffineTransfo
rm&); | 109 SVGTransform(SVGTransformType, float, const FloatPoint&, const AffineTransfo
rm&); |
110 | 110 |
111 friend bool operator==(const SVGTransform& a, const SVGTransform& b); | 111 friend bool operator==(const SVGTransform& a, const SVGTransform& b); |
112 | 112 |
113 SVGTransformType m_transformType; | 113 SVGTransformType m_transformType; |
114 float m_angle; | 114 float m_angle; |
115 FloatPoint m_center; | 115 FloatPoint m_center; |
116 AffineTransform m_matrix; | 116 AffineTransform m_matrix; |
117 }; | 117 }; |
118 | 118 |
119 inline bool operator==(const SVGTransform& a, const SVGTransform& b) | 119 inline bool operator==(const SVGTransform& a, const SVGTransform& b) |
120 { | 120 { |
121 return a.m_transformType == b.m_transformType && a.m_angle == b.m_angle && a
.m_matrix == b.m_matrix; | 121 return a.m_transformType == b.m_transformType && a.m_angle == b.m_angle && a
.m_matrix == b.m_matrix; |
122 } | 122 } |
123 | 123 |
124 inline bool operator!=(const SVGTransform& a, const SVGTransform& b) | 124 inline bool operator!=(const SVGTransform& a, const SVGTransform& b) |
125 { | 125 { |
126 return !(a == b); | 126 return !(a == b); |
127 } | 127 } |
128 | 128 |
129 inline PassRefPtr<SVGTransform> toSVGTransform(PassRefPtr<NewSVGPropertyBase> pa
ssBase) | 129 inline PassRefPtr<SVGTransform> toSVGTransform(PassRefPtr<SVGPropertyBase> passB
ase) |
130 { | 130 { |
131 RefPtr<NewSVGPropertyBase> base = passBase; | 131 RefPtr<SVGPropertyBase> base = passBase; |
132 ASSERT(base->type() == SVGTransform::classType()); | 132 ASSERT(base->type() == SVGTransform::classType()); |
133 return static_pointer_cast<SVGTransform>(base.release()); | 133 return static_pointer_cast<SVGTransform>(base.release()); |
134 } | 134 } |
135 | 135 |
136 } // namespace WebCore | 136 } // namespace WebCore |
137 | 137 |
138 #endif | 138 #endif |
OLD | NEW |