Bug 1359008 - Don't use nsIDOM* in TextEditRules's member. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 24 Apr 2017 19:40:12 +0900
changeset 405201 ac3d3acf9a9e15122fd5ac3af6a697a5cdf8598b
parent 405200 f4353d26ccd15cf4311f2044bbff134820b6da48
child 405202 e84bf70bc70ba03c6cd3e2279dc5d446f2bb161b
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1359008
milestone55.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 1359008 - Don't use nsIDOM* in TextEditRules's member. r=masayuki To clean up TextEditRules, I would like to replace nsIDOMNode with nsINode and nsIContent in TextEditRules. GetTopEnclosingPre is unused define, so I also remove it. MozReview-Commit-ID: 6LraexH5t4m
editor/libeditor/TextEditRules.cpp
editor/libeditor/TextEditRules.h
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -21,20 +21,18 @@
 #include "nsCRTGlue.h"
 #include "nsComponentManagerUtils.h"
 #include "nsContentUtils.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsGkAtoms.h"
 #include "nsIContent.h"
 #include "nsIDOMDocument.h"
-#include "nsIDOMElement.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMNodeFilter.h"
-#include "nsIDOMNodeIterator.h"
 #include "nsIDOMText.h"
 #include "nsNameSpaceManager.h"
 #include "nsINode.h"
 #include "nsIPlaintextEditor.h"
 #include "nsISupportsBase.h"
 #include "nsLiteralString.h"
 #include "nsUnicharUtils.h"
 #include "nsIHTMLCollection.h"
@@ -186,17 +184,17 @@ TextEditRules::BeforeEdit(EditAction act
   }
   mActionNesting++;
 
   // get the selection and cache the position before editing
   NS_ENSURE_STATE(mTextEditor);
   RefPtr<Selection> selection = mTextEditor->GetSelection();
   NS_ENSURE_STATE(selection);
 
-  selection->GetAnchorNode(getter_AddRefs(mCachedSelectionNode));
+  mCachedSelectionNode = selection->GetAnchorNode();
   selection->GetAnchorOffset(&mCachedSelectionOffset);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 TextEditRules::AfterEdit(EditAction action,
                          nsIEditor::EDirection aDirection)
@@ -211,17 +209,17 @@ TextEditRules::AfterEdit(EditAction acti
   if (!--mActionNesting) {
     NS_ENSURE_STATE(mTextEditor);
     RefPtr<Selection> selection = mTextEditor->GetSelection();
     NS_ENSURE_STATE(selection);
 
     NS_ENSURE_STATE(mTextEditor);
     nsresult rv =
       mTextEditor->HandleInlineSpellCheck(action, selection,
-                                          mCachedSelectionNode,
+                                          GetAsDOMNode(mCachedSelectionNode),
                                           mCachedSelectionOffset,
                                           nullptr, 0, nullptr, 0);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // if only trailing <br> remaining remove it
     rv = RemoveRedundantTrailingBR();
     if (NS_FAILED(rv)) {
       return rv;
@@ -990,17 +988,17 @@ TextEditRules::DidUndo(Selection* aSelec
   // If aResult is an error, we return it.
   NS_ENSURE_SUCCESS(aResult, aResult);
 
   NS_ENSURE_STATE(mTextEditor);
   dom::Element* theRoot = mTextEditor->GetRoot();
   NS_ENSURE_TRUE(theRoot, NS_ERROR_FAILURE);
   nsIContent* node = mTextEditor->GetLeftmostChild(theRoot);
   if (node && mTextEditor->IsMozEditorBogusNode(node)) {
-    mBogusNode = do_QueryInterface(node);
+    mBogusNode = node;
   } else {
     mBogusNode = nullptr;
   }
   return aResult;
 }
 
 nsresult
 TextEditRules::WillRedo(Selection* aSelection,
@@ -1040,17 +1038,17 @@ TextEditRules::DidRedo(Selection* aSelec
   if (len != 1) {
     // only in the case of one br could there be the bogus node
     mBogusNode = nullptr;
     return NS_OK;
   }
 
   RefPtr<Element> node = nodeList->Item(0);
   if (mTextEditor->IsMozEditorBogusNode(node)) {
-    mBogusNode = do_QueryInterface(node);
+    mBogusNode = node;
   } else {
     mBogusNode = nullptr;
   }
   return NS_OK;
 }
 
 nsresult
 TextEditRules::WillOutputText(Selection* aSelection,
@@ -1126,17 +1124,17 @@ TextEditRules::RemoveRedundantTrailingBR
     return NS_OK;
   }
 
   // Rather than deleting this node from the DOM tree we should instead
   // morph this br into the bogus node
   elem->UnsetAttr(kNameSpaceID_None, nsGkAtoms::type, true);
 
   // set mBogusNode to be this <br>
-  mBogusNode = do_QueryInterface(elem);
+  mBogusNode = elem;
 
   // give it the bogus node attribute
   elem->SetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom,
                 kMOZEditorBogusNodeValue, false);
   return NS_OK;
 }
 
 nsresult
@@ -1215,26 +1213,24 @@ TextEditRules::CreateBogusNodeIfNeeded(S
     return NS_OK;
   }
 
   // Create a br.
   nsCOMPtr<Element> newContent = mTextEditor->CreateHTMLContent(nsGkAtoms::br);
   NS_ENSURE_STATE(newContent);
 
   // set mBogusNode to be the newly created <br>
-  mBogusNode = do_QueryInterface(newContent);
-  NS_ENSURE_TRUE(mBogusNode, NS_ERROR_NULL_POINTER);
+  mBogusNode = newContent;
 
   // Give it a special attribute.
   newContent->SetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom,
                       kMOZEditorBogusNodeValue, false);
 
   // Put the node in the document.
-  nsCOMPtr<nsIDOMNode> bodyNode = do_QueryInterface(body);
-  nsresult rv = mTextEditor->InsertNode(mBogusNode, bodyNode, 0);
+  nsresult rv = mTextEditor->InsertNode(*mBogusNode, *body, 0);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Set selection.
   aSelection->CollapseNative(body, 0);
   return NS_OK;
 }
 
 
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -11,17 +11,16 @@
 #include "nsCycleCollectionParticipant.h"
 #include "nsIEditRules.h"
 #include "nsIEditor.h"
 #include "nsISupportsImpl.h"
 #include "nsITimer.h"
 #include "nsString.h"
 #include "nscore.h"
 
-class nsIDOMElement;
 class nsIDOMNode;
 
 namespace mozilla {
 
 class AutoLockRulesSniffing;
 class TextEditor;
 namespace dom {
 class Selection;
@@ -119,17 +118,16 @@ protected:
   nsresult WillInsertText(EditAction aAction,
                           Selection* aSelection,
                           bool* aCancel,
                           bool* aHandled,
                           const nsAString* inString,
                           nsAString* outString,
                           int32_t aMaxLength);
   nsresult DidInsertText(Selection* aSelection, nsresult aResult);
-  nsresult GetTopEnclosingPre(nsIDOMNode* aNode, nsIDOMNode** aOutPreNode);
 
   nsresult WillInsertBreak(Selection* aSelection, bool* aCancel,
                            bool* aHandled, int32_t aMaxLength);
   nsresult DidInsertBreak(Selection* aSelection, nsresult aResult);
 
   void WillInsert(Selection& aSelection, bool* aCancel);
   nsresult DidInsert(Selection* aSelection, nsresult aResult);
 
@@ -230,19 +228,19 @@ private:
 
 protected:
   // A buffer we use to store the real value of password editors.
   nsString mPasswordText;
   // A buffer we use to track the IME composition string.
   nsString mPasswordIMEText;
   uint32_t mPasswordIMEIndex;
   // Magic node acts as placeholder in empty doc.
-  nsCOMPtr<nsIDOMNode> mBogusNode;
+  nsCOMPtr<nsIContent> mBogusNode;
   // Cached selected node.
-  nsCOMPtr<nsIDOMNode> mCachedSelectionNode;
+  nsCOMPtr<nsINode> mCachedSelectionNode;
   // Cached selected offset.
   int32_t mCachedSelectionOffset;
   uint32_t mActionNesting;
   bool mLockRulesSniffing;
   bool mDidExplicitlySetInterline;
   // In bidirectional text, delete characters not visually adjacent to the
   // caret without moving the caret first.
   bool mDeleteBidiImmediately;