mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 456106, use new drag and drop api in browser and toolkit, r=mano
This commit is contained in:
parent
444dc5a9aa
commit
2b862dc7a3
@ -2302,16 +2302,6 @@ function PageProxyClearIcon ()
|
||||
gProxyFavIcon.removeAttribute("src");
|
||||
}
|
||||
|
||||
|
||||
function PageProxyDragGesture(aEvent)
|
||||
{
|
||||
if (gProxyFavIcon.getAttribute("pageproxystate") == "valid") {
|
||||
nsDragAndDrop.startDrag(aEvent, proxyIconDNDObserver);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function PageProxyClickHandler(aEvent)
|
||||
{
|
||||
if (aEvent.button == 1 && gPrefService.getBoolPref("middlemouse.paste"))
|
||||
@ -2668,56 +2658,88 @@ function FillInHTMLTooltip(tipElement)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
var browserDragAndDrop = {
|
||||
getDragURLFromDataTransfer : function (dt)
|
||||
{
|
||||
var types = dt.types;
|
||||
for (var t = 0; t < types.length; t++) {
|
||||
var type = types[t];
|
||||
switch (type) {
|
||||
case "text/uri-list":
|
||||
var url = dt.getData("URL").replace(/^\s+|\s+$/g, "");
|
||||
return [url, url];
|
||||
case "text/plain":
|
||||
case "text/x-moz-text-internal":
|
||||
var url = dt.getData(type).replace(/^\s+|\s+$/g, "");
|
||||
return [url, url];
|
||||
case "text/x-moz-url":
|
||||
var split = dt.getData(type).split("\n");
|
||||
return [split[0], split[1]];
|
||||
case "application/x-moz-file":
|
||||
var file = dt.mozGetDataAt(type, 0);
|
||||
var name = file instanceof Components.interfaces.nsIFile ? file.leafName : "";
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var fileHandler = ioService.getProtocolHandler("file")
|
||||
.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
return [fileHandler.getURLSpecFromFile(file), name];
|
||||
}
|
||||
}
|
||||
return [ , ];
|
||||
},
|
||||
|
||||
dragOver : function (aEvent, statusString)
|
||||
{
|
||||
var types = aEvent.dataTransfer.types;
|
||||
if (types.contains("application/x-moz-file") ||
|
||||
types.contains("text/x-moz-url") ||
|
||||
types.contains("text/uri-list") ||
|
||||
types.contains("text/plain")) {
|
||||
aEvent.preventDefault();
|
||||
|
||||
if (statusString) {
|
||||
var statusTextFld = document.getElementById("statusbar-display");
|
||||
statusTextFld.label = gNavigatorBundle.getString(statusString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var proxyIconDNDObserver = {
|
||||
onDragStart: function (aEvent, aXferData, aDragAction)
|
||||
{
|
||||
if (gProxyFavIcon.getAttribute("pageproxystate") != "valid")
|
||||
return;
|
||||
|
||||
var value = content.location.href;
|
||||
var urlString = value + "\n" + content.document.title;
|
||||
var htmlString = "<a href=\"" + value + "\">" + value + "</a>";
|
||||
|
||||
aXferData.data = new TransferData();
|
||||
aXferData.data.addDataForFlavour("text/x-moz-url", urlString);
|
||||
aXferData.data.addDataForFlavour("text/unicode", value);
|
||||
aXferData.data.addDataForFlavour("text/html", htmlString);
|
||||
|
||||
// we're copying the URL from the proxy icon, not moving
|
||||
// we specify all of them though, because d&d sucks and OS's
|
||||
// get confused if they don't get the one they want
|
||||
aDragAction.action =
|
||||
Components.interfaces.nsIDragService.DRAGDROP_ACTION_COPY |
|
||||
Components.interfaces.nsIDragService.DRAGDROP_ACTION_MOVE |
|
||||
Components.interfaces.nsIDragService.DRAGDROP_ACTION_LINK;
|
||||
var dt = aEvent.dataTransfer;
|
||||
dt.setData("text/x-moz-url", urlString);
|
||||
dt.setData("text/uri-list", value);
|
||||
dt.setData("text/plain", value);
|
||||
dt.setData("text/html", htmlString);
|
||||
}
|
||||
}
|
||||
|
||||
var homeButtonObserver = {
|
||||
onDrop: function (aEvent, aXferData, aDragSession)
|
||||
onDrop: function (aEvent)
|
||||
{
|
||||
var url = transferUtils.retrieveURLFromData(aXferData.data, aXferData.flavour.contentType);
|
||||
let url = browserDragAndDrop.getDragURLFromDataTransfer(aEvent.dataTransfer)[0];
|
||||
setTimeout(openHomeDialog, 0, url);
|
||||
},
|
||||
|
||||
onDragOver: function (aEvent, aFlavour, aDragSession)
|
||||
onDragOver: function (aEvent)
|
||||
{
|
||||
var statusTextFld = document.getElementById("statusbar-display");
|
||||
statusTextFld.label = gNavigatorBundle.getString("droponhomebutton");
|
||||
aDragSession.dragAction = Components.interfaces.nsIDragService.DRAGDROP_ACTION_LINK;
|
||||
browserDragAndDrop.dragOver(aEvent, "droponhomebutton");
|
||||
aEvent.dropEffect = "link";
|
||||
},
|
||||
|
||||
onDragExit: function (aEvent, aDragSession)
|
||||
onDragLeave: function (aEvent)
|
||||
{
|
||||
var statusTextFld = document.getElementById("statusbar-display");
|
||||
statusTextFld.label = "";
|
||||
},
|
||||
|
||||
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-text-internal"); // for tabs
|
||||
return flavourSet;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2746,136 +2768,100 @@ function openHomeDialog(aURL)
|
||||
}
|
||||
|
||||
var bookmarksButtonObserver = {
|
||||
onDrop: function (aEvent, aXferData, aDragSession)
|
||||
onDrop: function (aEvent)
|
||||
{
|
||||
var split = aXferData.data.split("\n");
|
||||
var url = split[0];
|
||||
if (url != aXferData.data) // do nothing if it's not a valid URL
|
||||
PlacesUIUtils.showMinimalAddBookmarkUI(makeURI(url), split[1]);
|
||||
let [url, name] = browserDragAndDrop.getDragURLFromDataTransfer(aEvent.dataTransfer);
|
||||
try {
|
||||
PlacesUIUtils.showMinimalAddBookmarkUI(makeURI(url), name);
|
||||
} catch(ex) { }
|
||||
},
|
||||
|
||||
onDragOver: function (aEvent, aFlavour, aDragSession)
|
||||
onDragOver: function (aEvent)
|
||||
{
|
||||
var statusTextFld = document.getElementById("statusbar-display");
|
||||
statusTextFld.label = gNavigatorBundle.getString("droponbookmarksbutton");
|
||||
aDragSession.dragAction = Components.interfaces.nsIDragService.DRAGDROP_ACTION_LINK;
|
||||
browserDragAndDrop.dragOver(aEvent, "droponbookmarksbutton");
|
||||
aEvent.dropEffect = "link";
|
||||
},
|
||||
|
||||
onDragExit: function (aEvent, aDragSession)
|
||||
onDragLeave: function (aEvent)
|
||||
{
|
||||
var statusTextFld = document.getElementById("statusbar-display");
|
||||
statusTextFld.label = "";
|
||||
},
|
||||
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
|
||||
flavourSet.appendFlavour("text/x-moz-url");
|
||||
flavourSet.appendFlavour("text/unicode");
|
||||
return flavourSet;
|
||||
}
|
||||
}
|
||||
|
||||
var newTabButtonObserver = {
|
||||
onDragOver: function(aEvent, aFlavour, aDragSession) {
|
||||
var statusTextFld = document.getElementById("statusbar-display");
|
||||
statusTextFld.label = gNavigatorBundle.getString("droponnewtabbutton");
|
||||
return true;
|
||||
onDragOver: function (aEvent)
|
||||
{
|
||||
browserDragAndDrop.dragOver(aEvent, "droponnewtabbutton");
|
||||
},
|
||||
onDragExit: function (aEvent, aDragSession) {
|
||||
|
||||
onDragLeave: function (aEvent)
|
||||
{
|
||||
var statusTextFld = document.getElementById("statusbar-display");
|
||||
statusTextFld.label = "";
|
||||
},
|
||||
onDrop: function (aEvent, aXferData, aDragSession) {
|
||||
var xferData = aXferData.data.split("\n");
|
||||
var draggedText = xferData[0] || xferData[1];
|
||||
|
||||
onDrop: function (aEvent)
|
||||
{
|
||||
let url = browserDragAndDrop.getDragURLFromDataTransfer(aEvent.dataTransfer)[0];
|
||||
var postData = {};
|
||||
var url = getShortcutOrURI(draggedText, postData);
|
||||
url = getShortcutOrURI(url, postData);
|
||||
if (url) {
|
||||
nsDragAndDrop.dragDropSecurityCheck(aEvent, aDragSession, url);
|
||||
nsDragAndDrop.dragDropSecurityCheck(aEvent, null, url);
|
||||
// allow third-party services to fixup this URL
|
||||
openNewTabWith(url, null, postData.value, aEvent, true);
|
||||
}
|
||||
},
|
||||
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");
|
||||
return true;
|
||||
},
|
||||
onDragExit: function (aEvent, aDragSession)
|
||||
{
|
||||
var statusTextFld = document.getElementById("statusbar-display");
|
||||
statusTextFld.label = "";
|
||||
},
|
||||
onDrop: function (aEvent, aXferData, aDragSession)
|
||||
{
|
||||
var xferData = aXferData.data.split("\n");
|
||||
var draggedText = xferData[0] || xferData[1];
|
||||
var postData = {};
|
||||
var url = getShortcutOrURI(draggedText, postData);
|
||||
if (url) {
|
||||
nsDragAndDrop.dragDropSecurityCheck(aEvent, aDragSession, url);
|
||||
// allow third-party services to fixup this URL
|
||||
openNewWindowWith(url, null, postData.value, true);
|
||||
}
|
||||
},
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour("text/unicode");
|
||||
flavourSet.appendFlavour("text/x-moz-url");
|
||||
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
|
||||
flavourSet.appendFlavour("text/x-moz-text-internal"); // for tabs
|
||||
return flavourSet;
|
||||
onDragOver: function (aEvent)
|
||||
{
|
||||
browserDragAndDrop.dragOver(aEvent, "droponnewwindowbutton");
|
||||
},
|
||||
onDragLeave: function (aEvent)
|
||||
{
|
||||
var statusTextFld = document.getElementById("statusbar-display");
|
||||
statusTextFld.label = "";
|
||||
},
|
||||
onDrop: function (aEvent)
|
||||
{
|
||||
let url = browserDragAndDrop.getDragURLFromDataTransfer(aEvent.dataTransfer)[0];
|
||||
var postData = {};
|
||||
url = getShortcutOrURI(url, postData);
|
||||
if (url) {
|
||||
nsDragAndDrop.dragDropSecurityCheck(aEvent, null, url);
|
||||
// allow third-party services to fixup this URL
|
||||
openNewWindowWith(url, null, postData.value, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var DownloadsButtonDNDObserver = {
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// nsDragAndDrop
|
||||
onDragOver: function (aEvent, aFlavour, aDragSession)
|
||||
onDragOver: function (aEvent)
|
||||
{
|
||||
var statusTextFld = document.getElementById("statusbar-display");
|
||||
statusTextFld.label = gNavigatorBundle.getString("dropondownloadsbutton");
|
||||
aDragSession.canDrop = (aFlavour.contentType == "text/x-moz-url" ||
|
||||
aFlavour.contentType == "text/unicode");
|
||||
var types = aEvent.dataTransfer.types;
|
||||
if (types.contains("text/x-moz-url") ||
|
||||
types.contains("text/uri-list") ||
|
||||
types.contains("text/plain"))
|
||||
aEvent.preventDefault();
|
||||
},
|
||||
|
||||
onDragExit: function (aEvent, aDragSession)
|
||||
onDragLeave: function (aEvent)
|
||||
{
|
||||
var statusTextFld = document.getElementById("statusbar-display");
|
||||
statusTextFld.label = "";
|
||||
},
|
||||
|
||||
onDrop: function (aEvent, aXferData, aDragSession)
|
||||
onDrop: function (aEvent)
|
||||
{
|
||||
var split = aXferData.data.split("\n");
|
||||
var url = split[0];
|
||||
if (url != aXferData.data) { //do nothing, not a valid URL
|
||||
nsDragAndDrop.dragDropSecurityCheck(aEvent, aDragSession, url);
|
||||
|
||||
var name = split[1];
|
||||
saveURL(url, name, null, true, true);
|
||||
}
|
||||
},
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour("text/x-moz-url");
|
||||
flavourSet.appendFlavour("text/unicode");
|
||||
return flavourSet;
|
||||
let [url, name] = browserDragAndDrop.getDragURLFromDataTransfer(aEvent.dataTransfer);
|
||||
nsDragAndDrop.dragDropSecurityCheck(aEvent, null, url);
|
||||
saveURL(url, name, null, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5021,15 +5007,21 @@ function middleMousePaste(event)
|
||||
*/
|
||||
|
||||
var contentAreaDNDObserver = {
|
||||
onDrop: function (aEvent, aXferData, aDragSession)
|
||||
onDragOver: function (aEvent)
|
||||
{
|
||||
var types = aEvent.dataTransfer.types;
|
||||
if (types.contains("application/x-moz-file") ||
|
||||
types.contains("text/x-moz-url") ||
|
||||
types.contains("text/uri-list") ||
|
||||
types.contains("text/plain"))
|
||||
aEvent.preventDefault();
|
||||
},
|
||||
onDrop: function (aEvent)
|
||||
{
|
||||
if (aEvent.getPreventDefault())
|
||||
return;
|
||||
|
||||
var dragType = aXferData.flavour.contentType;
|
||||
var dragData = aXferData.data;
|
||||
|
||||
var url = transferUtils.retrieveURLFromData(dragData, dragType);
|
||||
let [url, name] = browserDragAndDrop.getDragURLFromDataTransfer(aEvent.dataTransfer);
|
||||
|
||||
// valid urls don't contain spaces ' '; if we have a space it
|
||||
// isn't a valid url, or if it's a javascript: or data: url,
|
||||
@ -5038,7 +5030,7 @@ var contentAreaDNDObserver = {
|
||||
/^\s*(javascript|data):/.test(url))
|
||||
return;
|
||||
|
||||
nsDragAndDrop.dragDropSecurityCheck(aEvent, aDragSession, url);
|
||||
nsDragAndDrop.dragDropSecurityCheck(aEvent, null, url);
|
||||
|
||||
switch (document.documentElement.getAttribute('windowtype')) {
|
||||
case "navigator:browser":
|
||||
@ -5054,18 +5046,7 @@ var contentAreaDNDObserver = {
|
||||
// keep the event from being handled by the dragDrop listeners
|
||||
// built-in to gecko if they happen to be above us.
|
||||
aEvent.preventDefault();
|
||||
},
|
||||
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour(TAB_DROP_TYPE);
|
||||
flavourSet.appendFlavour("text/x-moz-url");
|
||||
flavourSet.appendFlavour("text/plain");
|
||||
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
|
||||
return flavourSet;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function MultiplexHandler(event)
|
||||
|
@ -344,9 +344,10 @@
|
||||
<toolbarbutton id="home-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
|
||||
persist="class"
|
||||
label="&homeButton.label;"
|
||||
ondragover="nsDragAndDrop.dragOver(event, homeButtonObserver);"
|
||||
ondragdrop="nsDragAndDrop.drop(event, homeButtonObserver);"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, homeButtonObserver);"
|
||||
ondragover="homeButtonObserver.onDragOver(event)"
|
||||
ondragenter="homeButtonObserver.onDragOver(event)"
|
||||
ondrop="homeButtonObserver.onDrop(event)"
|
||||
ondragleave="homeButtonObserver.onDragLeave(event)"
|
||||
onclick="BrowserGoHome(event);"/>
|
||||
|
||||
<toolbaritem id="urlbar-container" align="center" flex="400" persist="width"
|
||||
@ -389,7 +390,7 @@
|
||||
<image id="urlbar-throbber" busy="false"/>
|
||||
<image id="page-proxy-favicon" validate="never"
|
||||
pageproxystate="invalid"
|
||||
ondraggesture="PageProxyDragGesture(event);"
|
||||
ondragstart="proxyIconDNDObserver.onDragStart(event);"
|
||||
onerror="this.removeAttribute('src');"/>
|
||||
</stack>
|
||||
<label id="identity-icon-label" crop="center" flex="1"/>
|
||||
@ -449,10 +450,10 @@
|
||||
|
||||
<toolbarbutton id="downloads-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
|
||||
observes="Tools:Downloads"
|
||||
ondragdrop="nsDragAndDrop.drop(event, DownloadsButtonDNDObserver); event.stopPropagation()"
|
||||
ondragover="nsDragAndDrop.dragOver(event, DownloadsButtonDNDObserver); event.stopPropagation()"
|
||||
ondragenter="nsDragAndDrop.dragEnter(event, DownloadsButtonDNDObserver); event.stopPropagation()"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, DownloadsButtonDNDObserver); event.stopPropagation()"
|
||||
ondrop="DownloadsButtonDNDObserver.onDrop(event)"
|
||||
ondragover="DownloadsButtonDNDObserver.onDragOver(event)"
|
||||
ondragenter="DownloadsButtonDNDObserver.onDragOver(event)"
|
||||
ondragleave="DownloadsButtonDNDObserver.onDragLeave(event)"
|
||||
label="&downloads.label;"
|
||||
tooltiptext="&downloads.tooltip;"/>
|
||||
|
||||
@ -463,25 +464,28 @@
|
||||
<toolbarbutton id="bookmarks-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
|
||||
observes="viewBookmarksSidebar"
|
||||
tooltiptext="&bookmarksButton.tooltip;"
|
||||
ondragover="nsDragAndDrop.dragOver(event, bookmarksButtonObserver);"
|
||||
ondragdrop="nsDragAndDrop.drop(event, bookmarksButtonObserver);"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, bookmarksButtonObserver);"/>
|
||||
ondrop="bookmarksButtonObserver.onDrop(event)"
|
||||
ondragover="bookmarksButtonObserver.onDragOver(event)"
|
||||
ondragenter="bookmarksButtonObserver.onDragOver(event)"
|
||||
ondragleave="bookmarksButtonObserver.onDragLeave(event)"/>
|
||||
|
||||
<toolbarbutton id="new-tab-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
|
||||
label="&tabCmd.label;"
|
||||
command="cmd_newNavigatorTab"
|
||||
tooltiptext="&newTabButton.tooltip;"
|
||||
ondragover="nsDragAndDrop.dragOver(event, newTabButtonObserver);"
|
||||
ondragdrop="nsDragAndDrop.drop(event, newTabButtonObserver);"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, newTabButtonObserver);"/>
|
||||
ondrop="newTabButtonObserver.onDrop(event)"
|
||||
ondragover="newTabButtonObserver.onDragOver(event)"
|
||||
ondragenter="newTabButtonObserver.onDragOver(event)"
|
||||
ondragleave="newTabButtonObserver.onDragLeave(event)"/>
|
||||
|
||||
<toolbarbutton id="new-window-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
|
||||
label="&newNavigatorCmd.label;"
|
||||
command="key_newNavigator"
|
||||
tooltiptext="&newWindowButton.tooltip;"
|
||||
ondragover="nsDragAndDrop.dragOver(event, newWindowButtonObserver);"
|
||||
ondragdrop="nsDragAndDrop.drop(event, newWindowButtonObserver);"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, newWindowButtonObserver);"/>
|
||||
ondrop="newWindowButtonObserver.onDrop(event)"
|
||||
ondragover="newWindowButtonObserver.onDragOver(event)"
|
||||
ondragenter="newWindowButtonObserver.onDragOver(event)"
|
||||
ondragleave="newWindowButtonObserver.onDragLeave(event)"/>
|
||||
|
||||
<toolbarbutton id="cut-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
|
||||
label="&cutCmd.label;"
|
||||
@ -557,7 +561,7 @@
|
||||
contentcontextmenu="contentAreaContextMenu"
|
||||
onnewtab="BrowserOpenTab();"
|
||||
autocompletepopup="PopupAutoComplete"
|
||||
ondrop="nsDragAndDrop.drop(event, contentAreaDNDObserver);"
|
||||
ondrop="contentAreaDNDObserver.onDrop(event)"
|
||||
onclick="return contentAreaClick(event, false);"/>
|
||||
</vbox>
|
||||
</hbox>
|
||||
@ -571,7 +575,7 @@
|
||||
<findbar browserid="content" id="FindToolbar"/>
|
||||
|
||||
<statusbar class="chromeclass-status" id="status-bar"
|
||||
ondrop="nsDragAndDrop.drop(event, contentAreaDNDObserver);">
|
||||
ondrop="contentAreaDNDObserver.onDrop(event)">
|
||||
<statusbarpanel id="statusbar-display" label="" flex="1"/>
|
||||
<statusbarpanel class="statusbarpanel-progress" collapsed="true" id="statusbar-progresspanel">
|
||||
<progressmeter class="progressmeter-statusbar" id="statusbar-icon" mode="normal" value="0"/>
|
||||
|
@ -216,7 +216,7 @@
|
||||
<!-- Media information -->
|
||||
<vbox id="mediaPanel">
|
||||
<tree id="imagetree" onselect="onImageSelect();" contextmenu="picontext"
|
||||
ondraggesture="onBeginLinkDrag(event,'image-address','image-alt')">
|
||||
ondragstart="onBeginLinkDrag(event,'image-address','image-alt')">
|
||||
<treecols>
|
||||
<treecol sortSeparators="true" persist="hidden width" flex="10"
|
||||
width="10" id="image-address" label="&mediaAddress;"/>
|
||||
|
@ -122,6 +122,7 @@ _BROWSER_FILES = browser_sanitize-timespans.js \
|
||||
browser_tabs_owner.js \
|
||||
browser_bug491431.js \
|
||||
browser_bug304198.js \
|
||||
browser_drag.js \
|
||||
$(NULL)
|
||||
|
||||
ifeq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
|
||||
|
23
browser/base/content/test/browser_drag.js
Normal file
23
browser/base/content/test/browser_drag.js
Normal file
@ -0,0 +1,23 @@
|
||||
function test()
|
||||
{
|
||||
// ---- Test dragging the proxy icon ---
|
||||
|
||||
var value = content.location.href;
|
||||
var urlString = value + "\n" + content.document.title;
|
||||
var htmlString = "<a href=\"" + value + "\">" + value + "</a>";
|
||||
|
||||
var expected = [ [
|
||||
"text/x-moz-url: " + urlString,
|
||||
"text/uri-list: " + value,
|
||||
"text/plain: " + value,
|
||||
"text/html: " + htmlString
|
||||
] ];
|
||||
|
||||
// set the valid attribute so dropping is allowed
|
||||
var proxyicon = document.getElementById("page-proxy-favicon")
|
||||
var oldstate = proxyicon.getAttribute("pageproxystate");
|
||||
proxyicon.setAttribute("pageproxystate", "valid");
|
||||
var dt = EventUtils.synthesizeDragStart(proxyicon, expected);
|
||||
is(dt, null, "drag on proxy icon");
|
||||
proxyicon.setAttribute("pageproxystate", oldstate);
|
||||
}
|
@ -238,22 +238,27 @@
|
||||
</method>
|
||||
|
||||
<method name="onDragOver">
|
||||
<parameter name="aEvent"/>
|
||||
<body>
|
||||
return true;
|
||||
var types = aEvent.dataTransfer.types;
|
||||
if (types.contains("application/x-moz-file") ||
|
||||
types.contains("text/x-moz-url") ||
|
||||
types.contains("text/uri-list") ||
|
||||
types.contains("text/unicode"))
|
||||
aEvent.preventDefault();
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="onDrop">
|
||||
<parameter name="aEvent"/>
|
||||
<parameter name="aXferData"/>
|
||||
<parameter name="aDragSession"/>
|
||||
<body><![CDATA[
|
||||
var url = transferUtils.retrieveURLFromData(aXferData.data, aXferData.flavour.contentType);
|
||||
aEvent.stopPropagation();
|
||||
var url = browserDragAndDrop.getDragURLFromDataTransfer(aEvent.dataTransfer)[0];
|
||||
|
||||
// The URL bar automatically handles inputs with newline characters,
|
||||
// so we can get away with treating text/x-moz-url flavours as text/unicode.
|
||||
// so we can get away with treating text/x-moz-url flavours as text/plain.
|
||||
if (url) {
|
||||
nsDragAndDrop.dragDropSecurityCheck(aEvent, aDragSession, url);
|
||||
nsDragAndDrop.dragDropSecurityCheck(aEvent, null, url);
|
||||
|
||||
this.value = url;
|
||||
SetPageProxyState("invalid");
|
||||
@ -269,21 +274,6 @@
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<method name="getSupportedFlavours">
|
||||
<body><![CDATA[
|
||||
var flavourSet = new FlavourSet();
|
||||
|
||||
// Favor text/x-moz-url since text/unicode coming from Win32 1.8 branch
|
||||
// drops contains URL\ntext. The previous comment here said that
|
||||
// plain text drops often come with text/x-moz-url flavor, but I
|
||||
// haven't seen that, so hopefully that behavior has changed.
|
||||
flavourSet.appendFlavour("text/x-moz-url");
|
||||
flavourSet.appendFlavour("text/unicode");
|
||||
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
|
||||
return flavourSet;
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<method name="_getSelectedValueForClipboard">
|
||||
<body><![CDATA[
|
||||
var val = this.value.substring(this.selectionStart, this.selectionEnd);
|
||||
@ -449,8 +439,8 @@
|
||||
event.stopPropagation();
|
||||
]]></handler>
|
||||
<handler event="focus" phase="capturing" action="this._hideURLTooltip();"/>
|
||||
<handler event="dragover" phase="capturing" action="nsDragAndDrop.dragOver(event, this);"/>
|
||||
<handler event="drop" phase="capturing" action="nsDragAndDrop.drop(event, this);"/>
|
||||
<handler event="dragover" phase="capturing" action="this.onDragOver(event, this);"/>
|
||||
<handler event="drop" phase="capturing" action="this.onDrop(event, this);"/>
|
||||
<handler event="select"><![CDATA[
|
||||
if (!Cc["@mozilla.org/widget/clipboard;1"]
|
||||
.getService(Ci.nsIClipboard)
|
||||
|
@ -224,22 +224,13 @@ var gEngineManagerDialog = {
|
||||
}
|
||||
};
|
||||
|
||||
var gDragObserver = {
|
||||
onDragStart: function (aEvent, aXferData, aDragAction) {
|
||||
var selectedIndex = gEngineView.selectedIndex;
|
||||
if (selectedIndex == -1)
|
||||
return;
|
||||
|
||||
aXferData.data = new TransferData();
|
||||
aXferData.data.addDataForFlavour(ENGINE_FLAVOR, selectedIndex.toString());
|
||||
|
||||
aDragAction.action = Ci.nsIDragService.DRAGDROP_ACTION_MOVE;
|
||||
},
|
||||
onDrop: function (aEvent, aXferData, aDragSession) { },
|
||||
onDragExit: function (aEvent, aDragSession) { },
|
||||
onDragOver: function (aEvent, aFlavour, aDragSession) { },
|
||||
getSupportedFlavours: function() { return null; }
|
||||
};
|
||||
function onDragEngineStart(event) {
|
||||
var selectedIndex = gEngineView.selectedIndex;
|
||||
if (selectedIndex > 0) {
|
||||
event.dataTransfer.setData(ENGINE_FLAVOR, selectedIndex.toString());
|
||||
event.dataTransfer.effectAllowed = "move";
|
||||
}
|
||||
}
|
||||
|
||||
// "Operation" objects
|
||||
function EngineMoveOp(aEngineClone, aNewIndex) {
|
||||
|
@ -58,8 +58,6 @@
|
||||
|
||||
<script type="application/x-javascript"
|
||||
src="chrome://browser/content/search/engineManager.js"/>
|
||||
<script type="application/x-javascript"
|
||||
src="chrome://global/content/nsDragAndDrop.js"/>
|
||||
|
||||
<commandset id="engineManagerCommandSet">
|
||||
<command id="cmd_remove"
|
||||
@ -90,7 +88,7 @@
|
||||
<tree id="engineList" flex="1" rows="10" hidecolumnpicker="true"
|
||||
seltype="single" onselect="gEngineManagerDialog.onSelect();">
|
||||
<treechildren id="engineChildren" flex="1"
|
||||
ondraggesture="nsDragAndDrop.startDrag(event, gDragObserver);"/>
|
||||
ondragstart="onDragEngineStart(event)"/>
|
||||
<treecols>
|
||||
<treecol id="engineName" flex="4" label="&columnLabel.name;"/>
|
||||
<treecol id="engineKeyword" flex="1" label="&columnLabel.keyword;"/>
|
||||
|
@ -67,7 +67,6 @@
|
||||
onunload="window.XULBrowserWindow.destroy();">
|
||||
|
||||
<script type="application/javascript" src="chrome://help/content/help.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/nsDragAndDrop.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/viewZoomOverlay.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/globalOverlay.js"/>
|
||||
|
||||
|
@ -68,7 +68,6 @@
|
||||
persist="screenX screenY width height sizemode">
|
||||
|
||||
<script type="application/javascript" src="chrome://global/content/globalOverlay.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/nsDragAndDrop.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/printUtils.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/viewSource.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/viewPartialSource.js"/>
|
||||
@ -185,9 +184,7 @@
|
||||
</menubar>
|
||||
</toolbox>
|
||||
|
||||
<vbox id="appcontent" flex="1"
|
||||
ondragdrop="nsDragAndDrop.drop(event, contentAreaDNDObserver);">
|
||||
|
||||
<vbox id="appcontent" flex="1" ondrop="contentAreaDNDObserver.drop(event);">
|
||||
<browser id="content" type="content-primary" name="content" src="about:blank" flex="1"
|
||||
disablehistory="true" context="viewSourceContextMenu"/>
|
||||
<findbar id="FindToolbar" browserid="content"/>
|
||||
|
@ -74,7 +74,6 @@
|
||||
<script type="application/javascript" src="chrome://global/content/viewSource.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/viewZoomOverlay.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/contentAreaUtils.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/nsDragAndDrop.js"/>
|
||||
|
||||
<stringbundle id="viewSourceBundle" src="chrome://global/locale/viewSource.properties"/>
|
||||
|
||||
@ -235,8 +234,7 @@
|
||||
</menubar>
|
||||
</toolbox>
|
||||
|
||||
<vbox id="appcontent" flex="1"
|
||||
ondragdrop="nsDragAndDrop.drop(event, contentAreaDNDObserver);">
|
||||
<vbox id="appcontent" flex="1" ondrop="contentAreaDNDObserver.drop(event);">
|
||||
|
||||
<browser id="content" type="content-primary" name="content" src="about:blank" flex="1"
|
||||
context="viewSourceContextMenu" showcaret="true"/>
|
||||
|
@ -732,262 +732,219 @@ function isToolbarItem(aElt)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//// Drag and Drop observers
|
||||
|
||||
function onToolbarDragStart(aEvent)
|
||||
{
|
||||
nsDragAndDrop.startDrag(aEvent, dragStartObserver);
|
||||
}
|
||||
|
||||
function onToolbarDragOver(aEvent)
|
||||
{
|
||||
nsDragAndDrop.dragOver(aEvent, toolbarDNDObserver);
|
||||
}
|
||||
|
||||
function onToolbarDrop(aEvent)
|
||||
{
|
||||
nsDragAndDrop.drop(aEvent, toolbarDNDObserver);
|
||||
}
|
||||
|
||||
function onToolbarDragLeave(aEvent)
|
||||
{
|
||||
if (gCurrentDragOverItem)
|
||||
setDragActive(gCurrentDragOverItem, false);
|
||||
}
|
||||
|
||||
var dragStartObserver =
|
||||
function onToolbarDragStart(aEvent)
|
||||
{
|
||||
onDragStart: function (aEvent, aXferData, aDragAction) {
|
||||
var documentId = gToolboxDocument.documentElement.id;
|
||||
|
||||
var item = aEvent.target;
|
||||
while (item && item.localName != "toolbarpaletteitem")
|
||||
item = item.parentNode;
|
||||
|
||||
item.setAttribute("dragactive", "true");
|
||||
|
||||
aXferData.data = new TransferDataSet();
|
||||
var data = new TransferData();
|
||||
data.addDataForFlavour("text/toolbarwrapper-id/"+documentId, item.firstChild.id);
|
||||
aXferData.data.push(data);
|
||||
aDragAction.action = Components.interfaces.nsIDragService.DRAGDROP_ACTION_MOVE;
|
||||
}
|
||||
var documentId = gToolboxDocument.documentElement.id;
|
||||
|
||||
var item = aEvent.target;
|
||||
while (item && item.localName != "toolbarpaletteitem")
|
||||
item = item.parentNode;
|
||||
|
||||
item.setAttribute("dragactive", "true");
|
||||
|
||||
var dt = aEvent.dataTransfer;
|
||||
dt.setData("text/toolbarwrapper-id/" + documentId, item.firstChild.id);
|
||||
dt.effectAllowed = "move";
|
||||
}
|
||||
|
||||
var toolbarDNDObserver =
|
||||
function onToolbarDragOver(aEvent)
|
||||
{
|
||||
onDragOver: function (aEvent, aFlavour, aDragSession)
|
||||
{
|
||||
var toolbar = aEvent.target;
|
||||
var dropTarget = aEvent.target;
|
||||
while (toolbar && toolbar.localName != "toolbar") {
|
||||
dropTarget = toolbar;
|
||||
toolbar = toolbar.parentNode;
|
||||
}
|
||||
|
||||
var previousDragItem = gCurrentDragOverItem;
|
||||
var documentId = gToolboxDocument.documentElement.id;
|
||||
if (!aEvent.dataTransfer.types.contains("text/toolbarwrapper-id/" + documentId))
|
||||
return;
|
||||
|
||||
// Make sure we are dragging over a customizable toolbar.
|
||||
if (!isCustomizableToolbar(toolbar)) {
|
||||
gCurrentDragOverItem = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (dropTarget.localName == "toolbar") {
|
||||
gCurrentDragOverItem = dropTarget;
|
||||
} else {
|
||||
gCurrentDragOverItem = null;
|
||||
|
||||
var direction = window.getComputedStyle(dropTarget.parentNode, null).direction;
|
||||
var dropTargetCenter = dropTarget.boxObject.x + (dropTarget.boxObject.width / 2);
|
||||
var dragAfter;
|
||||
if (direction == "ltr")
|
||||
dragAfter = aEvent.clientX > dropTargetCenter;
|
||||
else
|
||||
dragAfter = aEvent.clientX < dropTargetCenter;
|
||||
|
||||
if (dragAfter) {
|
||||
gCurrentDragOverItem = dropTarget.nextSibling;
|
||||
if (!gCurrentDragOverItem)
|
||||
gCurrentDragOverItem = toolbar;
|
||||
} else
|
||||
gCurrentDragOverItem = dropTarget;
|
||||
}
|
||||
|
||||
if (previousDragItem && gCurrentDragOverItem != previousDragItem) {
|
||||
setDragActive(previousDragItem, false);
|
||||
}
|
||||
|
||||
setDragActive(gCurrentDragOverItem, true);
|
||||
|
||||
aDragSession.canDrop = true;
|
||||
},
|
||||
var toolbar = aEvent.target;
|
||||
var dropTarget = aEvent.target;
|
||||
while (toolbar && toolbar.localName != "toolbar") {
|
||||
dropTarget = toolbar;
|
||||
toolbar = toolbar.parentNode;
|
||||
}
|
||||
|
||||
onDrop: function (aEvent, aXferData, aDragSession)
|
||||
{
|
||||
if (!gCurrentDragOverItem)
|
||||
return;
|
||||
|
||||
setDragActive(gCurrentDragOverItem, false);
|
||||
var previousDragItem = gCurrentDragOverItem;
|
||||
|
||||
var draggedItemId = aXferData.data;
|
||||
if (gCurrentDragOverItem.id == draggedItemId)
|
||||
return;
|
||||
|
||||
var toolbar = aEvent.target;
|
||||
while (toolbar.localName != "toolbar")
|
||||
toolbar = toolbar.parentNode;
|
||||
|
||||
var draggedPaletteWrapper = document.getElementById("wrapper-"+draggedItemId);
|
||||
if (!draggedPaletteWrapper) {
|
||||
// The wrapper has been dragged from the toolbar.
|
||||
|
||||
// Get the wrapper from the toolbar document and make sure that
|
||||
// it isn't being dropped on itself.
|
||||
var wrapper = gToolboxDocument.getElementById("wrapper-"+draggedItemId);
|
||||
if (wrapper == gCurrentDragOverItem)
|
||||
return;
|
||||
|
||||
// Don't allow static kids (e.g., the menubar) to move.
|
||||
if (wrapper.parentNode.firstPermanentChild && wrapper.parentNode.firstPermanentChild.id == wrapper.firstChild.id)
|
||||
return;
|
||||
if (wrapper.parentNode.lastPermanentChild && wrapper.parentNode.lastPermanentChild.id == wrapper.firstChild.id)
|
||||
return;
|
||||
|
||||
// Remove the item from its place in the toolbar.
|
||||
wrapper.parentNode.removeChild(wrapper);
|
||||
|
||||
// Determine which toolbar we are dropping on.
|
||||
var dropToolbar = null;
|
||||
if (gCurrentDragOverItem.localName == "toolbar")
|
||||
dropToolbar = gCurrentDragOverItem;
|
||||
else
|
||||
dropToolbar = gCurrentDragOverItem.parentNode;
|
||||
|
||||
// Insert the item into the toolbar.
|
||||
if (gCurrentDragOverItem != dropToolbar)
|
||||
dropToolbar.insertBefore(wrapper, gCurrentDragOverItem);
|
||||
else
|
||||
dropToolbar.appendChild(wrapper);
|
||||
} else {
|
||||
// The item has been dragged from the palette
|
||||
|
||||
// Create a new wrapper for the item. We don't know the id yet.
|
||||
var wrapper = createWrapper("", gToolboxDocument);
|
||||
|
||||
// Ask the toolbar to clone the item's template, place it inside the wrapper, and insert it in the toolbar.
|
||||
var newItem = toolbar.insertItem(draggedItemId, gCurrentDragOverItem == toolbar ? null : gCurrentDragOverItem, wrapper);
|
||||
|
||||
// Prepare the item and wrapper to look good on the toolbar.
|
||||
cleanupItemForToolbar(newItem, wrapper);
|
||||
wrapper.id = "wrapper-"+newItem.id;
|
||||
wrapper.flex = newItem.flex;
|
||||
|
||||
// Remove the wrapper from the palette.
|
||||
var currentRow = draggedPaletteWrapper.parentNode;
|
||||
if (draggedItemId != "separator" &&
|
||||
draggedItemId != "spring" &&
|
||||
draggedItemId != "spacer")
|
||||
{
|
||||
currentRow.removeChild(draggedPaletteWrapper);
|
||||
|
||||
while (currentRow) {
|
||||
// Pull the first child of the next row up
|
||||
// into this row.
|
||||
var nextRow = currentRow.nextSibling;
|
||||
|
||||
if (!nextRow) {
|
||||
var last = currentRow.lastChild;
|
||||
var first = currentRow.firstChild;
|
||||
if (first == last) {
|
||||
// Kill the row.
|
||||
currentRow.parentNode.removeChild(currentRow);
|
||||
break;
|
||||
}
|
||||
|
||||
if (last.localName == "spacer") {
|
||||
var flex = last.getAttribute("flex");
|
||||
last.setAttribute("flex", ++flex);
|
||||
// Reflow doesn't happen for some reason. Trigger it with a hide/show. ICK! -dwh
|
||||
last.hidden = true;
|
||||
last.hidden = false;
|
||||
break;
|
||||
} else {
|
||||
// Make a spacer and give it a flex of 1.
|
||||
var spacer = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
||||
"spacer");
|
||||
spacer.setAttribute("flex", "1");
|
||||
currentRow.appendChild(spacer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
currentRow.appendChild(nextRow.firstChild);
|
||||
currentRow = currentRow.nextSibling;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we are dragging over a customizable toolbar.
|
||||
if (!isCustomizableToolbar(toolbar)) {
|
||||
gCurrentDragOverItem = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (dropTarget.localName == "toolbar") {
|
||||
gCurrentDragOverItem = dropTarget;
|
||||
} else {
|
||||
gCurrentDragOverItem = null;
|
||||
|
||||
toolboxChanged();
|
||||
},
|
||||
|
||||
_flavourSet: null,
|
||||
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
if (!this._flavourSet) {
|
||||
this._flavourSet = new FlavourSet();
|
||||
var documentId = gToolboxDocument.documentElement.id;
|
||||
this._flavourSet.appendFlavour("text/toolbarwrapper-id/"+documentId);
|
||||
}
|
||||
return this._flavourSet;
|
||||
var direction = window.getComputedStyle(dropTarget.parentNode, null).direction;
|
||||
var dropTargetCenter = dropTarget.boxObject.x + (dropTarget.boxObject.width / 2);
|
||||
var dragAfter;
|
||||
if (direction == "ltr")
|
||||
dragAfter = aEvent.clientX > dropTargetCenter;
|
||||
else
|
||||
dragAfter = aEvent.clientX < dropTargetCenter;
|
||||
|
||||
if (dragAfter) {
|
||||
gCurrentDragOverItem = dropTarget.nextSibling;
|
||||
if (!gCurrentDragOverItem)
|
||||
gCurrentDragOverItem = toolbar;
|
||||
} else
|
||||
gCurrentDragOverItem = dropTarget;
|
||||
}
|
||||
|
||||
if (previousDragItem && gCurrentDragOverItem != previousDragItem) {
|
||||
setDragActive(previousDragItem, false);
|
||||
}
|
||||
|
||||
setDragActive(gCurrentDragOverItem, true);
|
||||
|
||||
aEvent.preventDefault();
|
||||
}
|
||||
|
||||
var paletteDNDObserver =
|
||||
function onToolbarDrop(aEvent)
|
||||
{
|
||||
onDragOver: function (aEvent, aFlavour, aDragSession)
|
||||
{
|
||||
aDragSession.canDrop = true;
|
||||
},
|
||||
|
||||
onDrop: function(aEvent, aXferData, aDragSession)
|
||||
{
|
||||
var itemId = aXferData.data;
|
||||
|
||||
var wrapper = gToolboxDocument.getElementById("wrapper-"+itemId);
|
||||
if (wrapper) {
|
||||
// Don't allow static kids (e.g., the menubar) to move.
|
||||
if (wrapper.parentNode.firstPermanentChild && wrapper.parentNode.firstPermanentChild.id == wrapper.firstChild.id)
|
||||
return;
|
||||
if (wrapper.parentNode.lastPermanentChild && wrapper.parentNode.lastPermanentChild.id == wrapper.firstChild.id)
|
||||
return;
|
||||
if (!gCurrentDragOverItem)
|
||||
return;
|
||||
|
||||
var wrapperType = wrapper.getAttribute("type");
|
||||
if (wrapperType != "separator" &&
|
||||
wrapperType != "spacer" &&
|
||||
wrapperType != "spring") {
|
||||
appendPaletteItem(document.importNode(wrapper.firstChild, true));
|
||||
gToolbox.palette.appendChild(wrapper.firstChild);
|
||||
setDragActive(gCurrentDragOverItem, false);
|
||||
|
||||
var documentId = gToolboxDocument.documentElement.id;
|
||||
var draggedItemId = aEvent.dataTransfer.getData("text/toolbarwrapper-id/" + documentId);
|
||||
if (gCurrentDragOverItem.id == draggedItemId)
|
||||
return;
|
||||
|
||||
var toolbar = aEvent.target;
|
||||
while (toolbar.localName != "toolbar")
|
||||
toolbar = toolbar.parentNode;
|
||||
|
||||
var draggedPaletteWrapper = document.getElementById("wrapper-"+draggedItemId);
|
||||
if (!draggedPaletteWrapper) {
|
||||
// The wrapper has been dragged from the toolbar.
|
||||
// Get the wrapper from the toolbar document and make sure that
|
||||
// it isn't being dropped on itself.
|
||||
var wrapper = gToolboxDocument.getElementById("wrapper-"+draggedItemId);
|
||||
if (wrapper == gCurrentDragOverItem)
|
||||
return;
|
||||
|
||||
// Don't allow static kids (e.g., the menubar) to move.
|
||||
if (wrapper.parentNode.firstPermanentChild && wrapper.parentNode.firstPermanentChild.id == wrapper.firstChild.id)
|
||||
return;
|
||||
if (wrapper.parentNode.lastPermanentChild && wrapper.parentNode.lastPermanentChild.id == wrapper.firstChild.id)
|
||||
return;
|
||||
|
||||
// Remove the item from its place in the toolbar.
|
||||
wrapper.parentNode.removeChild(wrapper);
|
||||
|
||||
// Determine which toolbar we are dropping on.
|
||||
var dropToolbar = null;
|
||||
if (gCurrentDragOverItem.localName == "toolbar")
|
||||
dropToolbar = gCurrentDragOverItem;
|
||||
else
|
||||
dropToolbar = gCurrentDragOverItem.parentNode;
|
||||
|
||||
// Insert the item into the toolbar.
|
||||
if (gCurrentDragOverItem != dropToolbar)
|
||||
dropToolbar.insertBefore(wrapper, gCurrentDragOverItem);
|
||||
else
|
||||
dropToolbar.appendChild(wrapper);
|
||||
} else {
|
||||
// The item has been dragged from the palette
|
||||
|
||||
// Create a new wrapper for the item. We don't know the id yet.
|
||||
var wrapper = createWrapper("", gToolboxDocument);
|
||||
|
||||
// Ask the toolbar to clone the item's template, place it inside the wrapper, and insert it in the toolbar.
|
||||
var newItem = toolbar.insertItem(draggedItemId, gCurrentDragOverItem == toolbar ? null : gCurrentDragOverItem, wrapper);
|
||||
|
||||
// Prepare the item and wrapper to look good on the toolbar.
|
||||
cleanupItemForToolbar(newItem, wrapper);
|
||||
wrapper.id = "wrapper-"+newItem.id;
|
||||
wrapper.flex = newItem.flex;
|
||||
|
||||
// Remove the wrapper from the palette.
|
||||
var currentRow = draggedPaletteWrapper.parentNode;
|
||||
if (draggedItemId != "separator" &&
|
||||
draggedItemId != "spring" &&
|
||||
draggedItemId != "spacer")
|
||||
{
|
||||
currentRow.removeChild(draggedPaletteWrapper);
|
||||
|
||||
while (currentRow) {
|
||||
// Pull the first child of the next row up
|
||||
// into this row.
|
||||
var nextRow = currentRow.nextSibling;
|
||||
|
||||
if (!nextRow) {
|
||||
var last = currentRow.lastChild;
|
||||
var first = currentRow.firstChild;
|
||||
if (first == last) {
|
||||
// Kill the row.
|
||||
currentRow.parentNode.removeChild(currentRow);
|
||||
break;
|
||||
}
|
||||
|
||||
if (last.localName == "spacer") {
|
||||
var flex = last.getAttribute("flex");
|
||||
last.setAttribute("flex", ++flex);
|
||||
// Reflow doesn't happen for some reason. Trigger it with a hide/show. ICK! -dwh
|
||||
last.hidden = true;
|
||||
last.hidden = false;
|
||||
break;
|
||||
} else {
|
||||
// Make a spacer and give it a flex of 1.
|
||||
var spacer = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
||||
"spacer");
|
||||
spacer.setAttribute("flex", "1");
|
||||
currentRow.appendChild(spacer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
currentRow.appendChild(nextRow.firstChild);
|
||||
currentRow = currentRow.nextSibling;
|
||||
}
|
||||
|
||||
// The item was dragged out of the toolbar.
|
||||
wrapper.parentNode.removeChild(wrapper);
|
||||
}
|
||||
|
||||
toolboxChanged();
|
||||
},
|
||||
|
||||
_flavourSet: null,
|
||||
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
if (!this._flavourSet) {
|
||||
this._flavourSet = new FlavourSet();
|
||||
var documentId = gToolboxDocument.documentElement.id;
|
||||
this._flavourSet.appendFlavour("text/toolbarwrapper-id/"+documentId);
|
||||
}
|
||||
return this._flavourSet;
|
||||
}
|
||||
|
||||
gCurrentDragOverItem = null;
|
||||
|
||||
toolboxChanged();
|
||||
};
|
||||
|
||||
function onPaletteDragOver(aEvent)
|
||||
{
|
||||
var documentId = gToolboxDocument.documentElement.id;
|
||||
if (aEvent.dataTransfer.types.contains("text/toolbarwrapper-id/" + documentId))
|
||||
aEvent.preventDefault();
|
||||
}
|
||||
|
||||
function onPaletteDrop(aEvent)
|
||||
{
|
||||
var documentId = gToolboxDocument.documentElement.id;
|
||||
var itemId = aEvent.dataTransfer.getData("text/toolbarwrapper-id/" + documentId);
|
||||
|
||||
var wrapper = gToolboxDocument.getElementById("wrapper-"+itemId);
|
||||
if (wrapper) {
|
||||
// Don't allow static kids (e.g., the menubar) to move.
|
||||
if (wrapper.parentNode.firstPermanentChild && wrapper.parentNode.firstPermanentChild.id == wrapper.firstChild.id)
|
||||
return;
|
||||
if (wrapper.parentNode.lastPermanentChild && wrapper.parentNode.lastPermanentChild.id == wrapper.firstChild.id)
|
||||
return;
|
||||
|
||||
var wrapperType = wrapper.getAttribute("type");
|
||||
if (wrapperType != "separator" &&
|
||||
wrapperType != "spacer" &&
|
||||
wrapperType != "spring") {
|
||||
appendPaletteItem(document.importNode(wrapper.firstChild, true));
|
||||
gToolbox.palette.appendChild(wrapper.firstChild);
|
||||
}
|
||||
|
||||
// The item was dragged out of the toolbar.
|
||||
wrapper.parentNode.removeChild(wrapper);
|
||||
}
|
||||
|
||||
toolboxChanged();
|
||||
}
|
||||
|
@ -57,7 +57,6 @@
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<script type="application/javascript" src="chrome://global/content/customizeToolbar.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/nsDragAndDrop.js"/>
|
||||
|
||||
<stringbundle id="stringBundle" src="chrome://global/locale/customizeToolbar.properties"/>
|
||||
|
||||
@ -73,9 +72,9 @@
|
||||
</description>
|
||||
|
||||
<vbox flex="1" id="palette-box"
|
||||
ondraggesture="nsDragAndDrop.startDrag(event, dragStartObserver);"
|
||||
ondragover="nsDragAndDrop.dragOver(event, paletteDNDObserver);"
|
||||
ondragdrop="nsDragAndDrop.drop(event, paletteDNDObserver);"/>
|
||||
ondragstart="onToolbarDragStart(event)"
|
||||
ondragover="onPaletteDragOver(event)"
|
||||
ondrop="onPaletteDrop(event)"/>
|
||||
|
||||
<box align="center">
|
||||
<label value="&show.label;"/>
|
||||
|
@ -37,6 +37,17 @@
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// USE OF THIS API FOR DRAG AND DROP IS DEPRECATED!
|
||||
// Do not use this file for new code.
|
||||
//
|
||||
// For documentation about what to use instead, see:
|
||||
// http://developer.mozilla.org/En/DragDrop/Drag_and_Drop
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* nsTransferable - a wrapper for nsITransferable that simplifies
|
||||
* javascript clipboard and drag&drop. for use in
|
||||
@ -574,6 +585,9 @@ var nsDragAndDrop = {
|
||||
**/
|
||||
dragDropSecurityCheck: function (aEvent, aDragSession, aDraggedText)
|
||||
{
|
||||
if (!aDragSession)
|
||||
aDragSession = this.mDragService.getCurrentSession();
|
||||
|
||||
var sourceDoc = aDragSession.sourceDocument;
|
||||
if (!sourceDoc)
|
||||
return;
|
||||
|
@ -68,24 +68,6 @@
|
||||
</getter>
|
||||
</property>
|
||||
|
||||
<method name="getSupportedFlavours">
|
||||
<body><![CDATA[
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour("text/unicode");
|
||||
return flavourSet;
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<method name="onDrop">
|
||||
<parameter name="aEvent"/>
|
||||
<parameter name="aXferData"/>
|
||||
<parameter name="aDragSession"/>
|
||||
<body><![CDATA[
|
||||
this.value = aXferData.data;
|
||||
this.findbar._find(aXferData.data);
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<method name="_handleEnter">
|
||||
<parameter name="aEvent"/>
|
||||
<body><![CDATA[
|
||||
@ -206,7 +188,10 @@
|
||||
]]></handler>
|
||||
|
||||
<handler event="drop" phase="capturing"><![CDATA[
|
||||
nsDragAndDrop.drop(event, this);
|
||||
var value = event.dataTransfer.getData("text/plain");
|
||||
this.value = value;
|
||||
this.findbar._find(value);
|
||||
event.stopPropagation();
|
||||
]]></handler>
|
||||
</handlers>
|
||||
</binding>
|
||||
|
@ -674,29 +674,26 @@ function buildContextMenu(aEvent)
|
||||
|
||||
var gDownloadDNDObserver =
|
||||
{
|
||||
onDragOver: function (aEvent, aFlavour, aDragSession)
|
||||
onDragOver: function (aEvent)
|
||||
{
|
||||
aDragSession.canDrop = true;
|
||||
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, aXferData, aDragSession)
|
||||
onDrop: function(aEvent)
|
||||
{
|
||||
var split = aXferData.data.split("\n");
|
||||
var url = split[0];
|
||||
if (url != aXferData.data) { //do nothing, not a valid URL
|
||||
var name = split[1];
|
||||
saveURL(url, name, null, true, true);
|
||||
var dt = aEvent.dataTransfer;
|
||||
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");
|
||||
}
|
||||
},
|
||||
_flavourSet: null,
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
if (!this._flavourSet) {
|
||||
this._flavourSet = new FlavourSet();
|
||||
this._flavourSet.appendFlavour("text/x-moz-url");
|
||||
this._flavourSet.appendFlavour("text/unicode");
|
||||
}
|
||||
return this._flavourSet;
|
||||
if (url)
|
||||
saveURL(url, name ? name : url, null, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,6 @@
|
||||
<script type="application/javascript" src="chrome://mozapps/content/downloads/downloads.js"/>
|
||||
<script type="application/javascript" src="chrome://mozapps/content/downloads/DownloadProgressListener.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/contentAreaUtils.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/nsDragAndDrop.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/globalOverlay.js"/>
|
||||
|
||||
<stringbundleset id="downloadSet">
|
||||
@ -179,8 +178,8 @@
|
||||
<richlistbox id="downloadView" seltype="multiple" flex="1"
|
||||
context="downloadContextMenu"
|
||||
ondblclick="onDownloadDblClick(event);"
|
||||
ondragover="nsDragAndDrop.dragOver(event, gDownloadDNDObserver);"
|
||||
ondragdrop="nsDragAndDrop.drop(event, gDownloadDNDObserver);">
|
||||
ondragover="gDownloadDNDObserver.onDragOver(event)"
|
||||
ondrop="gDownloadDNDObserver.onDrop(event)">
|
||||
</richlistbox>
|
||||
|
||||
<windowdragbox id="search" align="center">
|
||||
|
@ -1888,7 +1888,6 @@ function buildContextMenu(aEvent)
|
||||
var gExtensionsDNDObserver =
|
||||
{
|
||||
_ioServ: null,
|
||||
_canDrop: false,
|
||||
|
||||
_ensureServices: function ()
|
||||
{
|
||||
@ -1898,31 +1897,38 @@ var gExtensionsDNDObserver =
|
||||
},
|
||||
|
||||
// returns a JS object whose properties are used by xpinstall
|
||||
_getDataFromDragSession: function (aDragSession, aPosition)
|
||||
_getDragData: function (dataTransfer, aIndex)
|
||||
{
|
||||
var fileData = { };
|
||||
// if this fails we do not have valid data to drop
|
||||
try {
|
||||
var xfer = Components.classes["@mozilla.org/widget/transferable;1"]
|
||||
.createInstance(Components.interfaces.nsITransferable);
|
||||
xfer.addDataFlavor("text/x-moz-url");
|
||||
xfer.addDataFlavor("application/x-moz-file", "nsIFile");
|
||||
aDragSession.getData(xfer, aPosition);
|
||||
var url = dataTransfer.mozGetDataAt("text/uri-list", aIndex);
|
||||
if (!url) {
|
||||
url = dataTransfer.mozGetDataAt("text/x-moz-url", aIndex);
|
||||
url = url ? url.split("\n")[0] : null;
|
||||
if (!url) {
|
||||
var file = dataTransfer.mozGetDataAt("application/x-moz-file", aIndex);
|
||||
|
||||
var flavour = { }, data = { }, length = { };
|
||||
xfer.getAnyTransferData(flavour, data, length);
|
||||
var selectedFlavour = this.getSupportedFlavours().flavourTable[flavour.value];
|
||||
var xferData = new FlavourData(data.value, length.value, selectedFlavour);
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var fileHandler = this._ioServ.getProtocolHandler("file")
|
||||
.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
url = fileHandler.getURLSpecFromFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
var fileURL = transferUtils.retrieveURLFromData(xferData.data,
|
||||
xferData.flavour.contentType);
|
||||
fileData.fileURL = fileURL;
|
||||
if (!url) {
|
||||
url = dataTransfer.mozGetDataAt("text/plain", aIndex)
|
||||
if (!url)
|
||||
return null;
|
||||
}
|
||||
|
||||
var uri = this._ioServ.newURI(fileURL, null, null);
|
||||
var url = uri.QueryInterface(nsIURL);
|
||||
fileData.fileName = url.fileName;
|
||||
fileData.fileURL = url;
|
||||
|
||||
switch (url.fileExtension) {
|
||||
var uri = this._ioServ.newURI(url, null, null).QueryInterface(nsIURL);
|
||||
fileData.fileName = uri.fileName;
|
||||
|
||||
switch (uri.fileExtension) {
|
||||
case "xpi":
|
||||
fileData.type = nsIUpdateItem.TYPE_EXTENSION;
|
||||
break;
|
||||
@ -1940,31 +1946,16 @@ var gExtensionsDNDObserver =
|
||||
return fileData;
|
||||
},
|
||||
|
||||
canDrop: function (aEvent, aDragSession) { return this._canDrop; },
|
||||
|
||||
onDragEnter: function (aEvent, aDragSession)
|
||||
onDragOver: function (aEvent)
|
||||
{
|
||||
// XXXrstrong - bug 269568, GTK2 drag and drop is returning invalid data for
|
||||
// dragenter and dragover. To workaround this we always set canDrop to true
|
||||
// and just use the xfer data returned in ondrop which is valid.
|
||||
#ifndef MOZ_WIDGET_GTK2
|
||||
this._ensureServices();
|
||||
|
||||
var count = aDragSession.numDropItems;
|
||||
for (var i = 0; i < count; ++i) {
|
||||
var fileData = this._getDataFromDragSession(aDragSession, i);
|
||||
if (!fileData) {
|
||||
this._canDrop = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
this._canDrop = true;
|
||||
var types = aEvent.dataTransfer.types;
|
||||
if (types.contains("text/uri-list") ||
|
||||
types.contains("text/x-moz-url") ||
|
||||
types.contains("application/x-moz-file"))
|
||||
aEvent.preventDefault();
|
||||
},
|
||||
|
||||
onDragOver: function (aEvent, aFlavor, aDragSession) { },
|
||||
|
||||
onDrop: function(aEvent, aXferData, aDragSession)
|
||||
onDrop: function(aEvent)
|
||||
{
|
||||
if (!isXPInstallEnabled())
|
||||
return;
|
||||
@ -1976,9 +1967,10 @@ var gExtensionsDNDObserver =
|
||||
var xpiCount = 0;
|
||||
var themeCount = 0;
|
||||
|
||||
var count = aDragSession.numDropItems;
|
||||
var dataTransfer = aEvent.dataTransfer;
|
||||
var count = dataTransfer.mozItemCount;
|
||||
for (var i = 0; i < count; ++i) {
|
||||
var fileData = this._getDataFromDragSession(aDragSession, i);
|
||||
var fileData = this._getDragData(dataTransfer, i);
|
||||
if (!fileData)
|
||||
continue;
|
||||
|
||||
@ -1995,16 +1987,6 @@ var gExtensionsDNDObserver =
|
||||
|
||||
if (xpiCount > 0)
|
||||
InstallTrigger.install(xpinstallObj);
|
||||
},
|
||||
_flavourSet: null,
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
if (!this._flavourSet) {
|
||||
this._flavourSet = new FlavourSet();
|
||||
this._flavourSet.appendFlavour("text/x-moz-url");
|
||||
this._flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
|
||||
}
|
||||
return this._flavourSet;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -65,7 +65,6 @@
|
||||
<script type="application/javascript" src="chrome://global/content/globalOverlay.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/contentAreaUtils.js"/>
|
||||
<script type="application/javascript" src="chrome://mozapps/content/extensions/extensions.js"/>
|
||||
<script type="application/javascript" src="chrome://global/content/nsDragAndDrop.js"/>
|
||||
|
||||
<stringbundleset id="extensionsSet">
|
||||
<stringbundle id="brandStrings" src="chrome://branding/locale/brand.properties"/>
|
||||
@ -200,9 +199,9 @@
|
||||
<hbox flex="1">
|
||||
<richlistbox id="extensionsView" flex="1"
|
||||
datasources="rdf:null" context="addonContextMenu"
|
||||
ondragenter="nsDragAndDrop.dragEnter(event, gExtensionsDNDObserver);"
|
||||
ondragover="nsDragAndDrop.dragOver(event, gExtensionsDNDObserver);"
|
||||
ondragdrop="nsDragAndDrop.drop(event, gExtensionsDNDObserver);"
|
||||
ondragenter="gExtensionsDNDObserver.onDragOver(event)"
|
||||
ondragover="gExtensionsDNDObserver.onDragOver(event)"
|
||||
ondrop="gExtensionsDNDObserver.onDrop(event)"
|
||||
ondblclick="onViewDoubleClick(event);"/>
|
||||
|
||||
<splitter id="themeSplitter" hidden="true" collapse="none" persist="state"/>
|
||||
|
Loading…
Reference in New Issue
Block a user