2011-09-25 21:04:27 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-09-25 21:04:27 +00:00
|
|
|
|
|
|
|
#ifndef MOZILLA_SVGTRANSFORM_H__
|
|
|
|
#define MOZILLA_SVGTRANSFORM_H__
|
|
|
|
|
|
|
|
#include "gfxMatrix.h"
|
2012-01-26 09:57:21 +00:00
|
|
|
#include "nsDebug.h"
|
2011-09-25 21:04:27 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-12-23 04:54:24 +00:00
|
|
|
// Transform Types
|
|
|
|
static const unsigned short SVG_TRANSFORM_UNKNOWN = 0;
|
|
|
|
static const unsigned short SVG_TRANSFORM_MATRIX = 1;
|
|
|
|
static const unsigned short SVG_TRANSFORM_TRANSLATE = 2;
|
|
|
|
static const unsigned short SVG_TRANSFORM_SCALE = 3;
|
|
|
|
static const unsigned short SVG_TRANSFORM_ROTATE = 4;
|
|
|
|
static const unsigned short SVG_TRANSFORM_SKEWX = 5;
|
|
|
|
static const unsigned short SVG_TRANSFORM_SKEWY = 6;
|
|
|
|
|
2011-09-25 21:04:27 +00:00
|
|
|
/*
|
|
|
|
* The DOM wrapper class for this class is DOMSVGTransformMatrix.
|
|
|
|
*/
|
|
|
|
class SVGTransform
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Default ctor initialises to matrix type with identity matrix
|
|
|
|
SVGTransform()
|
|
|
|
: mMatrix() // Initialises to identity
|
|
|
|
, mAngle(0.f)
|
|
|
|
, mOriginX(0.f)
|
|
|
|
, mOriginY(0.f)
|
2012-12-23 04:54:24 +00:00
|
|
|
, mType(SVG_TRANSFORM_MATRIX)
|
2011-09-25 21:04:27 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
SVGTransform(const gfxMatrix& aMatrix)
|
|
|
|
: mMatrix(aMatrix)
|
|
|
|
, mAngle(0.f)
|
|
|
|
, mOriginX(0.f)
|
|
|
|
, mOriginY(0.f)
|
2012-12-23 04:54:24 +00:00
|
|
|
, mType(SVG_TRANSFORM_MATRIX)
|
2011-09-25 21:04:27 +00:00
|
|
|
{ }
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool operator==(const SVGTransform& rhs) const {
|
2011-09-25 21:04:27 +00:00
|
|
|
return mType == rhs.mType &&
|
|
|
|
MatricesEqual(mMatrix, rhs.mMatrix) &&
|
|
|
|
mAngle == rhs.mAngle &&
|
|
|
|
mOriginX == rhs.mOriginX &&
|
|
|
|
mOriginY == rhs.mOriginY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetValueAsString(nsAString& aValue) const;
|
|
|
|
|
|
|
|
float Angle() const {
|
|
|
|
return mAngle;
|
|
|
|
}
|
|
|
|
void GetRotationOrigin(float& aOriginX, float& aOriginY) const {
|
|
|
|
aOriginX = mOriginX;
|
|
|
|
aOriginY = mOriginY;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t Type() const {
|
2011-09-25 21:04:27 +00:00
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gfxMatrix& Matrix() const { return mMatrix; }
|
|
|
|
void SetMatrix(const gfxMatrix& aMatrix);
|
|
|
|
void SetTranslate(float aTx, float aTy);
|
|
|
|
void SetScale(float aSx, float aSy);
|
|
|
|
void SetRotate(float aAngle, float aCx, float aCy);
|
|
|
|
nsresult SetSkewX(float aAngle);
|
|
|
|
nsresult SetSkewY(float aAngle);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool MatricesEqual(const gfxMatrix& a, const gfxMatrix& b)
|
2011-09-25 21:04:27 +00:00
|
|
|
{
|
|
|
|
return a.xx == b.xx &&
|
|
|
|
a.yx == b.yx &&
|
|
|
|
a.xy == b.xy &&
|
|
|
|
a.yy == b.yy &&
|
|
|
|
a.x0 == b.x0 &&
|
|
|
|
a.y0 == b.y0;
|
|
|
|
}
|
|
|
|
|
2012-02-15 23:40:46 +00:00
|
|
|
protected:
|
2011-09-25 21:04:27 +00:00
|
|
|
gfxMatrix mMatrix;
|
|
|
|
float mAngle, mOriginX, mOriginY;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t mType;
|
2011-09-25 21:04:27 +00:00
|
|
|
};
|
|
|
|
|
2011-09-25 21:04:31 +00:00
|
|
|
/*
|
|
|
|
* A slightly more light-weight version of SVGTransform for SMIL animation.
|
|
|
|
*
|
|
|
|
* Storing the parameters in an array (rather than a matrix) also allows simpler
|
|
|
|
* (transform type-agnostic) interpolation and addition.
|
|
|
|
*
|
|
|
|
* The meaning of the mParams array depends on the transform type as follows:
|
|
|
|
*
|
|
|
|
* Type | mParams[0], mParams[1], mParams[2], ...
|
|
|
|
* --------------------+-----------------------------------------
|
|
|
|
* translate | tx, ty
|
|
|
|
* scale | sx, sy
|
|
|
|
* rotate | rotation-angle (in degrees), cx, cy
|
|
|
|
* skewX | skew-angle (in degrees)
|
|
|
|
* skewY | skew-angle (in degrees)
|
|
|
|
* matrix | a, b, c, d, e, f
|
|
|
|
*
|
|
|
|
* The matrix type is never generated by animation code (it is only produced
|
|
|
|
* when the user inserts one via the DOM) and often requires special handling
|
|
|
|
* when we do encounter it. Therefore many users of this class are only
|
|
|
|
* interested in the first three parameters and so we provide a special
|
|
|
|
* constructor for setting those parameters only.
|
|
|
|
*/
|
|
|
|
class SVGTransformSMILData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Number of float-params required in constructor, if constructing one of the
|
|
|
|
// 'simple' transform types (all but matrix type)
|
2012-08-22 15:56:38 +00:00
|
|
|
static const uint32_t NUM_SIMPLE_PARAMS = 3;
|
2011-09-25 21:04:31 +00:00
|
|
|
|
|
|
|
// Number of float-params required in constructor for matrix type.
|
|
|
|
// This is also the number of params we actually store, regardless of type.
|
2012-08-22 15:56:38 +00:00
|
|
|
static const uint32_t NUM_STORED_PARAMS = 6;
|
2011-09-25 21:04:31 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
explicit SVGTransformSMILData(uint16_t aType)
|
2011-09-25 21:04:31 +00:00
|
|
|
: mTransformType(aType)
|
|
|
|
{
|
2012-12-23 04:54:24 +00:00
|
|
|
NS_ABORT_IF_FALSE(aType >= SVG_TRANSFORM_MATRIX &&
|
|
|
|
aType <= SVG_TRANSFORM_SKEWY,
|
2011-09-25 21:04:31 +00:00
|
|
|
"Unexpected transform type");
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < NUM_STORED_PARAMS; ++i) {
|
2011-09-25 21:04:31 +00:00
|
|
|
mParams[i] = 0.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
SVGTransformSMILData(uint16_t aType, float (&aParams)[NUM_SIMPLE_PARAMS])
|
2011-09-25 21:04:31 +00:00
|
|
|
: mTransformType(aType)
|
|
|
|
{
|
2012-12-23 04:54:24 +00:00
|
|
|
NS_ABORT_IF_FALSE(aType >= SVG_TRANSFORM_TRANSLATE &&
|
|
|
|
aType <= SVG_TRANSFORM_SKEWY,
|
2011-09-25 21:04:31 +00:00
|
|
|
"Expected 'simple' transform type");
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < NUM_SIMPLE_PARAMS; ++i) {
|
2011-09-25 21:04:31 +00:00
|
|
|
mParams[i] = aParams[i];
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = NUM_SIMPLE_PARAMS; i < NUM_STORED_PARAMS; ++i) {
|
2011-09-25 21:04:31 +00:00
|
|
|
mParams[i] = 0.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conversion to/from a fully-fledged SVGTransform
|
|
|
|
SVGTransformSMILData(const SVGTransform& aTransform);
|
|
|
|
SVGTransform ToSVGTransform() const;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool operator==(const SVGTransformSMILData& aOther) const
|
2011-09-25 21:04:31 +00:00
|
|
|
{
|
|
|
|
if (mTransformType != aOther.mTransformType)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-09-25 21:04:31 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < NUM_STORED_PARAMS; ++i) {
|
2011-09-25 21:04:31 +00:00
|
|
|
if (mParams[i] != aOther.mParams[i]) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-09-25 21:04:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2011-09-25 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool operator!=(const SVGTransformSMILData& aOther) const
|
2011-09-25 21:04:31 +00:00
|
|
|
{
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t mTransformType;
|
2011-09-25 21:04:31 +00:00
|
|
|
float mParams[NUM_STORED_PARAMS];
|
|
|
|
};
|
|
|
|
|
2011-09-25 21:04:27 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // MOZILLA_SVGTRANSFORM_H__
|