Bug 1387143 part 21. Remove nsISelection getters for anchor and focus points. r=mats
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 08 May 2018 13:52:38 -0400
changeset 471667 feaacb78a655de78b106c8b1fcd6f5ad6af9c5e7
parent 471666 7fc2c97cc372ee868693db92409de6571af4f59f
child 471668 13aee20c6c4b00fa2183fa5b7f975f17ce788a86
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs1387143
milestone62.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 1387143 part 21. Remove nsISelection getters for anchor and focus points. r=mats Instead of copying spec-duplicating comments from nsISelection.idl to Selection.webidl, this just points the latter to the right spec.
dom/base/Selection.cpp
dom/base/nsContentAreaDragDrop.cpp
dom/base/nsIContent.h
dom/base/nsISelection.idl
dom/webidl/Selection.webidl
layout/base/PresShell.cpp
layout/base/nsCaret.cpp
layout/base/nsCaret.h
layout/generic/TextOverflow.cpp
layout/generic/nsFrameSelection.cpp
layout/svg/SVGTextFrame.cpp
widget/nsBaseDragService.cpp
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -795,55 +795,16 @@ Selection::FocusRef()
 
   if (GetDirection() == eDirNext){
     return mAnchorFocusRange->EndRef();
   }
 
   return mAnchorFocusRange->StartRef();
 }
 
-NS_IMETHODIMP
-Selection::GetAnchorNode(nsIDOMNode** aAnchorNode)
-{
-  nsINode* anchorNode = GetAnchorNode();
-  if (anchorNode) {
-    return CallQueryInterface(anchorNode, aAnchorNode);
-  }
-
-  *aAnchorNode = nullptr;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-Selection::GetAnchorOffset(int32_t* aAnchorOffset)
-{
-  *aAnchorOffset = static_cast<int32_t>(AnchorOffset());
-  return NS_OK;
-}
-
-// note: this can return a nil focus node
-NS_IMETHODIMP
-Selection::GetFocusNode(nsIDOMNode** aFocusNode)
-{
-  nsINode* focusNode = GetFocusNode();
-  if (focusNode) {
-    return CallQueryInterface(focusNode, aFocusNode);
-  }
-
-  *aFocusNode = nullptr;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-Selection::GetFocusOffset(int32_t* aFocusOffset)
-{
-  *aFocusOffset = static_cast<int32_t>(FocusOffset());
-  return NS_OK;
-}
-
 void
 Selection::SetAnchorFocusRange(int32_t indx)
 {
   if (indx >= (int32_t)mRanges.Length())
     return;
   if (indx < 0) //release all
   {
     mAnchorFocusRange = nullptr;
--- a/dom/base/nsContentAreaDragDrop.cpp
+++ b/dom/base/nsContentAreaDragDrop.cpp
@@ -75,17 +75,17 @@ private:
   void AddString(DataTransfer* aDataTransfer,
                  const nsAString& aFlavor,
                  const nsAString& aData,
                  nsIPrincipal* aPrincipal,
                  bool aHidden=false);
   nsresult AddStringsToDataTransfer(nsIContent* aDragNode,
                                     DataTransfer* aDataTransfer);
   nsresult GetImageData(imgIContainer* aImage, imgIRequest* aRequest);
-  static nsresult GetDraggableSelectionData(nsISelection* inSelection,
+  static nsresult GetDraggableSelectionData(Selection* inSelection,
                                             nsIContent* inRealTargetNode,
                                             nsIContent **outImageOrLinkNode,
                                             bool* outDragSelectedText);
   static already_AddRefed<nsIContent> FindParentLinkNode(nsIContent* inNode);
   static MOZ_MUST_USE nsresult
   GetAnchorURL(nsIContent* inNode, nsAString& outURL);
   static void GetNodeString(nsIContent* inNode, nsAString & outNodeString);
   static void CreateLinkText(const nsAString& inURL, const nsAString & inText,
@@ -939,17 +939,17 @@ DragDataProducer::AddStringsToDataTransf
   }
 
   return NS_OK;
 }
 
 // note that this can return NS_OK, but a null out param (by design)
 // static
 nsresult
-DragDataProducer::GetDraggableSelectionData(nsISelection* inSelection,
+DragDataProducer::GetDraggableSelectionData(Selection* inSelection,
                                             nsIContent* inRealTargetNode,
                                             nsIContent **outImageOrLinkNode,
                                             bool* outDragSelectedText)
 {
   NS_ENSURE_ARG(inSelection);
   NS_ENSURE_ARG(inRealTargetNode);
   NS_ENSURE_ARG_POINTER(outImageOrLinkNode);
 
@@ -962,35 +962,31 @@ DragDataProducer::GetDraggableSelectionD
   inSelection->GetIsCollapsed(&isCollapsed);
   if (!isCollapsed) {
     nsCOMPtr<nsIDOMNode> realTargetNode = do_QueryInterface(inRealTargetNode);
     inSelection->ContainsNode(realTargetNode, false,
                               &selectionContainsTarget);
 
     if (selectionContainsTarget) {
       // track down the anchor node, if any, for the url
-      nsCOMPtr<nsIDOMNode> selectionStart;
-      inSelection->GetAnchorNode(getter_AddRefs(selectionStart));
-
-      nsCOMPtr<nsIDOMNode> selectionEnd;
-      inSelection->GetFocusNode(getter_AddRefs(selectionEnd));
+      nsINode* selectionStart = inSelection->GetAnchorNode();
+      nsINode* selectionEnd = inSelection->GetFocusNode();
 
       // look for a selection around a single node, like an image.
       // in this case, drag the image, rather than a serialization of the HTML
       // XXX generalize this to other draggable element types?
       if (selectionStart == selectionEnd) {
-        nsCOMPtr<nsIContent> selStartContent = do_QueryInterface(selectionStart);
+        nsCOMPtr<nsIContent> selStartContent = nsIContent::FromNodeOrNull(selectionStart);
         if (selStartContent && selStartContent->HasChildNodes()) {
           // see if just one node is selected
-          int32_t anchorOffset, focusOffset;
-          inSelection->GetAnchorOffset(&anchorOffset);
-          inSelection->GetFocusOffset(&focusOffset);
-          if (abs(anchorOffset - focusOffset) == 1) {
-            int32_t childOffset =
-              (anchorOffset < focusOffset) ? anchorOffset : focusOffset;
+          uint32_t anchorOffset = inSelection->AnchorOffset();
+          uint32_t focusOffset = inSelection->FocusOffset();
+          if (anchorOffset == focusOffset + 1 ||
+              focusOffset == anchorOffset + 1) {
+            uint32_t childOffset = std::min(anchorOffset, focusOffset);
             nsIContent *childContent =
               selStartContent->GetChildAt_Deprecated(childOffset);
             // if we find an image, we'll fall into the node-dragging code,
             // rather the the selection-dragging code
             if (nsContentUtils::IsDraggableImage(childContent)) {
               NS_ADDREF(*outImageOrLinkNode = childContent);
               return NS_OK;
             }
--- a/dom/base/nsIContent.h
+++ b/dom/base/nsIContent.h
@@ -67,16 +67,18 @@ public:
   }
 #endif // MOZILLA_INTERNAL_API
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENT_IID)
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS(nsIContent)
 
+  NS_IMPL_FROMNODE_HELPER(nsIContent, IsContent())
+
   /**
    * Bind this content node to a tree.  If this method throws, the caller must
    * call UnbindFromTree() on the node.  In the typical case of a node being
    * appended to a parent, this will be called after the node has been added to
    * the parent's child list and before nsIDocumentObserver notifications for
    * the addition are dispatched.
    * @param aDocument The new document for the content node.  May not be null
    *                  if aParent is null.  Must match the current document of
--- a/dom/base/nsISelection.idl
+++ b/dom/base/nsISelection.idl
@@ -24,36 +24,16 @@ class Selection;
  *
  * @version 1.0
  */
 
 [shim(Selection), uuid(e0a4d4b3-f34e-44bd-b1f2-4e3bde9b6915)]
 interface nsISelection : nsISupports
 {
     /**
-     * Returns the node in which the selection begins.
-     */
-    readonly attribute nsIDOMNode anchorNode;
-
-    /**
-     * The offset within the (text) node where the selection begins.
-     */
-    readonly attribute long anchorOffset;
-
-    /**
-     * Returns the node in which the selection ends.
-     */
-    readonly attribute nsIDOMNode focusNode;
-
-    /**
-     * The offset within the (text) node where the selection ends.
-     */
-    readonly attribute long focusOffset;
-
-    /**
      * Indicates if the selection is collapsed or not.
      */
     readonly attribute boolean isCollapsed;
     [noscript,notxpcom,nostdcall] boolean collapsed();
 
     /**
      * Collapses the selection to a single point, at the specified offset
      * in the given DOM node. When the selection is collapsed, and the content
--- a/dom/webidl/Selection.webidl
+++ b/dom/webidl/Selection.webidl
@@ -1,15 +1,15 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * The origin of this IDL file is
- * https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#concept-selection
+ * https://w3c.github.io/selection-api/#selection-interface
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 interface Selection {
   readonly attribute Node?         anchorNode;
   readonly attribute unsigned long anchorOffset;
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -52,17 +52,16 @@
 #include "FrameLayerBuilder.h"
 #include "nsViewManager.h"
 #include "nsView.h"
 #include "nsCRTGlue.h"
 #include "prinrval.h"
 #include "nsTArray.h"
 #include "nsCOMArray.h"
 #include "nsContainerFrame.h"
-#include "nsISelection.h"
 #include "mozilla/dom/Selection.h"
 #include "nsGkAtoms.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMNode.h"
 #include "nsRange.h"
 #include "nsWindowSizes.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
@@ -2857,22 +2856,20 @@ nsIPresShell::GetContentForScrolling() c
   return GetSelectedContentForScrolling();
 }
 
 already_AddRefed<nsIContent>
 nsIPresShell::GetSelectedContentForScrolling() const
 {
   nsCOMPtr<nsIContent> selectedContent;
   if (mSelection) {
-    nsISelection* domSelection =
+    Selection* domSelection =
       mSelection->GetSelection(SelectionType::eNormal);
     if (domSelection) {
-      nsCOMPtr<nsIDOMNode> focusedNode;
-      domSelection->GetFocusNode(getter_AddRefs(focusedNode));
-      selectedContent = do_QueryInterface(focusedNode);
+      selectedContent = nsIContent::FromNodeOrNull(domSelection->GetFocusNode());
     }
   }
   return selectedContent.forget();
 }
 
 nsIScrollableFrame*
 nsIPresShell::GetNearestScrollableFrame(
                 nsIFrame* aFrame,
@@ -8258,28 +8255,26 @@ PresShell::PrepareToUseCaretPosition(nsI
   NS_ENSURE_TRUE(caret, false);
 
   bool caretVisible = caret->IsVisible();
   if (!caretVisible)
     return false;
 
   // caret selection, this is a temporary weak reference, so no refcounting is
   // needed
-  nsISelection* domSelection = caret->GetSelection();
+  Selection* domSelection = caret->GetSelection();
   NS_ENSURE_TRUE(domSelection, false);
 
   // since the match could be an anonymous textnode inside a
   // <textarea> or text <input>, we need to get the outer frame
   // note: frames are not refcounted
   nsIFrame* frame = nullptr; // may be nullptr
-  nsCOMPtr<nsIDOMNode> node;
-  rv = domSelection->GetFocusNode(getter_AddRefs(node));
-  NS_ENSURE_SUCCESS(rv, false);
+  nsINode* node = domSelection->GetFocusNode();
   NS_ENSURE_TRUE(node, false);
-  nsCOMPtr<nsIContent> content(do_QueryInterface(node));
+  nsCOMPtr<nsIContent> content = nsIContent::FromNode(node);
   if (content) {
     nsIContent* nonNative = content->FindFirstNonChromeOnlyAccessContent();
     content = nonNative;
   }
 
   if (content) {
     // It seems like ScrollSelectionIntoView should be enough, but it's
     // not. The problem is that scrolling the selection into view when it is
--- a/layout/base/nsCaret.cpp
+++ b/layout/base/nsCaret.cpp
@@ -219,17 +219,17 @@ void nsCaret::Terminate()
   mDomSelectionWeak = nullptr;
   mPresShell = nullptr;
 
   mOverrideContent = nullptr;
 }
 
 NS_IMPL_ISUPPORTS(nsCaret, nsISelectionListener)
 
-nsISelection* nsCaret::GetSelection()
+Selection* nsCaret::GetSelection()
 {
   return mDomSelectionWeak;
 }
 
 void nsCaret::SetSelection(Selection *aDOMSel)
 {
   MOZ_ASSERT(aDOMSel);
   mDomSelectionWeak = aDOMSel;
@@ -386,17 +386,17 @@ nsCaret::GetFrameAndOffset(Selection* aS
   nsINode* focusNode;
   int32_t focusOffset;
 
   if (aOverrideNode) {
     focusNode = aOverrideNode;
     focusOffset = aOverrideOffset;
   } else if (aSelection) {
     focusNode = aSelection->GetFocusNode();
-    aSelection->GetFocusOffset(&focusOffset);
+    focusOffset = aSelection->FocusOffset();
   } else {
     return nullptr;
   }
 
   if (!focusNode || !focusNode->IsContent()) {
     return nullptr;
   }
 
@@ -421,30 +421,23 @@ nsCaret::GetGeometry(nsISelection* aSele
   Selection* selection = aSelection ? aSelection->AsSelection() : nullptr;
   nsIFrame* frame = GetFrameAndOffset(selection, nullptr, 0, &frameOffset);
   if (frame) {
     *aRect = GetGeometryForFrame(frame, frameOffset, nullptr);
   }
   return frame;
 }
 
-Selection*
-nsCaret::GetSelectionInternal()
-{
-  nsISelection* domSelection = GetSelection();
-  return domSelection ? domSelection->AsSelection() : nullptr;
-}
-
 void nsCaret::SchedulePaint(nsISelection* aSelection)
 {
   Selection* selection;
   if (aSelection) {
     selection = aSelection->AsSelection();
   } else {
-    selection = GetSelectionInternal();
+    selection = GetSelection();
   }
   nsINode* focusNode;
   if (mOverrideContent) {
     focusNode = mOverrideContent;
   } else if (selection) {
     focusNode = selection->GetFocusNode();
   } else {
     return;
@@ -494,17 +487,17 @@ nsCaret::CheckSelectionLanguageChange()
   bool isKeyboardRTL = false;
   nsIBidiKeyboard* bidiKeyboard = nsContentUtils::GetBidiKeyboard();
   if (bidiKeyboard) {
     bidiKeyboard->IsLangRTL(&isKeyboardRTL);
   }
   // Call SelectionLanguageChange on every paint. Mostly it will be a noop
   // but it should be fast anyway. This guarantees we never paint the caret
   // at the wrong place.
-  Selection* selection = GetSelectionInternal();
+  Selection* selection = GetSelection();
   if (selection) {
     selection->SelectionLanguageChange(isKeyboardRTL);
   }
 }
 
 nsIFrame*
 nsCaret::GetPaintGeometry(nsRect* aRect)
 {
@@ -513,17 +506,17 @@ nsCaret::GetPaintGeometry(nsRect* aRect)
     return nullptr;
   }
 
   // Update selection language direction now so the new direction will be
   // taken into account when computing the caret position below.
   CheckSelectionLanguageChange();
 
   int32_t frameOffset;
-  nsIFrame* frame = GetFrameAndOffset(GetSelectionInternal(),
+  nsIFrame* frame = GetFrameAndOffset(GetSelection(),
       mOverrideContent, mOverrideOffset, &frameOffset);
   if (!frame) {
     return nullptr;
   }
 
   // now we have a frame, check whether it's appropriate to show the caret here
   const nsStyleUserInterface* userinterface = frame->StyleUserInterface();
   if ((!mIgnoreUserModify &&
@@ -545,17 +538,17 @@ nsCaret::GetPaintGeometry(nsRect* aRect)
   ComputeCaretRects(frame, frameOffset, &caretRect, &hookRect);
 
   aRect->UnionRect(caretRect, hookRect);
   return frame;
 }
 
 nsIFrame*
 nsCaret::GetFrame(int32_t* aContentOffset) {
-  return GetFrameAndOffset(GetSelectionInternal(),
+  return GetFrameAndOffset(GetSelection(),
                            mOverrideContent,
                            mOverrideOffset,
                            aContentOffset);
 }
 
 void nsCaret::PaintCaret(DrawTarget& aDrawTarget,
                          nsIFrame* aForFrame,
                          const nsPoint &aOffset)
@@ -868,20 +861,18 @@ bool nsCaret::IsMenuPopupHidingCaret()
     return false; // No popups, so caret can't be hidden by them.
 
   // Get the selection focus content, that's where the caret would
   // go if it was drawn.
   nsCOMPtr<nsIDOMNode> node;
   if (!mDomSelectionWeak) {
     return true; // No selection/caret to draw.
   }
-  mDomSelectionWeak->GetFocusNode(getter_AddRefs(node));
-  if (!node)
-    return true; // No selection/caret to draw.
-  nsCOMPtr<nsIContent> caretContent = do_QueryInterface(node);
+  nsCOMPtr<nsIContent> caretContent =
+    nsIContent::FromNodeOrNull(mDomSelectionWeak->GetFocusNode());
   if (!caretContent)
     return true; // No selection/caret to draw.
 
   // If there's a menu popup open before the popup with
   // the caret, don't show the caret.
   for (uint32_t i=0; i<popups.Length(); i++) {
     nsMenuPopupFrame* popupFrame = static_cast<nsMenuPopupFrame*>(popups[i]);
     nsIContent* popupContent = popupFrame->GetContent();
--- a/layout/base/nsCaret.h
+++ b/layout/base/nsCaret.h
@@ -48,17 +48,17 @@ class nsCaret final : public nsISelectio
     NS_DECL_ISUPPORTS
 
     typedef mozilla::CaretAssociationHint CaretAssociationHint;
 
     nsresult Init(nsIPresShell *inPresShell);
     void Terminate();
 
     void SetSelection(mozilla::dom::Selection *aDOMSel);
-    nsISelection* GetSelection();
+    mozilla::dom::Selection* GetSelection();
 
     /**
      * Sets whether the caret should only be visible in nodes that are not
      * user-modify: read-only, or whether it should be visible in all nodes.
      *
      * @param aIgnoreUserModify true to have the cursor visible in all nodes,
      *                          false to have it visible in all nodes except
      *                          those with user-modify: read-only
@@ -81,17 +81,17 @@ class nsCaret final : public nsISelectio
         return false;
       }
 
       if (!mShowDuringSelection) {
         mozilla::dom::Selection* selection;
         if (aSelection) {
           selection = static_cast<mozilla::dom::Selection*>(aSelection);
         } else {
-          selection = GetSelectionInternal();
+          selection = GetSelection();
         }
         if (!selection || !selection->IsCollapsed()) {
           return false;
         }
       }
 
       if (IsMenuPopupHidingCaret()) {
         return false;
@@ -208,18 +208,16 @@ class nsCaret final : public nsISelectio
 protected:
     static void   CaretBlinkCallback(nsITimer *aTimer, void *aClosure);
 
     void          CheckSelectionLanguageChange();
 
     void          ResetBlinking();
     void          StopBlinking();
 
-    mozilla::dom::Selection* GetSelectionInternal();
-
     struct Metrics {
       nscoord mBidiIndicatorSize; // width and height of bidi indicator
       nscoord mCaretWidth;        // full caret width including bidi indicator
     };
     static Metrics ComputeMetrics(nsIFrame* aFrame, int32_t aOffset,
                                   nscoord aCaretHeight);
 
     // Returns true if we should not draw the caret because of XUL menu popups.
--- a/layout/generic/TextOverflow.cpp
+++ b/layout/generic/TextOverflow.cpp
@@ -18,17 +18,17 @@
 #include "nsIScrollableFrame.h"
 #include "nsLayoutUtils.h"
 #include "nsPresContext.h"
 #include "nsRect.h"
 #include "nsTextFrame.h"
 #include "nsIFrameInlines.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Likely.h"
-#include "nsISelection.h"
+#include "mozilla/dom/Selection.h"
 #include "TextDrawTarget.h"
 
 using mozilla::layout::TextDrawTarget;
 
 namespace mozilla {
 namespace css {
 
 class LazyReferenceRenderingDrawTargetGetterFromFrame final :
@@ -823,21 +823,20 @@ TextOverflow::CanHaveTextOverflow(nsIFra
   // Its anon block inherits 'text-overflow' and does what is expected.
   if (aBlockFrame->IsComboboxControlFrame()) {
     return false;
   }
 
   // Inhibit the markers if a descendant content owns the caret.
   RefPtr<nsCaret> caret = aBlockFrame->PresShell()->GetCaret();
   if (caret && caret->IsVisible()) {
-    nsCOMPtr<nsISelection> domSelection = caret->GetSelection();
+    RefPtr<dom::Selection> domSelection = caret->GetSelection();
     if (domSelection) {
-      nsCOMPtr<nsIDOMNode> node;
-      domSelection->GetFocusNode(getter_AddRefs(node));
-      nsCOMPtr<nsIContent> content = do_QueryInterface(node);
+      nsCOMPtr<nsIContent> content =
+        nsIContent::FromNodeOrNull(domSelection->GetFocusNode());
       if (content && nsContentUtils::ContentIsDescendantOf(content,
                        aBlockFrame->GetContent())) {
         return false;
       }
     }
   }
   return true;
 }
--- a/layout/generic/nsFrameSelection.cpp
+++ b/layout/generic/nsFrameSelection.cpp
@@ -444,39 +444,22 @@ nsFrameSelection::ConstrainFrameAndPoint
 
   *aRetFrame = aFrame;
   aRetPoint  = aPoint;
 
   //
   // Get the frame and content for the selection's anchor point!
   //
 
-  nsresult result;
-  nsCOMPtr<nsIDOMNode> anchorNode;
-  int32_t anchorOffset = 0;
-
   int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
   if (!mDomSelections[index])
     return NS_ERROR_NULL_POINTER;
 
-  result = mDomSelections[index]->GetAnchorNode(getter_AddRefs(anchorNode));
-
-  if (NS_FAILED(result))
-    return result;
-
-  if (!anchorNode)
-    return NS_OK;
-
-  result = mDomSelections[index]->GetAnchorOffset(&anchorOffset);
-
-  if (NS_FAILED(result))
-    return result;
-
-  nsCOMPtr<nsIContent> anchorContent = do_QueryInterface(anchorNode);
-
+  nsCOMPtr<nsIContent> anchorContent =
+    do_QueryInterface(mDomSelections[index]->GetAnchorNode());
   if (!anchorContent)
     return NS_ERROR_FAILURE;
 
   //
   // Now find the root of the subtree containing the anchor's content.
   //
 
   NS_ENSURE_STATE(mShell);
--- a/layout/svg/SVGTextFrame.cpp
+++ b/layout/svg/SVGTextFrame.cpp
@@ -20,21 +20,21 @@
 #include "mozilla/gfx/PatternHelpers.h"
 #include "mozilla/Likely.h"
 #include "nsAlgorithm.h"
 #include "nsBidiPresUtils.h"
 #include "nsBlockFrame.h"
 #include "nsCaret.h"
 #include "nsContentUtils.h"
 #include "nsGkAtoms.h"
-#include "nsISelection.h"
 #include "nsQuickSort.h"
 #include "SVGObserverUtils.h"
 #include "nsSVGOuterSVGFrame.h"
 #include "nsSVGPaintServerFrame.h"
+#include "mozilla/dom/Selection.h"
 #include "mozilla/dom/SVGRect.h"
 #include "mozilla/dom/SVGTextContentElementBinding.h"
 #include "nsSVGIntegrationUtils.h"
 #include "nsSVGUtils.h"
 #include "nsTArray.h"
 #include "nsTextFrame.h"
 #include "nsTextNode.h"
 #include "SVGAnimatedNumberList.h"
@@ -3516,24 +3516,22 @@ SVGTextFrame::NotifySVGChanged(uint32_t 
 }
 
 /**
  * Gets the offset into a DOM node that the specified caret is positioned at.
  */
 static int32_t
 GetCaretOffset(nsCaret* aCaret)
 {
-  nsCOMPtr<nsISelection> selection = aCaret->GetSelection();
+  RefPtr<Selection> selection = aCaret->GetSelection();
   if (!selection) {
     return -1;
   }
 
-  int32_t offset = -1;
-  selection->GetAnchorOffset(&offset);
-  return offset;
+  return selection->AnchorOffset();
 }
 
 /**
  * Returns whether the caret should be painted for a given TextRenderedRun
  * by checking whether the caret is in the range covered by the rendered run.
  *
  * @param aThisRun The TextRenderedRun to be painted.
  * @param aCaret The caret.
--- a/widget/nsBaseDragService.cpp
+++ b/widget/nsBaseDragService.cpp
@@ -332,18 +332,18 @@ nsBaseDragService::InvokeDragSessionWith
 
   mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
   mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
   mInputSource = aDragEvent->MozInputSource();
 
   // just get the focused node from the selection
   // XXXndeakin this should actually be the deepest node that contains both
   // endpoints of the selection
-  nsCOMPtr<nsIDOMNode> node;
-  aSelection->GetFocusNode(getter_AddRefs(node));
+  nsCOMPtr<nsIDOMNode> node = aSelection->GetFocusNode() ?
+    aSelection->GetFocusNode()->AsDOMNode() : nullptr;
 
   nsresult rv = InvokeDragSession(node, aPrincipalURISpec,
                                   aTransferableArray,
                                   nullptr, aActionType,
                                   nsIContentPolicy::TYPE_OTHER);
 
   if (NS_FAILED(rv)) {
     mHasImage = false;