Bug 1447889 part 1. Change nsCopySupport to work with Selection a bit more. r=mystor
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 27 Mar 2018 00:35:20 -0400
changeset 463663 6c4b0fd365f2b2228546dd037e4f995168a497b7
parent 463662 898598ebe01890668a5a1d9288e5d64d54c29337
child 463664 2ca7872fa5b6ef0a99c334979229926f1084002b
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [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 1. Change nsCopySupport to work with Selection a bit more. r=mystor MozReview-Commit-ID: B8HePBcalWU
dom/base/nsCopySupport.cpp
dom/base/nsCopySupport.h
layout/base/nsDocumentViewer.cpp
--- a/dom/base/nsCopySupport.cpp
+++ b/dom/base/nsCopySupport.cpp
@@ -683,50 +683,49 @@ static nsresult AppendImagePromise(nsITr
   aTransferable->SetContentPolicyType(nsIContentPolicy::TYPE_INTERNAL_IMAGE);
 
   // add the dataless file promise flavor
   return aTransferable->AddDataFlavor(kFilePromiseMime);
 }
 #endif // XP_WIN
 
 nsIContent*
-nsCopySupport::GetSelectionForCopy(nsIDocument* aDocument, nsISelection** aSelection)
+nsCopySupport::GetSelectionForCopy(nsIDocument* aDocument, Selection** aSelection)
 {
   *aSelection = nullptr;
 
   nsIPresShell* presShell = aDocument->GetShell();
   if (!presShell)
     return nullptr;
 
   nsCOMPtr<nsIContent> focusedContent;
   nsCOMPtr<nsISelectionController> selectionController =
     presShell->GetSelectionControllerForFocusedContent(
       getter_AddRefs(focusedContent));
   if (!selectionController) {
     return nullptr;
   }
 
-  selectionController->GetSelection(nsISelectionController::SELECTION_NORMAL,
-                                    aSelection);
+  RefPtr<Selection> sel =
+    selectionController->GetDOMSelection(nsISelectionController::SELECTION_NORMAL);
+  sel.forget(aSelection);
   return focusedContent;
 }
 
 bool
 nsCopySupport::CanCopy(nsIDocument* aDocument)
 {
   if (!aDocument)
     return false;
 
-  nsCOMPtr<nsISelection> sel;
+  RefPtr<Selection> sel;
   GetSelectionForCopy(aDocument, getter_AddRefs(sel));
   NS_ENSURE_TRUE(sel, false);
 
-  bool isCollapsed;
-  sel->GetIsCollapsed(&isCollapsed);
-  return !isCollapsed;
+  return !sel->IsCollapsed();
 }
 
 static bool
 IsInsideRuby(nsINode* aNode)
 {
   for (; aNode; aNode = aNode->GetParent()) {
     if (aNode->IsHTMLElement(nsGkAtoms::ruby)) {
       return true;
@@ -755,17 +754,17 @@ IsSelectionInsideRuby(nsISelection* aSel
   }
   return true;
 }
 
 bool
 nsCopySupport::FireClipboardEvent(EventMessage aEventMessage,
                                   int32_t aClipboardType,
                                   nsIPresShell* aPresShell,
-                                  nsISelection* aSelection,
+                                  Selection* aSelection,
                                   bool* aActionTaken)
 {
   if (aActionTaken) {
     *aActionTaken = false;
   }
 
   EventMessage originalEventMessage = aEventMessage;
   if (originalEventMessage == ePasteNoFormatting) {
@@ -785,19 +784,20 @@ nsCopySupport::FireClipboardEvent(EventM
     return false;
 
   nsCOMPtr<nsPIDOMWindowOuter> piWindow = doc->GetWindow();
   if (!piWindow)
     return false;
 
   // if a selection was not supplied, try to find it
   nsCOMPtr<nsIContent> content;
-  nsCOMPtr<nsISelection> sel = aSelection;
-  if (!sel)
+  RefPtr<Selection> sel = aSelection;
+  if (!sel) {
     content = GetSelectionForCopy(doc, getter_AddRefs(sel));
+  }
 
   // retrieve the event target node from the start of the selection
   nsresult rv;
   if (sel) {
     nsCOMPtr<nsIDOMRange> range;
     rv = sel->GetRangeAt(0, getter_AddRefs(range));
     if (NS_SUCCEEDED(rv) && range) {
       nsCOMPtr<nsIDOMNode> startContainer;
--- a/dom/base/nsCopySupport.h
+++ b/dom/base/nsCopySupport.h
@@ -15,16 +15,22 @@ class nsINode;
 class nsISelection;
 class nsIDocument;
 class nsIImageLoadingContent;
 class nsIContent;
 class nsITransferable;
 class nsIPresShell;
 class nsILoadContext;
 
+namespace mozilla {
+namespace dom {
+class Selection;
+} // namespace dom
+} // namespace mozilla
+
 class nsCopySupport
 {
   // class of static helper functions for copy support
   public:
     static nsresult ClearSelectionCache();
     static nsresult HTMLCopy(nsISelection *aSel, nsIDocument *aDoc,
                              int16_t aClipboardID, bool aWithRubyAnnotation);
     static nsresult DoHooks(nsIDocument *aDoc, nsITransferable *aTrans,
@@ -51,17 +57,17 @@ class nsCopySupport
                                            nsITransferable** aTransferable);
     /**
      * Retrieve the selection for the given document. If the current focus
      * within the document has its own selection, aSelection will be set to it
      * and this focused content node returned. Otherwise, aSelection will be
      * set to the document's selection and null will be returned.
      */
     static nsIContent* GetSelectionForCopy(nsIDocument* aDocument,
-                                           nsISelection** aSelection);
+                                           mozilla::dom::Selection** aSelection);
 
     /**
      * Returns true if a copy operation is currently permitted based on the
      * current focus and selection within the specified document.
      */
     static bool CanCopy(nsIDocument* aDocument);
 
     /**
@@ -88,13 +94,13 @@ class nsCopySupport
      * If aActionTaken is non-NULL, it will be set to true if an action was
      * taken, whether it be the default action or the default being prevented.
      *
      * If the event is cancelled or an error occurs, false will be returned.
      */
     static bool FireClipboardEvent(mozilla::EventMessage aEventMessage,
                                    int32_t aClipboardType,
                                    nsIPresShell* aPresShell,
-                                   nsISelection* aSelection,
+                                   mozilla::dom::Selection* aSelection,
                                    bool* aActionTaken = nullptr);
 };
 
 #endif
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2793,25 +2793,24 @@ NS_IMETHODIMP nsDocumentViewer::GetCopya
 NS_IMETHODIMP nsDocumentViewer::GetContents(const char *mimeType, bool selectionOnly, nsAString& aOutValue)
 {
   aOutValue.Truncate();
 
   NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
   NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_INITIALIZED);
 
   // Now we have the selection.  Make sure it's nonzero:
-  nsCOMPtr<nsISelection> sel;
+  RefPtr<Selection> sel;
   if (selectionOnly) {
     nsCopySupport::GetSelectionForCopy(mDocument, getter_AddRefs(sel));
     NS_ENSURE_TRUE(sel, NS_ERROR_FAILURE);
 
-    bool isCollapsed;
-    sel->GetIsCollapsed(&isCollapsed);
-    if (isCollapsed)
+    if (sel->IsCollapsed()) {
       return NS_OK;
+    }
   }
 
   // call the copy code
   return nsCopySupport::GetContents(nsDependentCString(mimeType), 0, sel,
                                     mDocument, aOutValue);
 }
 
 NS_IMETHODIMP nsDocumentViewer::GetCanGetContents(bool *aCanGetContents)