/src/mozilla-central/dom/svg/nsSVGTransform.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef MOZILLA_SVGTRANSFORM_H__ |
8 | | #define MOZILLA_SVGTRANSFORM_H__ |
9 | | |
10 | | #include "gfxMatrix.h" |
11 | | #include "mozilla/dom/SVGTransformBinding.h" |
12 | | #include "mozilla/gfx/Matrix.h" |
13 | | #include "nsDebug.h" |
14 | | |
15 | | namespace mozilla { |
16 | | |
17 | | /* |
18 | | * The DOM wrapper class for this class is DOMSVGTransformMatrix. |
19 | | */ |
20 | | class nsSVGTransform |
21 | | { |
22 | | public: |
23 | | // Default ctor initialises to matrix type with identity matrix |
24 | | nsSVGTransform() |
25 | | : mMatrix() // Initialises to identity |
26 | | , mAngle(0.f) |
27 | | , mOriginX(0.f) |
28 | | , mOriginY(0.f) |
29 | | , mType(dom::SVGTransform_Binding::SVG_TRANSFORM_MATRIX) |
30 | 0 | { } |
31 | | |
32 | | explicit nsSVGTransform(const gfxMatrix& aMatrix) |
33 | | : mMatrix(aMatrix) |
34 | | , mAngle(0.f) |
35 | | , mOriginX(0.f) |
36 | | , mOriginY(0.f) |
37 | | , mType(dom::SVGTransform_Binding::SVG_TRANSFORM_MATRIX) |
38 | 0 | { } |
39 | | |
40 | 0 | bool operator==(const nsSVGTransform& rhs) const { |
41 | 0 | return mType == rhs.mType && |
42 | 0 | MatricesEqual(mMatrix, rhs.mMatrix) && |
43 | 0 | mAngle == rhs.mAngle && |
44 | 0 | mOriginX == rhs.mOriginX && |
45 | 0 | mOriginY == rhs.mOriginY; |
46 | 0 | } |
47 | | |
48 | | void GetValueAsString(nsAString& aValue) const; |
49 | | |
50 | 0 | float Angle() const { |
51 | 0 | return mAngle; |
52 | 0 | } |
53 | 0 | void GetRotationOrigin(float& aOriginX, float& aOriginY) const { |
54 | 0 | aOriginX = mOriginX; |
55 | 0 | aOriginY = mOriginY; |
56 | 0 | } |
57 | 0 | uint16_t Type() const { |
58 | 0 | return mType; |
59 | 0 | } |
60 | | |
61 | 0 | const gfxMatrix& GetMatrix() const { return mMatrix; } |
62 | | void SetMatrix(const gfxMatrix& aMatrix); |
63 | | void SetTranslate(float aTx, float aTy); |
64 | | void SetScale(float aSx, float aSy); |
65 | | void SetRotate(float aAngle, float aCx, float aCy); |
66 | | nsresult SetSkewX(float aAngle); |
67 | | nsresult SetSkewY(float aAngle); |
68 | | |
69 | | static bool MatricesEqual(const gfxMatrix& a, const gfxMatrix& b) |
70 | 0 | { |
71 | 0 | return a._11 == b._11 && |
72 | 0 | a._12 == b._12 && |
73 | 0 | a._21 == b._21 && |
74 | 0 | a._22 == b._22 && |
75 | 0 | a._31 == b._31 && |
76 | 0 | a._32 == b._32; |
77 | 0 | } |
78 | | |
79 | | protected: |
80 | | gfxMatrix mMatrix; |
81 | | float mAngle, mOriginX, mOriginY; |
82 | | uint16_t mType; |
83 | | }; |
84 | | |
85 | | /* |
86 | | * A slightly more light-weight version of nsSVGTransform for SMIL animation. |
87 | | * |
88 | | * Storing the parameters in an array (rather than a matrix) also allows simpler |
89 | | * (transform type-agnostic) interpolation and addition. |
90 | | * |
91 | | * The meaning of the mParams array depends on the transform type as follows: |
92 | | * |
93 | | * Type | mParams[0], mParams[1], mParams[2], ... |
94 | | * --------------------+----------------------------------------- |
95 | | * translate | tx, ty |
96 | | * scale | sx, sy |
97 | | * rotate | rotation-angle (in degrees), cx, cy |
98 | | * skewX | skew-angle (in degrees) |
99 | | * skewY | skew-angle (in degrees) |
100 | | * matrix | a, b, c, d, e, f |
101 | | * |
102 | | * The matrix type is never generated by animation code (it is only produced |
103 | | * when the user inserts one via the DOM) and often requires special handling |
104 | | * when we do encounter it. Therefore many users of this class are only |
105 | | * interested in the first three parameters and so we provide a special |
106 | | * constructor for setting those parameters only. |
107 | | */ |
108 | | class SVGTransformSMILData |
109 | | { |
110 | | public: |
111 | | // Number of float-params required in constructor, if constructing one of the |
112 | | // 'simple' transform types (all but matrix type) |
113 | | static const uint32_t NUM_SIMPLE_PARAMS = 3; |
114 | | |
115 | | // Number of float-params required in constructor for matrix type. |
116 | | // This is also the number of params we actually store, regardless of type. |
117 | | static const uint32_t NUM_STORED_PARAMS = 6; |
118 | | |
119 | | explicit SVGTransformSMILData(uint16_t aType) |
120 | | : mTransformType(aType) |
121 | 0 | { |
122 | 0 | MOZ_ASSERT(aType >=dom::SVGTransform_Binding:: SVG_TRANSFORM_MATRIX && |
123 | 0 | aType <= dom::SVGTransform_Binding::SVG_TRANSFORM_SKEWY, |
124 | 0 | "Unexpected transform type"); |
125 | 0 | for (uint32_t i = 0; i < NUM_STORED_PARAMS; ++i) { |
126 | 0 | mParams[i] = 0.f; |
127 | 0 | } |
128 | 0 | } |
129 | | |
130 | | SVGTransformSMILData(uint16_t aType, float (&aParams)[NUM_SIMPLE_PARAMS]) |
131 | | : mTransformType(aType) |
132 | 0 | { |
133 | 0 | MOZ_ASSERT(aType >= dom::SVGTransform_Binding::SVG_TRANSFORM_TRANSLATE && |
134 | 0 | aType <= dom::SVGTransform_Binding::SVG_TRANSFORM_SKEWY, |
135 | 0 | "Expected 'simple' transform type"); |
136 | 0 | for (uint32_t i = 0; i < NUM_SIMPLE_PARAMS; ++i) { |
137 | 0 | mParams[i] = aParams[i]; |
138 | 0 | } |
139 | 0 | for (uint32_t i = NUM_SIMPLE_PARAMS; i < NUM_STORED_PARAMS; ++i) { |
140 | 0 | mParams[i] = 0.f; |
141 | 0 | } |
142 | 0 | } |
143 | | |
144 | | // Conversion to/from a fully-fledged nsSVGTransform |
145 | | explicit SVGTransformSMILData(const nsSVGTransform& aTransform); |
146 | | nsSVGTransform ToSVGTransform() const; |
147 | | |
148 | | bool operator==(const SVGTransformSMILData& aOther) const |
149 | 0 | { |
150 | 0 | if (mTransformType != aOther.mTransformType) |
151 | 0 | return false; |
152 | 0 | |
153 | 0 | for (uint32_t i = 0; i < NUM_STORED_PARAMS; ++i) { |
154 | 0 | if (mParams[i] != aOther.mParams[i]) { |
155 | 0 | return false; |
156 | 0 | } |
157 | 0 | } |
158 | 0 |
|
159 | 0 | return true; |
160 | 0 | } |
161 | | |
162 | | bool operator!=(const SVGTransformSMILData& aOther) const |
163 | 0 | { |
164 | 0 | return !(*this == aOther); |
165 | 0 | } |
166 | | |
167 | | uint16_t mTransformType; |
168 | | float mParams[NUM_STORED_PARAMS]; |
169 | | }; |
170 | | |
171 | | } // namespace mozilla |
172 | | |
173 | | #endif // MOZILLA_SVGTRANSFORM_H__ |