Bug 1054735 part 1 - Clean up nsAutoReplaceContainerSelNotify; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Wed, 20 Aug 2014 15:25:16 +0300
changeset 200523 5ffe54b22d8a3b907dc365b2f56fb159a05dc678
parent 200522 f7e9920fe407566c68c5d162d58f5c705b3251f8
child 200524 8d121ead4ff775c871adbb1e0ec368066748c867
push id47927
push userayg@aryeh.name
push dateWed, 20 Aug 2014 12:25:31 +0000
treeherdermozilla-inbound@e59ab9d1ae98 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1054735
milestone34.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 1054735 part 1 - Clean up nsAutoReplaceContainerSelNotify; r=ehsan
editor/libeditor/nsEditor.cpp
editor/libeditor/nsSelectionState.cpp
editor/libeditor/nsSelectionState.h
--- a/editor/libeditor/nsEditor.cpp
+++ b/editor/libeditor/nsEditor.cpp
@@ -1550,18 +1550,18 @@ nsEditor::ReplaceContainer(Element* aOld
   }
   if (aCloneAttributes == eCloneAttributes) {
     CloneAttributes(ret, aOldContainer);
   }
   
   // notify our internal selection state listener
   // (Note: A nsAutoSelectionReset object must be created
   //  before calling this to initialize mRangeUpdater)
-  nsAutoReplaceContainerSelNotify selStateNotify(mRangeUpdater,
-      aOldContainer->AsDOMNode(), ret->AsDOMNode());
+  AutoReplaceContainerSelNotify selStateNotify(mRangeUpdater, aOldContainer,
+                                               ret);
   {
     nsAutoTxnsConserveSelection conserveSelection(this);
     while (aOldContainer->HasChildren()) {
       nsCOMPtr<nsIContent> child = aOldContainer->GetFirstChild();
 
       res = DeleteNode(child);
       NS_ENSURE_SUCCESS(res, nullptr);
 
--- a/editor/libeditor/nsSelectionState.cpp
+++ b/editor/libeditor/nsSelectionState.cpp
@@ -534,17 +534,17 @@ nsRangeUpdater::WillReplaceContainer()
 {
   if (mLock) return NS_ERROR_UNEXPECTED;  
   mLock = true;
   return NS_OK;
 }
 
 
 nsresult
-nsRangeUpdater::DidReplaceContainer(nsINode* aOriginalNode, nsINode* aNewNode)
+nsRangeUpdater::DidReplaceContainer(Element* aOriginalNode, Element* aNewNode)
 {
   NS_ENSURE_TRUE(mLock, NS_ERROR_UNEXPECTED);
   mLock = false;
 
   NS_ENSURE_TRUE(aOriginalNode && aNewNode, NS_ERROR_NULL_POINTER);
   uint32_t count = mArray.Length();
   if (!count) {
     return NS_OK;
@@ -559,25 +559,16 @@ nsRangeUpdater::DidReplaceContainer(nsIN
     }
     if (item->endNode == aOriginalNode) {
       item->endNode = aNewNode;
     }
   }
   return NS_OK;
 }
 
-nsresult
-nsRangeUpdater::DidReplaceContainer(nsIDOMNode* aOriginalNode,
-                                    nsIDOMNode* aNewNode)
-{
-  nsCOMPtr<nsINode> originalNode = do_QueryInterface(aOriginalNode);
-  nsCOMPtr<nsINode> newNode = do_QueryInterface(aNewNode);
-  return DidReplaceContainer(originalNode, newNode);
-}
-
 
 nsresult
 nsRangeUpdater::WillRemoveContainer()
 {
   if (mLock) return NS_ERROR_UNEXPECTED;  
   mLock = true;
   return NS_OK;
 }
--- a/editor/libeditor/nsSelectionState.h
+++ b/editor/libeditor/nsSelectionState.h
@@ -112,18 +112,18 @@ class nsRangeUpdater
                               const nsAString &aString);
     nsresult SelAdjInsertText(nsIDOMCharacterData *aTextNode, int32_t aOffset, const nsAString &aString);
     nsresult SelAdjDeleteText(nsIContent* aTextNode, int32_t aOffset,
                               int32_t aLength);
     nsresult SelAdjDeleteText(nsIDOMCharacterData *aTextNode, int32_t aOffset, int32_t aLength);
     // the following gravity routines need will/did sandwiches, because the other gravity
     // routines will be called inside of these sandwiches, but should be ignored.
     nsresult WillReplaceContainer();
-    nsresult DidReplaceContainer(nsINode* aOriginalNode, nsINode* aNewNode);
-    nsresult DidReplaceContainer(nsIDOMNode *aOriginalNode, nsIDOMNode *aNewNode);
+    nsresult DidReplaceContainer(mozilla::dom::Element* aOriginalNode,
+                                 mozilla::dom::Element* aNewNode);
     nsresult WillRemoveContainer();
     nsresult DidRemoveContainer(nsINode* aNode, nsINode* aParent,
                                 int32_t aOffset, uint32_t aNodeOrigLen);
     nsresult DidRemoveContainer(nsIDOMNode *aNode, nsIDOMNode *aParent, int32_t aOffset, uint32_t aNodeOrigLen);
     nsresult WillInsertContainer();
     nsresult DidInsertContainer();
     void WillMoveNode();
     void DidMoveNode(nsINode* aOldParent, int32_t aOldOffset,
@@ -188,42 +188,48 @@ class MOZ_STACK_CLASS nsAutoTrackDOMPoin
         *mDOMNode = GetAsDOMNode(mRangeItem->startNode);
       }
       *mOffset = mRangeItem->startOffset;
     }
 };
 
 
 
-/***************************************************************************
+/******************************************************************************
  * another helper class for nsSelectionState.  stack based class for doing
  * Will/DidReplaceContainer()
  */
 
-class MOZ_STACK_CLASS nsAutoReplaceContainerSelNotify
+namespace mozilla {
+namespace dom {
+class MOZ_STACK_CLASS AutoReplaceContainerSelNotify
 {
   private:
     nsRangeUpdater &mRU;
-    nsIDOMNode *mOriginalNode;
-    nsIDOMNode *mNewNode;
+    Element* mOriginalElement;
+    Element* mNewElement;
 
   public:
-    nsAutoReplaceContainerSelNotify(nsRangeUpdater &aRangeUpdater, nsIDOMNode *aOriginalNode, nsIDOMNode *aNewNode) :
-    mRU(aRangeUpdater)
-    ,mOriginalNode(aOriginalNode)
-    ,mNewNode(aNewNode)
+    AutoReplaceContainerSelNotify(nsRangeUpdater& aRangeUpdater,
+                                  Element* aOriginalElement,
+                                  Element* aNewElement)
+      : mRU(aRangeUpdater)
+      , mOriginalElement(aOriginalElement)
+      , mNewElement(aNewElement)
     {
       mRU.WillReplaceContainer();
     }
-    
-    ~nsAutoReplaceContainerSelNotify()
+
+    ~AutoReplaceContainerSelNotify()
     {
-      mRU.DidReplaceContainer(mOriginalNode, mNewNode);
+      mRU.DidReplaceContainer(mOriginalElement, mNewElement);
     }
 };
+}
+}
 
 
 /***************************************************************************
  * another helper class for nsSelectionState.  stack based class for doing
  * Will/DidRemoveContainer()
  */
 
 class MOZ_STACK_CLASS nsAutoRemoveContainerSelNotify