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:31 +04:00
|
|
|
|
|
|
|
#ifndef MOZILLA_DOMSVGTRANSFORMLIST_H__
|
|
|
|
#define MOZILLA_DOMSVGTRANSFORMLIST_H__
|
|
|
|
|
2013-04-15 02:56:34 +04:00
|
|
|
#include "mozilla/dom/SVGAnimatedTransformList.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "SVGTransformList.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-09-06 00:49:53 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2011-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
class nsSVGElement;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-01-12 00:30:21 +04:00
|
|
|
namespace dom {
|
|
|
|
class SVGMatrix;
|
2013-04-02 23:17:41 +04:00
|
|
|
class SVGTransform;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2013-01-12 00:30:21 +04:00
|
|
|
|
2011-09-26 01:04:31 +04:00
|
|
|
/**
|
|
|
|
* Class DOMSVGTransformList
|
|
|
|
*
|
|
|
|
* This class is used to create the DOM tearoff objects that wrap internal
|
|
|
|
* SVGTransformList objects.
|
|
|
|
*
|
2013-04-15 02:56:34 +04:00
|
|
|
* See the architecture comment in SVGAnimatedTransformList.h.
|
2011-09-26 01:04:31 +04:00
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class DOMSVGTransformList final : public nsISupports,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsWrapperCache
|
2011-09-26 01:04:31 +04:00
|
|
|
{
|
2013-12-25 02:09:22 +04:00
|
|
|
friend class AutoChangeTransformListNotifier;
|
2013-04-02 23:17:41 +04:00
|
|
|
friend class dom::SVGTransform;
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2014-06-24 20:36:45 +04:00
|
|
|
~DOMSVGTransformList() {
|
|
|
|
// Our mAList's weak ref to us must be nulled out when we die. If GC has
|
|
|
|
// unlinked us using the cycle collector code, then that has already
|
|
|
|
// happened, and mAList is null.
|
|
|
|
if (mAList) {
|
|
|
|
( IsAnimValList() ? mAList->mAnimVal : mAList->mBaseVal ) = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-26 01:04:31 +04:00
|
|
|
public:
|
2013-12-22 21:56:39 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGTransformList)
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-04-15 02:56:34 +04:00
|
|
|
DOMSVGTransformList(dom::SVGAnimatedTransformList *aAList,
|
2011-09-26 01:04:31 +04:00
|
|
|
const SVGTransformList &aInternalList)
|
|
|
|
: mAList(aAList)
|
|
|
|
{
|
|
|
|
// aInternalList must be passed in explicitly because we can't use
|
|
|
|
// InternalList() here. (Because it depends on IsAnimValList, which depends
|
|
|
|
// on this object having been assigned to aAList's mBaseVal or mAnimVal,
|
2018-03-18 21:09:51 +03:00
|
|
|
// which hasn't happened yet.)
|
2011-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
InternalListLengthWillChange(aInternalList.Length()); // Sync mItems
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
2011-08-22 13:14:13 +04:00
|
|
|
|
|
|
|
nsISupports* GetParentObject()
|
|
|
|
{
|
|
|
|
return static_cast<nsIContent*>(Element());
|
|
|
|
}
|
|
|
|
|
2011-09-26 01:04:31 +04:00
|
|
|
/**
|
|
|
|
* This will normally be the same as InternalList().Length(), except if we've
|
|
|
|
* hit OOM in which case our length will be zero.
|
|
|
|
*/
|
2012-09-05 18:52:57 +04:00
|
|
|
uint32_t LengthNoFlush() const {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mItems.IsEmpty() || mItems.Length() == InternalList().Length(),
|
|
|
|
"DOM wrapper's list length is out of sync");
|
2011-09-26 01:04:31 +04:00
|
|
|
return mItems.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Called to notify us to synchronize our length and detach excess items.
|
2012-08-22 19:56:38 +04:00
|
|
|
void InternalListLengthWillChange(uint32_t aNewLength);
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-12-25 02:09:22 +04: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 mAList->IsAnimating();
|
|
|
|
}
|
2015-11-04 08:42:41 +03:00
|
|
|
/**
|
|
|
|
* Returns true if there is an animated list mirroring the base list.
|
|
|
|
*/
|
|
|
|
bool AnimListMirrorsBaseList() const {
|
|
|
|
return mAList->mAnimVal && !mAList->IsAnimating();
|
|
|
|
}
|
2013-12-25 02:09:22 +04:00
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
uint32_t NumberOfItems() const
|
|
|
|
{
|
|
|
|
if (IsAnimValList()) {
|
|
|
|
Element()->FlushAnimations();
|
|
|
|
}
|
|
|
|
return LengthNoFlush();
|
|
|
|
}
|
|
|
|
void Clear(ErrorResult& error);
|
2013-04-02 23:17:41 +04:00
|
|
|
already_AddRefed<dom::SVGTransform> Initialize(dom::SVGTransform& newItem,
|
|
|
|
ErrorResult& error);
|
2013-07-12 14:25:25 +04:00
|
|
|
already_AddRefed<dom::SVGTransform> GetItem(uint32_t index,
|
|
|
|
ErrorResult& error);
|
|
|
|
already_AddRefed<dom::SVGTransform> IndexedGetter(uint32_t index, bool& found,
|
|
|
|
ErrorResult& error);
|
2013-04-02 23:17:41 +04:00
|
|
|
already_AddRefed<dom::SVGTransform> InsertItemBefore(dom::SVGTransform& newItem,
|
|
|
|
uint32_t index,
|
|
|
|
ErrorResult& error);
|
|
|
|
already_AddRefed<dom::SVGTransform> ReplaceItem(dom::SVGTransform& newItem,
|
|
|
|
uint32_t index,
|
|
|
|
ErrorResult& error);
|
|
|
|
already_AddRefed<dom::SVGTransform> RemoveItem(uint32_t index,
|
|
|
|
ErrorResult& error);
|
|
|
|
already_AddRefed<dom::SVGTransform> AppendItem(dom::SVGTransform& newItem,
|
|
|
|
ErrorResult& error)
|
2012-09-06 00:49:53 +04:00
|
|
|
{
|
|
|
|
return InsertItemBefore(newItem, LengthNoFlush(), error);
|
|
|
|
}
|
2013-04-02 23:17:41 +04:00
|
|
|
already_AddRefed<dom::SVGTransform> CreateSVGTransformFromMatrix(dom::SVGMatrix& matrix);
|
|
|
|
already_AddRefed<dom::SVGTransform> Consolidate(ErrorResult& error);
|
2012-09-06 00:49:53 +04:00
|
|
|
uint32_t Length() const
|
|
|
|
{
|
|
|
|
return NumberOfItems();
|
|
|
|
}
|
|
|
|
|
2011-09-26 01:04:31 +04:00
|
|
|
private:
|
|
|
|
|
2011-11-26 14:22:15 +04:00
|
|
|
nsSVGElement* Element() const {
|
2011-09-26 01:04:31 +04:00
|
|
|
return mAList->mElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Used to determine if this list is the baseVal or animVal list.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsAnimValList() const {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(this == mAList->mBaseVal || this == mAList->mAnimVal,
|
|
|
|
"Calling IsAnimValList() too early?!");
|
2011-09-26 01:04:31 +04:00
|
|
|
return this == mAList->mAnimVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a reference to this object's corresponding internal SVGTransformList.
|
|
|
|
*
|
|
|
|
* To simplify the code we just have this one method for obtaining both
|
|
|
|
* baseVal and animVal internal lists. This means that animVal lists don't
|
|
|
|
* get const protection, but our setter methods guard against changing
|
|
|
|
* animVal lists.
|
|
|
|
*/
|
2011-11-26 14:22:15 +04:00
|
|
|
SVGTransformList& InternalList() const;
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-07-12 14:25:25 +04:00
|
|
|
/// Returns the SVGTransform at aIndex, creating it if necessary.
|
|
|
|
already_AddRefed<dom::SVGTransform> GetItemAt(uint32_t aIndex);
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void MaybeInsertNullInAnimValListAt(uint32_t aIndex);
|
|
|
|
void MaybeRemoveItemFromAnimValListAt(uint32_t aIndex);
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-04-02 23:17:41 +04:00
|
|
|
// Weak refs to our SVGTransform items. The items are friends and take care
|
2011-09-26 01:04:31 +04:00
|
|
|
// of clearing our pointer to them when they die.
|
2013-04-02 23:17:41 +04:00
|
|
|
FallibleTArray<dom::SVGTransform*> mItems;
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<dom::SVGAnimatedTransformList> mAList;
|
2011-09-26 01:04:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // MOZILLA_DOMSVGTRANSFORMLIST_H__
|