Bug 1436285 - Part 1. Don't use nsIDOMNode version of GetStartNodeAndOffset and GetEndNodeAndOffset. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Wed, 28 Feb 2018 11:32:28 +0900
changeset 760737 0912b22cf75bb7e0178d97fd868a9dba7cb35170
parent 760648 5297541590781af40ff09e067646f3115960af75
child 760738 274494edc2c5705dc1fb36a658005c78090a8a33
push id100743
push userbmo:m_kato@ga2.so-net.ne.jp
push dateWed, 28 Feb 2018 02:37:03 +0000
reviewersmasayuki
bugs1436285
milestone60.0a1
Bug 1436285 - Part 1. Don't use nsIDOMNode version of GetStartNodeAndOffset and GetEndNodeAndOffset. r?masayuki To get a rid of some methods, I would like to replace nsIDOMNode usages with nsINode. MozReview-Commit-ID: B0FVczayND0
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditorDataTransfer.cpp
editor/libeditor/TextEditRules.cpp
editor/libeditor/TextEditRules.h
editor/libeditor/TextEditRulesBidi.cpp
editor/libeditor/TypeInState.cpp
editor/libeditor/TypeInState.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -2198,17 +2198,17 @@ HTMLEditRules::WillDeleteSelection(Selec
     NS_ENSURE_TRUE(host, NS_ERROR_FAILURE);
     rv = CheckForEmptyBlock(startNode, host, aSelection, aAction, aHandled);
     NS_ENSURE_SUCCESS(rv, rv);
     if (*aHandled) {
       return NS_OK;
     }
 
     // Test for distance between caret and text that will be deleted
-    rv = CheckBidiLevelForDeletion(aSelection, GetAsDOMNode(startNode),
+    rv = CheckBidiLevelForDeletion(aSelection, startNode,
                                    startOffset, aAction, aCancel);
     NS_ENSURE_SUCCESS(rv, rv);
     if (*aCancel) {
       return NS_OK;
     }
 
     NS_ENSURE_STATE(mHTMLEditor);
     rv = mHTMLEditor->ExtendSelectionForDelete(aSelection, &aAction);
@@ -7988,17 +7988,17 @@ HTMLEditRules::AdjustSpecialBreaks()
     }
   }
 }
 
 nsresult
 HTMLEditRules::AdjustWhitespace(Selection* aSelection)
 {
   // get selection point
-  nsCOMPtr<nsIDOMNode> selNode;
+  nsCOMPtr<nsINode> selNode;
   int32_t selOffset;
   nsresult rv =
     EditorBase::GetStartNodeAndOffset(aSelection,
                                       getter_AddRefs(selNode), &selOffset);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // ask whitespace object to tweak nbsp's
   NS_ENSURE_STATE(mHTMLEditor);
@@ -8013,28 +8013,31 @@ HTMLEditRules::PinSelectionToNewBlock(Se
     return NS_OK;
   }
 
   if (NS_WARN_IF(!mNewBlock)) {
     return NS_ERROR_NULL_POINTER;
   }
 
   // get the (collapsed) selection location
-  nsCOMPtr<nsIDOMNode> selNode;
+  nsCOMPtr<nsINode> selNode;
   int32_t selOffset;
   nsresult rv =
     EditorBase::GetStartNodeAndOffset(aSelection,
                                       getter_AddRefs(selNode), &selOffset);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+  if (NS_WARN_IF(!selNode)) {
+    return NS_ERROR_FAILURE;
+  }
 
   // use ranges and sRangeHelper to compare sel point to new block
-  nsCOMPtr<nsINode> node = do_QueryInterface(selNode);
-  NS_ENSURE_STATE(node);
-  RefPtr<nsRange> range = new nsRange(node);
-  rv = range->CollapseTo(node, selOffset);
+  RefPtr<nsRange> range = new nsRange(selNode);
+  rv = range->CollapseTo(selNode, selOffset);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   bool nodeBefore, nodeAfter;
   rv = nsRange::CompareNodeToRange(mNewBlock, range, &nodeBefore, &nodeAfter);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (nodeBefore && nodeAfter) {
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -222,29 +222,29 @@ HTMLEditor::DoInsertHTMLWithContext(cons
                                            address_of(fragmentAsNode),
                                            address_of(streamStartParent),
                                            address_of(streamEndParent),
                                            &streamStartOffset,
                                            &streamEndOffset,
                                            aTrustedInput);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIDOMNode> targetNode;
+  nsCOMPtr<nsINode> targetNode;
   int32_t targetOffset=0;
 
   if (!aDestNode) {
     // if caller didn't provide the destination/target node,
     // fetch the paste insertion point from our selection
     rv = GetStartNodeAndOffset(selection, getter_AddRefs(targetNode), &targetOffset);
     NS_ENSURE_SUCCESS(rv, rv);
     if (!targetNode || !IsEditable(targetNode)) {
       return NS_ERROR_FAILURE;
     }
   } else {
-    targetNode = aDestNode;
+    targetNode = do_QueryInterface(aDestNode);
     targetOffset = aDestOffset;
   }
 
   // if we have a destination / target node, we want to insert there
   // rather than in place of the selection
   // ignore aDeleteSelection here if no aDestNode since deletion will
   // also occur later; this block is intended to cover the various
   // scenarios where we are dropping in an editor (and may want to delete
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -26,17 +26,16 @@
 #include "nsComponentManagerUtils.h"
 #include "nsContentUtils.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsGkAtoms.h"
 #include "nsIContent.h"
 #include "nsIDocumentEncoder.h"
 #include "nsIDOMDocument.h"
-#include "nsIDOMNode.h"
 #include "nsNameSpaceManager.h"
 #include "nsINode.h"
 #include "nsIPlaintextEditor.h"
 #include "nsISupportsBase.h"
 #include "nsLiteralString.h"
 #include "nsTextNode.h"
 #include "nsUnicharUtils.h"
 #include "nsIHTMLCollection.h"
@@ -1028,17 +1027,17 @@ TextEditRules::WillDeleteSelection(Selec
       }
       // Otherwise nothing to do for this collapsed selection.
     }
     // Extended selection.
     else {
       mPasswordText.Cut(start, end-start);
     }
   } else {
-    nsCOMPtr<nsIDOMNode> startNode;
+    nsCOMPtr<nsINode> startNode;
     int32_t startOffset;
     nsresult rv =
       EditorBase::GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode),
                                         &startOffset);
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
 
     if (!aSelection->IsCollapsed()) {
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -257,17 +257,17 @@ protected:
    */
   already_AddRefed<Element>
   CreateBRInternal(const EditorRawDOMPoint& aPointToInsert,
                    bool aCreateMozBR);
 
   void UndefineCaretBidiLevel(Selection* aSelection);
 
   nsresult CheckBidiLevelForDeletion(Selection* aSelection,
-                                     nsIDOMNode* aSelNode,
+                                     nsINode* aSelNode,
                                      int32_t aSelOffset,
                                      nsIEditor::EDirection aAction,
                                      bool* aCancel);
 
   nsresult HideLastPWInput();
 
   nsresult CollapseSelectionToTrailingBRIfNeeded(Selection* aSelection);
 
--- a/editor/libeditor/TextEditRulesBidi.cpp
+++ b/editor/libeditor/TextEditRulesBidi.cpp
@@ -7,31 +7,30 @@
 
 #include "mozilla/TextEditor.h"
 #include "mozilla/dom/Selection.h"
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsFrameSelection.h"
 #include "nsIContent.h"
-#include "nsIDOMNode.h"
 #include "nsIEditor.h"
 #include "nsIPresShell.h"
 #include "nsISupportsImpl.h"
 #include "nsPresContext.h"
 #include "nscore.h"
 
 namespace mozilla {
 
 using namespace dom;
 
 // Test for distance between caret and text that will be deleted
 nsresult
 TextEditRules::CheckBidiLevelForDeletion(Selection* aSelection,
-                                         nsIDOMNode* aSelNode,
+                                         nsINode* aSelNode,
                                          int32_t aSelOffset,
                                          nsIEditor::EDirection aAction,
                                          bool* aCancel)
 {
   NS_ENSURE_ARG_POINTER(aCancel);
   *aCancel = false;
 
   nsCOMPtr<nsIPresShell> shell = mTextEditor->GetPresShell();
@@ -39,18 +38,20 @@ TextEditRules::CheckBidiLevelForDeletion
 
   nsPresContext *context = shell->GetPresContext();
   NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
 
   if (!context->BidiEnabled()) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsIContent> content = do_QueryInterface(aSelNode);
-  NS_ENSURE_TRUE(content, NS_ERROR_NULL_POINTER);
+  if (!aSelNode || !aSelNode->IsContent()) {
+    return NS_ERROR_NULL_POINTER;
+  }
+  nsCOMPtr<nsIContent> content = aSelNode->AsContent();
 
   nsBidiLevel levelBefore;
   nsBidiLevel levelAfter;
   RefPtr<nsFrameSelection> frameSelection =
     aSelection->AsSelection()->GetFrameSelection();
   NS_ENSURE_TRUE(frameSelection, NS_ERROR_NULL_POINTER);
 
   nsPrevNextBidiLevels levels = frameSelection->
--- a/editor/libeditor/TypeInState.cpp
+++ b/editor/libeditor/TypeInState.cpp
@@ -9,17 +9,17 @@
 
 #include "nsError.h"
 #include "mozilla/EditorBase.h"
 #include "mozilla/mozalloc.h"
 #include "mozilla/dom/Selection.h"
 #include "nsAString.h"
 #include "nsDebug.h"
 #include "nsGkAtoms.h"
-#include "nsIDOMNode.h"
+#include "nsINode.h"
 #include "nsISupportsBase.h"
 #include "nsISupportsImpl.h"
 #include "nsReadableUtils.h"
 #include "nsStringFwd.h"
 
 // Workaround for windows headers
 #ifdef SetProp
 #undef SetProp
@@ -86,19 +86,18 @@ TypeInState::OnSelectionChange(Selection
   // XXX: changed, and it notifies us more than once for the same change.
   // XXX:
   // XXX: The following code attempts to work around the bogus notifications,
   // XXX: and should probably be removed once bug 140303 is fixed.
   // XXX:
   // XXX: This code temporarily fixes the problem where clicking the mouse in
   // XXX: the same location clears the type-in-state.
 
-  // TODO: We can make this use nsINode instead of nsIDOMNode.
   if (aSelection.IsCollapsed() && aSelection.RangeCount()) {
-    nsCOMPtr<nsIDOMNode> selNode;
+    nsCOMPtr<nsINode> selNode;
     int32_t selOffset = 0;
 
     nsresult rv =
       EditorBase::GetStartNodeAndOffset(&aSelection, getter_AddRefs(selNode),
                                         &selOffset);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return;
     }
--- a/editor/libeditor/TypeInState.h
+++ b/editor/libeditor/TypeInState.h
@@ -15,17 +15,17 @@
 #include "nscore.h"
 
 // Workaround for windows headers
 #ifdef SetProp
 #undef SetProp
 #endif
 
 class nsAtom;
-class nsIDOMNode;
+class nsINode;
 
 namespace mozilla {
 
 class HTMLEditRules;
 namespace dom {
 class Selection;
 } // namespace dom
 
@@ -92,17 +92,17 @@ protected:
   bool IsPropSet(nsAtom* aProp, nsAtom* aAttr, nsAString* outValue,
                  int32_t& outIndex);
   bool IsPropCleared(nsAtom* aProp, nsAtom* aAttr);
   bool IsPropCleared(nsAtom* aProp, nsAtom* aAttr, int32_t& outIndex);
 
   nsTArray<PropItem*> mSetArray;
   nsTArray<PropItem*> mClearedArray;
   int32_t mRelativeFontSize;
-  nsCOMPtr<nsIDOMNode> mLastSelectionContainer;
+  nsCOMPtr<nsINode> mLastSelectionContainer;
   int32_t mLastSelectionOffset;
 
   friend class HTMLEditRules;
 };
 
 } // namespace mozilla
 
 #endif  // #ifndef TypeInState_h