Bug 1834993 - Fix nursery allocatable flag for objects with foreground finalizers...
[gecko.git] / dom / svg / SVGMPathElement.h
blob411d70a59840ce19303870164b2c0343fceafa40
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_SVGMPATHELEMENT_H_
8 #define DOM_SVG_SVGMPATHELEMENT_H_
10 #include "mozilla/dom/IDTracker.h"
11 #include "mozilla/dom/SVGElement.h"
12 #include "nsStubMutationObserver.h"
13 #include "SVGAnimatedString.h"
15 nsresult NS_NewSVGMPathElement(
16 nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
18 namespace mozilla::dom {
19 class SVGGeometryElement;
21 using SVGMPathElementBase = SVGElement;
23 class SVGMPathElement final : public SVGMPathElementBase,
24 public nsStubMutationObserver {
25 protected:
26 friend nsresult(::NS_NewSVGMPathElement(
27 nsIContent** aResult,
28 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
29 explicit SVGMPathElement(
30 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
31 ~SVGMPathElement();
33 JSObject* WrapNode(JSContext* aCx,
34 JS::Handle<JSObject*> aGivenProto) override;
36 public:
37 // interfaces:
38 NS_DECL_ISUPPORTS_INHERITED
40 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGMPathElement, SVGMPathElementBase)
42 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
44 // nsIContent interface
45 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
46 nsresult BindToTree(BindContext&, nsINode& aParent) override;
47 void UnbindFromTree(bool aNullParent) override;
49 // Element specializations
50 void AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
51 const nsAttrValue* aValue, const nsAttrValue* aOldValue,
52 nsIPrincipal* aMaybeScriptedPrincipal,
53 bool aNotify) override;
55 // Public helper method: If our xlink:href attribute links to a Shape
56 // element, this method returns a pointer to that element. Otherwise,
57 // this returns nullptr.
58 SVGGeometryElement* GetReferencedPath();
60 // WebIDL
61 already_AddRefed<DOMSVGAnimatedString> Href();
63 protected:
64 /**
65 * Helper that provides a reference to the 'path' element with the ID that is
66 * referenced by the 'mpath' element's 'href' attribute, and that will
67 * invalidate the parent of the 'mpath' and update mutation observers to the
68 * new path element if the element that that ID identifies changes to a
69 * different element (or none).
71 class PathElementTracker final : public IDTracker {
72 public:
73 explicit PathElementTracker(SVGMPathElement* aMpathElement)
74 : mMpathElement(aMpathElement) {}
76 protected:
77 // We need to be notified when target changes, in order to request a sample
78 // (which will clear animation effects that used the old target-path
79 // and recompute the animation effects using the new target-path).
80 void ElementChanged(Element* aFrom, Element* aTo) override {
81 IDTracker::ElementChanged(aFrom, aTo);
82 if (aFrom) {
83 aFrom->RemoveMutationObserver(mMpathElement);
85 if (aTo) {
86 aTo->AddMutationObserver(mMpathElement);
88 mMpathElement->NotifyParentOfMpathChange(mMpathElement->GetParent());
91 // We need to override IsPersistent to get persistent tracking (beyond the
92 // first time the target changes)
93 bool IsPersistent() override { return true; }
95 private:
96 SVGMPathElement* const mMpathElement;
99 StringAttributesInfo GetStringInfo() override;
101 void UpdateHrefTarget(nsIContent* aParent, const nsAString& aHrefStr);
102 void UnlinkHrefTarget(bool aNotifyParent);
103 void NotifyParentOfMpathChange(nsIContent* aParent);
105 enum { HREF, XLINK_HREF };
106 SVGAnimatedString mStringAttributes[2];
107 static StringInfo sStringInfo[2];
108 PathElementTracker mPathTracker;
111 } // namespace mozilla::dom
113 #endif // DOM_SVG_SVGMPATHELEMENT_H_