2011-09-25 14:04:27 -07: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 04:12:37 -07: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 14:04:27 -07:00
|
|
|
|
|
|
|
#include "DOMSVGTransform.h"
|
|
|
|
#include "DOMSVGMatrix.h"
|
|
|
|
#include "SVGAnimatedTransformList.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2011-09-25 14:04:27 -07:00
|
|
|
#include <math.h>
|
|
|
|
#include "nsContentUtils.h"
|
2012-09-30 09:40:24 -07:00
|
|
|
#include "nsAttrValueInlines.h"
|
2012-12-22 20:54:20 -08:00
|
|
|
#include "mozilla/dom/SVGTransformBinding.h"
|
2011-09-25 14:04:27 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods:
|
|
|
|
|
|
|
|
// We could use NS_IMPL_CYCLE_COLLECTION_1, except that in Unlink() we need to
|
|
|
|
// clear our list's weak ref to us to be safe. (The other option would be to
|
|
|
|
// not unlink and rely on the breaking of the other edges in the cycle, as
|
|
|
|
// NS_SVG_VAL_IMPL_CYCLE_COLLECTION does.)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(DOMSVGTransform)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGTransform)
|
|
|
|
// We may not belong to a list, so we must null check tmp->mList.
|
|
|
|
if (tmp->mList) {
|
2012-07-30 07:20:58 -07:00
|
|
|
tmp->mList->mItems[tmp->mListIndex] = nullptr;
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mList)
|
2012-12-22 20:54:20 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2011-09-25 14:04:27 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2012-12-22 20:54:20 -08:00
|
|
|
|
2011-09-25 14:04:27 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMSVGTransform)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mList)
|
2012-12-22 20:54:20 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2011-09-25 14:04:27 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2012-12-22 20:54:20 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DOMSVGTransform)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2011-09-25 14:04:27 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGTransform)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGTransform)
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
DOMCI_DATA(SVGTransform, mozilla::DOMSVGTransform)
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGTransform)
|
2012-12-22 20:54:20 -08:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2011-09-25 14:04:27 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(mozilla::DOMSVGTransform)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGTransform)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMSVGTransform)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGTransform)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
2012-12-22 20:54:20 -08:00
|
|
|
JSObject*
|
|
|
|
DOMSVGTransform::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
|
|
|
|
{
|
|
|
|
return mozilla::dom::SVGTransformBinding::Wrap(aCx, aScope, this, aTriedToWrap);
|
|
|
|
}
|
|
|
|
|
2011-09-25 14:04:27 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Ctors:
|
|
|
|
|
|
|
|
DOMSVGTransform::DOMSVGTransform(DOMSVGTransformList *aList,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aListIndex,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsAnimValItem)
|
2011-09-25 14:04:27 -07:00
|
|
|
: mList(aList)
|
|
|
|
, mListIndex(aListIndex)
|
|
|
|
, mIsAnimValItem(aIsAnimValItem)
|
2012-07-30 07:20:58 -07:00
|
|
|
, mTransform(nullptr)
|
|
|
|
, mMatrixTearoff(nullptr)
|
2011-09-25 14:04:27 -07:00
|
|
|
{
|
2012-12-22 20:54:20 -08:00
|
|
|
SetIsDOMBinding();
|
2011-09-25 14:04:27 -07:00
|
|
|
// These shifts are in sync with the members in the header.
|
|
|
|
NS_ABORT_IF_FALSE(aList &&
|
2012-09-22 17:48:27 -07:00
|
|
|
aListIndex <= MaxListIndex(), "bad arg");
|
2011-09-25 14:04:27 -07:00
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(IndexIsValid(), "Bad index for DOMSVGNumber!");
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMSVGTransform::DOMSVGTransform()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mList(nullptr)
|
2011-09-25 14:04:27 -07:00
|
|
|
, mListIndex(0)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mIsAnimValItem(false)
|
2011-09-25 14:04:27 -07:00
|
|
|
, mTransform(new SVGTransform()) // Default ctor for objects not in a list
|
|
|
|
// initialises to matrix type with identity
|
|
|
|
// matrix
|
2012-07-30 07:20:58 -07:00
|
|
|
, mMatrixTearoff(nullptr)
|
2011-09-25 14:04:27 -07:00
|
|
|
{
|
2012-12-22 20:54:20 -08:00
|
|
|
SetIsDOMBinding();
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMSVGTransform::DOMSVGTransform(const gfxMatrix &aMatrix)
|
2012-07-30 07:20:58 -07:00
|
|
|
: mList(nullptr)
|
2011-09-25 14:04:27 -07:00
|
|
|
, mListIndex(0)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mIsAnimValItem(false)
|
2011-09-25 14:04:27 -07:00
|
|
|
, mTransform(new SVGTransform(aMatrix))
|
2012-07-30 07:20:58 -07:00
|
|
|
, mMatrixTearoff(nullptr)
|
2011-09-25 14:04:27 -07:00
|
|
|
{
|
2012-12-22 20:54:20 -08:00
|
|
|
SetIsDOMBinding();
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMSVGTransform::DOMSVGTransform(const SVGTransform &aTransform)
|
2012-07-30 07:20:58 -07:00
|
|
|
: mList(nullptr)
|
2011-09-25 14:04:27 -07:00
|
|
|
, mListIndex(0)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mIsAnimValItem(false)
|
2011-09-25 14:04:27 -07:00
|
|
|
, mTransform(new SVGTransform(aTransform))
|
2012-07-30 07:20:58 -07:00
|
|
|
, mMatrixTearoff(nullptr)
|
2011-09-25 14:04:27 -07:00
|
|
|
{
|
2012-12-22 20:54:20 -08:00
|
|
|
SetIsDOMBinding();
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMSVGTransform methods:
|
|
|
|
|
|
|
|
/* readonly attribute unsigned short type; */
|
2012-12-22 20:54:20 -08:00
|
|
|
uint16_t
|
|
|
|
DOMSVGTransform::Type() const
|
|
|
|
{
|
|
|
|
return Transform().Type();
|
|
|
|
}
|
|
|
|
|
2011-09-25 14:04:27 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
DOMSVGTransform::GetType(uint16_t *aType)
|
2011-09-25 14:04:27 -07:00
|
|
|
{
|
2012-12-22 20:54:20 -08:00
|
|
|
*aType = Type();
|
2011-09-25 14:04:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-22 20:54:20 -08:00
|
|
|
already_AddRefed<DOMSVGMatrix>
|
|
|
|
DOMSVGTransform::Matrix()
|
2011-09-25 14:04:27 -07:00
|
|
|
{
|
|
|
|
if (!mMatrixTearoff) {
|
|
|
|
mMatrixTearoff = new DOMSVGMatrix(*this);
|
|
|
|
}
|
2012-12-22 20:54:20 -08:00
|
|
|
nsRefPtr<DOMSVGMatrix> matrix = mMatrixTearoff;
|
|
|
|
return matrix.forget();
|
|
|
|
}
|
2011-09-25 14:04:27 -07:00
|
|
|
|
2012-12-22 20:54:20 -08:00
|
|
|
/* readonly attribute nsIDOMSVGMatrix matrix; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMSVGTransform::GetMatrix(nsIDOMSVGMatrix * *aMatrix)
|
|
|
|
{
|
|
|
|
*aMatrix = Matrix().get();
|
2011-09-25 14:04:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute float angle; */
|
2012-12-22 20:54:20 -08:00
|
|
|
float
|
|
|
|
DOMSVGTransform::Angle() const
|
|
|
|
{
|
|
|
|
return Transform().Angle();
|
|
|
|
}
|
|
|
|
|
2011-09-25 14:04:27 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMSVGTransform::GetAngle(float *aAngle)
|
|
|
|
{
|
2012-12-22 20:54:20 -08:00
|
|
|
*aAngle = Angle();
|
2011-09-25 14:04:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-22 20:54:20 -08:00
|
|
|
void
|
|
|
|
DOMSVGTransform::SetMatrix(DOMSVGMatrix& aMatrix, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
if (mIsAnimValItem) {
|
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SetMatrix(aMatrix.Matrix());
|
|
|
|
}
|
|
|
|
|
2011-09-25 14:04:27 -07:00
|
|
|
/* void setMatrix (in nsIDOMSVGMatrix matrix); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMSVGTransform::SetMatrix(nsIDOMSVGMatrix *matrix)
|
|
|
|
{
|
|
|
|
nsCOMPtr<DOMSVGMatrix> domMatrix = do_QueryInterface(matrix);
|
|
|
|
if (!domMatrix)
|
|
|
|
return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
|
|
|
|
|
2012-12-22 20:54:20 -08:00
|
|
|
ErrorResult rv;
|
|
|
|
SetMatrix(*domMatrix, rv);
|
|
|
|
return rv.ErrorCode();
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
2012-12-22 20:54:20 -08:00
|
|
|
void
|
|
|
|
DOMSVGTransform::SetTranslate(float tx, float ty, ErrorResult& rv)
|
2011-09-25 14:04:27 -07:00
|
|
|
{
|
|
|
|
if (mIsAnimValItem) {
|
2012-12-22 20:54:20 -08:00
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
2012-02-15 15:40:46 -08:00
|
|
|
if (Transform().Type() == nsIDOMSVGTransform::SVG_TRANSFORM_TRANSLATE &&
|
2012-12-22 20:54:20 -08:00
|
|
|
Matrixgfx().x0 == tx && Matrixgfx().y0 == ty) {
|
|
|
|
return;
|
2012-02-15 15:40:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue = NotifyElementWillChange();
|
2011-09-25 14:04:27 -07:00
|
|
|
Transform().SetTranslate(tx, ty);
|
2012-02-15 15:40:46 -08:00
|
|
|
NotifyElementDidChange(emptyOrOldValue);
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
2012-12-22 20:54:20 -08:00
|
|
|
/* void setTranslate (in float tx, in float ty); */
|
2011-09-25 14:04:27 -07:00
|
|
|
NS_IMETHODIMP
|
2012-12-22 20:54:20 -08:00
|
|
|
DOMSVGTransform::SetTranslate(float tx, float ty)
|
|
|
|
{
|
|
|
|
NS_ENSURE_FINITE2(tx, ty, NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
ErrorResult rv;
|
|
|
|
SetTranslate(tx, ty, rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGTransform::SetScale(float sx, float sy, ErrorResult& rv)
|
2011-09-25 14:04:27 -07:00
|
|
|
{
|
|
|
|
if (mIsAnimValItem) {
|
2012-12-22 20:54:20 -08:00
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
2012-02-15 15:40:46 -08:00
|
|
|
if (Transform().Type() == nsIDOMSVGTransform::SVG_TRANSFORM_SCALE &&
|
2012-12-22 20:54:20 -08:00
|
|
|
Matrixgfx().xx == sx && Matrixgfx().yy == sy) {
|
|
|
|
return;
|
2012-02-15 15:40:46 -08:00
|
|
|
}
|
|
|
|
nsAttrValue emptyOrOldValue = NotifyElementWillChange();
|
2011-09-25 14:04:27 -07:00
|
|
|
Transform().SetScale(sx, sy);
|
2012-02-15 15:40:46 -08:00
|
|
|
NotifyElementDidChange(emptyOrOldValue);
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
2012-12-22 20:54:20 -08:00
|
|
|
/* void setScale (in float sx, in float sy); */
|
2011-09-25 14:04:27 -07:00
|
|
|
NS_IMETHODIMP
|
2012-12-22 20:54:20 -08:00
|
|
|
DOMSVGTransform::SetScale(float sx, float sy)
|
|
|
|
{
|
|
|
|
NS_ENSURE_FINITE2(sx, sy, NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
ErrorResult rv;
|
|
|
|
SetScale(sx, sy, rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGTransform::SetRotate(float angle, float cx, float cy, ErrorResult& rv)
|
2011-09-25 14:04:27 -07:00
|
|
|
{
|
|
|
|
if (mIsAnimValItem) {
|
2012-12-22 20:54:20 -08:00
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
2012-02-15 15:40:46 -08:00
|
|
|
if (Transform().Type() == nsIDOMSVGTransform::SVG_TRANSFORM_ROTATE) {
|
|
|
|
float currentCx, currentCy;
|
|
|
|
Transform().GetRotationOrigin(currentCx, currentCy);
|
|
|
|
if (Transform().Angle() == angle && currentCx == cx && currentCy == cy) {
|
2012-12-22 20:54:20 -08:00
|
|
|
return;
|
2012-02-15 15:40:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue = NotifyElementWillChange();
|
2011-09-25 14:04:27 -07:00
|
|
|
Transform().SetRotate(angle, cx, cy);
|
2012-02-15 15:40:46 -08:00
|
|
|
NotifyElementDidChange(emptyOrOldValue);
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
2012-12-22 20:54:20 -08:00
|
|
|
/* void setRotate (in float angle, in float cx, in float cy); */
|
2011-09-25 14:04:27 -07:00
|
|
|
NS_IMETHODIMP
|
2012-12-22 20:54:20 -08:00
|
|
|
DOMSVGTransform::SetRotate(float angle, float cx, float cy)
|
|
|
|
{
|
|
|
|
NS_ENSURE_FINITE3(angle, cx, cy, NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
ErrorResult rv;
|
|
|
|
SetRotate(angle, cx, cy, rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGTransform::SetSkewX(float angle, ErrorResult& rv)
|
2011-09-25 14:04:27 -07:00
|
|
|
{
|
|
|
|
if (mIsAnimValItem) {
|
2012-12-22 20:54:20 -08:00
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
2012-02-15 15:40:46 -08:00
|
|
|
if (Transform().Type() == nsIDOMSVGTransform::SVG_TRANSFORM_SKEWX &&
|
|
|
|
Transform().Angle() == angle) {
|
2012-12-22 20:54:20 -08:00
|
|
|
return;
|
2012-02-15 15:40:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue = NotifyElementWillChange();
|
2012-12-22 20:54:20 -08:00
|
|
|
nsresult result = Transform().SetSkewX(angle);
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
rv.Throw(result);
|
|
|
|
return;
|
|
|
|
}
|
2012-02-15 15:40:46 -08:00
|
|
|
NotifyElementDidChange(emptyOrOldValue);
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
2012-12-22 20:54:20 -08:00
|
|
|
/* void setSkewX (in float angle); */
|
2011-09-25 14:04:27 -07:00
|
|
|
NS_IMETHODIMP
|
2012-12-22 20:54:20 -08:00
|
|
|
DOMSVGTransform::SetSkewX(float angle)
|
|
|
|
{
|
|
|
|
NS_ENSURE_FINITE(angle, NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
ErrorResult rv;
|
|
|
|
SetSkewX(angle, rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGTransform::SetSkewY(float angle, ErrorResult& rv)
|
2011-09-25 14:04:27 -07:00
|
|
|
{
|
|
|
|
if (mIsAnimValItem) {
|
2012-12-22 20:54:20 -08:00
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
2012-02-15 15:40:46 -08:00
|
|
|
if (Transform().Type() == nsIDOMSVGTransform::SVG_TRANSFORM_SKEWY &&
|
|
|
|
Transform().Angle() == angle) {
|
2012-12-22 20:54:20 -08:00
|
|
|
return;
|
2012-02-15 15:40:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue = NotifyElementWillChange();
|
2012-12-22 20:54:20 -08:00
|
|
|
nsresult result = Transform().SetSkewY(angle);
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
rv.Throw(result);
|
|
|
|
return;
|
|
|
|
}
|
2012-02-15 15:40:46 -08:00
|
|
|
NotifyElementDidChange(emptyOrOldValue);
|
2012-12-22 20:54:20 -08:00
|
|
|
}
|
2011-09-25 14:04:27 -07:00
|
|
|
|
2012-12-22 20:54:20 -08:00
|
|
|
/* void setSkewY (in float angle); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMSVGTransform::SetSkewY(float angle)
|
|
|
|
{
|
|
|
|
NS_ENSURE_FINITE(angle, NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
ErrorResult rv;
|
|
|
|
SetSkewY(angle, rv);
|
|
|
|
return rv.ErrorCode();
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// List management methods:
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGTransform::InsertingIntoList(DOMSVGTransformList *aList,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aListIndex,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsAnimValItem)
|
2011-09-25 14:04:27 -07:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!HasOwner(), "Inserting item that is already in a list");
|
|
|
|
|
|
|
|
mList = aList;
|
|
|
|
mListIndex = aListIndex;
|
|
|
|
mIsAnimValItem = aIsAnimValItem;
|
2012-07-30 07:20:58 -07:00
|
|
|
mTransform = nullptr;
|
2011-09-25 14:04:27 -07:00
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(IndexIsValid(), "Bad index for DOMSVGLength!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGTransform::RemovingFromList()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!mTransform,
|
|
|
|
"Item in list also has another non-list value associated with it");
|
|
|
|
|
|
|
|
mTransform = new SVGTransform(InternalItem());
|
2012-07-30 07:20:58 -07:00
|
|
|
mList = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsAnimValItem = false;
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SVGTransform&
|
|
|
|
DOMSVGTransform::InternalItem()
|
|
|
|
{
|
|
|
|
SVGAnimatedTransformList *alist = Element()->GetAnimatedTransformList();
|
|
|
|
return mIsAnimValItem && alist->mAnimVal ?
|
|
|
|
(*alist->mAnimVal)[mListIndex] :
|
|
|
|
alist->mBaseVal[mListIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
const SVGTransform&
|
|
|
|
DOMSVGTransform::InternalItem() const
|
|
|
|
{
|
|
|
|
return const_cast<DOMSVGTransform *>(this)->InternalItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-09-25 14:04:27 -07:00
|
|
|
DOMSVGTransform::IndexIsValid()
|
|
|
|
{
|
|
|
|
SVGAnimatedTransformList *alist = Element()->GetAnimatedTransformList();
|
|
|
|
return (mIsAnimValItem &&
|
|
|
|
mListIndex < alist->GetAnimValue().Length()) ||
|
|
|
|
(!mIsAnimValItem &&
|
|
|
|
mListIndex < alist->GetBaseValue().Length());
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Interface for DOMSVGMatrix's use
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGTransform::SetMatrix(const gfxMatrix& aMatrix)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!mIsAnimValItem,
|
|
|
|
"Attempting to modify read-only transform");
|
2012-02-15 15:40:46 -08:00
|
|
|
|
|
|
|
if (Transform().Type() == nsIDOMSVGTransform::SVG_TRANSFORM_MATRIX &&
|
2012-12-22 20:54:20 -08:00
|
|
|
SVGTransform::MatricesEqual(Matrixgfx(), aMatrix)) {
|
2012-02-15 15:40:46 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue = NotifyElementWillChange();
|
2011-09-25 14:04:27 -07:00
|
|
|
Transform().SetMatrix(aMatrix);
|
2012-02-15 15:40:46 -08:00
|
|
|
NotifyElementDidChange(emptyOrOldValue);
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGTransform::ClearMatrixTearoff(DOMSVGMatrix* aMatrix)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mMatrixTearoff == aMatrix,
|
|
|
|
"Unexpected matrix pointer to be cleared");
|
2012-07-30 07:20:58 -07:00
|
|
|
mMatrixTearoff = nullptr;
|
2011-09-25 14:04:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation helpers
|
|
|
|
|
|
|
|
void
|
2012-02-15 15:40:46 -08:00
|
|
|
DOMSVGTransform::NotifyElementDidChange(const nsAttrValue& aEmptyOrOldValue)
|
2011-09-25 14:04:27 -07:00
|
|
|
{
|
|
|
|
if (HasOwner()) {
|
2012-02-15 15:40:46 -08:00
|
|
|
Element()->DidChangeTransformList(aEmptyOrOldValue);
|
2011-09-25 14:04:27 -07:00
|
|
|
if (mList->mAList->IsAnimating()) {
|
|
|
|
Element()->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|