Bug 1403345, part 4 - Rename nsReferencedElement to dom::IDTracker. r=longsonr
authorJonathan Watt <jwatt@jwatt.org>
Fri, 08 Sep 2017 10:02:05 +0100
changeset 383292 c404bb3b5af70eb280c0c6e2c0fa642aa5e4ab7f
parent 383291 47e852b8e34a31f1618e61273d51a805fa8d2157
child 383293 2aabd2eaef612827c1d243db70858e7c3dd52c0a
push id32588
push userkwierso@gmail.com
push dateWed, 27 Sep 2017 23:52:56 +0000
treeherdermozilla-central@5ebe2e8980c6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr
bugs1403345
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1403345, part 4 - Rename nsReferencedElement to dom::IDTracker. r=longsonr MozReview-Commit-ID: 3cGMHDHEhx0
dom/base/IDTracker.cpp
dom/base/IDTracker.h
dom/smil/nsSMILTimeValueSpec.h
dom/svg/SVGAnimationElement.h
dom/svg/SVGMPathElement.h
dom/svg/SVGUseElement.h
layout/svg/SVGObserverUtils.h
layout/svg/nsSVGFilterInstance.cpp
--- a/dom/base/IDTracker.cpp
+++ b/dom/base/IDTracker.cpp
@@ -11,19 +11,22 @@
 #include "nsIURI.h"
 #include "nsBindingManager.h"
 #include "nsEscape.h"
 #include "nsXBLPrototypeBinding.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMElement.h"
 #include "nsCycleCollectionParticipant.h"
 
+namespace mozilla {
+namespace dom {
+
 void
-nsReferencedElement::Reset(nsIContent* aFromContent, nsIURI* aURI,
-                           bool aWatch, bool aReferenceImage)
+IDTracker::Reset(nsIContent* aFromContent, nsIURI* aURI,
+                 bool aWatch, bool aReferenceImage)
 {
   MOZ_ASSERT(aFromContent, "Reset() expects non-null content pointer");
 
   Unlink();
 
   if (!aURI)
     return;
 
@@ -124,18 +127,18 @@ nsReferencedElement::Reset(nsIContent* a
   }
 
   mReferencingImage = aReferenceImage;
 
   HaveNewDocument(doc, aWatch, ref);
 }
 
 void
-nsReferencedElement::ResetWithID(nsIContent* aFromContent, const nsString& aID,
-                                 bool aWatch)
+IDTracker::ResetWithID(nsIContent* aFromContent, const nsString& aID,
+                       bool aWatch)
 {
   nsIDocument *doc = aFromContent->OwnerDoc();
   if (!doc)
     return;
 
   // XXX Need to take care of XBL/XBL2
 
   if (aWatch) {
@@ -146,18 +149,18 @@ nsReferencedElement::ResetWithID(nsICont
   }
 
   mReferencingImage = false;
 
   HaveNewDocument(doc, aWatch, aID);
 }
 
 void
-nsReferencedElement::HaveNewDocument(nsIDocument* aDocument, bool aWatch,
-                                     const nsString& aRef)
+IDTracker::HaveNewDocument(nsIDocument* aDocument, bool aWatch,
+                           const nsString& aRef)
 {
   if (aWatch) {
     mWatchDocument = aDocument;
     if (mWatchDocument) {
       mElement = mWatchDocument->AddIDTargetObserver(mWatchID, Observe, this,
                                                      mReferencingImage);
     }
     return;
@@ -170,46 +173,46 @@ nsReferencedElement::HaveNewDocument(nsI
   Element *e = mReferencingImage ? aDocument->LookupImageElement(aRef) :
                                    aDocument->GetElementById(aRef);
   if (e) {
     mElement = e;
   }
 }
 
 void
-nsReferencedElement::Traverse(nsCycleCollectionTraversalCallback* aCB)
+IDTracker::Traverse(nsCycleCollectionTraversalCallback* aCB)
 {
   NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*aCB, "mWatchDocument");
   aCB->NoteXPCOMChild(mWatchDocument);
   NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*aCB, "mContent");
   aCB->NoteXPCOMChild(mElement);
 }
 
 void
-nsReferencedElement::Unlink()
+IDTracker::Unlink()
 {
   if (mWatchDocument && mWatchID) {
     mWatchDocument->RemoveIDTargetObserver(mWatchID, Observe, this,
                                            mReferencingImage);
   }
   if (mPendingNotification) {
     mPendingNotification->Clear();
     mPendingNotification = nullptr;
   }
   mWatchDocument = nullptr;
   mWatchID = nullptr;
   mElement = nullptr;
   mReferencingImage = false;
 }
 
 bool
-nsReferencedElement::Observe(Element* aOldElement,
-                             Element* aNewElement, void* aData)
+IDTracker::Observe(Element* aOldElement,
+                   Element* aNewElement, void* aData)
 {
-  nsReferencedElement* p = static_cast<nsReferencedElement*>(aData);
+  IDTracker* p = static_cast<IDTracker*>(aData);
   if (p->mPendingNotification) {
     p->mPendingNotification->SetTo(aNewElement);
   } else {
     NS_ASSERTION(aOldElement == p->mElement, "Failed to track content!");
     ChangeNotification* watcher =
       new ChangeNotification(p, aOldElement, aNewElement);
     p->mPendingNotification = watcher;
     nsContentUtils::AddScriptRunner(watcher);
@@ -217,32 +220,35 @@ nsReferencedElement::Observe(Element* aO
   bool keepTracking = p->IsPersistent();
   if (!keepTracking) {
     p->mWatchDocument = nullptr;
     p->mWatchID = nullptr;
   }
   return keepTracking;
 }
 
-NS_IMPL_ISUPPORTS_INHERITED0(nsReferencedElement::ChangeNotification,
+NS_IMPL_ISUPPORTS_INHERITED0(IDTracker::ChangeNotification,
                              mozilla::Runnable)
 
-NS_IMPL_ISUPPORTS(nsReferencedElement::DocumentLoadNotification,
+NS_IMPL_ISUPPORTS(IDTracker::DocumentLoadNotification,
                   nsIObserver)
 
 NS_IMETHODIMP
-nsReferencedElement::DocumentLoadNotification::Observe(nsISupports* aSubject,
-                                                       const char* aTopic,
-                                                       const char16_t* aData)
+IDTracker::DocumentLoadNotification::Observe(nsISupports* aSubject,
+                                             const char* aTopic,
+                                             const char16_t* aData)
 {
   NS_ASSERTION(PL_strcmp(aTopic, "external-resource-document-created") == 0,
                "Unexpected topic");
   if (mTarget) {
     nsCOMPtr<nsIDocument> doc = do_QueryInterface(aSubject);
     mTarget->mPendingNotification = nullptr;
     NS_ASSERTION(!mTarget->mElement, "Why do we have content here?");
     // If we got here, that means we had Reset() called with aWatch ==
     // true.  So keep watching if IsPersistent().
     mTarget->HaveNewDocument(doc, mTarget->IsPersistent(), mRef);
     mTarget->ElementChanged(nullptr, mTarget->mElement);
   }
   return NS_OK;
 }
+
+} // namespace dom
+} // namespace mozilla
--- a/dom/base/IDTracker.h
+++ b/dom/base/IDTracker.h
@@ -1,25 +1,28 @@
 /* -*- 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 NSREFERENCEDELEMENT_H_
-#define NSREFERENCEDELEMENT_H_
+#ifndef mozilla_dom_IDTracker_h_
+#define mozilla_dom_IDTracker_h_
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/Element.h"
 #include "nsIAtom.h"
 #include "nsIDocument.h"
 #include "nsThreadUtils.h"
 
 class nsIURI;
 
+namespace mozilla {
+namespace dom {
+
 /**
  * Class to track what element is referenced by a given ID.
  *
  * To use it, call Reset() to set it up to watch a given URI. Call get()
  * anytime to determine the referenced element (which may be null if
  * the element isn't found). When the element changes, ElementChanged
  * will be called, so subclass this class if you want to receive that
  * notification. ElementChanged runs at safe-for-script time, i.e. outside
@@ -27,24 +30,24 @@ class nsIURI;
  * for changes (get() will then return null).
  *
  * By default this is a single-shot tracker --- i.e., when ElementChanged
  * fires, we will automatically stop tracking. get() will continue to return
  * the changed-to element.
  * Override IsPersistent to return true if you want to keep tracking after
  * the first change.
  */
-class nsReferencedElement {
+class IDTracker {
 public:
   typedef mozilla::dom::Element Element;
 
-  nsReferencedElement()
+  IDTracker()
     : mReferencingImage(false)
   {}
-  ~nsReferencedElement() {
+  ~IDTracker() {
     Unlink();
   }
 
   /**
    * Find which element, if any, is referenced.
    */
   Element* get() { return mElement; }
 
@@ -111,32 +114,32 @@ private:
                         Element* aNewElement, void* aData);
 
   class Notification : public nsISupports {
   public:
     virtual void SetTo(Element* aTo) = 0;
     virtual void Clear() { mTarget = nullptr; }
     virtual ~Notification() {}
   protected:
-    explicit Notification(nsReferencedElement* aTarget)
+    explicit Notification(IDTracker* aTarget)
       : mTarget(aTarget)
     {
       NS_PRECONDITION(aTarget, "Must have a target");
     }
-    nsReferencedElement* mTarget;
+    IDTracker* mTarget;
   };
 
   class ChangeNotification : public mozilla::Runnable,
                              public Notification
   {
   public:
-    ChangeNotification(nsReferencedElement* aTarget,
+    ChangeNotification(IDTracker* aTarget,
                        Element* aFrom,
                        Element* aTo)
-      : mozilla::Runnable("nsReferencedElement::ChangeNotification")
+      : mozilla::Runnable("IDTracker::ChangeNotification")
       , Notification(aTarget)
       , mFrom(aFrom)
       , mTo(aTo)
     {}
 
     NS_DECL_ISUPPORTS_INHERITED
     NS_IMETHOD Run() override {
       if (mTarget) {
@@ -157,17 +160,17 @@ private:
     RefPtr<Element> mTo;
   };
   friend class ChangeNotification;
 
   class DocumentLoadNotification : public Notification,
                                    public nsIObserver
   {
   public:
-    DocumentLoadNotification(nsReferencedElement* aTarget,
+    DocumentLoadNotification(IDTracker* aTarget,
                              const nsString& aRef) :
       Notification(aTarget)
     {
       if (!mTarget->IsPersistent()) {
         mRef = aRef;
       }
     }
 
@@ -185,23 +188,26 @@ private:
   nsCOMPtr<nsIAtom>      mWatchID;
   nsCOMPtr<nsIDocument>  mWatchDocument;
   RefPtr<Element> mElement;
   RefPtr<Notification> mPendingNotification;
   bool                   mReferencingImage;
 };
 
 inline void
-ImplCycleCollectionUnlink(nsReferencedElement& aField)
+ImplCycleCollectionUnlink(IDTracker& aField)
 {
   aField.Unlink();
 }
 
 inline void
 ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
-                            nsReferencedElement& aField,
+                            IDTracker& aField,
                             const char* aName,
                             uint32_t aFlags = 0)
 {
   aField.Traverse(&aCallback);
 }
 
-#endif /*NSREFERENCEDELEMENT_H_*/
+} // namespace dom
+} // namespace mozilla
+
+#endif /* mozilla_dom_IDTracker_h_ */
--- a/dom/smil/nsSMILTimeValueSpec.h
+++ b/dom/smil/nsSMILTimeValueSpec.h
@@ -81,30 +81,30 @@ protected:
   nsSMILTimedElement*           mOwner;
   bool                          mIsBegin; // Indicates if *we* are a begin spec,
                                           // not to be confused with
                                           // mParams.mSyncBegin which indicates
                                           // if we're synced with the begin of
                                           // the target.
   nsSMILTimeValueSpecParams     mParams;
 
-  class TimeReferenceElement : public nsReferencedElement
+  class TimeReferenceElement : public mozilla::dom::IDTracker
   {
   public:
     explicit TimeReferenceElement(nsSMILTimeValueSpec* aOwner) : mSpec(aOwner) { }
     void ResetWithElement(Element* aTo) {
       RefPtr<Element> from = get();
       Unlink();
       ElementChanged(from, aTo);
     }
 
   protected:
     virtual void ElementChanged(Element* aFrom, Element* aTo) override
     {
-      nsReferencedElement::ElementChanged(aFrom, aTo);
+      IDTracker::ElementChanged(aFrom, aTo);
       mSpec->UpdateReferencedElement(aFrom, aTo);
     }
     virtual bool IsPersistent() override { return true; }
   private:
     nsSMILTimeValueSpec* mSpec;
   };
 
   TimeReferenceElement mReferencedElement;
--- a/dom/svg/SVGAnimationElement.h
+++ b/dom/svg/SVGAnimationElement.h
@@ -94,26 +94,26 @@ public:
 
  protected:
   // nsSVGElement overrides
 
   void UpdateHrefTarget(nsIContent* aNodeForContext,
                         const nsAString& aHrefStr);
   void AnimationTargetChanged();
 
-  class TargetReference : public nsReferencedElement {
+  class TargetReference : public mozilla::dom::IDTracker {
   public:
     explicit TargetReference(SVGAnimationElement* aAnimationElement) :
       mAnimationElement(aAnimationElement) {}
   protected:
     // We need to be notified when target changes, in order to request a
     // sample (which will clear animation effects from old target and apply
     // them to the new target) and update any event registrations.
     virtual void ElementChanged(Element* aFrom, Element* aTo) override {
-      nsReferencedElement::ElementChanged(aFrom, aTo);
+      IDTracker::ElementChanged(aFrom, aTo);
       mAnimationElement->AnimationTargetChanged();
     }
 
     // We need to override IsPersistent to get persistent tracking (beyond the
     // first time the target changes)
     virtual bool IsPersistent() override { return true; }
   private:
     SVGAnimationElement* const mAnimationElement;
--- a/dom/svg/SVGMPathElement.h
+++ b/dom/svg/SVGMPathElement.h
@@ -61,26 +61,26 @@ 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 nsReferencedElement {
+  class PathReference : public mozilla::dom::IDTracker {
   public:
     explicit PathReference(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 {
-      nsReferencedElement::ElementChanged(aFrom, aTo);
+      IDTracker::ElementChanged(aFrom, aTo);
       if (aFrom) {
         aFrom->RemoveMutationObserver(mMpathElement);
       }
       if (aTo) {
         aTo->AddMutationObserver(mMpathElement);
       }
       mMpathElement->NotifyParentOfMpathChange(mMpathElement->GetParent());
     }
--- a/dom/svg/SVGUseElement.h
+++ b/dom/svg/SVGUseElement.h
@@ -76,22 +76,22 @@ public:
   already_AddRefed<SVGAnimatedLength> Y();
   already_AddRefed<SVGAnimatedLength> Width();
   already_AddRefed<SVGAnimatedLength> Height();
 
   nsIURI* GetSourceDocURI();
   URLExtraData* GetContentURLData() const { return mContentURLData; }
 
 protected:
-  class SourceReference : public nsReferencedElement {
+  class SourceReference : public mozilla::dom::IDTracker {
   public:
     explicit SourceReference(SVGUseElement* aContainer) : mContainer(aContainer) {}
   protected:
     virtual void ElementChanged(Element* aFrom, Element* aTo) override {
-      nsReferencedElement::ElementChanged(aFrom, aTo);
+      IDTracker::ElementChanged(aFrom, aTo);
       if (aFrom) {
         aFrom->RemoveMutationObserver(mContainer);
       }
       mContainer->TriggerReclone();
     }
   private:
     SVGUseElement* mContainer;
   };
--- a/layout/svg/SVGObserverUtils.h
+++ b/layout/svg/SVGObserverUtils.h
@@ -108,34 +108,36 @@ protected:
  * When a frame references a supporting resource, we create a property
  * object derived from nsSVGIDRenderingObserver to manage the relationship. The
  * property object is attached to the referencing frame.
  */
 class nsSVGIDRenderingObserver : public nsSVGRenderingObserver
 {
 public:
   typedef mozilla::dom::Element Element;
+  typedef mozilla::dom::IDTracker IDTracker;
+
   nsSVGIDRenderingObserver(nsIURI* aURI, nsIContent* aObservingContent,
                          bool aReferenceImage);
   virtual ~nsSVGIDRenderingObserver();
 
 protected:
   Element* GetTarget() override { return mElement.get(); }
 
   // This is called when the referenced resource changes.
   virtual void DoUpdate() override;
 
-  class SourceReference : public nsReferencedElement
+  class SourceReference : public IDTracker
   {
   public:
     explicit SourceReference(nsSVGIDRenderingObserver* aContainer) : mContainer(aContainer) {}
   protected:
     virtual void ElementChanged(Element* aFrom, Element* aTo) override {
       mContainer->StopListening();
-      nsReferencedElement::ElementChanged(aFrom, aTo);
+      IDTracker::ElementChanged(aFrom, aTo);
       mContainer->StartListening();
       mContainer->DoUpdate();
     }
     /**
      * Override IsPersistent because we want to keep tracking the element
      * for the ID even when it changes.
      */
     virtual bool IsPersistent() override { return true; }
--- a/layout/svg/nsSVGFilterInstance.cpp
+++ b/layout/svg/nsSVGFilterInstance.cpp
@@ -130,17 +130,17 @@ nsSVGFilterInstance::GetFilterFrame(nsIF
     : mFilter.GetURL()->ResolveLocalRef(mTargetContent);
 
   if (!url) {
     NS_NOTREACHED("an nsStyleFilter of type URL should have a non-null URL");
     return nullptr;
   }
 
   // Look up the filter element by URL.
-  nsReferencedElement filterElement;
+  IDTracker filterElement;
   bool watch = false;
   filterElement.Reset(mTargetContent, url, watch);
   Element* element = filterElement.get();
   if (!element) {
     // The URL points to no element.
     return nullptr;
   }