From 75d6398ebaa0324bf49739432a5211a81f5d5334 Mon Sep 17 00:00:00 2001 From: "mozilla.mano%sent.com" Date: Tue, 7 Jun 2005 19:43:43 +0000 Subject: [PATCH] Bug 179845 - Support dragging a link onto the 'New Tab' and 'New Window' toolbar buttons. patch from Ben Basson , r=mconnor, a=asa. --- browser/base/content/browser.js | 66 ++++++++++++++++++- browser/base/content/browser.xul | 10 ++- .../en-US/chrome/browser/browser.properties | 2 + 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 583c13e7396f..f8a47e90b4b1 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -2485,6 +2485,68 @@ var bookmarksButtonObserver = { } } +var newTabButtonObserver = { + onDragOver: function(aEvent, aFlavour, aDragSession) + { + var statusTextFld = document.getElementById("statusbar-display"); + statusTextFld.label = gNavigatorBundle.getString("droponnewtabbutton"); + aEvent.target.setAttribute("dragover", "true"); + return true; + }, + onDragExit: function (aEvent, aDragSession) + { + var statusTextFld = document.getElementById("statusbar-display"); + statusTextFld.label = ""; + aEvent.target.removeAttribute("dragover"); + }, + onDrop: function (aEvent, aXferData, aDragSession) + { + var xferData = aXferData.data.split("\n"); + var uri = xferData[0] ? xferData[0] : xferData[1]; + if (uri) + openNewTabWith(uri, aXferData, aEvent, false); + }, + getSupportedFlavours: function () + { + var flavourSet = new FlavourSet(); + flavourSet.appendFlavour("text/unicode"); + flavourSet.appendFlavour("text/x-moz-url"); + flavourSet.appendFlavour("application/x-moz-file", "nsIFile"); + return flavourSet; + } +} + +var newWindowButtonObserver = { + onDragOver: function(aEvent, aFlavour, aDragSession) + { + var statusTextFld = document.getElementById("statusbar-display"); + statusTextFld.label = gNavigatorBundle.getString("droponnewwindowbutton"); + aEvent.target.setAttribute("dragover", "true"); + return true; + }, + onDragExit: function (aEvent, aDragSession) + { + var statusTextFld = document.getElementById("statusbar-display"); + statusTextFld.label = ""; + aEvent.target.removeAttribute("dragover"); + }, + onDrop: function (aEvent, aXferData, aDragSession) + { + var xferData = aXferData.data.split("\n"); + var uri = xferData[0] ? xferData[0] : xferData[1]; + if (uri) + openNewWindowWith(uri, aXferData, null, false); + }, + getSupportedFlavours: function () + { + var flavourSet = new FlavourSet(); + flavourSet.appendFlavour("text/unicode"); + flavourSet.appendFlavour("text/x-moz-url"); + flavourSet.appendFlavour("application/x-moz-file", "nsIFile"); + return flavourSet; + } +} + var goButtonObserver = { onDragOver: function(aEvent, aFlavour, aDragSession) { @@ -2512,9 +2574,9 @@ var goButtonObserver = { getSupportedFlavours: function () { var flavourSet = new FlavourSet(); - flavourSet.appendFlavour("application/x-moz-file", "nsIFile"); - flavourSet.appendFlavour("text/x-moz-url"); flavourSet.appendFlavour("text/unicode"); + flavourSet.appendFlavour("text/x-moz-url"); + flavourSet.appendFlavour("application/x-moz-file", "nsIFile"); return flavourSet; } } diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index 1dd1bea0b4e5..bf8309de0f6e 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -343,12 +343,18 @@ + tooltiptext="&newTabButton.tooltip;" + ondragover="nsDragAndDrop.dragOver(event, newTabButtonObserver);" + ondragdrop="nsDragAndDrop.drop(event, newTabButtonObserver);" + ondragexit="nsDragAndDrop.dragExit(event, newTabButtonObserver);"/> + tooltiptext="&newWindowButton.tooltip;" + ondragover="nsDragAndDrop.dragOver(event, newWindowButtonObserver);" + ondragdrop="nsDragAndDrop.drop(event, newWindowButtonObserver);" + ondragexit="nsDragAndDrop.dragExit(event, newWindowButtonObserver);"/>