1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
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 mozilla_dom_SVGAnimatedTransformList_h
8 #define mozilla_dom_SVGAnimatedTransformList_h
10 #include "nsAutoPtr.h"
12 #include "nsCycleCollectionParticipant.h"
13 #include "nsSVGElement.h"
14 #include "nsWrapperCache.h"
15 #include "mozilla/Attributes.h"
19 class DOMSVGTransformList
;
20 class nsSVGAnimatedTransformList
;
25 * Class SVGAnimatedTransformList
27 * This class is used to create the DOM tearoff objects that wrap internal
28 * nsSVGAnimatedTransformList 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 SVGAnimatedTransformList MOZ_FINAL
: public nsWrapperCache
42 friend class mozilla::DOMSVGTransformList
;
45 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(SVGAnimatedTransformList
)
46 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(SVGAnimatedTransformList
)
49 * Factory method to create and return a SVGAnimatedTransformList wrapper
50 * for a given internal nsSVGAnimatedTransformList object. The factory takes
51 * care of caching the object that it returns so that the same object can be
52 * returned for the given nsSVGAnimatedTransformList each time it is requested.
53 * The cached object is only removed from the cache when it is destroyed due
54 * to there being no more references to it or to any of its descendant
55 * objects. If that happens, any subsequent call requesting the DOM wrapper
56 * for the nsSVGAnimatedTransformList will naturally result in a new
57 * SVGAnimatedTransformList being returned.
59 static already_AddRefed
<SVGAnimatedTransformList
>
60 GetDOMWrapper(nsSVGAnimatedTransformList
*aList
, nsSVGElement
*aElement
);
63 * This method returns the SVGAnimatedTransformList wrapper for an internal
64 * nsSVGAnimatedTransformList object if it currently has a wrapper. If it does
65 * not, then nullptr is returned.
67 static SVGAnimatedTransformList
*
68 GetDOMWrapperIfExists(nsSVGAnimatedTransformList
*aList
);
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.
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).
82 void InternalBaseValListWillChangeLengthTo(uint32_t aNewLength
);
83 void InternalAnimValListWillChangeLengthTo(uint32_t aNewLength
);
86 * Returns true if our attribute is animating (in which case our animVal is
87 * not simply a mirror of our baseVal).
89 bool IsAnimating() const;
92 nsSVGElement
* GetParentObject() const { return mElement
; }
93 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
94 // These aren't weak refs because mBaseVal and mAnimVal are weak
95 already_AddRefed
<DOMSVGTransformList
> BaseVal();
96 already_AddRefed
<DOMSVGTransformList
> AnimVal();
101 * Only our static GetDOMWrapper() factory method may create objects of our
104 explicit SVGAnimatedTransformList(nsSVGElement
*aElement
)
111 ~SVGAnimatedTransformList();
113 /// Get a reference to this DOM wrapper object's internal counterpart.
114 nsSVGAnimatedTransformList
& InternalAList();
115 const nsSVGAnimatedTransformList
& InternalAList() const;
117 // Weak refs to our DOMSVGTransformList baseVal/animVal objects. These objects
118 // are friends and take care of clearing these pointers when they die, making
119 // these true weak references.
120 DOMSVGTransformList
*mBaseVal
;
121 DOMSVGTransformList
*mAnimVal
;
123 // Strong ref to our element to keep it alive. We hold this not only for
124 // ourself, but also for our base/animVal and all of their items.
125 nsRefPtr
<nsSVGElement
> mElement
;
129 } // namespace mozilla
131 #endif // mozilla_dom_SVGAnimatedTransformList_h