DOMSVGAnimatedTransformList.h (5016B)
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 DOM_SVG_DOMSVGANIMATEDTRANSFORMLIST_H_ 8 #define DOM_SVG_DOMSVGANIMATEDTRANSFORMLIST_H_ 9 10 #include "SVGElement.h" 11 #include "mozilla/RefPtr.h" 12 #include "nsCycleCollectionParticipant.h" 13 #include "nsWrapperCache.h" 14 15 namespace mozilla { 16 17 class SVGAnimatedTransformList; 18 19 namespace dom { 20 21 class DOMSVGTransformList; 22 23 /** 24 * Class DOMSVGAnimatedTransformList 25 * 26 * This class is used to create the DOM tearoff objects that wrap internal 27 * SVGAnimatedTransformList objects. 28 * 29 * See the architecture comment in DOMSVGAnimatedLengthList.h (that's 30 * LENGTH list). The comment for that class largly applies to this one too 31 * and will go a long way to helping you understand the architecture here. 32 * 33 * This class is strongly intertwined with DOMSVGTransformList and 34 * DOMSVGTransform. 35 * Our DOMSVGTransformList base and anim vals are friends and take care of 36 * nulling out our pointers to them when they die (making our pointers to them 37 * true weak refs). 38 */ 39 class DOMSVGAnimatedTransformList final : public nsWrapperCache { 40 friend class DOMSVGTransformList; 41 42 public: 43 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING( 44 DOMSVGAnimatedTransformList) 45 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS( 46 DOMSVGAnimatedTransformList) 47 48 /** 49 * Factory method to create and return a DOMSVGAnimatedTransformList wrapper 50 * for a given internal SVGAnimatedTransformList 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 SVGAnimatedTransformList each time it is 53 * requested. The cached object is only removed from the cache when it is 54 * destroyed due to there being no more references to it or to any of its 55 * descendant objects. If that happens, any subsequent call requesting the DOM 56 * wrapper for the SVGAnimatedTransformList will naturally result in a new 57 * DOMSVGAnimatedTransformList being returned. 58 */ 59 static already_AddRefed<DOMSVGAnimatedTransformList> GetDOMWrapper( 60 SVGAnimatedTransformList* aList, SVGElement* aElement); 61 62 /** 63 * This method returns the DOMSVGAnimatedTransformList wrapper for an internal 64 * SVGAnimatedTransformList object if it currently has a wrapper. If it does 65 * not, then nullptr is returned. 66 */ 67 static DOMSVGAnimatedTransformList* GetDOMWrapperIfExists( 68 SVGAnimatedTransformList* 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 InternalBaseValListWillChangeLengthTo(uint32_t aNewLength); 83 void InternalAnimValListWillChangeLengthTo(uint32_t aNewLength); 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 SVGElement* GetParentObject() const { return mElement; } 93 JSObject* WrapObject(JSContext* aCx, 94 JS::Handle<JSObject*> aGivenProto) override; 95 // These aren't weak refs because mBaseVal and mAnimVal are weak 96 already_AddRefed<DOMSVGTransformList> BaseVal(); 97 already_AddRefed<DOMSVGTransformList> AnimVal(); 98 99 private: 100 /** 101 * Only our static GetDOMWrapper() factory method may create objects of our 102 * type. 103 */ 104 explicit DOMSVGAnimatedTransformList(SVGElement* aElement) 105 : mBaseVal(nullptr), mAnimVal(nullptr), mElement(aElement) {} 106 107 ~DOMSVGAnimatedTransformList(); 108 109 /// Get a reference to this DOM wrapper object's internal counterpart. 110 SVGAnimatedTransformList& InternalAList(); 111 const SVGAnimatedTransformList& InternalAList() const; 112 113 // Weak refs to our DOMSVGTransformList baseVal/animVal objects. These objects 114 // are friends and take care of clearing these pointers when they die, making 115 // these true weak references. 116 DOMSVGTransformList* mBaseVal; 117 DOMSVGTransformList* mAnimVal; 118 119 // Strong ref to our element to keep it alive. We hold this not only for 120 // ourself, but also for our base/animVal and all of their items. 121 RefPtr<SVGElement> mElement; 122 }; 123 124 } // namespace dom 125 } // namespace mozilla 126 127 #endif // DOM_SVG_DOMSVGANIMATEDTRANSFORMLIST_H_