Bug 1403500, part 3 - Document and do some renaming for SVGMPathElement's PathReference. r=longsonr
MozReview-Commit-ID: 7iWd34dp7cD
--- a/dom/svg/SVGMPathElement.cpp
+++ b/dom/svg/SVGMPathElement.cpp
@@ -36,33 +36,33 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(SVGMPathE
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGMPathElement,
SVGMPathElementBase)
tmp->UnlinkHrefTarget(false);
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGMPathElement,
SVGMPathElementBase)
- tmp->mHrefTarget.Traverse(&cb);
+ tmp->mPathTracker.Traverse(&cb);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(SVGMPathElement,
SVGMPathElementBase,
nsIDOMNode,
nsIDOMElement,
nsIDOMSVGElement,
nsIMutationObserver)
// Constructor
SVGMPathElement::SVGMPathElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
- : SVGMPathElementBase(aNodeInfo),
- mHrefTarget(this)
+ : SVGMPathElementBase(aNodeInfo)
+ , mPathTracker(this)
{
}
SVGMPathElement::~SVGMPathElement()
{
UnlinkHrefTarget(false);
}
@@ -83,17 +83,17 @@ SVGMPathElement::Href()
// nsIContent methods
nsresult
SVGMPathElement::BindToTree(nsIDocument* aDocument,
nsIContent* aParent,
nsIContent* aBindingParent,
bool aCompileEventHandlers)
{
- MOZ_ASSERT(!mHrefTarget.get(),
+ MOZ_ASSERT(!mPathTracker.get(),
"Shouldn't have href-target yet (or it should've been cleared)");
nsresult rv = SVGMPathElementBase::BindToTree(aDocument, aParent,
aBindingParent,
aCompileEventHandlers);
NS_ENSURE_SUCCESS(rv,rv);
if (aDocument) {
const nsAttrValue* hrefAttrValue =
@@ -200,23 +200,23 @@ SVGMPathElement::AttributeChanged(nsIDoc
//----------------------------------------------------------------------
// Public helper methods
SVGPathElement*
SVGMPathElement::GetReferencedPath()
{
if (!HasAttr(kNameSpaceID_XLink, nsGkAtoms::href) &&
!HasAttr(kNameSpaceID_None, nsGkAtoms::href)) {
- MOZ_ASSERT(!mHrefTarget.get(),
+ MOZ_ASSERT(!mPathTracker.get(),
"We shouldn't have a href target "
"if we don't have an xlink:href or href attribute");
return nullptr;
}
- nsIContent* genericTarget = mHrefTarget.get();
+ nsIContent* genericTarget = mPathTracker.get();
if (genericTarget && genericTarget->IsSVGElement(nsGkAtoms::path)) {
return static_cast<SVGPathElement*>(genericTarget);
}
return nullptr;
}
//----------------------------------------------------------------------
// Protected helper methods
@@ -226,47 +226,47 @@ SVGMPathElement::UpdateHrefTarget(nsICon
const nsAString& aHrefStr)
{
nsCOMPtr<nsIURI> targetURI;
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI),
aHrefStr, OwnerDoc(), baseURI);
// Stop observing old target (if any)
- if (mHrefTarget.get()) {
- mHrefTarget.get()->RemoveMutationObserver(this);
+ if (mPathTracker.get()) {
+ mPathTracker.get()->RemoveMutationObserver(this);
}
if (aParent) {
// Pass in |aParent| instead of |this| -- first argument is only used
// for a call to GetComposedDoc(), and |this| might not have a current
// document yet (if our caller is BindToTree).
- mHrefTarget.Reset(aParent, targetURI);
+ mPathTracker.Reset(aParent, targetURI);
} else {
// if we don't have a parent, then there's no animateMotion element
// depending on our target, so there's no point tracking it right now.
- mHrefTarget.Unlink();
+ mPathTracker.Unlink();
}
// Start observing new target (if any)
- if (mHrefTarget.get()) {
- mHrefTarget.get()->AddMutationObserver(this);
+ if (mPathTracker.get()) {
+ mPathTracker.get()->AddMutationObserver(this);
}
NotifyParentOfMpathChange(aParent);
}
void
SVGMPathElement::UnlinkHrefTarget(bool aNotifyParent)
{
// Stop observing old target (if any)
- if (mHrefTarget.get()) {
- mHrefTarget.get()->RemoveMutationObserver(this);
+ if (mPathTracker.get()) {
+ mPathTracker.get()->RemoveMutationObserver(this);
}
- mHrefTarget.Unlink();
+ mPathTracker.Unlink();
if (aNotifyParent) {
NotifyParentOfMpathChange(GetParent());
}
}
void
SVGMPathElement::NotifyParentOfMpathChange(nsIContent* aParent)
--- a/dom/svg/SVGMPathElement.h
+++ b/dom/svg/SVGMPathElement.h
@@ -61,20 +61,27 @@ public:
// element, this method returns a pointer to that element. Otherwise,
// this returns nullptr.
SVGPathElement* GetReferencedPath();
// WebIDL
already_AddRefed<SVGAnimatedString> Href();
protected:
- class PathReference : public mozilla::dom::IDTracker {
+ /**
+ * Helper that provides a reference to the 'path' element with the ID that is
+ * referenced by the 'mpath' element's 'href' attribuete, 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.
+ */
+ class PathElementTracker final : public IDTracker {
public:
- explicit PathReference(SVGMPathElement* aMpathElement) :
- mMpathElement(aMpathElement) {}
+ 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);
@@ -96,15 +103,15 @@ protected:
void UpdateHrefTarget(nsIContent* aParent, const nsAString& aHrefStr);
void UnlinkHrefTarget(bool aNotifyParent);
void NotifyParentOfMpathChange(nsIContent* aParent);
enum { HREF, XLINK_HREF };
nsSVGString mStringAttributes[2];
static StringInfo sStringInfo[2];
- PathReference mHrefTarget;
+ PathElementTracker mPathTracker;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_SVGMPathElement_h