Bug 1663089 [wpt PR 25399] - idle-detection: Implement requestPermission() method...
[gecko.git] / dom / svg / DOMSVGStringList.h
blobb1bd051697f3a457c21ffd6f1c80403fd8d05c8b
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef DOM_SVG_DOMSVGSTRINGLIST_H_
8 #define DOM_SVG_DOMSVGSTRINGLIST_H_
10 #include "nsCycleCollectionParticipant.h"
11 #include "SVGElement.h"
12 #include "mozilla/Attributes.h"
13 #include "mozilla/RefPtr.h"
15 namespace mozilla {
17 class ErrorResult;
18 class SVGStringList;
20 namespace dom {
22 /**
23 * Class DOMSVGStringList
25 * This class is used to create the DOM tearoff objects that wrap internal
26 * SVGPathData objects.
28 * See the architecture comment in DOMSVGAnimatedLengthList.h first (that's
29 * LENGTH list), then continue reading the remainder of this comment.
31 * The architecture of this class is similar to that of DOMSVGLengthList
32 * except for two important aspects:
34 * First, since there is no nsIDOMSVGAnimatedStringList interface in SVG, we
35 * have no parent DOMSVGAnimatedStringList (unlike DOMSVGLengthList which has
36 * a parent DOMSVGAnimatedLengthList class). As a consequence, much of the
37 * logic that would otherwise be in DOMSVGAnimatedStringList (and is in
38 * DOMSVGAnimatedLengthList) is contained in this class.
40 * Second, since there is no nsIDOMSVGString interface in SVG, we have no
41 * DOMSVGString items to maintain. As far as script is concerned, objects
42 * of this class contain a list of strings, not a list of mutable objects
43 * like the other SVG list types. As a result, unlike the other SVG list
44 * types, this class does not create its items lazily on demand and store
45 * them so it can return the same objects each time. It simply returns a new
46 * string each time any given item is requested.
48 class DOMSVGStringList final : public nsISupports, public nsWrapperCache {
49 friend class AutoChangeStringListNotifier;
51 public:
52 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
53 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGStringList)
55 dom::SVGElement* GetParentObject() const { return mElement; }
56 virtual JSObject* WrapObject(JSContext* aCx,
57 JS::Handle<JSObject*> aGivenProto) override;
59 uint32_t NumberOfItems() const;
60 uint32_t Length() const;
61 void Clear();
62 void Initialize(const nsAString& aNewItem, nsAString& aRetval,
63 ErrorResult& aRv);
64 void GetItem(uint32_t aIndex, nsAString& aRetval, ErrorResult& aRv);
65 void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aRetval);
66 void InsertItemBefore(const nsAString& aNewItem, uint32_t aIndex,
67 nsAString& aRetval, ErrorResult& aRv);
68 void ReplaceItem(const nsAString& aNewItem, uint32_t aIndex,
69 nsAString& aRetval, ErrorResult& aRv);
70 void RemoveItem(uint32_t aIndex, nsAString& aRetval, ErrorResult& aRv);
71 void AppendItem(const nsAString& aNewItem, nsAString& aRetval,
72 ErrorResult& aRv);
74 /**
75 * Factory method to create and return a DOMSVGStringList wrapper
76 * for a given internal SVGStringList object. The factory takes care
77 * of caching the object that it returns so that the same object can be
78 * returned for the given SVGStringList each time it is requested.
79 * The cached object is only removed from the cache when it is destroyed due
80 * to there being no more references to it. If that happens, any subsequent
81 * call requesting the DOM wrapper for the SVGStringList will naturally
82 * result in a new DOMSVGStringList being returned.
84 static already_AddRefed<DOMSVGStringList> GetDOMWrapper(
85 SVGStringList* aList, dom::SVGElement* aElement,
86 bool aIsConditionalProcessingAttribute, uint8_t aAttrEnum);
88 private:
89 /**
90 * Only our static GetDOMWrapper() factory method may create objects of our
91 * type.
93 DOMSVGStringList(dom::SVGElement* aElement,
94 bool aIsConditionalProcessingAttribute, uint8_t aAttrEnum)
95 : mElement(aElement),
96 mAttrEnum(aAttrEnum),
97 mIsConditionalProcessingAttribute(aIsConditionalProcessingAttribute) {}
99 ~DOMSVGStringList();
101 SVGStringList& InternalList() const;
103 void RemoveFromTearoffTable();
105 // Strong ref to our element to keep it alive.
106 RefPtr<dom::SVGElement> mElement;
108 uint8_t mAttrEnum;
110 bool mIsConditionalProcessingAttribute;
113 } // namespace dom
114 } // namespace mozilla
116 #endif // DOM_SVG_DOMSVGSTRINGLIST_H_