Bumping manifests a=b2g-bump
[gecko.git] / dom / svg / DOMSVGLengthList.h
blob1f9eba6e13e6853114f13d1f2ca862f3c5883131
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef MOZILLA_DOMSVGLENGTHLIST_H__
7 #define MOZILLA_DOMSVGLENGTHLIST_H__
9 #include "DOMSVGAnimatedLengthList.h"
10 #include "nsAutoPtr.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsDebug.h"
13 #include "nsTArray.h"
14 #include "SVGLengthList.h"
15 #include "mozilla/Attributes.h"
16 #include "mozilla/ErrorResult.h"
18 class nsSVGElement;
20 namespace mozilla {
22 class DOMSVGLength;
24 /**
25 * Class DOMSVGLengthList
27 * This class is used to create the DOM tearoff objects that wrap internal
28 * SVGLengthList objects.
30 * See the architecture comment in DOMSVGAnimatedLengthList.h.
32 * This class is strongly intertwined with DOMSVGAnimatedLengthList and
33 * DOMSVGLength. We are a friend of DOMSVGAnimatedLengthList, and are
34 * responsible for nulling out our DOMSVGAnimatedLengthList's pointer to us
35 * when we die, essentially making its pointer to us a weak pointer. Similarly,
36 * our DOMSVGLength items are friends of us and responsible for nulling out our
37 * pointers to them.
39 * Our DOM items are created lazily on demand as and when script requests them.
41 class DOMSVGLengthList MOZ_FINAL : public nsISupports,
42 public nsWrapperCache
44 friend class AutoChangeLengthListNotifier;
45 friend class DOMSVGLength;
47 ~DOMSVGLengthList() {
48 // Our mAList's weak ref to us must be nulled out when we die. If GC has
49 // unlinked us using the cycle collector code, then that has already
50 // happened, and mAList is null.
51 if (mAList) {
52 ( IsAnimValList() ? mAList->mAnimVal : mAList->mBaseVal ) = nullptr;
56 public:
57 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
58 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGLengthList)
60 DOMSVGLengthList(DOMSVGAnimatedLengthList *aAList,
61 const SVGLengthList &aInternalList)
62 : mAList(aAList)
64 // aInternalList must be passed in explicitly because we can't use
65 // InternalList() here. (Because it depends on IsAnimValList, which depends
66 // on this object having been assigned to aAList's mBaseVal or mAnimVal,
67 // which hasn't happend yet.)
69 InternalListLengthWillChange(aInternalList.Length()); // Sync mItems
72 virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
74 nsISupports* GetParentObject()
76 return static_cast<nsIContent*>(Element());
79 /**
80 * This will normally be the same as InternalList().Length(), except if we've
81 * hit OOM in which case our length will be zero.
83 uint32_t LengthNoFlush() const {
84 NS_ABORT_IF_FALSE(mItems.Length() == 0 ||
85 mItems.Length() == InternalList().Length(),
86 "DOM wrapper's list length is out of sync");
87 return mItems.Length();
90 /// Called to notify us to syncronize our length and detach excess items.
91 void InternalListLengthWillChange(uint32_t aNewLength);
93 /**
94 * Returns true if our attribute is animating (in which case our animVal is
95 * not simply a mirror of our baseVal).
97 bool IsAnimating() const {
98 return mAList->IsAnimating();
101 uint32_t NumberOfItems() const
103 if (IsAnimValList()) {
104 Element()->FlushAnimations();
106 return LengthNoFlush();
108 void Clear(ErrorResult& aError);
109 already_AddRefed<DOMSVGLength> Initialize(DOMSVGLength& newItem,
110 ErrorResult& error);
111 already_AddRefed<DOMSVGLength> GetItem(uint32_t index,
112 ErrorResult& error);
113 already_AddRefed<DOMSVGLength> IndexedGetter(uint32_t index, bool& found,
114 ErrorResult& error);
115 already_AddRefed<DOMSVGLength> InsertItemBefore(DOMSVGLength& newItem,
116 uint32_t index,
117 ErrorResult& error);
118 already_AddRefed<DOMSVGLength> ReplaceItem(DOMSVGLength& newItem,
119 uint32_t index,
120 ErrorResult& error);
121 already_AddRefed<DOMSVGLength> RemoveItem(uint32_t index,
122 ErrorResult& error);
123 already_AddRefed<DOMSVGLength> AppendItem(DOMSVGLength& newItem,
124 ErrorResult& error)
126 return InsertItemBefore(newItem, LengthNoFlush(), error);
128 uint32_t Length() const
130 return NumberOfItems();
133 private:
135 nsSVGElement* Element() const {
136 return mAList->mElement;
139 uint8_t AttrEnum() const {
140 return mAList->mAttrEnum;
143 uint8_t Axis() const {
144 return mAList->mAxis;
147 /// Used to determine if this list is the baseVal or animVal list.
148 bool IsAnimValList() const {
149 NS_ABORT_IF_FALSE(this == mAList->mBaseVal || this == mAList->mAnimVal,
150 "Calling IsAnimValList() too early?!");
151 return this == mAList->mAnimVal;
155 * Get a reference to this object's corresponding internal SVGLengthList.
157 * To simplify the code we just have this one method for obtaining both
158 * baseVal and animVal internal lists. This means that animVal lists don't
159 * get const protection, but our setter methods guard against changing
160 * animVal lists.
162 SVGLengthList& InternalList() const;
164 /// Returns the DOMSVGLength at aIndex, creating it if necessary.
165 already_AddRefed<DOMSVGLength> GetItemAt(uint32_t aIndex);
167 void MaybeInsertNullInAnimValListAt(uint32_t aIndex);
168 void MaybeRemoveItemFromAnimValListAt(uint32_t aIndex);
170 // Weak refs to our DOMSVGLength items. The items are friends and take care
171 // of clearing our pointer to them when they die.
172 FallibleTArray<DOMSVGLength*> mItems;
174 nsRefPtr<DOMSVGAnimatedLengthList> mAList;
177 } // namespace mozilla
179 #endif // MOZILLA_DOMSVGLENGTHLIST_H__