Bug 1029141 - Refactor SVGTextFrame::MutationObserver, de-virtualizing & privatizing its public destructor. r=dholbert
authorAnuj Agarwal <anujagarwal464@gmail.com>
Wed, 02 Jul 2014 12:09:00 +0200
changeset 193264 5900f66edaf9dec24d1c5583e394e1f2b587d3d1
parent 193263 0519b4b09abb7f5c316e22d5f9669d0ca324fabe
child 193265 d980cd9e34825f984ca5357a34f37f4fb3de11fd
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersdholbert
bugs1029141
milestone33.0a1
Bug 1029141 - Refactor SVGTextFrame::MutationObserver, de-virtualizing & privatizing its public destructor. r=dholbert
layout/svg/SVGTextFrame.cpp
layout/svg/SVGTextFrame.h
--- a/layout/svg/SVGTextFrame.cpp
+++ b/layout/svg/SVGTextFrame.cpp
@@ -3162,17 +3162,17 @@ SVGTextFrame::Init(nsIContent*       aCo
                    nsIFrame*         aPrevInFlow)
 {
   NS_ASSERTION(aContent->IsSVG(nsGkAtoms::text), "Content is not an SVG text");
 
   SVGTextFrameBase::Init(aContent, aParent, aPrevInFlow);
   AddStateBits((aParent->GetStateBits() & NS_STATE_SVG_CLIPPATH_CHILD) |
                NS_FRAME_SVG_LAYOUT | NS_FRAME_IS_SVG_TEXT);
 
-  mMutationObserver.StartObserving(this);
+  mMutationObserver = new MutationObserver(this);
 }
 
 void
 SVGTextFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
                                const nsRect& aDirtyRect,
                                const nsDisplayListSet& aLists)
 {
   if (NS_SUBTREE_DIRTY(this)) {
--- a/layout/svg/SVGTextFrame.h
+++ b/layout/svg/SVGTextFrame.h
@@ -424,49 +424,42 @@ public:
   gfxRect TransformFrameRectFromTextChild(const nsRect& aRect,
                                           nsIFrame* aChildFrame);
 
 private:
   /**
    * Mutation observer used to watch for text positioning attribute changes
    * on descendent text content elements (like <tspan>s).
    */
-  class MutationObserver : public nsStubMutationObserver {
+  class MutationObserver MOZ_FINAL : public nsStubMutationObserver {
   public:
-    MutationObserver()
-      : mFrame(nullptr)
-    {
-    }
-
-    void StartObserving(SVGTextFrame* aFrame)
+    MutationObserver(SVGTextFrame* aFrame)
+      : mFrame(aFrame)
     {
-      NS_ASSERTION(!mFrame, "should not be observing yet!");
-      mFrame = aFrame;
-      aFrame->GetContent()->AddMutationObserver(this);
-    }
-
-    virtual ~MutationObserver()
-    {
-      if (mFrame) {
-        mFrame->GetContent()->RemoveMutationObserver(this);
-      }
+      MOZ_ASSERT(mFrame, "MutationObserver needs a non-null frame");
+      mFrame->GetContent()->AddMutationObserver(this);
     }
 
     // nsISupports
     NS_DECL_ISUPPORTS
 
     // nsIMutationObserver
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
     NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
     NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
 
   private:
-    SVGTextFrame* mFrame;
+    ~MutationObserver()
+    {
+      mFrame->GetContent()->RemoveMutationObserver(this);
+    }
+
+    SVGTextFrame* const mFrame;
   };
 
   /**
    * Reflows the anonymous block child if it is dirty or has dirty
    * children, or if the SVGTextFrame itself is dirty.
    */
   void MaybeReflowAnonymousBlockChild();
 
@@ -632,17 +625,17 @@ private:
                              gfxTextContextPaint* aOuterContextPaint,
                              SVGTextContextPaint::Paint& aTargetPaint,
                              nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
                              const FramePropertyDescriptor* aProperty);
 
   /**
    * The MutationObserver we have registered for the <text> element subtree.
    */
-  MutationObserver mMutationObserver;
+  nsRefPtr<MutationObserver> mMutationObserver;
 
   /**
    * Cached canvasTM value.
    */
   nsAutoPtr<gfxMatrix> mCanvasTM;
 
   /**
    * The number of characters in the DOM after the final nsTextFrame.  For
@@ -692,17 +685,9 @@ private:
 
   /**
    * The amount that we need to scale each rendered run to account for
    * lengthAdjust="spacingAndGlyphs".
    */
   float mLengthAdjustScaleFactor;
 };
 
-namespace mozilla {
-template<>
-struct HasDangerousPublicDestructor<SVGTextFrame::MutationObserver>
-{
-  static const bool value = true;
-};
-}
-
 #endif