2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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-26 01:04:27 +04:00
|
|
|
|
|
|
|
#ifndef MOZILLA_SVGTRANSFORM_H__
|
|
|
|
#define MOZILLA_SVGTRANSFORM_H__
|
|
|
|
|
|
|
|
#include "gfxMatrix.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsDebug.h"
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-12-23 08:54:24 +04: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-26 01:04:27 +04:00
|
|
|
/*
|
|
|
|
* The DOM wrapper class for this class is DOMSVGTransformMatrix.
|
|
|
|
*/
|
2013-04-02 23:17:41 +04:00
|
|
|
class nsSVGTransform
|
2011-09-26 01:04:27 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Default ctor initialises to matrix type with identity matrix
|
2013-04-02 23:17:41 +04:00
|
|
|
nsSVGTransform()
|
2011-09-26 01:04:27 +04:00
|
|
|
: mMatrix() // Initialises to identity
|
|
|
|
, mAngle(0.f)
|
|
|
|
, mOriginX(0.f)
|
|
|
|
, mOriginY(0.f)
|
2012-12-23 08:54:24 +04:00
|
|
|
, mType(SVG_TRANSFORM_MATRIX)
|
2011-09-26 01:04:27 +04:00
|
|
|
{ }
|
|
|
|
|
2014-09-01 05:08:04 +04:00
|
|
|
explicit nsSVGTransform(const gfxMatrix& aMatrix)
|
2011-09-26 01:04:27 +04:00
|
|
|
: mMatrix(aMatrix)
|
|
|
|
, mAngle(0.f)
|
|
|
|
, mOriginX(0.f)
|
|
|
|
, mOriginY(0.f)
|
2012-12-23 08:54:24 +04:00
|
|
|
, mType(SVG_TRANSFORM_MATRIX)
|
2011-09-26 01:04:27 +04:00
|
|
|
{ }
|
|
|
|
|
2013-04-02 23:17:41 +04:00
|
|
|
bool operator==(const nsSVGTransform& rhs) const {
|
2011-09-26 01:04:27 +04: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 19:56:38 +04:00
|
|
|
uint16_t Type() const {
|
2011-09-26 01:04:27 +04:00
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
|
2014-03-18 06:41:35 +04:00
|
|
|
const gfxMatrix& GetMatrix() const { return mMatrix; }
|
2011-09-26 01:04:27 +04:00
|
|
|
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 10:19:26 +04:00
|
|
|
static bool MatricesEqual(const gfxMatrix& a, const gfxMatrix& b)
|
2011-09-26 01:04:27 +04:00
|
|
|
{
|
2014-06-17 21:35:51 +04:00
|
|
|
return a._11 == b._11 &&
|
|
|
|
a._12 == b._12 &&
|
|
|
|
a._21 == b._21 &&
|
|
|
|
a._22 == b._22 &&
|
|
|
|
a._31 == b._31 &&
|
|
|
|
a._32 == b._32;
|
2011-09-26 01:04:27 +04:00
|
|
|
}
|
|
|
|
|
2012-02-16 03:40:46 +04:00
|
|
|
protected:
|
2011-09-26 01:04:27 +04:00
|
|
|
gfxMatrix mMatrix;
|
|
|
|
float mAngle, mOriginX, mOriginY;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mType;
|
2011-09-26 01:04:27 +04:00
|
|
|
};
|
|
|
|
|
2011-09-26 01:04:31 +04:00
|
|
|
/*
|
2013-04-02 23:17:41 +04:00
|
|
|
* A slightly more light-weight version of nsSVGTransform for SMIL animation.
|
2011-09-26 01:04:31 +04:00
|
|
|
*
|
|
|
|
* 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 19:56:38 +04:00
|
|
|
static const uint32_t NUM_SIMPLE_PARAMS = 3;
|
2011-09-26 01:04:31 +04: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 19:56:38 +04:00
|
|
|
static const uint32_t NUM_STORED_PARAMS = 6;
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
explicit SVGTransformSMILData(uint16_t aType)
|
2011-09-26 01:04:31 +04:00
|
|
|
: mTransformType(aType)
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aType >= SVG_TRANSFORM_MATRIX && aType <= SVG_TRANSFORM_SKEWY,
|
|
|
|
"Unexpected transform type");
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < NUM_STORED_PARAMS; ++i) {
|
2011-09-26 01:04:31 +04:00
|
|
|
mParams[i] = 0.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
SVGTransformSMILData(uint16_t aType, float (&aParams)[NUM_SIMPLE_PARAMS])
|
2011-09-26 01:04:31 +04:00
|
|
|
: mTransformType(aType)
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aType >= SVG_TRANSFORM_TRANSLATE && aType <= SVG_TRANSFORM_SKEWY,
|
|
|
|
"Expected 'simple' transform type");
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < NUM_SIMPLE_PARAMS; ++i) {
|
2011-09-26 01:04:31 +04:00
|
|
|
mParams[i] = aParams[i];
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = NUM_SIMPLE_PARAMS; i < NUM_STORED_PARAMS; ++i) {
|
2011-09-26 01:04:31 +04:00
|
|
|
mParams[i] = 0.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-02 23:17:41 +04:00
|
|
|
// Conversion to/from a fully-fledged nsSVGTransform
|
2014-09-01 05:08:04 +04:00
|
|
|
explicit SVGTransformSMILData(const nsSVGTransform& aTransform);
|
2013-04-02 23:17:41 +04:00
|
|
|
nsSVGTransform ToSVGTransform() const;
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool operator==(const SVGTransformSMILData& aOther) const
|
2011-09-26 01:04:31 +04:00
|
|
|
{
|
|
|
|
if (mTransformType != aOther.mTransformType)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < NUM_STORED_PARAMS; ++i) {
|
2011-09-26 01:04:31 +04:00
|
|
|
if (mParams[i] != aOther.mParams[i]) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool operator!=(const SVGTransformSMILData& aOther) const
|
2011-09-26 01:04:31 +04:00
|
|
|
{
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mTransformType;
|
2011-09-26 01:04:31 +04:00
|
|
|
float mParams[NUM_STORED_PARAMS];
|
|
|
|
};
|
|
|
|
|
2011-09-26 01:04:27 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // MOZILLA_SVGTRANSFORM_H__
|