Line data Source code
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/. */
6 :
7 : #ifndef MOZILLA_DOMSVGANIMATEDNUMBERLIST_H__
8 : #define MOZILLA_DOMSVGANIMATEDNUMBERLIST_H__
9 :
10 : #include "nsCOMPtr.h"
11 : #include "nsCycleCollectionParticipant.h"
12 : #include "nsSVGElement.h"
13 : #include "nsWrapperCache.h"
14 : #include "mozilla/Attributes.h"
15 :
16 : namespace mozilla {
17 :
18 : class DOMSVGNumberList;
19 : class SVGAnimatedNumberList;
20 : class SVGNumberList;
21 :
22 : /**
23 : * Class DOMSVGAnimatedNumberList
24 : *
25 : * This class is used to create the DOM tearoff objects that wrap internal
26 : * SVGAnimatedNumberList objects.
27 : *
28 : * See the architecture comment in DOMSVGAnimatedLengthList.h (that's
29 : * LENGTH list). The comment for that class largly applies to this one too
30 : * and will go a long way to helping you understand the architecture here.
31 : *
32 : * This class is strongly intertwined with DOMSVGNumberList and DOMSVGNumber.
33 : * Our DOMSVGNumberList base and anim vals are friends and take care of nulling
34 : * out our pointers to them when they die (making our pointers to them true
35 : * weak refs).
36 : */
37 : class DOMSVGAnimatedNumberList final : public nsISupports,
38 : public nsWrapperCache
39 : {
40 : friend class DOMSVGNumberList;
41 :
42 : public:
43 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
44 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGAnimatedNumberList)
45 :
46 : /**
47 : * Factory method to create and return a DOMSVGAnimatedNumberList wrapper
48 : * for a given internal SVGAnimatedNumberList object. The factory takes care
49 : * of caching the object that it returns so that the same object can be
50 : * returned for the given SVGAnimatedNumberList each time it is requested.
51 : * The cached object is only removed from the cache when it is destroyed due
52 : * to there being no more references to it or to any of its descendant
53 : * objects. If that happens, any subsequent call requesting the DOM wrapper
54 : * for the SVGAnimatedNumberList will naturally result in a new
55 : * DOMSVGAnimatedNumberList being returned.
56 : */
57 : static already_AddRefed<DOMSVGAnimatedNumberList>
58 : GetDOMWrapper(SVGAnimatedNumberList *aList,
59 : nsSVGElement *aElement,
60 : uint8_t aAttrEnum);
61 :
62 : /**
63 : * This method returns the DOMSVGAnimatedNumberList wrapper for an internal
64 : * SVGAnimatedNumberList object if it currently has a wrapper. If it does
65 : * not, then nullptr is returned.
66 : */
67 : static DOMSVGAnimatedNumberList*
68 : GetDOMWrapperIfExists(SVGAnimatedNumberList *aList);
69 :
70 : /**
71 : * Called by internal code to notify us when we need to sync the length of
72 : * our baseVal DOM list with its internal list. This is called just prior to
73 : * the length of the internal baseVal list being changed so that any DOM list
74 : * items that need to be removed from the DOM list can first get their values
75 : * from their internal counterpart.
76 : *
77 : * The only time this method could fail is on OOM when trying to increase the
78 : * length of the DOM list. If that happens then this method simply clears the
79 : * list and returns. Callers just proceed as normal, and we simply accept
80 : * that the DOM list will be empty (until successfully set to a new value).
81 : */
82 : void InternalBaseValListWillChangeTo(const SVGNumberList& aNewValue);
83 : void InternalAnimValListWillChangeTo(const SVGNumberList& aNewValue);
84 :
85 : /**
86 : * Returns true if our attribute is animating (in which case our animVal is
87 : * not simply a mirror of our baseVal).
88 : */
89 : bool IsAnimating() const;
90 :
91 : // WebIDL
92 0 : nsSVGElement* GetParentObject() const { return mElement; }
93 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
94 : // These aren't weak refs because mBaseVal and mAnimVal are weak
95 : already_AddRefed<DOMSVGNumberList> BaseVal();
96 : already_AddRefed<DOMSVGNumberList> AnimVal();
97 :
98 : private:
99 :
100 : /**
101 : * Only our static GetDOMWrapper() factory method may create objects of our
102 : * type.
103 : */
104 0 : DOMSVGAnimatedNumberList(nsSVGElement *aElement, uint8_t aAttrEnum)
105 0 : : mBaseVal(nullptr)
106 : , mAnimVal(nullptr)
107 : , mElement(aElement)
108 0 : , mAttrEnum(aAttrEnum)
109 : {
110 0 : }
111 :
112 : ~DOMSVGAnimatedNumberList();
113 :
114 : /// Get a reference to this DOM wrapper object's internal counterpart.
115 : SVGAnimatedNumberList& InternalAList();
116 : const SVGAnimatedNumberList& InternalAList() const;
117 :
118 : // Weak refs to our DOMSVGNumberList baseVal/animVal objects. These objects
119 : // are friends and take care of clearing these pointers when they die, making
120 : // these true weak references.
121 : DOMSVGNumberList *mBaseVal;
122 : DOMSVGNumberList *mAnimVal;
123 :
124 : // Strong ref to our element to keep it alive. We hold this not only for
125 : // ourself, but also for our base/animVal and all of their items.
126 : RefPtr<nsSVGElement> mElement;
127 :
128 : uint8_t mAttrEnum;
129 : };
130 :
131 : } // namespace mozilla
132 :
133 : #endif // MOZILLA_DOMSVGANIMATEDNUMBERLIST_H__
|