Bug 304835 - Attachments aren't draggable from compose windows; r=bienvenu
authorJim <squibblyflabbetydoo@gmail.com>
Fri, 17 Dec 2010 10:17:38 +0000
changeset 6852 2df02366747d0dcbaa8672a011482349fff81d51
parent 6851 85faf50deb16ec623f6f97ce3bfb31d700d59fb2
child 6853 929bd9af213ef02fdbc38323147c0e49083aaac8
push idunknown
push userunknown
push dateunknown
reviewersbienvenu
bugs304835
Bug 304835 - Attachments aren't draggable from compose windows; r=bienvenu
mail/base/content/mailCore.js
mail/base/content/msgHdrViewOverlay.js
mail/components/compose/content/messengercompose.xul
--- a/mail/base/content/mailCore.js
+++ b/mail/base/content/mailCore.js
@@ -501,8 +501,103 @@ function getMostRecentMailWindow() {
       return null;
 
     win = windowList.getNext();
   }
 #endif
 
   return win;
 }
+
+var attachmentAreaDNDObserver = {
+  onDragStart: function (aEvent, aAttachmentData, aDragAction)
+  {
+    var target = aEvent.target;
+
+    // The message reader will hold an attachment in a descriptionitem, while
+    // the compose window holds it in a listitem.
+    if (target.localName == "descriptionitem" ||
+        target.localName == "listitem")
+    {
+      var attachment = target.attachment;
+      if (attachment.contentType == "text/x-moz-deleted")
+        return;
+
+      var name = attachment.name || attachment.displayName;
+
+      var data = new TransferData();
+      if (attachment.url && name)
+      {
+        // Only add type/filename info for non-file URLs that don't already
+        // have it.
+        if (/(^file:|&filename=)/.test(attachment.url))
+          var info = attachment.url;
+        else
+          var info = attachment.url + "&type=" + attachment.contentType +
+                     "&filename=" + encodeURIComponent(name);
+
+        data.addDataForFlavour("text/x-moz-url",
+                               info + "\n" + name + "\n" + attachment.size);
+        data.addDataForFlavour("text/x-moz-url-data", attachment.url);
+        data.addDataForFlavour("text/x-moz-url-desc", name);
+        data.addDataForFlavour("application/x-moz-file-promise-url",
+                               attachment.url);
+        data.addDataForFlavour("application/x-moz-file-promise",
+                               new nsFlavorDataProvider(), 0,
+                               Components.interfaces.nsISupports);
+      }
+      aAttachmentData.data = data;
+    }
+  }
+};
+
+function nsFlavorDataProvider()
+{
+}
+
+nsFlavorDataProvider.prototype =
+{
+  QueryInterface : function(iid)
+  {
+      if (iid.equals(Components.interfaces.nsIFlavorDataProvider) ||
+          iid.equals(Components.interfaces.nsISupports))
+        return this;
+      throw Components.results.NS_NOINTERFACE;
+  },
+
+  getFlavorData : function(aTransferable, aFlavor, aData, aDataLen)
+  {
+    // get the url for the attachment
+    if (aFlavor == "application/x-moz-file-promise")
+    {
+      var urlPrimitive = { };
+      var dataSize = { };
+      aTransferable.getTransferData("application/x-moz-file-promise-url", urlPrimitive, dataSize);
+
+      var srcUrlPrimitive = urlPrimitive.value.QueryInterface(Components.interfaces.nsISupportsString);
+
+      // now get the destination file location from kFilePromiseDirectoryMime
+      var dirPrimitive = {};
+      aTransferable.getTransferData("application/x-moz-file-promise-dir", dirPrimitive, dataSize);
+      var destDirectory = dirPrimitive.value.QueryInterface(Components.interfaces.nsILocalFile);
+
+      // now save the attachment to the specified location
+      // XXX: we need more information than just the attachment url to save it, fortunately, we have an array
+      // of all the current attachments so we can cheat and scan through them
+
+      var attachment = null;
+      for each (let index in Iterator(currentAttachments, true))
+      {
+        attachment = currentAttachments[index];
+        if (attachment.url == srcUrlPrimitive)
+          break;
+      }
+
+      // call our code for saving attachments
+      if (attachment)
+      {
+        var destFilePath = messenger.saveAttachmentToFolder(attachment.contentType, attachment.url, encodeURIComponent(attachment.displayName), attachment.uri, destDirectory);
+        aData.value = destFilePath.QueryInterface(Components.interfaces.nsISupports);
+        aDataLen.value = 4;
+      }
+    }
+  }
+}
--- a/mail/base/content/msgHdrViewOverlay.js
+++ b/mail/base/content/msgHdrViewOverlay.js
@@ -2175,99 +2175,16 @@ function CopyWebsiteAddress(websiteAddre
 
     var contractid = "@mozilla.org/widget/clipboardhelper;1";
     var iid = Components.interfaces.nsIClipboardHelper;
     var clipboard = Components.classes[contractid].getService(iid);
     clipboard.copyString(websiteAddress);
   }
 }
 
-var attachmentAreaDNDObserver = {
-  onDragStart: function (aEvent, aAttachmentData, aDragAction)
-  {
-    var target = aEvent.target;
-    if (target.localName == "descriptionitem")
-    {
-      var attachment = target.attachment;
-      if (attachment.contentType == "text/x-moz-deleted")
-        return;
-
-      var data = new TransferData();
-      if (attachment.url && attachment.displayName)
-      {
-        var info = attachment.url + "&type=" + attachment.contentType +
-                   "&filename=" + encodeURIComponent(attachment.displayName);
-        data.addDataForFlavour("text/x-moz-url",
-                               info + "\n" + attachment.displayName + "\n" + attachment.size);
-        data.addDataForFlavour("text/x-moz-url-data", attachment.url);
-        data.addDataForFlavour("text/x-moz-url-desc", attachment.displayName);
-        data.addDataForFlavour("application/x-moz-file-promise-url",
-                               attachment.url);
-        data.addDataForFlavour("application/x-moz-file-promise",
-                               new nsFlavorDataProvider(), 0,
-                               Components.interfaces.nsISupports);
-      }
-      aAttachmentData.data = data;
-    }
-  }
-};
-
-function nsFlavorDataProvider()
-{
-}
-
-nsFlavorDataProvider.prototype =
-{
-  QueryInterface : function(iid)
-  {
-      if (iid.equals(Components.interfaces.nsIFlavorDataProvider) ||
-          iid.equals(Components.interfaces.nsISupports))
-        return this;
-      throw Components.results.NS_NOINTERFACE;
-  },
-
-  getFlavorData : function(aTransferable, aFlavor, aData, aDataLen)
-  {
-    // get the url for the attachment
-    if (aFlavor == "application/x-moz-file-promise")
-    {
-      var urlPrimitive = { };
-      var dataSize = { };
-      aTransferable.getTransferData("application/x-moz-file-promise-url", urlPrimitive, dataSize);
-
-      var srcUrlPrimitive = urlPrimitive.value.QueryInterface(Components.interfaces.nsISupportsString);
-
-      // now get the destination file location from kFilePromiseDirectoryMime
-      var dirPrimitive = {};
-      aTransferable.getTransferData("application/x-moz-file-promise-dir", dirPrimitive, dataSize);
-      var destDirectory = dirPrimitive.value.QueryInterface(Components.interfaces.nsILocalFile);
-
-      // now save the attachment to the specified location
-      // XXX: we need more information than just the attachment url to save it, fortunately, we have an array
-      // of all the current attachments so we can cheat and scan through them
-
-      var attachment = null;
-      for each (let index in Iterator(currentAttachments, true))
-      {
-        attachment = currentAttachments[index];
-        if (attachment.url == srcUrlPrimitive)
-          break;
-      }
-
-      // call our code for saving attachments
-      if (attachment)
-      {
-        var destFilePath = messenger.saveAttachmentToFolder(attachment.contentType, attachment.url, encodeURIComponent(attachment.displayName), attachment.uri, destDirectory);
-        aData.value = destFilePath.QueryInterface(Components.interfaces.nsISupports);
-        aDataLen.value = 4;
-      }
-    }
-  }
-}
-
 function nsDummyMsgHeader()
 {
 }
 
 nsDummyMsgHeader.prototype =
 {
   mProperties : new Array,
   getStringProperty : function(aProperty) {
--- a/mail/components/compose/content/messengercompose.xul
+++ b/mail/components/compose/content/messengercompose.xul
@@ -718,17 +718,18 @@
         <splitter id="attachmentbucket-sizer" collapsed="true" collapse="after"/>
         <vbox id="attachments-box" collapsed="true">
           <label id="attachmentBucketText" value="&attachments.label;" crop="right"
                  accesskey="&attachments.accesskey;" control="attachmentBucket"/>
           <listbox seltype="multiple" id="attachmentBucket" flex="1" rows="4"
                    tabindex="0"
                    context="msgComposeAttachmentContext"
                    onkeypress="if (event.keyCode == 8 || event.keyCode == 46) RemoveSelectedAttachment();"
-                   onclick="AttachmentBucketClicked(event);"/>
+                   onclick="AttachmentBucketClicked(event);"
+                   ondraggesture="nsDragAndDrop.startDrag(event, attachmentAreaDNDObserver);"/>
         </vbox>
       </hbox>
     </toolbar>   
 
     <!-- These toolbar items get filled out from the editorOverlay -->
     <toolbar class="chromeclass-toolbar" id="FormatToolbar" persist="collapsed"
              customizable="true" nowindowdrag="true">
       <menulist id="ParagraphSelect"/>