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-07-17 01:42:12 +04:00
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef DOM_SVG_DOMSVGLENGTHLIST_H_
|
|
|
|
#define DOM_SVG_DOMSVGLENGTHLIST_H_
|
2010-07-17 01:42:12 +04:00
|
|
|
|
|
|
|
#include "DOMSVGAnimatedLengthList.h"
|
2020-08-03 12:32:36 +03:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "SVGLengthList.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2020-02-20 00:58:31 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2010-07-17 01:42:12 +04:00
|
|
|
|
2020-08-25 21:25:52 +03:00
|
|
|
// {cbecb7a4-d6f3-47b5-b5a3-3e5bdbf5b2f9}
|
|
|
|
#define MOZILLA_DOMSVGLENGTHLIST_IID \
|
|
|
|
{ \
|
|
|
|
0xcbecb7a4, 0xd6f3, 0xd6f3, { \
|
|
|
|
0xb5, 0xa3, 0x3e, 0x5b, 0xdb, 0xf5, 0xb2, 0xf9 \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
namespace mozilla {
|
2020-11-23 19:12:02 +03:00
|
|
|
class ErrorResult;
|
2010-07-17 01:42:12 +04:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
namespace dom {
|
2018-12-28 16:42:46 +03:00
|
|
|
class DOMSVGLength;
|
2018-12-21 11:58:14 +03:00
|
|
|
class SVGElement;
|
|
|
|
|
2020-08-03 12:32:36 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AutoChangeLengthListNotifier
|
|
|
|
// Stack-based helper class to pair calls to WillChangeLengthList and
|
|
|
|
// DidChangeLengthList. Used by DOMSVGLength and DOMSVGLengthList.
|
|
|
|
template <class T>
|
|
|
|
class MOZ_RAII AutoChangeLengthListNotifier : public mozAutoDocUpdate {
|
|
|
|
public:
|
|
|
|
explicit AutoChangeLengthListNotifier(T* aValue)
|
|
|
|
: mozAutoDocUpdate(aValue->Element()->GetComposedDoc(), true),
|
|
|
|
mValue(aValue) {
|
|
|
|
MOZ_ASSERT(aValue, "Expecting non-null value");
|
|
|
|
mEmptyOrOldValue =
|
|
|
|
mValue->Element()->WillChangeLengthList(mValue->AttrEnum(), *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoChangeLengthListNotifier() {
|
|
|
|
mValue->Element()->DidChangeLengthList(mValue->AttrEnum(), mEmptyOrOldValue,
|
|
|
|
*this);
|
|
|
|
if (mValue->IsAnimating()) {
|
|
|
|
mValue->Element()->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
T* const mValue;
|
|
|
|
nsAttrValue mEmptyOrOldValue;
|
|
|
|
};
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
/**
|
|
|
|
* Class DOMSVGLengthList
|
|
|
|
*
|
|
|
|
* This class is used to create the DOM tearoff objects that wrap internal
|
|
|
|
* SVGLengthList objects.
|
|
|
|
*
|
|
|
|
* See the architecture comment in DOMSVGAnimatedLengthList.h.
|
|
|
|
*
|
|
|
|
* This class is strongly intertwined with DOMSVGAnimatedLengthList and
|
|
|
|
* DOMSVGLength. We are a friend of DOMSVGAnimatedLengthList, and are
|
|
|
|
* responsible for nulling out our DOMSVGAnimatedLengthList's pointer to us
|
|
|
|
* when we die, essentially making its pointer to us a weak pointer. Similarly,
|
|
|
|
* our DOMSVGLength items are friends of us and responsible for nulling out our
|
|
|
|
* pointers to them.
|
|
|
|
*
|
|
|
|
* Our DOM items are created lazily on demand as and when script requests them.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class DOMSVGLengthList final : public nsISupports, public nsWrapperCache {
|
2020-08-03 12:32:36 +03:00
|
|
|
template <class T>
|
2013-12-25 02:09:22 +04:00
|
|
|
friend class AutoChangeLengthListNotifier;
|
2010-07-17 01:42:12 +04:00
|
|
|
friend class DOMSVGLength;
|
|
|
|
|
2014-06-24 20:36:45 +04:00
|
|
|
~DOMSVGLengthList() {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
public:
|
2020-08-25 21:25:52 +03:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOMSVGLENGTHLIST_IID)
|
2010-07-17 01:42:12 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2011-08-22 13:14:13 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGLengthList)
|
2010-07-17 01:42:12 +04:00
|
|
|
|
2011-02-06 12:11:26 +03:00
|
|
|
DOMSVGLengthList(DOMSVGAnimatedLengthList* aAList,
|
|
|
|
const SVGLengthList& aInternalList)
|
2010-07-17 01:42:12 +04:00
|
|
|
: mAList(aAList) {
|
2011-02-06 12:11:26 +03:00
|
|
|
// 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.)
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2011-02-06 12:11:26 +03:00
|
|
|
InternalListLengthWillChange(aInternalList.Length()); // Sync mItems
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
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()); }
|
|
|
|
|
2010-07-17 01:42:12 +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.Length() == 0 || mItems.Length() == InternalList().Length(),
|
|
|
|
"DOM wrapper's list length is out of sync");
|
2010-07-17 01:42:12 +04:00
|
|
|
return mItems.Length();
|
|
|
|
}
|
|
|
|
|
2018-03-18 21:09:51 +03:00
|
|
|
/// 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);
|
2010-07-17 01:42:12 +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& aError);
|
2014-04-12 01:26:29 +04:00
|
|
|
already_AddRefed<DOMSVGLength> Initialize(DOMSVGLength& newItem,
|
2014-04-11 19:24:06 +04:00
|
|
|
ErrorResult& error);
|
2014-04-12 01:26:29 +04:00
|
|
|
already_AddRefed<DOMSVGLength> GetItem(uint32_t index, ErrorResult& error);
|
|
|
|
already_AddRefed<DOMSVGLength> IndexedGetter(uint32_t index, bool& found,
|
2014-04-11 20:07:42 +04:00
|
|
|
ErrorResult& error);
|
2014-04-12 01:26:29 +04:00
|
|
|
already_AddRefed<DOMSVGLength> InsertItemBefore(DOMSVGLength& newItem,
|
|
|
|
uint32_t index,
|
|
|
|
ErrorResult& error);
|
|
|
|
already_AddRefed<DOMSVGLength> ReplaceItem(DOMSVGLength& newItem,
|
|
|
|
uint32_t index,
|
|
|
|
ErrorResult& error);
|
|
|
|
already_AddRefed<DOMSVGLength> RemoveItem(uint32_t index, ErrorResult& error);
|
|
|
|
already_AddRefed<DOMSVGLength> AppendItem(DOMSVGLength& newItem,
|
|
|
|
ErrorResult& error) {
|
2012-09-06 00:49:53 +04:00
|
|
|
return InsertItemBefore(newItem, LengthNoFlush(), error);
|
|
|
|
}
|
2020-02-20 00:58:31 +03:00
|
|
|
void IndexedSetter(uint32_t index, DOMSVGLength& newValue,
|
2020-04-22 20:26:16 +03:00
|
|
|
ErrorResult& error);
|
2012-09-06 00:49:53 +04:00
|
|
|
uint32_t Length() const { return NumberOfItems(); }
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
private:
|
2018-12-21 11:58:14 +03:00
|
|
|
dom::SVGElement* Element() const { return mAList->mElement; }
|
2010-07-17 01:42:12 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t AttrEnum() const { return mAList->mAttrEnum; }
|
2010-07-17 01:42:12 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t Axis() const { return mAList->mAxis; }
|
2010-07-17 01:42:12 +04:00
|
|
|
|
|
|
|
/// 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?!");
|
2010-07-17 01:42:12 +04:00
|
|
|
return this == mAList->mAnimVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a reference to this object's corresponding internal SVGLengthList.
|
|
|
|
*
|
2010-12-03 19:40:23 +03:00
|
|
|
* To simplify the code we just have this one method for obtaining both
|
2010-07-17 01:42:12 +04:00
|
|
|
* 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
|
|
|
SVGLengthList& InternalList() const;
|
2010-07-17 01:42:12 +04:00
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
/// Returns the DOMSVGLength at aIndex, creating it if necessary.
|
|
|
|
already_AddRefed<DOMSVGLength> GetItemAt(uint32_t aIndex);
|
2010-07-17 01:42:12 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void MaybeInsertNullInAnimValListAt(uint32_t aIndex);
|
|
|
|
void MaybeRemoveItemFromAnimValListAt(uint32_t aIndex);
|
2011-02-16 10:54:26 +03:00
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
// Weak refs to our DOMSVGLength items. The items are friends and take care
|
|
|
|
// of clearing our pointer to them when they die.
|
2013-03-23 20:47:31 +04:00
|
|
|
FallibleTArray<DOMSVGLength*> mItems;
|
2010-07-17 01:42:12 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMSVGAnimatedLengthList> mAList;
|
2010-07-17 01:42:12 +04:00
|
|
|
};
|
|
|
|
|
2020-08-25 21:25:52 +03:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(DOMSVGLengthList, MOZILLA_DOMSVGLENGTHLIST_IID)
|
|
|
|
|
2018-12-28 16:42:46 +03:00
|
|
|
} // namespace dom
|
2010-07-17 01:42:12 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // DOM_SVG_DOMSVGLENGTHLIST_H_
|