Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / svg / DOMSVGAnimatedNumberList.h
blob95c94540630e8fc18371a356ee659302fbba7336
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_DOMSVGANIMATEDNUMBERLIST_H_
8 #define DOM_SVG_DOMSVGANIMATEDNUMBERLIST_H_
10 #include "nsCycleCollectionParticipant.h"
11 #include "SVGElement.h"
12 #include "nsWrapperCache.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/RefPtr.h"
16 namespace mozilla {
18 class SVGAnimatedNumberList;
19 class SVGNumberList;
21 namespace dom {
23 class DOMSVGNumberList;
25 /**
26 * Class DOMSVGAnimatedNumberList
28 * This class is used to create the DOM tearoff objects that wrap internal
29 * SVGAnimatedNumberList objects.
31 * See the architecture comment in DOMSVGAnimatedLengthList.h (that's
32 * LENGTH list). The comment for that class largly applies to this one too
33 * and will go a long way to helping you understand the architecture here.
35 * This class is strongly intertwined with DOMSVGNumberList and DOMSVGNumber.
36 * Our DOMSVGNumberList base and anim vals are friends and take care of nulling
37 * out our pointers to them when they die (making our pointers to them true
38 * weak refs).
40 class DOMSVGAnimatedNumberList final : public nsWrapperCache {
41 friend class DOMSVGNumberList;
43 public:
44 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMSVGAnimatedNumberList)
45 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DOMSVGAnimatedNumberList)
47 /**
48 * Factory method to create and return a DOMSVGAnimatedNumberList wrapper
49 * for a given internal SVGAnimatedNumberList object. The factory takes care
50 * of caching the object that it returns so that the same object can be
51 * returned for the given SVGAnimatedNumberList each time it is requested.
52 * The cached object is only removed from the cache when it is destroyed due
53 * to there being no more references to it or to any of its descendant
54 * objects. If that happens, any subsequent call requesting the DOM wrapper
55 * for the SVGAnimatedNumberList will naturally result in a new
56 * DOMSVGAnimatedNumberList being returned.
58 static already_AddRefed<DOMSVGAnimatedNumberList> GetDOMWrapper(
59 SVGAnimatedNumberList* aList, dom::SVGElement* aElement,
60 uint8_t aAttrEnum);
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.
67 static DOMSVGAnimatedNumberList* GetDOMWrapperIfExists(
68 SVGAnimatedNumberList* aList);
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.
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 InternalBaseValListWillChangeTo(const SVGNumberList& aNewValue);
83 void InternalAnimValListWillChangeTo(const SVGNumberList& aNewValue);
85 /**
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;
91 // WebIDL
92 dom::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<DOMSVGNumberList> BaseVal();
97 already_AddRefed<DOMSVGNumberList> AnimVal();
99 private:
101 * Only our static GetDOMWrapper() factory method may create objects of our
102 * type.
104 DOMSVGAnimatedNumberList(dom::SVGElement* aElement, uint8_t aAttrEnum)
105 : mBaseVal(nullptr),
106 mAnimVal(nullptr),
107 mElement(aElement),
108 mAttrEnum(aAttrEnum) {}
110 ~DOMSVGAnimatedNumberList();
112 /// Get a reference to this DOM wrapper object's internal counterpart.
113 SVGAnimatedNumberList& InternalAList();
114 const SVGAnimatedNumberList& InternalAList() const;
116 // Weak refs to our DOMSVGNumberList baseVal/animVal objects. These objects
117 // are friends and take care of clearing these pointers when they die, making
118 // these true weak references.
119 DOMSVGNumberList* mBaseVal;
120 DOMSVGNumberList* mAnimVal;
122 // Strong ref to our element to keep it alive. We hold this not only for
123 // ourself, but also for our base/animVal and all of their items.
124 RefPtr<dom::SVGElement> mElement;
126 uint8_t mAttrEnum;
129 } // namespace dom
130 } // namespace mozilla
132 #endif // DOM_SVG_DOMSVGANIMATEDNUMBERLIST_H_