Bug 1447889 part 5. Remove nsIDOMRange::GetCommonAncestorContainer. r=mystor
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 27 Mar 2018 00:35:21 -0400
changeset 410134 063c747e3f312941362a5f29ec2feed00c24f8f0
parent 410133 a4caa4937a31727493981a6c130f704bea96b4c8
child 410135 a55c7ad25f9a81d0451d7c9f191f976c617ab1d3
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 5. Remove nsIDOMRange::GetCommonAncestorContainer. r=mystor MozReview-Commit-ID: 18bnPYjRld5
dom/base/nsCopySupport.cpp
dom/base/nsDocumentEncoder.cpp
dom/base/nsRange.cpp
dom/interfaces/range/nsIDOMRange.idl
toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
toolkit/components/typeaheadfind/nsTypeAheadFind.h
--- a/dom/base/nsCopySupport.cpp
+++ b/dom/base/nsCopySupport.cpp
@@ -726,30 +726,22 @@ IsInsideRuby(nsINode* aNode)
     if (aNode->IsHTMLElement(nsGkAtoms::ruby)) {
       return true;
     }
   }
   return false;
 }
 
 static bool
-IsSelectionInsideRuby(nsISelection* aSelection)
+IsSelectionInsideRuby(Selection* aSelection)
 {
-  int32_t rangeCount;
-  nsresult rv = aSelection->GetRangeCount(&rangeCount);
-  if (NS_FAILED(rv)) {
-    return false;
-  }
+  uint32_t rangeCount = aSelection->RangeCount();;
   for (auto i : IntegerRange(rangeCount)) {
-    nsCOMPtr<nsIDOMRange> range;
-    aSelection->GetRangeAt(i, getter_AddRefs(range));
-    nsCOMPtr<nsIDOMNode> node;
-    range->GetCommonAncestorContainer(getter_AddRefs(node));
-    nsCOMPtr<nsINode> n = do_QueryInterface(node);
-    if (!IsInsideRuby(n)) {
+    nsRange* range = aSelection->GetRangeAt(i);
+    if (!IsInsideRuby(range->GetCommonAncestor())) {
       return false;
     }
   }
   return true;
 }
 
 bool
 nsCopySupport::FireClipboardEvent(EventMessage aEventMessage,
--- a/dom/base/nsDocumentEncoder.cpp
+++ b/dom/base/nsDocumentEncoder.cpp
@@ -1235,34 +1235,33 @@ nsHTMLCopyEncoder::SetSelection(nsISelec
 {
   // check for text widgets: we need to recognize these so that
   // we don't tweak the selection to be outside of the magic
   // div that ender-lite text widgets are embedded in.
 
   if (!aSelection)
     return NS_ERROR_NULL_POINTER;
 
-  nsCOMPtr<nsIDOMNode> commonParent;
   Selection* selection = aSelection->AsSelection();
   uint32_t rangeCount = selection->RangeCount();
 
   // if selection is uninitialized return
   if (!rangeCount) {
     return NS_ERROR_FAILURE;
   }
 
   // we'll just use the common parent of the first range.  Implicit assumption
   // here that multi-range selections are table cell selections, in which case
   // the common parent is somewhere in the table and we don't really care where.
   RefPtr<nsRange> range = selection->GetRangeAt(0);
   if (!range) {
     // XXXbz can this happen given rangeCount > 0?
     return NS_ERROR_NULL_POINTER;
   }
-  range->GetCommonAncestorContainer(getter_AddRefs(commonParent));
+  nsINode* commonParent = range->GetCommonAncestor();
 
   for (nsCOMPtr<nsIContent> selContent(do_QueryInterface(commonParent));
        selContent;
        selContent = selContent->GetParent())
   {
     // checking for selection inside a plaintext form widget
     if (selContent->IsAnyOfHTMLElements(nsGkAtoms::input, nsGkAtoms::textarea))
     {
--- a/dom/base/nsRange.cpp
+++ b/dom/base/nsRange.cpp
@@ -1214,30 +1214,16 @@ nsRange::GetCommonAncestorContainer(Erro
   if (!mIsPositioned) {
     aRv.Throw(NS_ERROR_NOT_INITIALIZED);
     return nullptr;
   }
 
   return nsContentUtils::GetCommonAncestor(mStart.Container(), mEnd.Container());
 }
 
-NS_IMETHODIMP
-nsRange::GetCommonAncestorContainer(nsIDOMNode** aCommonParent)
-{
-  ErrorResult rv;
-  nsINode* commonAncestor = GetCommonAncestorContainer(rv);
-  if (commonAncestor) {
-    NS_ADDREF(*aCommonParent = commonAncestor->AsDOMNode());
-  } else {
-    *aCommonParent = nullptr;
-  }
-
-  return rv.StealNSResult();
-}
-
 /* static */
 bool
 nsRange::IsValidOffset(nsINode* aNode, uint32_t aOffset)
 {
   return aNode &&
          IsValidOffset(aOffset) &&
          static_cast<size_t>(aOffset) <= aNode->Length();
 }
--- a/dom/interfaces/range/nsIDOMRange.idl
+++ b/dom/interfaces/range/nsIDOMRange.idl
@@ -11,17 +11,16 @@
  * For more information on this interface please see
  * http://www.w3.org/TR/DOM-Level-2-Traversal-Range/
  */
 
 [builtinclass, uuid(1f94055c-42e7-4a30-96a1-6a804f1c2d1e)]
 interface nsIDOMRange : nsISupports
 {
   readonly attribute boolean          collapsed;
-  readonly attribute nsIDOMNode       commonAncestorContainer;
 
   void               setStart(in nsIDOMNode refNode, in unsigned long offset);
   void               setEnd(in nsIDOMNode refNode, in unsigned long offset);
   void               setStartBefore(in nsIDOMNode refNode);
   void               setStartAfter(in nsIDOMNode refNode);
   void               setEndBefore(in nsIDOMNode refNode);
   void               setEndAfter(in nsIDOMNode refNode);
   void               collapse(in boolean toStart);
--- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
+++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
@@ -1340,32 +1340,30 @@ nsTypeAheadFind::IsRangeRendered(nsIDOMR
   nsINode* node = range->GetStartContainer();
 
   nsIDocument* doc = node->OwnerDoc();
   nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
   if (!presShell) {
     return NS_ERROR_UNEXPECTED;
   }
   RefPtr<nsPresContext> presContext = presShell->GetPresContext();
-  *aResult = IsRangeRendered(presShell, presContext, aRange);
+  *aResult = IsRangeRendered(presShell, presContext, range);
   return NS_OK;
 }
 
 bool
 nsTypeAheadFind::IsRangeRendered(nsIPresShell *aPresShell,
                                  nsPresContext *aPresContext,
-                                 nsIDOMRange *aRange)
+                                 nsRange *aRange)
 {
   NS_ASSERTION(aPresShell && aPresContext && aRange,
                "params are invalid");
 
-  nsCOMPtr<nsIDOMNode> node;
-  aRange->GetCommonAncestorContainer(getter_AddRefs(node));
-
-  nsCOMPtr<nsIContent> content(do_QueryInterface(node));
+  nsCOMPtr<nsIContent> content =
+    do_QueryInterface(aRange->GetCommonAncestor());
   if (!content) {
     return false;
   }
 
   nsIFrame *frame = content->GetPrimaryFrame();
   if (!frame) {
     return false;  // No frame! Not visible then.
   }
--- a/toolkit/components/typeaheadfind/nsTypeAheadFind.h
+++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.h
@@ -57,17 +57,17 @@ protected:
                     nsISelection **aDomSel);
   // *aNewRange may not be collapsed.  If you want to collapse it in a
   // particular way, you need to do it yourself.
   bool IsRangeVisible(nsIPresShell *aPresShell, nsPresContext *aPresContext,
                       nsRange *aRange, bool aMustBeVisible,
                       bool aGetTopVisibleLeaf, nsIDOMRange **aNewRange,
                       bool *aUsesIndependentSelection);
   bool IsRangeRendered(nsIPresShell *aPresShell, nsPresContext *aPresContext,
-                          nsIDOMRange *aRange);
+                       nsRange *aRange);
   nsresult FindItNow(nsIPresShell *aPresShell, bool aIsLinksOnly,
                      bool aIsFirstVisiblePreferred, bool aFindPrev,
                      uint16_t* aResult);
   nsresult GetSearchContainers(nsISupports *aContainer,
                                nsISelectionController *aSelectionController,
                                bool aIsFirstVisiblePreferred,
                                bool aFindPrev, nsIPresShell **aPresShell,
                                nsPresContext **aPresContext);