Back out HTML5 drag-drop changes since they were backed out in mozilla-central
authorRobert O'Callahan <robert@ocallahan.org>
Tue, 26 Aug 2008 09:43:03 +1200
changeset 191 0ee43b1c92676204e5cce145a37f15a08bbafd6d
parent 190 cbedd5ecd01a3813bccd9b1e5b646c47a4783777
child 192 1c152d4608543640fa113d799704accb64b4eec5
push idunknown
push userunknown
push dateunknown
Back out HTML5 drag-drop changes since they were backed out in mozilla-central
mail/base/content/ABSearchDialog.xul
mail/extensions/newsblog/content/feed-subscriptions.js
mailnews/base/resources/content/messengerdnd.js
suite/browser/pageinfo/pageInfo.js
--- a/mail/base/content/ABSearchDialog.xul
+++ b/mail/base/content/ABSearchDialog.xul
@@ -63,17 +63,16 @@
 
   <stringbundleset id="stringbundleset">
     <stringbundle id="bundle_addressBook" src="chrome://messenger/locale/addressbook/addressBook.properties"/>
     <stringbundle id="bundle_search" src="chrome://messenger/locale/search.properties"/>
     <stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
     <stringbundle id="bundle_brand" src="chrome://branding/locale/brand.properties"/>
   </stringbundleset>
 
-  <script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
   <script type="application/x-javascript" src="chrome://messenger/content/mailWindow.js"/>
   <script type="application/x-javascript" src="chrome://messenger/content/msgMail3PaneWindow.js"/>
   <script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
   <script type="application/x-javascript" src="chrome://messenger/content/commandglue.js"/>
   <script type="application/x-javascript" src="chrome://messenger/content/ABSearchDialog.js"/>
   <script type="application/x-javascript" src="chrome://messenger/content/addressbook/abResultsPane.js"/>
   <script type="application/x-javascript" src="chrome://messenger/content/addressbook/abCommon.js"/>
 
--- a/mail/extensions/newsblog/content/feed-subscriptions.js
+++ b/mail/extensions/newsblog/content/feed-subscriptions.js
@@ -795,18 +795,28 @@ var gFeedSubscriptionsWindow = {
     if (seln.count != 1) 
       return;
 
     // only initiate a drag if the item is a feed (i.e. ignore folders/containers)
     var item = this.mView.getItemAtIndex(seln.currentIndex);
     if (!item || item.container)
       return;
 
-    event.dataTransfer.setData("text/x-moz-feed-index", seln.currentIndex.toString());
-    event.dataTransfer.effectAllowed = "move";
+    var transfer = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable); 
+    var transArray = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray);
+    var dragData = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
+
+    transfer.addDataFlavor("text/x-moz-feed-index"); // i made this flavor type up
+    dragData.data = seln.currentIndex.toString();
+
+    transfer.setTransferData ( "text/x-moz-feed-index", dragData, seln.currentIndex.toString() * 2 );  // doublebyte byte data
+    transArray.AppendElement(transfer.QueryInterface(Components.interfaces.nsISupports));
+
+    var dragService = Components.classes["@mozilla.org/widget/dragservice;1"].getService().QueryInterface(nsIDragService);
+    dragService.invokeDragSession ( aEvent.target, transArray, null, nsIDragService.DRAGDROP_ACTION_MOVE);
   },
 
   mFeedDownloadCallback:
   {
     downloaded: function(feed, aErrorCode)
     {
       // feed is null if our attempt to parse the feed failed
       if (aErrorCode == kNewsBlogSuccess)
--- a/mailnews/base/resources/content/messengerdnd.js
+++ b/mailnews/base/resources/content/messengerdnd.js
@@ -460,15 +460,82 @@ function BeginDragThreadPane(event)
     //no major disadvantage even if it is a copy operation
 
     SetNextMessageAfterDelete();
     return BeginDragTree(event, threadTree, selectedMessages, "text/x-moz-message");
 }
 
 function BeginDragTree(event, tree, selArray, flavor)
 {
-    var dataTransfer = event.dataTransfer;
-    dataTransfer.setData(flavor, selArray);
-    dataTransfer.effectAllowed = "copyMove";
-    dataTransfer.addElement(event.originalTarget);
+    var dragStarted = false;
+
+    var transArray = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray);
+    if ( !transArray ) 
+      return false;
+
+    // let's build the drag region
+    var region = null;
+    try {
+      region = Components.classes["@mozilla.org/gfx/region;1"].createInstance(Components.interfaces.nsIScriptableRegion);
+      region.init();
+      var obo = tree.treeBoxObject;
+      var bo = obo.treeBody.boxObject;
+      var sel= tree.view.selection;
+
+      var rowX = bo.x;
+      var rowY = bo.y;
+      var rowHeight = obo.rowHeight;
+      var rowWidth = bo.width;
 
-    return false;  // don't propagate the event if a drag has begun
+      //add a rectangle for each visible selected row
+      for (var i = obo.getFirstVisibleRow(); i <= obo.getLastVisibleRow(); i ++)
+      {
+        if (sel.isSelected(i))
+          region.unionRect(rowX, rowY, rowWidth, rowHeight);
+        rowY = rowY + rowHeight;
+      }
+      
+      //and finally, clip the result to be sure we don't spill over...
+      if(!region.isEmpty())
+        region.intersectRect(bo.x, bo.y, bo.width, bo.height);
+    } catch(ex) {
+      dump("Error while building selection region: " + ex + "\n");
+      region = null;
+    }
+    
+    var count = selArray.length;
+    debugDump("selArray.length = " + count + "\n");
+    for (i = 0; i < count; ++i ) {
+        var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
+        if (!trans) 
+          return false;
+
+        var genTextData = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
+        if (!genTextData) 
+          return false;
+
+        trans.addDataFlavor(flavor);
+
+        // get id (url)
+        var id = selArray[i];
+        // If a folder drag, id is a folder object instead of a folder URI
+        if (id instanceof nsIMsgFolder)
+          id = id.URI;
+
+        genTextData.data = id;
+        debugDump("    ID #" + i + " = " + id + "\n");
+
+        trans.setTransferData ( flavor, genTextData, id.length * 2 );  // doublebyte byte data
+
+        // put it into the transferable as an |nsISupports|
+        var genTrans = trans.QueryInterface(Components.interfaces.nsISupports);
+        transArray.AppendElement(genTrans);
+    }
+
+    dragService.invokeDragSessionWithImage(event.target, transArray, region,
+                                           nsIDragService.DRAGDROP_ACTION_COPY +
+                                           nsIDragService.DRAGDROP_ACTION_MOVE,
+                                           null, 0, 0, event);
+
+    dragStarted = true;
+
+    return(!dragStarted);  // don't propagate the event if a drag has begun
 }
--- a/suite/browser/pageinfo/pageInfo.js
+++ b/suite/browser/pageinfo/pageInfo.js
@@ -702,26 +702,42 @@ function onBeginLinkDrag(event,urlField,
   var tree = event.target;
   if (!("treeBoxObject" in tree))
     tree = tree.parentNode;
 
   var row = tree.treeBoxObject.getRowAt(event.clientX, event.clientY);
   if (row == -1)
     return;
 
+  // Getting drag-system needed services
+  var dragService = Components.classes[DRAGSERVICE_CONTRACTID].getService()
+                              .QueryInterface(Components.interfaces.nsIDragService);
+  var transArray = Components.classes[ARRAY_CONTRACTID]
+                             .createInstance(Components.interfaces.nsISupportsArray);
+  if (!transArray)
+    return;
+
+  var trans = Components.classes[TRANSFERABLE_CONTRACTID]
+                        .createInstance(Components.interfaces.nsITransferable);
+  if (!trans)
+    return;
+
   // Adding URL flavor
+  trans.addDataFlavor("text/x-moz-url");
   var col = tree.columns[urlField];
   var url = tree.view.getCellText(row, col);
   col = tree.columns[descField];
   var desc = tree.view.getCellText(row, col);
+  var stringURL = Components.classes[STRING_CONTRACTID]
+                            .createInstance(Components.interfaces.nsISupportsString);
+  stringURL.data = url + "\n" + desc;
+  trans.setTransferData("text/x-moz-url", stringURL, stringURL.data.length * 2 );
+  transArray.AppendElement(trans.QueryInterface(Components.interfaces.nsISupports));
 
-  var dataTransfer = event.dataTransfer;
-  dataTransfer.setData("text/x-moz-url", url + "\n" + desc);
-  dataTransfer.setData("text/url-list", url);
-  dataTransfer.setData("text/plain", url);
+  dragService.invokeDragSession(event.target, transArray, null, dragService.DRAGDROP_ACTION_NONE);
 }
 
 //******** Image Stuff
 function getSelectedImage(tree)
 {
   if (!gImageView.rowCount)
     return null;