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
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef DOM_SVG_DOMSVGTRANSFORM_H_
|
|
|
|
#define DOM_SVG_DOMSVGTRANSFORM_H_
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
#include "DOMSVGTransformList.h"
|
2017-07-05 18:18:49 +03:00
|
|
|
#include "gfxMatrix.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsID.h"
|
2018-12-29 12:15:40 +03:00
|
|
|
#include "SVGTransform.h"
|
2012-12-23 08:54:20 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2020-02-25 23:03:26 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2012-01-26 13:57:21 +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
|
|
|
|
2020-06-14 10:26:27 +03:00
|
|
|
struct DOMMatrix2DInit;
|
2018-12-21 11:58:14 +03:00
|
|
|
class SVGElement;
|
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.
|
|
|
|
*/
|
2018-12-28 20:20:15 +03:00
|
|
|
class DOMSVGTransform final : public nsWrapperCache {
|
2020-08-03 12:32:36 +03:00
|
|
|
template <class T>
|
|
|
|
friend class AutoChangeTransformListNotifier;
|
2013-12-25 02:09:22 +04:00
|
|
|
|
2011-09-26 01:04:27 +04:00
|
|
|
public:
|
2018-12-28 20:20:15 +03:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMSVGTransform)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DOMSVGTransform)
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
/**
|
2018-12-28 20:20:15 +03:00
|
|
|
* Generic ctor for DOMSVGTransform objects that are created for an attribute.
|
2011-09-26 01:04:27 +04:00
|
|
|
*/
|
2018-12-28 20:20:15 +03:00
|
|
|
DOMSVGTransform(DOMSVGTransformList* aList, uint32_t aListIndex,
|
|
|
|
bool aIsAnimValItem);
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ctors for creating the objects returned by:
|
|
|
|
* SVGSVGElement.createSVGTransform(),
|
2020-06-14 10:26:27 +03:00
|
|
|
* SVGSVGElement.createSVGTransformFromMatrix(in DOMMatrix2DInit matrix),
|
|
|
|
* SVGTransformList.createSVGTransformFromMatrix(in DOMMatrix2DInit matrix)
|
2011-09-26 01:04:27 +04:00
|
|
|
* which do not initially belong to an attribute.
|
|
|
|
*/
|
2020-09-10 19:38:31 +03:00
|
|
|
DOMSVGTransform();
|
2018-12-28 20:20:15 +03:00
|
|
|
explicit DOMSVGTransform(const gfxMatrix& aMatrix);
|
2020-09-10 19:38:31 +03:00
|
|
|
DOMSVGTransform(const DOMMatrix2DInit& aMatrix, ErrorResult& rv);
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ctor for creating an unowned copy. Used with Clone().
|
|
|
|
*/
|
2019-04-27 10:57:50 +03:00
|
|
|
explicit DOMSVGTransform(const SVGTransform& aTransform);
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an unowned copy of an owned transform. The caller is responsible for
|
|
|
|
* the first AddRef().
|
|
|
|
*/
|
2018-12-28 20:20:15 +03:00
|
|
|
DOMSVGTransform* Clone() {
|
2011-09-26 01:04:27 +04:00
|
|
|
NS_ASSERTION(mList, "unexpected caller");
|
2018-12-28 20:20:15 +03:00
|
|
|
return new DOMSVGTransform(InternalItem());
|
2011-09-26 01:04:27 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsInList() const { return !!mList; }
|
2011-09-26 01:04:27 +04:00
|
|
|
|
2020-08-03 12:32:36 +03:00
|
|
|
/**
|
|
|
|
* Returns true if our attribute is animating (in which case our animVal is
|
|
|
|
* not simply a mirror of our baseVal).
|
|
|
|
*/
|
|
|
|
bool IsAnimating() const { return mList && mList->IsAnimating(); }
|
|
|
|
|
2011-09-26 01:04:27 +04:00
|
|
|
/**
|
|
|
|
* 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 { return !!mList; }
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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, 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) { mListIndex = aListIndex; }
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
2018-12-29 12:15:40 +03:00
|
|
|
SVGTransform ToSVGTransform() const { return Transform(); }
|
2011-09-26 01:04:27 +04:00
|
|
|
|
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;
|
2020-06-14 10:26:27 +03:00
|
|
|
void SetMatrix(const DOMMatrix2DInit& 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:
|
2018-12-28 20:20:15 +03:00
|
|
|
~DOMSVGTransform();
|
2014-06-24 20:36:45 +04:00
|
|
|
|
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 { return mIsAnimValItem; }
|
2012-12-23 08:54:20 +04:00
|
|
|
const gfxMatrix& Matrixgfx() const { return Transform().GetMatrix(); }
|
2011-09-26 01:04:27 +04:00
|
|
|
void SetMatrix(const gfxMatrix& aMatrix);
|
|
|
|
|
|
|
|
private:
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* Element() { return mList->Element(); }
|
2011-09-26 01:04:27 +04:00
|
|
|
|
|
|
|
/**
|
2018-12-29 12:15:40 +03:00
|
|
|
* Get a reference to the internal SVGTransform list item that this DOM
|
2011-09-26 01:04:27 +04:00
|
|
|
* wrapper object currently wraps.
|
|
|
|
*/
|
2018-12-29 12:15:40 +03:00
|
|
|
SVGTransform& InternalItem();
|
|
|
|
const SVGTransform& 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
|
|
|
|
|
2018-12-29 12:15:40 +03:00
|
|
|
const SVGTransform& Transform() const {
|
2011-09-26 01:04:27 +04:00
|
|
|
return HasOwner() ? InternalItem() : *mTransform;
|
|
|
|
}
|
2018-12-29 12:15:40 +03:00
|
|
|
SVGTransform& 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
|
|
|
|
2018-12-29 12:15:40 +03:00
|
|
|
// Usually this class acts as a wrapper for an SVGTransform 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
|
2018-12-29 12:15:40 +03:00
|
|
|
// with any particular list and thus, no internal SVGTransform object. In
|
|
|
|
// that case we allocate an SVGTransform object on the heap to store the
|
2013-04-02 23:17:41 +04:00
|
|
|
// data.
|
2020-02-25 23:03:26 +03:00
|
|
|
UniquePtr<SVGTransform> 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
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // DOM_SVG_DOMSVGTRANSFORM_H_
|