2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef DOM_SVG_SVGMPATHELEMENT_H_
|
|
|
|
#define DOM_SVG_SVGMPATHELEMENT_H_
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2017-09-08 12:02:05 +03:00
|
|
|
#include "mozilla/dom/IDTracker.h"
|
2019-04-04 20:40:56 +03:00
|
|
|
#include "mozilla/dom/SVGElement.h"
|
2010-04-29 03:00:54 +04:00
|
|
|
#include "nsStubMutationObserver.h"
|
2019-04-04 20:40:56 +03:00
|
|
|
#include "SVGAnimatedString.h"
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
nsresult NS_NewSVGMPathElement(
|
2014-06-20 06:01:40 +04:00
|
|
|
nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2022-05-09 23:41:17 +03:00
|
|
|
namespace mozilla::dom {
|
2020-10-01 19:19:37 +03:00
|
|
|
class SVGGeometryElement;
|
2013-01-05 05:50:22 +04:00
|
|
|
|
2020-07-15 13:37:55 +03:00
|
|
|
using SVGMPathElementBase = SVGElement;
|
2018-12-21 11:58:14 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class SVGMPathElement final : public SVGMPathElementBase,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsStubMutationObserver {
|
2010-04-29 03:00:54 +04:00
|
|
|
protected:
|
2013-01-05 05:50:22 +04:00
|
|
|
friend nsresult(::NS_NewSVGMPathElement(
|
|
|
|
nsIContent** aResult,
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
|
2018-09-21 23:45:49 +03:00
|
|
|
explicit SVGMPathElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
|
2013-01-05 05:50:22 +04:00
|
|
|
~SVGMPathElement();
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2010-04-29 03:00:54 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
// interfaces:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGMPathElement, SVGMPathElementBase)
|
2010-04-29 03:00:54 +04:00
|
|
|
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
|
|
|
|
// nsIContent interface
|
2018-08-09 02:58:44 +03:00
|
|
|
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
|
2019-05-29 01:47:08 +03:00
|
|
|
virtual void UnbindFromTree(bool aNullParent) override;
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
// Element specializations
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
2010-04-29 03:00:54 +04:00
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAttrValue& aResult) override;
|
2018-01-04 05:03:29 +03:00
|
|
|
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
|
|
|
bool aNotify) override;
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2020-10-01 19:19:37 +03:00
|
|
|
// Public helper method: If our xlink:href attribute links to a Shape
|
2010-04-29 03:00:54 +04:00
|
|
|
// element, this method returns a pointer to that element. Otherwise,
|
2012-07-30 18:20:58 +04:00
|
|
|
// this returns nullptr.
|
2020-10-01 19:19:37 +03:00
|
|
|
SVGGeometryElement* GetReferencedPath();
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
// WebIDL
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedString> Href();
|
2013-01-05 05:50:22 +04:00
|
|
|
|
2010-04-29 03:00:54 +04:00
|
|
|
protected:
|
2017-09-12 16:37:10 +03:00
|
|
|
/**
|
|
|
|
* Helper that provides a reference to the 'path' element with the ID that is
|
|
|
|
* referenced by the 'mpath' element's 'href' attribute, and that will
|
|
|
|
* invalidate the parent of the 'mpath' and update mutation observers to the
|
|
|
|
* new path element if the element that that ID identifies changes to a
|
|
|
|
* different element (or none).
|
|
|
|
*/
|
|
|
|
class PathElementTracker final : public IDTracker {
|
2010-04-29 03:00:54 +04:00
|
|
|
public:
|
2017-09-12 16:37:10 +03:00
|
|
|
explicit PathElementTracker(SVGMPathElement* aMpathElement)
|
|
|
|
: mMpathElement(aMpathElement) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-04-29 03:00:54 +04:00
|
|
|
protected:
|
|
|
|
// We need to be notified when target changes, in order to request a sample
|
|
|
|
// (which will clear animation effects that used the old target-path
|
|
|
|
// and recompute the animation effects using the new target-path).
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ElementChanged(Element* aFrom, Element* aTo) override {
|
2017-09-08 12:02:05 +03:00
|
|
|
IDTracker::ElementChanged(aFrom, aTo);
|
2010-04-29 03:00:54 +04:00
|
|
|
if (aFrom) {
|
|
|
|
aFrom->RemoveMutationObserver(mMpathElement);
|
|
|
|
}
|
|
|
|
if (aTo) {
|
|
|
|
aTo->AddMutationObserver(mMpathElement);
|
|
|
|
}
|
|
|
|
mMpathElement->NotifyParentOfMpathChange(mMpathElement->GetParent());
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to override IsPersistent to get persistent tracking (beyond the
|
|
|
|
// first time the target changes)
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsPersistent() override { return true; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-04-29 03:00:54 +04:00
|
|
|
private:
|
2013-01-05 05:50:22 +04:00
|
|
|
SVGMPathElement* const mMpathElement;
|
2010-04-29 03:00:54 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual StringAttributesInfo GetStringInfo() override;
|
2010-04-29 03:00:54 +04:00
|
|
|
|
|
|
|
void UpdateHrefTarget(nsIContent* aParent, const nsAString& aHrefStr);
|
2011-09-29 10:19:26 +04:00
|
|
|
void UnlinkHrefTarget(bool aNotifyParent);
|
2010-04-29 03:00:54 +04:00
|
|
|
void NotifyParentOfMpathChange(nsIContent* aParent);
|
|
|
|
|
2016-07-06 11:40:30 +03:00
|
|
|
enum { HREF, XLINK_HREF };
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedString mStringAttributes[2];
|
2016-07-06 11:40:30 +03:00
|
|
|
static StringInfo sStringInfo[2];
|
2017-09-12 16:37:10 +03:00
|
|
|
PathElementTracker mPathTracker;
|
2010-04-29 03:00:54 +04:00
|
|
|
};
|
|
|
|
|
2022-05-09 23:41:17 +03:00
|
|
|
} // namespace mozilla::dom
|
2013-01-05 05:50:22 +04:00
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // DOM_SVG_SVGMPATHELEMENT_H_
|