mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 21:28:55 +00:00

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
121 lines
4.3 KiB
C++
121 lines
4.3 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/. */
|
|
|
|
#ifndef mozilla_dom_SVGMPathElement_h
|
|
#define mozilla_dom_SVGMPathElement_h
|
|
|
|
#include "mozilla/dom/IDTracker.h"
|
|
#include "mozilla/dom/SVGElement.h"
|
|
#include "nsStubMutationObserver.h"
|
|
#include "SVGAnimatedString.h"
|
|
|
|
nsresult NS_NewSVGMPathElement(
|
|
nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
class SVGPathElement;
|
|
|
|
typedef SVGElement SVGMPathElementBase;
|
|
|
|
class SVGMPathElement final : public SVGMPathElementBase,
|
|
public nsStubMutationObserver {
|
|
protected:
|
|
friend nsresult(::NS_NewSVGMPathElement(
|
|
nsIContent** aResult,
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
|
|
explicit SVGMPathElement(
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
|
|
~SVGMPathElement();
|
|
|
|
virtual JSObject* WrapNode(JSContext* aCx,
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
public:
|
|
// interfaces:
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGMPathElement, SVGMPathElementBase)
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
// nsIContent interface
|
|
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
|
virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
|
|
virtual void UnbindFromTree(bool aNullParent) override;
|
|
|
|
// Element specializations
|
|
virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
const nsAString& aValue,
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
|
nsAttrValue& aResult) override;
|
|
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
|
const nsAttrValue* aValue,
|
|
const nsAttrValue* aOldValue,
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
|
bool aNotify) override;
|
|
|
|
// Public helper method: If our xlink:href attribute links to a <path>
|
|
// element, this method returns a pointer to that element. Otherwise,
|
|
// this returns nullptr.
|
|
SVGPathElement* GetReferencedPath();
|
|
|
|
// WebIDL
|
|
already_AddRefed<DOMSVGAnimatedString> Href();
|
|
|
|
protected:
|
|
/**
|
|
* 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 {
|
|
public:
|
|
explicit PathElementTracker(SVGMPathElement* aMpathElement)
|
|
: mMpathElement(aMpathElement) {}
|
|
|
|
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).
|
|
virtual void ElementChanged(Element* aFrom, Element* aTo) override {
|
|
IDTracker::ElementChanged(aFrom, aTo);
|
|
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)
|
|
virtual bool IsPersistent() override { return true; }
|
|
|
|
private:
|
|
SVGMPathElement* const mMpathElement;
|
|
};
|
|
|
|
virtual StringAttributesInfo GetStringInfo() override;
|
|
|
|
void UpdateHrefTarget(nsIContent* aParent, const nsAString& aHrefStr);
|
|
void UnlinkHrefTarget(bool aNotifyParent);
|
|
void NotifyParentOfMpathChange(nsIContent* aParent);
|
|
|
|
enum { HREF, XLINK_HREF };
|
|
SVGAnimatedString mStringAttributes[2];
|
|
static StringInfo sStringInfo[2];
|
|
PathElementTracker mPathTracker;
|
|
};
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|
|
|
|
#endif // mozilla_dom_SVGMPathElement_h
|