Bug 567377 - Support drag and drop for Linux. r=mak77
authorJan Horak <jhorak@redhat.com>
Thu, 25 Oct 2012 17:43:24 -0400
changeset 111581 79154a91fb155d1f62899e00d5162f9aeabee98a
parent 111580 4c21f7b5e8e33871a293972d5d8ff3fbfc598d26
child 111582 e1c7f51957048eb824b22d86e5ad92c6b1ce8468
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmak77
bugs567377
milestone19.0a1
Bug 567377 - Support drag and drop for Linux. r=mak77
browser/components/downloads/content/downloads.js
browser/components/downloads/content/indicator.js
toolkit/mozapps/downloads/content/downloads.js
toolkit/mozapps/downloads/tests/chrome/test_bug_462172.xul
--- a/browser/components/downloads/content/downloads.js
+++ b/browser/components/downloads/content/downloads.js
@@ -745,16 +745,19 @@ const DownloadsView = {
     let localFile = controller.dataItem.localFile;
     if (!localFile.exists()) {
       return;
     }
 
     let dataTransfer = aEvent.dataTransfer;
     dataTransfer.mozSetDataAt("application/x-moz-file", localFile, 0);
     dataTransfer.effectAllowed = "copyMove";
+    var url = Services.io.newFileURI(localFile).spec;
+    dataTransfer.setData("text/uri-list", url);
+    dataTransfer.setData("text/plain", url);
     dataTransfer.addElement(element);
 
     aEvent.stopPropagation();
   }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 //// DownloadsViewItem
--- a/browser/components/downloads/content/indicator.js
+++ b/browser/components/downloads/content/indicator.js
@@ -517,16 +517,22 @@ const DownloadsIndicatorView = {
   {
     browserDragAndDrop.dragOver(aEvent);
   },
 
   onDragExit: function () { },
 
   onDrop: function DIV_onDrop(aEvent)
   {
+    let dt = aEvent.dataTransfer;
+    // If dragged item is from our source, do not try to
+    // redownload already downloaded file.
+    if (dt.mozGetDataAt("application/x-moz-file", 0))
+      return;
+
     let name = {};
     let url = browserDragAndDrop.drop(aEvent, name);
     if (url) {
       saveURL(url, name.value, null, true, true);
       aEvent.preventDefault();
     }
   },
 
--- a/toolkit/mozapps/downloads/content/downloads.js
+++ b/toolkit/mozapps/downloads/content/downloads.js
@@ -677,32 +677,40 @@ var gDownloadDNDObserver =
       return;
     var dl = gDownloadsView.selectedItem;
     var f = getLocalFileFromNativePathOrUrl(dl.getAttribute("file"));
     if (!f.exists())
       return;
 
     var dt = aEvent.dataTransfer;
     dt.mozSetDataAt("application/x-moz-file", f, 0);
+    var url = Services.io.newFileURI(f).spec;
+    dt.setData("text/uri-list", url);
+    dt.setData("text/plain", url);
     dt.effectAllowed = "copyMove";
     dt.addElement(dl);
   },
 
   onDragOver: function (aEvent)
   {
     var types = aEvent.dataTransfer.types;
     if (types.contains("text/uri-list") ||
         types.contains("text/x-moz-url") ||
         types.contains("text/plain"))
       aEvent.preventDefault();
   },
 
   onDrop: function(aEvent)
   {
     var dt = aEvent.dataTransfer;
+    // If dragged item is from our source, do not try to
+    // redownload already downloaded file.
+    if (dt.mozGetDataAt("application/x-moz-file", 0))
+      return;
+
     var url = dt.getData("URL");
     var name;
     if (!url) {
       url = dt.getData("text/x-moz-url") || dt.getData("text/plain");
       [url, name] = url.split("\n");
     }
     if (url)
       saveURL(url, name ? name : url, null, true, true, document);
--- a/toolkit/mozapps/downloads/tests/chrome/test_bug_462172.xul
+++ b/toolkit/mozapps/downloads/tests/chrome/test_bug_462172.xul
@@ -61,29 +61,45 @@ const DownloadData = [
     target: realFilePath,
     state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED},
   { name: kFiller,
     source: kFillerURL,
     target: missingFilePath,
     state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED}
 ];
 
+function compareStrFunc(actualData, expectedData) {
+  return expectedData === actualData;
+}
+
 function compareFunc(actualData, expectedData) {
   return expectedData.equals(actualData);
 }
 
 var dragRealFile = [[
   { type  :"application/x-moz-file",
     data  : realFile,
-    eqTest  : compareFunc }
+    eqTest  : compareFunc },
+  { type  : "text/uri-list",
+    data  : realFilePath,
+    eqTest  : compareStrFunc },
+  { type  : "text/plain",
+    data  : realFilePath,
+    eqTest  : compareStrFunc }
 ]];
 var dragMissingFile = [[
   { type  :"application/x-moz-file",
     data  : missingFile,
-    eqTest  : compareFunc }
+    eqTest  : compareFunc },
+  { type  : "text/uri-list",
+    data  : missingFilePath,
+    eqTest  : compareStrFunc },
+  { type  : "text/plain",
+    data  : missingFilePath,
+    eqTest  : compareStrFunc }
 ]];
 
 function test() {
 
   var dmui = getDMUI();
   if (!dmui) {
     todo(false, "skip test for toolkit download manager UI");
     return;