Bug 1261299 - Add a method nsCopySupport::SetSelectionCache instead of relying on the method used to set the os clipboard. draft
authorJimmy Wang <jimmyw22@gmail.com>
Tue, 09 Aug 2016 13:02:14 -0400
changeset 398739 b6b7d8f08a29ff28c7a84ca8550023a3552b7654
parent 398680 a4ec1d42094e9922fd1cc759b34731cbf2c56c90
child 527730 1ee2aaad69a267311b218e8a84b0872d029e86c4
push id25611
push userjimmyw22@gmail.com
push dateTue, 09 Aug 2016 17:02:37 +0000
bugs1261299
milestone51.0a1
Bug 1261299 - Add a method nsCopySupport::SetSelectionCache instead of relying on the method used to set the os clipboard. MozReview-Commit-ID: KvmdD2XqKBh
dom/base/nsCopySupport.cpp
dom/base/nsCopySupport.h
layout/generic/nsSelection.cpp
--- a/dom/base/nsCopySupport.cpp
+++ b/dom/base/nsCopySupport.cpp
@@ -303,16 +303,28 @@ nsCopySupport::HTMLCopy(nsISelection* aS
   uint32_t flags = nsIDocumentEncoder::SkipInvisibleContent;
   if (aWithRubyAnnotation) {
     flags |= nsIDocumentEncoder::OutputRubyAnnotation;
   }
   return SelectionCopyHelper(aSel, aDoc, true, aClipboardID, flags, nullptr);
 }
 
 nsresult
+nsCopySupport::SetSelectionCache(nsISelection* aSel, nsIDocument* aDoc)
+{
+  nsresult rv;
+  nsCOMPtr<nsITransferable> transferable;
+  rv = nsCopySupport::GetTransferableForSelection(aSel, aDoc,
+                                                  getter_AddRefs(transferable));
+  nsCOMPtr<nsIClipboard> clipboard = do_GetService(kCClipboardCID, &rv);
+  clipboard->SetData(transferable, nullptr, nsIClipboard::kSelectionCache);
+  return rv;
+}
+
+nsresult
 nsCopySupport::ClearSelectionCache()
 {
   nsresult rv;
   nsCOMPtr<nsIClipboard> clipboard = do_GetService(kCClipboardCID, &rv);
   clipboard->EmptyClipboard(nsIClipboard::kSelectionCache);
   return rv;
 }
 
--- a/dom/base/nsCopySupport.h
+++ b/dom/base/nsCopySupport.h
@@ -21,16 +21,17 @@ class nsAString;
 class nsIPresShell;
 class nsILoadContext;
 
 class nsCopySupport
 {
   // class of static helper functions for copy support
   public:
     static nsresult ClearSelectionCache();
+    static nsresult SetSelectionCache(nsISelection* aSel, nsIDocument* aDoc);
     static nsresult HTMLCopy(nsISelection *aSel, nsIDocument *aDoc,
                              int16_t aClipboardID, bool aWithRubyAnnotation);
     static nsresult DoHooks(nsIDocument *aDoc, nsITransferable *aTrans,
                             bool *aDoPutOnClipboard);
 
     // Get the selection, or entire document, in the format specified by the mime type
     // (text/html or text/plain). If aSel is non-null, use it, otherwise get the entire
     // doc.
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -6517,16 +6517,20 @@ nsAutoCopyListener::NotifySelectionChang
     }
     /* clear X clipboard? */
     return NS_OK;
   }
 
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc);
   NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
+  if (mCachedClipboard == nsIClipboard::kSelectionCache) {
+    return nsCopySupport::SetSelectionCache(aSel, doc);
+  }
+
   // call the copy code
   return nsCopySupport::HTMLCopy(aSel, doc,
                                  mCachedClipboard, false);
 }
 
 /**
  * See Bug 1288453.
  *