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-03 19:40:23 +03:00
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef DOM_SVG_DOMSVGNUMBERLIST_H_
|
|
|
|
#define DOM_SVG_DOMSVGNUMBERLIST_H_
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
#include "DOMSVGAnimatedNumberList.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "SVGNumberList.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"
|
2019-01-25 02:40:25 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
namespace dom {
|
2018-12-28 16:42:46 +03:00
|
|
|
class DOMSVGNumber;
|
2018-12-21 11:58:14 +03:00
|
|
|
class SVGElement;
|
|
|
|
|
2010-12-03 19:40:23 +03:00
|
|
|
/**
|
|
|
|
* Class DOMSVGNumberList
|
|
|
|
*
|
|
|
|
* This class is used to create the DOM tearoff objects that wrap internal
|
|
|
|
* SVGNumberList objects.
|
|
|
|
*
|
|
|
|
* See the architecture comment in DOMSVGAnimatedNumberList.h.
|
|
|
|
*
|
|
|
|
* This class is strongly intertwined with DOMSVGAnimatedNumberList and
|
|
|
|
* DOMSVGNumber. We are a friend of DOMSVGAnimatedNumberList, and are
|
|
|
|
* responsible for nulling out our DOMSVGAnimatedNumberList's pointer to us
|
|
|
|
* when we die, essentially making its pointer to us a weak pointer. Similarly,
|
|
|
|
* our DOMSVGNumber 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 DOMSVGNumberList final : public nsISupports, public nsWrapperCache {
|
2013-12-25 02:09:22 +04:00
|
|
|
friend class AutoChangeNumberListNotifier;
|
2010-12-03 19:40:23 +03:00
|
|
|
friend class DOMSVGNumber;
|
|
|
|
|
2014-06-24 20:36:45 +04:00
|
|
|
~DOMSVGNumberList() {
|
|
|
|
// 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-12-03 19:40:23 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2011-08-22 13:14:13 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGNumberList)
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
DOMSVGNumberList(DOMSVGAnimatedNumberList* aAList,
|
|
|
|
const SVGNumberList& aInternalList)
|
|
|
|
: 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.)
|
2010-12-03 19:40:23 +03:00
|
|
|
|
2011-02-06 12:11:26 +03:00
|
|
|
InternalListLengthWillChange(aInternalList.Length()); // Sync mItems
|
2010-12-03 19:40:23 +03: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-12-03 19:40:23 +03: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-12-03 19:40:23 +03: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-12-03 19:40:23 +03: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);
|
2019-04-27 10:57:50 +03:00
|
|
|
already_AddRefed<DOMSVGNumber> Initialize(DOMSVGNumber& aItem,
|
2013-07-12 14:25:26 +04:00
|
|
|
ErrorResult& error);
|
2014-05-30 11:36:52 +04:00
|
|
|
already_AddRefed<DOMSVGNumber> GetItem(uint32_t index, ErrorResult& error);
|
|
|
|
already_AddRefed<DOMSVGNumber> IndexedGetter(uint32_t index, bool& found,
|
2012-09-06 00:49:53 +04:00
|
|
|
ErrorResult& error);
|
2019-04-27 10:57:50 +03:00
|
|
|
already_AddRefed<DOMSVGNumber> InsertItemBefore(DOMSVGNumber& aItem,
|
2014-05-30 11:36:52 +04:00
|
|
|
uint32_t index,
|
|
|
|
ErrorResult& error);
|
2019-04-27 10:57:50 +03:00
|
|
|
already_AddRefed<DOMSVGNumber> ReplaceItem(DOMSVGNumber& aItem,
|
2014-05-30 11:36:52 +04:00
|
|
|
uint32_t index,
|
|
|
|
ErrorResult& error);
|
|
|
|
already_AddRefed<DOMSVGNumber> RemoveItem(uint32_t index, ErrorResult& error);
|
|
|
|
already_AddRefed<DOMSVGNumber> AppendItem(DOMSVGNumber& newItem,
|
|
|
|
ErrorResult& error) {
|
2012-09-06 00:49:53 +04:00
|
|
|
return InsertItemBefore(newItem, LengthNoFlush(), error);
|
|
|
|
}
|
|
|
|
uint32_t Length() const { return NumberOfItems(); }
|
|
|
|
|
2010-12-03 19:40:23 +03:00
|
|
|
private:
|
2018-12-21 11:58:14 +03:00
|
|
|
dom::SVGElement* Element() const { return mAList->mElement; }
|
2010-12-03 19:40:23 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t AttrEnum() const { return mAList->mAttrEnum; }
|
2010-12-03 19:40:23 +03: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-12-03 19:40:23 +03:00
|
|
|
return this == mAList->mAnimVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a reference to this object's corresponding internal SVGNumberList.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
SVGNumberList& InternalList() const;
|
2010-12-03 19:40:23 +03:00
|
|
|
|
2014-05-30 11:36:52 +04:00
|
|
|
/// Returns the DOMSVGNumber at aIndex, creating it if necessary.
|
|
|
|
already_AddRefed<DOMSVGNumber> GetItemAt(uint32_t aIndex);
|
2010-12-03 19:40:23 +03: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-12-03 19:40:23 +03:00
|
|
|
// Weak refs to our DOMSVGNumber 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<DOMSVGNumber*> mItems;
|
2010-12-03 19:40:23 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMSVGAnimatedNumberList> mAList;
|
2010-12-03 19:40:23 +03:00
|
|
|
};
|
|
|
|
|
2018-12-28 16:42:46 +03:00
|
|
|
} // namespace dom
|
2010-12-03 19:40:23 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // DOM_SVG_DOMSVGNUMBERLIST_H_
|