Bug 1447889 part 8. Remove nsIDOMRange::SelectNode/SelectNodeContents. r=mystor
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 27 Mar 2018 00:35:21 -0400
changeset 410137 f9403cedcdb7fc23ba3a51678514f7aae8000e8f
parent 410136 37568a081a19a8bd293d2c7a5554c094a40d9564
child 410138 5e13b554508bdd65da38da389e915877b95b87e0
push id33718
push userbtara@mozilla.com
push dateTue, 27 Mar 2018 09:16:52 +0000
treeherdermozilla-central@97cdd8febc40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmystor
bugs1447889
milestone61.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 1447889 part 8. Remove nsIDOMRange::SelectNode/SelectNodeContents. r=mystor MozReview-Commit-ID: 2hbF6pT31Xd
dom/base/nsCopySupport.cpp
dom/base/nsRange.cpp
dom/html/nsHTMLDocument.cpp
dom/interfaces/range/nsIDOMRange.idl
editor/spellchecker/nsFilteredContentIterator.cpp
layout/base/PresShell.cpp
toolkit/components/find/nsFind.cpp
--- a/dom/base/nsCopySupport.cpp
+++ b/dom/base/nsCopySupport.cpp
@@ -330,25 +330,26 @@ nsresult
 nsCopySupport::GetTransferableForNode(nsINode* aNode,
                                       nsIDocument* aDoc,
                                       nsITransferable** aTransferable)
 {
   // Make a temporary selection with aNode in a single range.
   // XXX We should try to get rid of the Selection object here.
   // XXX bug 1245883
   nsCOMPtr<nsISelection> selection = new Selection();
-  nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode);
-  NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
   RefPtr<nsRange> range = new nsRange(aNode);
-  nsresult rv = range->SelectNode(node);
-  NS_ENSURE_SUCCESS(rv, rv);
   ErrorResult result;
+  range->SelectNode(*aNode, result);
+  if (NS_WARN_IF(result.Failed())) {
+    return result.StealNSResult();
+  }
   selection->AsSelection()->AddRangeInternal(*range, aDoc, result);
-  rv = result.StealNSResult();
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(result.Failed())) {
+    return result.StealNSResult();
+  }
   // It's not the primary selection - so don't skip invisible content.
   uint32_t flags = 0;
   return SelectionCopyHelper(selection, aDoc, false, 0, flags,
                              aTransferable);
 }
 
 nsresult nsCopySupport::DoHooks(nsIDocument *aDoc, nsITransferable *aTrans,
                                 bool *aDoPutOnClipboard)
--- a/dom/base/nsRange.cpp
+++ b/dom/base/nsRange.cpp
@@ -1652,27 +1652,16 @@ nsRange::Collapse(bool aToStart)
 void
 nsRange::CollapseJS(bool aToStart)
 {
   AutoCalledByJSRestore calledByJSRestorer(*this);
   mCalledByJS = true;
   Collapse(aToStart);
 }
 
-NS_IMETHODIMP
-nsRange::SelectNode(nsIDOMNode* aN)
-{
-  nsCOMPtr<nsINode> node = do_QueryInterface(aN);
-  NS_ENSURE_TRUE(node, NS_ERROR_DOM_INVALID_NODE_TYPE_ERR);
-
-  ErrorResult rv;
-  SelectNode(*node, rv);
-  return rv.StealNSResult();
-}
-
 void
 nsRange::SelectNodeJS(nsINode& aNode, ErrorResult& aErr)
 {
   AutoCalledByJSRestore calledByJSRestorer(*this);
   mCalledByJS = true;
   SelectNode(aNode, aErr);
 }
 
@@ -1704,27 +1693,16 @@ nsRange::SelectNode(nsINode& aNode, Erro
     return;
   }
 
   AutoInvalidateSelection atEndOfBlock(this);
   DoSetRange(RawRangeBoundary(container, index),
              RawRangeBoundary(container, index + 1), newRoot);
 }
 
-NS_IMETHODIMP
-nsRange::SelectNodeContents(nsIDOMNode* aN)
-{
-  nsCOMPtr<nsINode> node = do_QueryInterface(aN);
-  NS_ENSURE_TRUE(node, NS_ERROR_DOM_INVALID_NODE_TYPE_ERR);
-
-  ErrorResult rv;
-  SelectNodeContents(*node, rv);
-  return rv.StealNSResult();
-}
-
 void
 nsRange::SelectNodeContentsJS(nsINode& aNode, ErrorResult& aErr)
 {
   AutoCalledByJSRestore calledByJSRestorer(*this);
   mCalledByJS = true;
   SelectNodeContents(aNode, aErr);
 }
 
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -2192,31 +2192,31 @@ nsHTMLDocument::DeferredContentEditableC
   EditingState oldState = mEditingState;
 
   nsresult rv = EditingStateChanged();
   NS_ENSURE_SUCCESS_VOID(rv);
 
   if (oldState == mEditingState && mEditingState == eContentEditable) {
     // We just changed the contentEditable state of a node, we need to reset
     // the spellchecking state of that node.
-    nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aElement);
-    if (node) {
+    if (aElement) {
       nsPIDOMWindowOuter *window = GetWindow();
       if (!window)
         return;
 
       nsIDocShell *docshell = window->GetDocShell();
       if (!docshell)
         return;
 
       RefPtr<HTMLEditor> htmlEditor = docshell->GetHTMLEditor();
       if (htmlEditor) {
         RefPtr<nsRange> range = new nsRange(aElement);
-        rv = range->SelectNode(node);
-        if (NS_FAILED(rv)) {
+        IgnoredErrorResult res;
+        range->SelectNode(*aElement, res);
+        if (res.Failed()) {
           // The node might be detached from the document at this point,
           // which would cause this call to fail.  In this case, we can
           // safely ignore the contenteditable count change.
           return;
         }
 
         nsCOMPtr<nsIInlineSpellChecker> spellChecker;
         rv = htmlEditor->GetInlineSpellChecker(false,
--- a/dom/interfaces/range/nsIDOMRange.idl
+++ b/dom/interfaces/range/nsIDOMRange.idl
@@ -16,18 +16,16 @@
 interface nsIDOMRange : nsISupports
 {
   readonly attribute boolean          collapsed;
 
   void               setStartBefore(in nsIDOMNode refNode);
   void               setStartAfter(in nsIDOMNode refNode);
   void               setEndBefore(in nsIDOMNode refNode);
   void               setEndAfter(in nsIDOMNode refNode);
-  void               selectNode(in nsIDOMNode refNode);
-  void               selectNodeContents(in nsIDOMNode refNode);
 
   // CompareHow
   const unsigned short      START_TO_START                 = 0;
   const unsigned short      START_TO_END                   = 1;
   const unsigned short      END_TO_END                     = 2;
   const unsigned short      END_TO_START                   = 3;
 
   short              compareBoundaryPoints(in unsigned short how,
--- a/editor/spellchecker/nsFilteredContentIterator.cpp
+++ b/editor/spellchecker/nsFilteredContentIterator.cpp
@@ -62,20 +62,17 @@ nsFilteredContentIterator::Init(nsINode*
   NS_ENSURE_ARG_POINTER(aRoot);
   NS_ENSURE_TRUE(mPreIterator, NS_ERROR_FAILURE);
   NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
   mIsOutOfRange    = false;
   mDirection       = eForward;
   mCurrentIterator = mPreIterator;
 
   mRange = new nsRange(aRoot);
-  nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(aRoot));
-  if (domNode) {
-    mRange->SelectNode(domNode);
-  }
+  mRange->SelectNode(*aRoot, IgnoreErrors());
 
   nsresult rv = mPreIterator->Init(mRange);
   NS_ENSURE_SUCCESS(rv, rv);
   return mIterator->Init(mRange);
 }
 
 //------------------------------------------------------------
 nsresult
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -3175,23 +3175,21 @@ PresShell::GoToAnchor(const nsAString& a
 
     // Should we select the target? This action is controlled by a
     // preference: the default is to not select.
     bool selectAnchor = Preferences::GetBool("layout.selectanchor");
 
     // Even if select anchor pref is false, we must still move the
     // caret there. That way tabbing will start from the new
     // location
-    RefPtr<nsIDOMRange> jumpToRange = new nsRange(mDocument);
+    RefPtr<nsRange> jumpToRange = new nsRange(mDocument);
     while (content && content->GetFirstChild()) {
       content = content->GetFirstChild();
     }
-    nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
-    NS_ASSERTION(node, "No nsIDOMNode for descendant of anchor");
-    jumpToRange->SelectNodeContents(node);
+    jumpToRange->SelectNodeContents(*content, IgnoreErrors());
     // Select the anchor
     RefPtr<Selection> sel = mSelection->GetSelection(SelectionType::eNormal);
     if (sel) {
       sel->RemoveAllRanges();
       sel->AddRange(jumpToRange);
       if (!selectAnchor) {
         // Use a caret (collapsed selection) at the start of the anchor
         sel->CollapseToStart();
@@ -5151,18 +5149,21 @@ PresShell::RenderNode(nsIDOMNode* aNode,
   nsTArray<UniquePtr<RangePaintInfo>> rangeItems;
 
   // nothing to draw if the node isn't in a document
   nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   if (!node->IsInUncomposedDoc())
     return nullptr;
 
   RefPtr<nsRange> range = new nsRange(node);
-  if (NS_FAILED(range->SelectNode(aNode)))
+  IgnoredErrorResult rv;
+  range->SelectNode(*node, rv);
+  if (rv.Failed()) {
     return nullptr;
+  }
 
   UniquePtr<RangePaintInfo> info = CreateRangePaintInfo(range, area, false);
   if (info && !rangeItems.AppendElement(Move(info))) {
     return nullptr;
   }
 
   if (aRegion) {
     // combine the area with the supplied region
--- a/toolkit/components/find/nsFind.cpp
+++ b/toolkit/components/find/nsFind.cpp
@@ -387,27 +387,32 @@ nsFindContentIterator::SetupInnerIterato
   RefPtr<TextEditor> textEditor = tcFrame->GetTextEditor();
   if (!textEditor || textEditor->IsDisabled()) {
     return;
   }
 
   nsCOMPtr<nsIDOMElement> rootElement;
   textEditor->GetRootElement(getter_AddRefs(rootElement));
 
+  nsCOMPtr<nsINode> rootNode = do_QueryInterface(rootElement);
+  if (!rootNode) {
+    return;
+  }
+
   RefPtr<nsRange> innerRange = CreateRange(aContent);
   RefPtr<nsRange> outerRange = CreateRange(aContent);
   if (!innerRange || !outerRange) {
     return;
   }
 
   // now create the inner-iterator
   mInnerIterator = do_CreateInstance(kCPreContentIteratorCID);
 
   if (mInnerIterator) {
-    innerRange->SelectNodeContents(rootElement);
+    innerRange->SelectNodeContents(*rootNode, IgnoreErrors());
 
     // fix up the inner bounds, we may have to only lookup a portion
     // of the text control if the current node is a boundary point
     if (aContent == mStartOuterContent) {
       innerRange->SetStart(*mStartNode, mStartOffset, IgnoreErrors());
     }
     if (aContent == mEndOuterContent) {
       innerRange->SetEnd(*mEndNode, mEndOffset, IgnoreErrors());