Bug 1403500, part 2 - Document and do some renaming for SVGUseElement's SourceReference. r=longsonr
MozReview-Commit-ID: 9Q1xrG2BNnT
--- a/dom/svg/SVGUseElement.cpp
+++ b/dom/svg/SVGUseElement.cpp
@@ -57,28 +57,29 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_IN
SVGUseElementBase)
nsAutoScriptBlocker scriptBlocker;
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOriginal)
tmp->UnlinkSource();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGUseElement,
SVGUseElementBase)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOriginal)
- tmp->mSource.Traverse(&cb);
+ tmp->mReferencedElementTracker.Traverse(&cb);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(SVGUseElement,
SVGUseElementBase,
nsIMutationObserver)
//----------------------------------------------------------------------
// Implementation
SVGUseElement::SVGUseElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
- : SVGUseElementBase(aNodeInfo), mSource(this)
+ : SVGUseElementBase(aNodeInfo)
+ , mReferencedElementTracker(this)
{
}
SVGUseElement::~SVGUseElement()
{
UnlinkSource();
}
@@ -208,22 +209,22 @@ SVGUseElement::NodeWillBeDestroyed(const
UnlinkSource();
}
//----------------------------------------------------------------------
already_AddRefed<nsIContent>
SVGUseElement::CreateAnonymousContent()
{
- if (mSource.get()) {
- mSource.get()->RemoveMutationObserver(this);
+ if (mReferencedElementTracker.get()) {
+ mReferencedElementTracker.get()->RemoveMutationObserver(this);
}
LookupHref();
- nsIContent* targetContent = mSource.get();
+ nsIContent* targetContent = mReferencedElementTracker.get();
if (!targetContent)
return nullptr;
// make sure target is valid type for <use>
// QIable nsSVGGraphicsElement would eliminate enumerating all elements
if (!targetContent->IsAnyOfSVGElements(nsGkAtoms::svg,
nsGkAtoms::symbol,
nsGkAtoms::g,
@@ -298,17 +299,17 @@ SVGUseElement::CreateAnonymousContent()
#endif // DEBUG
return newcontent.forget();
}
nsIURI*
SVGUseElement::GetSourceDocURI()
{
- nsIContent* targetContent = mSource.get();
+ nsIContent* targetContent = mReferencedElementTracker.get();
if (!targetContent)
return nullptr;
return targetContent->OwnerDoc()->GetDocumentURI();
}
bool
SVGUseElement::OurWidthAndHeightAreUsed() const
@@ -376,17 +377,17 @@ SVGUseElement::LookupHref()
mOriginal ? mOriginal->GetBaseURI() : GetBaseURI();
nsCOMPtr<nsIURI> baseURI = nsContentUtils::IsLocalRefURL(href)
? SVGObserverUtils::GetBaseURLForLocalRef(this, originURI)
: originURI;
nsCOMPtr<nsIURI> targetURI;
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), href,
GetComposedDoc(), baseURI);
- mSource.Reset(this, targetURI);
+ mReferencedElementTracker.Reset(this, targetURI);
}
void
SVGUseElement::TriggerReclone()
{
nsIDocument *doc = GetComposedDoc();
if (!doc)
return;
@@ -394,20 +395,20 @@ SVGUseElement::TriggerReclone()
if (!presShell)
return;
presShell->PostRecreateFramesFor(this);
}
void
SVGUseElement::UnlinkSource()
{
- if (mSource.get()) {
- mSource.get()->RemoveMutationObserver(this);
+ if (mReferencedElementTracker.get()) {
+ mReferencedElementTracker.get()->RemoveMutationObserver(this);
}
- mSource.Unlink();
+ mReferencedElementTracker.Unlink();
}
//----------------------------------------------------------------------
// nsSVGElement methods
/* virtual */ gfxMatrix
SVGUseElement::PrependLocalTransformsTo(
const gfxMatrix &aMatrix, SVGTransformTypes aWhich) const
--- a/dom/svg/SVGUseElement.h
+++ b/dom/svg/SVGUseElement.h
@@ -76,29 +76,36 @@ public:
already_AddRefed<SVGAnimatedLength> Y();
already_AddRefed<SVGAnimatedLength> Width();
already_AddRefed<SVGAnimatedLength> Height();
nsIURI* GetSourceDocURI();
URLExtraData* GetContentURLData() const { return mContentURLData; }
protected:
- class SourceReference : public mozilla::dom::IDTracker {
+ /**
+ * Helper that provides a reference to the element with the ID that is
+ * referenced by the 'use' element's 'href' attribuete, and that will update
+ * the 'use' element if the element that that ID identifies changes.
+ */
+ class ElementTracker final : public IDTracker {
public:
- explicit SourceReference(SVGUseElement* aContainer) : mContainer(aContainer) {}
+ explicit ElementTracker(SVGUseElement* aOwningUseElement)
+ : mOwningUseElement(aOwningUseElement)
+ {}
protected:
virtual void ElementChanged(Element* aFrom, Element* aTo) override {
IDTracker::ElementChanged(aFrom, aTo);
if (aFrom) {
- aFrom->RemoveMutationObserver(mContainer);
+ aFrom->RemoveMutationObserver(mOwningUseElement);
}
- mContainer->TriggerReclone();
+ mOwningUseElement->TriggerReclone();
}
private:
- SVGUseElement* mContainer;
+ SVGUseElement* mOwningUseElement;
};
nsSVGUseFrame* GetFrame() const;
virtual LengthAttributesInfo GetLengthInfo() override;
virtual StringAttributesInfo GetStringInfo() override;
/**
@@ -117,16 +124,16 @@ protected:
static LengthInfo sLengthInfo[4];
enum { HREF, XLINK_HREF };
nsSVGString mStringAttributes[2];
static StringInfo sStringInfo[2];
nsCOMPtr<nsIContent> mOriginal; // if we've been cloned, our "real" copy
nsCOMPtr<nsIContent> mClone; // cloned tree
- SourceReference mSource; // observed element
+ ElementTracker mReferencedElementTracker;
RefPtr<URLExtraData> mContentURLData; // URL data for its anonymous content
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_SVGUseElement_h