2015-05-03 19:32:37 +00: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 11:12:37 +00: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-25 21:03:26 +00:00
|
|
|
|
2013-01-11 20:30:21 +00:00
|
|
|
#include "mozilla/dom/SVGMatrix.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2011-09-25 21:03:26 +00:00
|
|
|
#include <math.h>
|
2012-12-23 04:54:20 +00:00
|
|
|
#include "mozilla/dom/SVGMatrixBinding.h"
|
2014-10-01 09:26:00 +00:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
2011-09-25 21:03:26 +00:00
|
|
|
|
2012-09-22 19:26:05 +00:00
|
|
|
const double radPerDegree = 2.0 * M_PI / 360.0;
|
2011-09-25 21:03:26 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-01-11 20:30:21 +00:00
|
|
|
namespace dom {
|
2011-09-25 21:03:26 +00:00
|
|
|
|
2014-04-29 08:57:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(SVGMatrix, mTransform)
|
2011-09-25 21:03:26 +00:00
|
|
|
|
2013-03-02 06:08:42 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(SVGMatrix, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(SVGMatrix, Release)
|
2011-09-25 21:03:26 +00:00
|
|
|
|
2013-04-02 19:17:41 +00:00
|
|
|
SVGTransform*
|
2013-01-11 20:30:21 +00:00
|
|
|
SVGMatrix::GetParentObject() const
|
2012-12-23 04:54:20 +00:00
|
|
|
{
|
|
|
|
return mTransform;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
SVGMatrix::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-12-23 04:54:20 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return SVGMatrixBinding::Wrap(aCx, this, aGivenProto);
|
2012-12-23 04:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-11 20:30:21 +00:00
|
|
|
SVGMatrix::SetA(float aA, ErrorResult& rv)
|
2011-09-25 21:03:26 +00:00
|
|
|
{
|
|
|
|
if (IsAnimVal()) {
|
2012-12-23 04:54:20 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2011-09-25 21:03:26 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 02:41:35 +00:00
|
|
|
gfxMatrix mx = GetMatrix();
|
2014-06-17 17:35:51 +00:00
|
|
|
mx._11 = aA;
|
2011-09-25 21:03:26 +00:00
|
|
|
SetMatrix(mx);
|
2012-12-23 04:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-11 20:30:21 +00:00
|
|
|
SVGMatrix::SetB(float aB, ErrorResult& rv)
|
2011-09-25 21:03:26 +00:00
|
|
|
{
|
|
|
|
if (IsAnimVal()) {
|
2012-12-23 04:54:20 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2011-09-25 21:03:26 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 02:41:35 +00:00
|
|
|
gfxMatrix mx = GetMatrix();
|
2014-06-17 17:35:51 +00:00
|
|
|
mx._12 = aB;
|
2011-09-25 21:03:26 +00:00
|
|
|
SetMatrix(mx);
|
2012-12-23 04:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-11 20:30:21 +00:00
|
|
|
SVGMatrix::SetC(float aC, ErrorResult& rv)
|
2011-09-25 21:03:26 +00:00
|
|
|
{
|
|
|
|
if (IsAnimVal()) {
|
2012-12-23 04:54:20 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2011-09-25 21:03:26 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 02:41:35 +00:00
|
|
|
gfxMatrix mx = GetMatrix();
|
2014-06-17 17:35:51 +00:00
|
|
|
mx._21 = aC;
|
2011-09-25 21:03:26 +00:00
|
|
|
SetMatrix(mx);
|
2012-12-23 04:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-11 20:30:21 +00:00
|
|
|
SVGMatrix::SetD(float aD, ErrorResult& rv)
|
2011-09-25 21:03:26 +00:00
|
|
|
{
|
|
|
|
if (IsAnimVal()) {
|
2012-12-23 04:54:20 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2011-09-25 21:03:26 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 02:41:35 +00:00
|
|
|
gfxMatrix mx = GetMatrix();
|
2014-06-17 17:35:51 +00:00
|
|
|
mx._22 = aD;
|
2011-09-25 21:03:26 +00:00
|
|
|
SetMatrix(mx);
|
2012-12-23 04:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-11 20:30:21 +00:00
|
|
|
SVGMatrix::SetE(float aE, ErrorResult& rv)
|
2011-09-25 21:03:26 +00:00
|
|
|
{
|
|
|
|
if (IsAnimVal()) {
|
2012-12-23 04:54:20 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2011-09-25 21:03:26 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 02:41:35 +00:00
|
|
|
gfxMatrix mx = GetMatrix();
|
2014-06-17 17:35:51 +00:00
|
|
|
mx._31 = aE;
|
2011-09-25 21:03:26 +00:00
|
|
|
SetMatrix(mx);
|
2012-12-23 04:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-11 20:30:21 +00:00
|
|
|
SVGMatrix::SetF(float aF, ErrorResult& rv)
|
2011-09-25 21:03:26 +00:00
|
|
|
{
|
|
|
|
if (IsAnimVal()) {
|
2012-12-23 04:54:20 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2011-09-25 21:03:26 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 02:41:35 +00:00
|
|
|
gfxMatrix mx = GetMatrix();
|
2014-06-17 17:35:51 +00:00
|
|
|
mx._32 = aF;
|
2011-09-25 21:03:26 +00:00
|
|
|
SetMatrix(mx);
|
2012-12-23 04:54:20 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 20:30:21 +00:00
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGMatrix::Multiply(SVGMatrix& aMatrix)
|
2012-12-23 04:54:20 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGMatrix> matrix = new SVGMatrix(aMatrix.GetMatrix() * GetMatrix());
|
2012-12-23 04:54:20 +00:00
|
|
|
return matrix.forget();
|
2011-09-25 21:03:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 20:30:21 +00:00
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGMatrix::Inverse(ErrorResult& rv)
|
2012-12-23 04:54:20 +00:00
|
|
|
{
|
2014-07-11 07:06:39 +00:00
|
|
|
gfxMatrix mat = GetMatrix();
|
|
|
|
if (!mat.Invert()) {
|
2013-02-01 09:55:46 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
2012-12-23 04:54:20 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGMatrix> matrix = new SVGMatrix(mat);
|
2012-12-23 04:54:20 +00:00
|
|
|
return matrix.forget();
|
|
|
|
}
|
|
|
|
|
2013-01-11 20:30:21 +00:00
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGMatrix::Translate(float x, float y)
|
2012-12-23 04:54:20 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGMatrix> matrix =
|
2014-03-18 02:41:35 +00:00
|
|
|
new SVGMatrix(gfxMatrix(GetMatrix()).Translate(gfxPoint(x, y)));
|
2012-12-23 04:54:20 +00:00
|
|
|
return matrix.forget();
|
2011-09-25 21:03:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 20:30:21 +00:00
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGMatrix::Scale(float scaleFactor)
|
2012-12-23 04:54:20 +00:00
|
|
|
{
|
|
|
|
return ScaleNonUniform(scaleFactor, scaleFactor);
|
|
|
|
}
|
|
|
|
|
2013-01-11 20:30:21 +00:00
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGMatrix::ScaleNonUniform(float scaleFactorX,
|
|
|
|
float scaleFactorY)
|
2012-12-23 04:54:20 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGMatrix> matrix =
|
2014-03-18 02:41:35 +00:00
|
|
|
new SVGMatrix(gfxMatrix(GetMatrix()).Scale(scaleFactorX, scaleFactorY));
|
2012-12-23 04:54:20 +00:00
|
|
|
return matrix.forget();
|
|
|
|
}
|
|
|
|
|
2013-01-11 20:30:21 +00:00
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGMatrix::Rotate(float angle)
|
2012-12-23 04:54:20 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGMatrix> matrix =
|
2014-03-18 02:41:35 +00:00
|
|
|
new SVGMatrix(gfxMatrix(GetMatrix()).Rotate(angle*radPerDegree));
|
2012-12-23 04:54:20 +00:00
|
|
|
return matrix.forget();
|
|
|
|
}
|
|
|
|
|
2013-01-11 20:30:21 +00:00
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGMatrix::RotateFromVector(float x, float y, ErrorResult& rv)
|
2012-12-23 04:54:20 +00:00
|
|
|
{
|
|
|
|
if (x == 0.0 || y == 0.0) {
|
2013-02-01 09:55:46 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
2012-12-23 04:54:20 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGMatrix> matrix =
|
2014-03-18 02:41:35 +00:00
|
|
|
new SVGMatrix(gfxMatrix(GetMatrix()).Rotate(atan2(y, x)));
|
2012-12-23 04:54:20 +00:00
|
|
|
return matrix.forget();
|
|
|
|
}
|
|
|
|
|
2013-01-11 20:30:21 +00:00
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGMatrix::FlipX()
|
2012-12-23 04:54:20 +00:00
|
|
|
{
|
2014-03-18 02:41:35 +00:00
|
|
|
const gfxMatrix& mx = GetMatrix();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGMatrix> matrix =
|
2014-06-17 17:35:51 +00:00
|
|
|
new SVGMatrix(gfxMatrix(-mx._11, -mx._12, mx._21, mx._22, mx._31, mx._32));
|
2012-12-23 04:54:20 +00:00
|
|
|
return matrix.forget();
|
2011-09-25 21:03:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 20:30:21 +00:00
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGMatrix::FlipY()
|
2012-12-23 04:54:20 +00:00
|
|
|
{
|
2014-03-18 02:41:35 +00:00
|
|
|
const gfxMatrix& mx = GetMatrix();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGMatrix> matrix =
|
2014-06-17 17:35:51 +00:00
|
|
|
new SVGMatrix(gfxMatrix(mx._11, mx._12, -mx._21, -mx._22, mx._31, mx._32));
|
2012-12-23 04:54:20 +00:00
|
|
|
return matrix.forget();
|
|
|
|
}
|
|
|
|
|
2013-01-11 20:30:21 +00:00
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGMatrix::SkewX(float angle, ErrorResult& rv)
|
2011-09-25 21:03:26 +00:00
|
|
|
{
|
|
|
|
double ta = tan( angle*radPerDegree );
|
2014-10-01 09:26:00 +00:00
|
|
|
if (!IsFinite(ta)) {
|
2013-02-01 09:55:46 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
2012-12-23 04:54:20 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2011-09-25 21:03:26 +00:00
|
|
|
|
2014-03-18 02:41:35 +00:00
|
|
|
const gfxMatrix& mx = GetMatrix();
|
2014-06-17 17:35:51 +00:00
|
|
|
gfxMatrix skewMx(mx._11, mx._12,
|
|
|
|
(float) (mx._21 + mx._11*ta), (float) (mx._22 + mx._12*ta),
|
|
|
|
mx._31, mx._32);
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGMatrix> matrix = new SVGMatrix(skewMx);
|
2012-12-23 04:54:20 +00:00
|
|
|
return matrix.forget();
|
2011-09-25 21:03:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 20:30:21 +00:00
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGMatrix::SkewY(float angle, ErrorResult& rv)
|
2012-12-23 04:54:20 +00:00
|
|
|
{
|
2011-09-25 21:03:26 +00:00
|
|
|
double ta = tan( angle*radPerDegree );
|
2014-10-01 09:26:00 +00:00
|
|
|
if (!IsFinite(ta)) {
|
2013-02-01 09:55:46 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
2012-12-23 04:54:20 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2011-09-25 21:03:26 +00:00
|
|
|
|
2014-03-18 02:41:35 +00:00
|
|
|
const gfxMatrix& mx = GetMatrix();
|
2014-06-17 17:35:51 +00:00
|
|
|
gfxMatrix skewMx((float) (mx._11 + mx._21*ta), (float) (mx._12 + mx._22*ta),
|
|
|
|
mx._21, mx._22,
|
|
|
|
mx._31, mx._32);
|
2012-12-23 04:54:20 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGMatrix> matrix = new SVGMatrix(skewMx);
|
2012-12-23 04:54:20 +00:00
|
|
|
return matrix.forget();
|
2011-09-25 21:03:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 20:30:21 +00:00
|
|
|
} // namespace dom
|
2011-09-25 21:03:26 +00:00
|
|
|
} // namespace mozilla
|