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/. */
7 #ifndef DOM_SVG_SVGTRANSFORM_H_
8 #define DOM_SVG_SVGTRANSFORM_H_
10 #include "gfxMatrix.h"
11 #include "mozilla/dom/SVGTransformBinding.h"
12 #include "mozilla/gfx/Matrix.h"
18 * The DOM wrapper class for this class is DOMSVGTransform.
22 // Default ctor initialises to matrix type with identity matrix
27 mType(dom::SVGTransform_Binding::SVG_TRANSFORM_MATRIX
) {}
29 explicit SVGTransform(const gfxMatrix
& aMatrix
)
34 mType(dom::SVGTransform_Binding::SVG_TRANSFORM_MATRIX
) {}
36 bool operator==(const SVGTransform
& rhs
) const {
37 return mType
== rhs
.mType
&& MatricesEqual(mMatrix
, rhs
.mMatrix
) &&
38 mAngle
== rhs
.mAngle
&& mOriginX
== rhs
.mOriginX
&&
39 mOriginY
== rhs
.mOriginY
;
42 void GetValueAsString(nsAString
& aValue
) const;
44 float Angle() const { return mAngle
; }
45 void GetRotationOrigin(float& aOriginX
, float& aOriginY
) const {
49 uint16_t Type() const { return mType
; }
51 const gfxMatrix
& GetMatrix() const { return mMatrix
; }
52 void SetMatrix(const gfxMatrix
& aMatrix
);
53 void SetTranslate(float aTx
, float aTy
);
54 void SetScale(float aSx
, float aSy
);
55 void SetRotate(float aAngle
, float aCx
, float aCy
);
56 nsresult
SetSkewX(float aAngle
);
57 nsresult
SetSkewY(float aAngle
);
59 static bool MatricesEqual(const gfxMatrix
& a
, const gfxMatrix
& b
) {
60 return a
._11
== b
._11
&& a
._12
== b
._12
&& a
._21
== b
._21
&&
61 a
._22
== b
._22
&& a
._31
== b
._31
&& a
._32
== b
._32
;
66 float mAngle
, mOriginX
, mOriginY
;
71 * A slightly more light-weight version of SVGTransform for SMIL animation.
73 * Storing the parameters in an array (rather than a matrix) also allows simpler
74 * (transform type-agnostic) interpolation and addition.
76 * The meaning of the mParams array depends on the transform type as follows:
78 * Type | mParams[0], mParams[1], mParams[2], ...
79 * --------------------+-----------------------------------------
82 * rotate | rotation-angle (in degrees), cx, cy
83 * skewX | skew-angle (in degrees)
84 * skewY | skew-angle (in degrees)
85 * matrix | a, b, c, d, e, f
87 * The matrix type is never generated by animation code (it is only produced
88 * when the user inserts one via the DOM) and often requires special handling
89 * when we do encounter it. Therefore many users of this class are only
90 * interested in the first three parameters and so we provide a special
91 * constructor for setting those parameters only.
93 class SVGTransformSMILData
{
95 // Number of float-params required in constructor, if constructing one of the
96 // 'simple' transform types (all but matrix type)
97 static const uint32_t NUM_SIMPLE_PARAMS
= 3;
99 // Number of float-params required in constructor for matrix type.
100 // This is also the number of params we actually store, regardless of type.
101 static const uint32_t NUM_STORED_PARAMS
= 6;
103 explicit SVGTransformSMILData(uint16_t aType
) : mTransformType(aType
) {
104 MOZ_ASSERT(aType
>= dom::SVGTransform_Binding::SVG_TRANSFORM_MATRIX
&&
105 aType
<= dom::SVGTransform_Binding::SVG_TRANSFORM_SKEWY
,
106 "Unexpected transform type");
107 for (uint32_t i
= 0; i
< NUM_STORED_PARAMS
; ++i
) {
112 SVGTransformSMILData(uint16_t aType
, float (&aParams
)[NUM_SIMPLE_PARAMS
])
113 : mTransformType(aType
) {
114 MOZ_ASSERT(aType
>= dom::SVGTransform_Binding::SVG_TRANSFORM_TRANSLATE
&&
115 aType
<= dom::SVGTransform_Binding::SVG_TRANSFORM_SKEWY
,
116 "Expected 'simple' transform type");
117 for (uint32_t i
= 0; i
< NUM_SIMPLE_PARAMS
; ++i
) {
118 mParams
[i
] = aParams
[i
];
120 for (uint32_t i
= NUM_SIMPLE_PARAMS
; i
< NUM_STORED_PARAMS
; ++i
) {
125 // Conversion to/from a fully-fledged SVGTransform
126 explicit SVGTransformSMILData(const SVGTransform
& aTransform
);
127 SVGTransform
ToSVGTransform() const;
129 bool operator==(const SVGTransformSMILData
& aOther
) const {
130 if (mTransformType
!= aOther
.mTransformType
) return false;
132 for (uint32_t i
= 0; i
< NUM_STORED_PARAMS
; ++i
) {
133 if (mParams
[i
] != aOther
.mParams
[i
]) {
141 bool operator!=(const SVGTransformSMILData
& aOther
) const {
142 return !(*this == aOther
);
145 uint16_t mTransformType
;
146 float mParams
[NUM_STORED_PARAMS
];
149 } // namespace mozilla
151 #endif // DOM_SVG_SVGTRANSFORM_H_