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: */
|
2012-05-21 15:12:37 +04: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 15:15:53 +03:00
|
|
|
|
|
|
|
#include "DOMSVGPoint.h"
|
|
|
|
#include "DOMSVGPointList.h"
|
|
|
|
#include "SVGPoint.h"
|
2014-03-19 05:13:18 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2010-12-08 15:15:53 +03:00
|
|
|
#include "nsSVGElement.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2013-01-12 00:30:21 +04:00
|
|
|
#include "mozilla/dom/SVGMatrix.h"
|
2010-12-08 15:15:53 +03:00
|
|
|
|
|
|
|
// See the architecture comment in DOMSVGPointList.h.
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-03-19 05:13:18 +04:00
|
|
|
using namespace mozilla::gfx;
|
2010-12-08 15:15:53 +03:00
|
|
|
|
2013-12-25 02:09:22 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AutoChangePointNotifier
|
|
|
|
// Stack-based helper class to pair calls to WillChangePointList and
|
|
|
|
// DidChangePointList.
|
2015-09-03 19:15:23 +03:00
|
|
|
class MOZ_RAII AutoChangePointNotifier
|
2013-12-25 02:09:22 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 05:08:04 +04:00
|
|
|
explicit AutoChangePointNotifier(DOMSVGPoint* aPoint MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-12-25 02:09:22 +04:00
|
|
|
: mPoint(aPoint)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2013-12-25 12:33:48 +04:00
|
|
|
MOZ_ASSERT(mPoint, "Expecting non-null point");
|
2013-12-25 02:09:22 +04:00
|
|
|
MOZ_ASSERT(mPoint->HasOwner(),
|
|
|
|
"Expecting list to have an owner for notification");
|
|
|
|
mEmptyOrOldValue =
|
|
|
|
mPoint->Element()->WillChangePointList();
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoChangePointNotifier()
|
|
|
|
{
|
|
|
|
mPoint->Element()->DidChangePointList(mEmptyOrOldValue);
|
2018-11-20 10:01:49 +03:00
|
|
|
// Null check mPoint->mList, since DidChangePointList can run script,
|
|
|
|
// potentially removing mPoint from its list.
|
|
|
|
if (mPoint->mList && mPoint->mList->AttrIsAnimating()) {
|
2013-12-25 02:09:22 +04:00
|
|
|
mPoint->Element()->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-12-25 12:33:48 +04:00
|
|
|
DOMSVGPoint* const mPoint;
|
2013-12-25 02:09:22 +04:00
|
|
|
nsAttrValue mEmptyOrOldValue;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2013-12-25 02:09:22 +04:00
|
|
|
|
2012-12-23 08:54:19 +04:00
|
|
|
float
|
|
|
|
DOMSVGPoint::X()
|
2010-12-08 15:15:53 +03:00
|
|
|
{
|
|
|
|
if (mIsAnimValItem && HasOwner()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
Element()->FlushAnimations(); // May make HasOwner() == false
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
2012-12-23 08:54:19 +04: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 15:15:53 +03:00
|
|
|
|
|
|
|
if (HasOwner()) {
|
2012-02-16 03:40:46 +04:00
|
|
|
if (InternalItem().mX == aX) {
|
2012-12-23 08:54:19 +04:00
|
|
|
return;
|
2012-02-16 03:40:46 +04:00
|
|
|
}
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangePointNotifier notifier(this);
|
2010-12-08 15:15:53 +03:00
|
|
|
InternalItem().mX = aX;
|
2012-12-23 08:54:19 +04:00
|
|
|
return;
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
mPt.mX = aX;
|
|
|
|
}
|
|
|
|
|
2012-12-23 08:54:19 +04:00
|
|
|
float
|
|
|
|
DOMSVGPoint::Y()
|
2010-12-08 15:15:53 +03:00
|
|
|
{
|
|
|
|
if (mIsAnimValItem && HasOwner()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
Element()->FlushAnimations(); // May make HasOwner() == false
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
2012-12-23 08:54:19 +04: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 15:15:53 +03:00
|
|
|
|
|
|
|
if (HasOwner()) {
|
2012-02-16 03:40:46 +04:00
|
|
|
if (InternalItem().mY == aY) {
|
2012-12-23 08:54:19 +04:00
|
|
|
return;
|
2012-02-16 03:40:46 +04:00
|
|
|
}
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangePointNotifier notifier(this);
|
2010-12-08 15:15:53 +03:00
|
|
|
InternalItem().mY = aY;
|
2012-12-23 08:54:19 +04:00
|
|
|
return;
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
mPt.mY = aY;
|
|
|
|
}
|
|
|
|
|
2012-12-23 08:54:20 +04:00
|
|
|
already_AddRefed<nsISVGPoint>
|
2013-01-12 00:30:21 +04:00
|
|
|
DOMSVGPoint::MatrixTransform(dom::SVGMatrix& matrix)
|
2010-12-08 15:15:53 +03:00
|
|
|
{
|
|
|
|
float x = HasOwner() ? InternalItem().mX : mPt.mX;
|
|
|
|
float y = HasOwner() ? InternalItem().mY : mPt.mY;
|
|
|
|
|
2016-09-08 19:26:03 +03:00
|
|
|
Point pt = ToMatrix(matrix.GetMatrix()).TransformPoint(Point(x, y));
|
2012-12-23 08:54:20 +04:00
|
|
|
nsCOMPtr<nsISVGPoint> newPoint = new DOMSVGPoint(pt);
|
2012-12-23 08:54:19 +04:00
|
|
|
return newPoint.forget();
|
|
|
|
}
|