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_DOMSVGANIMATEDTRANSFORMLIST_H_
8 #define DOM_SVG_DOMSVGANIMATEDTRANSFORMLIST_H_
10 #include "nsCycleCollectionParticipant.h"
11 #include "SVGElement.h"
12 #include "nsWrapperCache.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/RefPtr.h"
18 class SVGAnimatedTransformList
;
22 class DOMSVGTransformList
;
25 * Class DOMSVGAnimatedTransformList
27 * This class is used to create the DOM tearoff objects that wrap internal
28 * SVGAnimatedTransformList objects.
30 * See the architecture comment in DOMSVGAnimatedLengthList.h (that's
31 * LENGTH list). The comment for that class largly applies to this one too
32 * and will go a long way to helping you understand the architecture here.
34 * This class is strongly intertwined with DOMSVGTransformList and
36 * Our DOMSVGTransformList base and anim vals are friends and take care of
37 * nulling out our pointers to them when they die (making our pointers to them
40 class DOMSVGAnimatedTransformList final
: public nsWrapperCache
{
41 friend class DOMSVGTransformList
;
44 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(
45 DOMSVGAnimatedTransformList
)
46 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(
47 DOMSVGAnimatedTransformList
)
50 * Factory method to create and return a DOMSVGAnimatedTransformList wrapper
51 * for a given internal SVGAnimatedTransformList object. The factory takes
52 * care of caching the object that it returns so that the same object can be
53 * returned for the given SVGAnimatedTransformList each time it is
54 * requested. The cached object is only removed from the cache when it is
55 * destroyed due to there being no more references to it or to any of its
56 * descendant objects. If that happens, any subsequent call requesting the DOM
57 * wrapper for the SVGAnimatedTransformList will naturally result in a new
58 * DOMSVGAnimatedTransformList being returned.
60 static already_AddRefed
<DOMSVGAnimatedTransformList
> GetDOMWrapper(
61 SVGAnimatedTransformList
* aList
, SVGElement
* aElement
);
64 * This method returns the DOMSVGAnimatedTransformList wrapper for an internal
65 * SVGAnimatedTransformList object if it currently has a wrapper. If it does
66 * not, then nullptr is returned.
68 static DOMSVGAnimatedTransformList
* GetDOMWrapperIfExists(
69 SVGAnimatedTransformList
* aList
);
72 * Called by internal code to notify us when we need to sync the length of
73 * our baseVal DOM list with its internal list. This is called just prior to
74 * the length of the internal baseVal list being changed so that any DOM list
75 * items that need to be removed from the DOM list can first get their values
76 * from their internal counterpart.
78 * The only time this method could fail is on OOM when trying to increase the
79 * length of the DOM list. If that happens then this method simply clears the
80 * list and returns. Callers just proceed as normal, and we simply accept
81 * that the DOM list will be empty (until successfully set to a new value).
83 void InternalBaseValListWillChangeLengthTo(uint32_t aNewLength
);
84 void InternalAnimValListWillChangeLengthTo(uint32_t aNewLength
);
87 * Returns true if our attribute is animating (in which case our animVal is
88 * not simply a mirror of our baseVal).
90 bool IsAnimating() const;
93 SVGElement
* GetParentObject() const { return mElement
; }
94 JSObject
* WrapObject(JSContext
* aCx
,
95 JS::Handle
<JSObject
*> aGivenProto
) override
;
96 // These aren't weak refs because mBaseVal and mAnimVal are weak
97 already_AddRefed
<DOMSVGTransformList
> BaseVal();
98 already_AddRefed
<DOMSVGTransformList
> AnimVal();
102 * Only our static GetDOMWrapper() factory method may create objects of our
105 explicit DOMSVGAnimatedTransformList(SVGElement
* aElement
)
106 : mBaseVal(nullptr), mAnimVal(nullptr), mElement(aElement
) {}
108 ~DOMSVGAnimatedTransformList();
110 /// Get a reference to this DOM wrapper object's internal counterpart.
111 SVGAnimatedTransformList
& InternalAList();
112 const SVGAnimatedTransformList
& InternalAList() const;
114 // Weak refs to our DOMSVGTransformList baseVal/animVal objects. These objects
115 // are friends and take care of clearing these pointers when they die, making
116 // these true weak references.
117 DOMSVGTransformList
* mBaseVal
;
118 DOMSVGTransformList
* mAnimVal
;
120 // Strong ref to our element to keep it alive. We hold this not only for
121 // ourself, but also for our base/animVal and all of their items.
122 RefPtr
<SVGElement
> mElement
;
126 } // namespace mozilla
128 #endif // DOM_SVG_DOMSVGANIMATEDTRANSFORMLIST_H_