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
|
|
|
|
2013-04-02 23:17:41 +04:00
|
|
|
#ifndef mozilla_dom_SVGTransform_h
|
|
|
|
#define mozilla_dom_SVGTransform_h
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
#include "DOMSVGTransformList.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsID.h"
|
2013-04-02 23:17:41 +04:00
|
|
|
#include "nsSVGTransform.h"
|
2012-12-23 08:54:20 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
|
|
|
|
class nsSVGElement;
|
|
|
|
|
2014-06-25 15:59:46 +04:00
|
|
|
class gfxMatrix;
|
2011-09-26 01:04:27 +04:00
|
|
|
|
2012-09-23 04:48:27 +04:00
|
|
|
#define MOZ_SVG_LIST_INDEX_BIT_COUNT 31 // supports > 2 billion list items
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-01-12 00:30:21 +04:00
|
|
|
namespace dom {
|
2013-04-02 23:17:41 +04:00
|
|
|
|
2013-01-12 00:30:21 +04:00
|
|
|
class SVGMatrix;
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DOM wrapper for an SVG transform. See DOMSVGLength.h.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class SVGTransform final : public nsWrapperCache
|
2011-09-26 01:04:27 +04:00
|
|
|
{
|
2013-12-25 02:09:22 +04:00
|
|
|
friend class AutoChangeTransformNotifier;
|
|
|
|
|
2011-09-26 01:04:27 +04:00
|
|
|
public:
|
2013-04-02 23:17:41 +04:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(SVGTransform)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(SVGTransform)
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
/**
|
2013-04-02 23:17:41 +04:00
|
|
|
* Generic ctor for SVGTransform objects that are created for an attribute.
|
2011-09-26 01:04:27 +04:00
|
|
|
*/
|
2013-04-02 23:17:41 +04:00
|
|
|
SVGTransform(DOMSVGTransformList *aList,
|
|
|
|
uint32_t aListIndex,
|
|
|
|
bool aIsAnimValItem);
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ctors for creating the objects returned by:
|
|
|
|
* SVGSVGElement.createSVGTransform(),
|
|
|
|
* SVGSVGElement.createSVGTransformFromMatrix(in SVGMatrix matrix),
|
|
|
|
* SVGTransformList.createSVGTransformFromMatrix(in SVGMatrix matrix)
|
|
|
|
* which do not initially belong to an attribute.
|
|
|
|
*/
|
2013-04-02 23:17:41 +04:00
|
|
|
explicit SVGTransform();
|
|
|
|
explicit SVGTransform(const gfxMatrix &aMatrix);
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ctor for creating an unowned copy. Used with Clone().
|
|
|
|
*/
|
2013-04-02 23:17:41 +04:00
|
|
|
explicit SVGTransform(const nsSVGTransform &aMatrix);
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an unowned copy of an owned transform. The caller is responsible for
|
|
|
|
* the first AddRef().
|
|
|
|
*/
|
2013-04-02 23:17:41 +04:00
|
|
|
SVGTransform* Clone() {
|
2011-09-26 01:04:27 +04:00
|
|
|
NS_ASSERTION(mList, "unexpected caller");
|
2013-04-02 23:17:41 +04:00
|
|
|
return new SVGTransform(InternalItem());
|
2011-09-26 01:04:27 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsInList() const {
|
2011-09-26 01:04:27 +04:00
|
|
|
return !!mList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In future, if this class is used for non-list transforms, this will be
|
|
|
|
* different to IsInList().
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasOwner() const {
|
2011-09-26 01:04:27 +04:00
|
|
|
return !!mList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called to notify this DOM object that it is being inserted
|
|
|
|
* into a list, and give it the information it needs as a result.
|
|
|
|
*
|
|
|
|
* This object MUST NOT already belong to a list when this method is called.
|
|
|
|
* That's not to say that script can't move these DOM objects between
|
|
|
|
* lists - it can - it's just that the logic to handle that (and send out
|
|
|
|
* the necessary notifications) is located elsewhere (in
|
|
|
|
* DOMSVGTransformList).)
|
|
|
|
*/
|
|
|
|
void InsertingIntoList(DOMSVGTransformList *aList,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aListIndex,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsAnimValItem);
|
2011-09-26 01:04:27 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t MaxListIndex() {
|
2011-09-26 01:04:27 +04:00
|
|
|
return (1U << MOZ_SVG_LIST_INDEX_BIT_COUNT) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This method is called to notify this object that its list index changed.
|
2012-08-22 19:56:38 +04:00
|
|
|
void UpdateListIndex(uint32_t aListIndex) {
|
2011-09-26 01:04:27 +04:00
|
|
|
mListIndex = aListIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called to notify this DOM object that it is about to be
|
|
|
|
* removed from its current DOM list so that it can first make a copy of its
|
|
|
|
* internal counterpart's values. (If it didn't do this, then it would
|
|
|
|
* "lose" its value on being removed.)
|
|
|
|
*/
|
|
|
|
void RemovingFromList();
|
|
|
|
|
2013-04-02 23:17:41 +04:00
|
|
|
nsSVGTransform ToSVGTransform() const {
|
2011-09-26 01:04:27 +04:00
|
|
|
return Transform();
|
|
|
|
}
|
|
|
|
|
2012-12-23 08:54:20 +04:00
|
|
|
// WebIDL
|
|
|
|
DOMSVGTransformList* GetParentObject() const { return mList; }
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2012-12-23 08:54:20 +04:00
|
|
|
uint16_t Type() const;
|
2014-03-18 06:41:35 +04:00
|
|
|
dom::SVGMatrix* GetMatrix();
|
2012-12-23 08:54:20 +04:00
|
|
|
float Angle() const;
|
2013-01-12 00:30:21 +04:00
|
|
|
void SetMatrix(dom::SVGMatrix& matrix, ErrorResult& rv);
|
2012-12-23 08:54:20 +04:00
|
|
|
void SetTranslate(float tx, float ty, ErrorResult& rv);
|
|
|
|
void SetScale(float sx, float sy, ErrorResult& rv);
|
|
|
|
void SetRotate(float angle, float cx, float cy, ErrorResult& rv);
|
|
|
|
void SetSkewX(float angle, ErrorResult& rv);
|
|
|
|
void SetSkewY(float angle, ErrorResult& rv);
|
|
|
|
|
2011-09-26 01:04:27 +04:00
|
|
|
protected:
|
2014-06-24 20:36:45 +04:00
|
|
|
~SVGTransform();
|
|
|
|
|
2013-01-12 00:30:21 +04:00
|
|
|
// Interface for SVGMatrix's use
|
|
|
|
friend class dom::SVGMatrix;
|
2016-01-06 04:08:45 +03:00
|
|
|
bool IsAnimVal() const {
|
2011-09-26 01:04:27 +04:00
|
|
|
return mIsAnimValItem;
|
|
|
|
}
|
2012-12-23 08:54:20 +04:00
|
|
|
const gfxMatrix& Matrixgfx() const {
|
2014-03-18 06:41:35 +04:00
|
|
|
return Transform().GetMatrix();
|
2011-09-26 01:04:27 +04:00
|
|
|
}
|
|
|
|
void SetMatrix(const gfxMatrix& aMatrix);
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsSVGElement* Element() {
|
|
|
|
return mList->Element();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-02 23:17:41 +04:00
|
|
|
* Get a reference to the internal nsSVGTransform list item that this DOM
|
2011-09-26 01:04:27 +04:00
|
|
|
* wrapper object currently wraps.
|
|
|
|
*/
|
2013-04-02 23:17:41 +04:00
|
|
|
nsSVGTransform& InternalItem();
|
|
|
|
const nsSVGTransform& InternalItem() const;
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IndexIsValid();
|
2011-09-26 01:04:27 +04:00
|
|
|
#endif
|
|
|
|
|
2013-04-02 23:17:41 +04:00
|
|
|
const nsSVGTransform& Transform() const {
|
2011-09-26 01:04:27 +04:00
|
|
|
return HasOwner() ? InternalItem() : *mTransform;
|
|
|
|
}
|
2013-04-02 23:17:41 +04:00
|
|
|
nsSVGTransform& Transform() {
|
2011-09-26 01:04:27 +04:00
|
|
|
return HasOwner() ? InternalItem() : *mTransform;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMSVGTransformList> mList;
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
// Bounds for the following are checked in the ctor, so be sure to update
|
|
|
|
// that if you change the capacity of any of the following.
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mListIndex:MOZ_SVG_LIST_INDEX_BIT_COUNT;
|
2012-09-23 04:48:27 +04:00
|
|
|
uint32_t mIsAnimValItem:1;
|
2011-09-26 01:04:27 +04:00
|
|
|
|
2013-04-02 23:17:41 +04:00
|
|
|
// Usually this class acts as a wrapper for an nsSVGTransform object which is
|
2011-09-26 01:04:27 +04:00
|
|
|
// part of a list and is accessed by going via the owning Element.
|
|
|
|
//
|
|
|
|
// However, in some circumstances, objects of this class may not be associated
|
2013-04-02 23:17:41 +04:00
|
|
|
// with any particular list and thus, no internal nsSVGTransform object. In
|
|
|
|
// that case we allocate an nsSVGTransform object on the heap to store the data.
|
|
|
|
nsAutoPtr<nsSVGTransform> mTransform;
|
2011-09-26 01:04:27 +04:00
|
|
|
};
|
|
|
|
|
2013-04-02 23:17:41 +04:00
|
|
|
} // namespace dom
|
2011-09-26 01:04:27 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#undef MOZ_SVG_LIST_INDEX_BIT_COUNT
|
|
|
|
|
2013-04-02 23:17:41 +04:00
|
|
|
#endif // mozilla_dom_SVGTransform_h
|