2010-12-08 04:15:53 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2010-12-08 04:15:53 -08:00
|
|
|
|
|
|
|
#include "DOMSVGPoint.h"
|
|
|
|
#include "DOMSVGPointList.h"
|
|
|
|
#include "SVGPoint.h"
|
2014-03-18 18:13:18 -07:00
|
|
|
#include "gfx2DGlue.h"
|
2010-12-08 04:15:53 -08:00
|
|
|
#include "nsSVGElement.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2013-01-11 12:30:21 -08:00
|
|
|
#include "mozilla/dom/SVGMatrix.h"
|
2010-12-08 04:15:53 -08:00
|
|
|
|
|
|
|
// See the architecture comment in DOMSVGPointList.h.
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-03-18 18:13:18 -07:00
|
|
|
using namespace mozilla::gfx;
|
2010-12-08 04:15:53 -08:00
|
|
|
|
2013-12-24 14:09:22 -08:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AutoChangePointNotifier
|
|
|
|
// Stack-based helper class to pair calls to WillChangePointList and
|
|
|
|
// DidChangePointList.
|
|
|
|
class MOZ_STACK_CLASS AutoChangePointNotifier
|
|
|
|
{
|
|
|
|
public:
|
2014-08-31 18:08:04 -07:00
|
|
|
explicit AutoChangePointNotifier(DOMSVGPoint* aPoint MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-12-24 14:09:22 -08:00
|
|
|
: mPoint(aPoint)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2013-12-25 00:33:48 -08:00
|
|
|
MOZ_ASSERT(mPoint, "Expecting non-null point");
|
2013-12-24 14:09:22 -08:00
|
|
|
MOZ_ASSERT(mPoint->HasOwner(),
|
|
|
|
"Expecting list to have an owner for notification");
|
|
|
|
mEmptyOrOldValue =
|
|
|
|
mPoint->Element()->WillChangePointList();
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoChangePointNotifier()
|
|
|
|
{
|
|
|
|
mPoint->Element()->DidChangePointList(mEmptyOrOldValue);
|
|
|
|
if (mPoint->mList->AttrIsAnimating()) {
|
|
|
|
mPoint->Element()->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-12-25 00:33:48 -08:00
|
|
|
DOMSVGPoint* const mPoint;
|
2013-12-24 14:09:22 -08:00
|
|
|
nsAttrValue mEmptyOrOldValue;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-22 20:54:19 -08:00
|
|
|
float
|
|
|
|
DOMSVGPoint::X()
|
2010-12-08 04:15:53 -08:00
|
|
|
{
|
|
|
|
if (mIsAnimValItem && HasOwner()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Element()->FlushAnimations(); // May make HasOwner() == false
|
2010-12-08 04:15:53 -08:00
|
|
|
}
|
2012-12-22 20:54:19 -08:00
|
|
|
return HasOwner() ? InternalItem().mX : mPt.mX;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGPoint::SetX(float aX, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
if (mIsAnimValItem || mIsReadonly) {
|
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2010-12-08 04:15:53 -08:00
|
|
|
|
|
|
|
if (HasOwner()) {
|
2012-02-15 15:40:46 -08:00
|
|
|
if (InternalItem().mX == aX) {
|
2012-12-22 20:54:19 -08:00
|
|
|
return;
|
2012-02-15 15:40:46 -08:00
|
|
|
}
|
2013-12-24 14:09:22 -08:00
|
|
|
AutoChangePointNotifier notifier(this);
|
2010-12-08 04:15:53 -08:00
|
|
|
InternalItem().mX = aX;
|
2012-12-22 20:54:19 -08:00
|
|
|
return;
|
2010-12-08 04:15:53 -08:00
|
|
|
}
|
|
|
|
mPt.mX = aX;
|
|
|
|
}
|
|
|
|
|
2012-12-22 20:54:19 -08:00
|
|
|
float
|
|
|
|
DOMSVGPoint::Y()
|
2010-12-08 04:15:53 -08:00
|
|
|
{
|
|
|
|
if (mIsAnimValItem && HasOwner()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Element()->FlushAnimations(); // May make HasOwner() == false
|
2010-12-08 04:15:53 -08:00
|
|
|
}
|
2012-12-22 20:54:19 -08:00
|
|
|
return HasOwner() ? InternalItem().mY : mPt.mY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGPoint::SetY(float aY, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
if (mIsAnimValItem || mIsReadonly) {
|
|
|
|
rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2010-12-08 04:15:53 -08:00
|
|
|
|
|
|
|
if (HasOwner()) {
|
2012-02-15 15:40:46 -08:00
|
|
|
if (InternalItem().mY == aY) {
|
2012-12-22 20:54:19 -08:00
|
|
|
return;
|
2012-02-15 15:40:46 -08:00
|
|
|
}
|
2013-12-24 14:09:22 -08:00
|
|
|
AutoChangePointNotifier notifier(this);
|
2010-12-08 04:15:53 -08:00
|
|
|
InternalItem().mY = aY;
|
2012-12-22 20:54:19 -08:00
|
|
|
return;
|
2010-12-08 04:15:53 -08:00
|
|
|
}
|
|
|
|
mPt.mY = aY;
|
|
|
|
}
|
|
|
|
|
2012-12-22 20:54:20 -08:00
|
|
|
already_AddRefed<nsISVGPoint>
|
2013-01-11 12:30:21 -08:00
|
|
|
DOMSVGPoint::MatrixTransform(dom::SVGMatrix& matrix)
|
2010-12-08 04:15:53 -08:00
|
|
|
{
|
|
|
|
float x = HasOwner() ? InternalItem().mX : mPt.mX;
|
|
|
|
float y = HasOwner() ? InternalItem().mY : mPt.mY;
|
|
|
|
|
2014-03-18 18:13:18 -07:00
|
|
|
Point pt = ToMatrix(matrix.GetMatrix()) * Point(x, y);
|
2012-12-22 20:54:20 -08:00
|
|
|
nsCOMPtr<nsISVGPoint> newPoint = new DOMSVGPoint(pt);
|
2012-12-22 20:54:19 -08:00
|
|
|
return newPoint.forget();
|
|
|
|
}
|