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 #include "mozilla/dom/SVGMPathElement.h"
10 #include "mozilla/ArrayUtils.h"
11 #include "mozilla/SVGObserverUtils.h"
12 #include "mozilla/dom/Document.h"
13 #include "mozilla/dom/SVGAnimateMotionElement.h"
14 #include "mozilla/dom/SVGGeometryElement.h"
15 #include "nsContentUtils.h"
16 #include "nsIReferrerInfo.h"
17 #include "mozilla/dom/SVGMPathElementBinding.h"
20 NS_IMPL_NS_NEW_SVG_ELEMENT(MPath
)
22 namespace mozilla::dom
{
24 JSObject
* SVGMPathElement::WrapNode(JSContext
* aCx
,
25 JS::Handle
<JSObject
*> aGivenProto
) {
26 return SVGMPathElement_Binding::Wrap(aCx
, this, aGivenProto
);
29 SVGElement::StringInfo
SVGMPathElement::sStringInfo
[2] = {
30 {nsGkAtoms::href
, kNameSpaceID_None
, false},
31 {nsGkAtoms::href
, kNameSpaceID_XLink
, false}};
33 // Cycle collection magic -- based on SVGUseElement
34 NS_IMPL_CYCLE_COLLECTION_CLASS(SVGMPathElement
)
36 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGMPathElement
,
38 tmp
->mMPathObserver
= nullptr;
39 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
41 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGMPathElement
,
43 SVGObserverUtils::TraverseMPathObserver(tmp
, &cb
);
44 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
46 //----------------------------------------------------------------------
47 // nsISupports methods
49 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(SVGMPathElement
,
53 SVGMPathElement::SVGMPathElement(
54 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
55 : SVGMPathElementBase(std::move(aNodeInfo
)) {}
57 //----------------------------------------------------------------------
60 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGMPathElement
)
62 already_AddRefed
<DOMSVGAnimatedString
> SVGMPathElement::Href() {
63 return mStringAttributes
[HREF
].IsExplicitlySet()
64 ? mStringAttributes
[HREF
].ToDOMAnimatedString(this)
65 : mStringAttributes
[XLINK_HREF
].ToDOMAnimatedString(this);
68 //----------------------------------------------------------------------
71 void SVGMPathElement::UnbindFromTree(bool aNullParent
) {
72 mMPathObserver
= nullptr;
73 NotifyParentOfMpathChange();
74 SVGMPathElementBase::UnbindFromTree(aNullParent
);
77 void SVGMPathElement::AfterSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
78 const nsAttrValue
* aValue
,
79 const nsAttrValue
* aOldValue
,
80 nsIPrincipal
* aMaybeScriptedPrincipal
,
82 if (aName
== nsGkAtoms::href
&&
83 (aNamespaceID
== kNameSpaceID_None
||
84 (aNamespaceID
== kNameSpaceID_XLink
&& !HasAttr(nsGkAtoms::href
)))) {
85 mMPathObserver
= nullptr;
86 NotifyParentOfMpathChange();
89 return SVGMPathElementBase::AfterSetAttr(
90 aNamespaceID
, aName
, aValue
, aOldValue
, aMaybeScriptedPrincipal
, aNotify
);
93 //----------------------------------------------------------------------
96 SVGElement::StringAttributesInfo
SVGMPathElement::GetStringInfo() {
97 return StringAttributesInfo(mStringAttributes
, sStringInfo
,
98 ArrayLength(sStringInfo
));
101 //----------------------------------------------------------------------
102 // Public helper methods
104 void SVGMPathElement::HrefAsString(nsAString
& aHref
) {
105 if (mStringAttributes
[SVGMPathElement::HREF
].IsExplicitlySet()) {
106 mStringAttributes
[SVGMPathElement::HREF
].GetBaseValue(aHref
, this);
108 mStringAttributes
[SVGMPathElement::XLINK_HREF
].GetBaseValue(aHref
, this);
112 SVGGeometryElement
* SVGMPathElement::GetReferencedPath() {
113 return SVGObserverUtils::GetAndObserveMPathsPath(this);
116 void SVGMPathElement::NotifyParentOfMpathChange() {
117 if (auto* animateMotionParent
=
118 SVGAnimateMotionElement::FromNodeOrNull(GetParent())) {
119 animateMotionParent
->MpathChanged();
120 AnimationNeedsResample();
124 } // namespace mozilla::dom