Bug 774125 - Switch to new drag and drop api for home button r=neil
This commit is contained in:
Родитель
ea67830e45
Коммит
83cd7a1f13
|
@ -242,11 +242,11 @@
|
||||||
oncommand="BrowserHome(event);"
|
oncommand="BrowserHome(event);"
|
||||||
onclick="if (event.button == 1) BrowserHome(event);"
|
onclick="if (event.button == 1) BrowserHome(event);"
|
||||||
tooltip="home-button-tooltip"
|
tooltip="home-button-tooltip"
|
||||||
ondraggesture="nsDragAndDrop.startDrag(event, homeButtonObserver)"
|
ondragstart="homeButtonObserver.onDragStart(event);"
|
||||||
ondragdrop="nsDragAndDrop.drop(event, homeButtonObserver); event.stopPropagation()"
|
ondragdrop="homeButtonObserver.onDrop(event);"
|
||||||
ondragenter="event.stopPropagation()"
|
ondragenter="event.stopPropagation();"
|
||||||
ondragexit="nsDragAndDrop.dragExit(event, homeButtonObserver); event.stopPropagation()"
|
ondragexit="homeButtonObserver.onDragExit(event);"
|
||||||
ondragover="nsDragAndDrop.dragOver(event, homeButtonObserver); event.stopPropagation()"/>
|
ondragover="homeButtonObserver.onDragOver(event);"/>
|
||||||
|
|
||||||
<toolbaritem id="nav-bar-inner"
|
<toolbaritem id="nav-bar-inner"
|
||||||
flex="4"
|
flex="4"
|
||||||
|
|
|
@ -59,6 +59,12 @@ function BeginDragLink(aEvent, aHref, aTitle)
|
||||||
dt.setData("text/plain", aHref);
|
dt.setData("text/plain", aHref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function DragLinkOver(aEvent)
|
||||||
|
{
|
||||||
|
if (Services.droppedLinkHandler.canDropLink(aEvent, true))
|
||||||
|
aEvent.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
var proxyIconDNDObserver = {
|
var proxyIconDNDObserver = {
|
||||||
onDragStart: function (aEvent)
|
onDragStart: function (aEvent)
|
||||||
{
|
{
|
||||||
|
@ -71,55 +77,44 @@ var proxyIconDNDObserver = {
|
||||||
};
|
};
|
||||||
|
|
||||||
var homeButtonObserver = {
|
var homeButtonObserver = {
|
||||||
onDragStart: function (aEvent, aXferData, aDragAction)
|
onDragStart: function (aEvent)
|
||||||
{
|
{
|
||||||
var homepage = nsPreferences.getLocalizedUnicharPref("browser.startup.homepage", "about:blank");
|
var homepage = GetLocalizedStringPref("browser.startup.homepage",
|
||||||
|
"about:blank");
|
||||||
|
|
||||||
if (homepage)
|
if (homepage)
|
||||||
{
|
|
||||||
// XXX find a readable title string for homepage, perhaps do a history lookup.
|
|
||||||
var htmlString = "<a href=\"" + homepage + "\">" + homepage + "</a>";
|
|
||||||
aXferData.data = new TransferData();
|
|
||||||
aXferData.data.addDataForFlavour("text/x-moz-url", homepage + "\n" + homepage);
|
|
||||||
aXferData.data.addDataForFlavour("text/html", htmlString);
|
|
||||||
aXferData.data.addDataForFlavour("text/unicode", homepage);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
onDrop: function (aEvent, aXferData, aDragSession)
|
|
||||||
{
|
{
|
||||||
var url = transferUtils.retrieveURLFromData(aXferData.data, aXferData.flavour.contentType);
|
// XXX find a readable title string for homepage,
|
||||||
setTimeout(openHomeDialog, 0, url);
|
// perhaps do a history lookup.
|
||||||
},
|
BeginDragLink(aEvent, homepage, homepage);
|
||||||
|
|
||||||
onDragOver: function (aEvent, aFlavour, aDragSession)
|
|
||||||
{
|
|
||||||
const nsIDragService = Components.interfaces.nsIDragService;
|
|
||||||
if (aEvent.target == aDragSession.dataTransfer.mozSourceNode)
|
|
||||||
{
|
|
||||||
aDragSession.dragAction = nsIDragService.DRAGDROP_ACTION_NONE;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var statusTextFld = document.getElementById("statusbar-display");
|
|
||||||
statusTextFld.label = gNavigatorBundle.getString("droponhomebutton");
|
|
||||||
aDragSession.dragAction = nsIDragService.DRAGDROP_ACTION_LINK;
|
|
||||||
},
|
|
||||||
|
|
||||||
onDragExit: function (aEvent, aDragSession)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
|
onDrop: function (aEvent)
|
||||||
|
{
|
||||||
|
aEvent.stopPropagation();
|
||||||
|
// disallow setting home pages that inherit the principal
|
||||||
|
var url = Services.droppedLinkHandler.dropLink(aEvent, {}, true);
|
||||||
|
setTimeout(openHomeDialog, 0, url);
|
||||||
|
},
|
||||||
|
|
||||||
|
onDragOver: function (aEvent)
|
||||||
|
{
|
||||||
|
if (aEvent.target == aEvent.dataTransfer.mozSourceNode)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DragLinkOver(aEvent);
|
||||||
|
aEvent.dropEffect = "link";
|
||||||
|
var statusTextFld = document.getElementById("statusbar-display");
|
||||||
|
statusTextFld.label = gNavigatorBundle.getString("droponhomebutton");
|
||||||
|
},
|
||||||
|
|
||||||
|
onDragExit: function (aEvent)
|
||||||
|
{
|
||||||
|
aEvent.stopPropagation();
|
||||||
|
document.getElementById("statusbar-display").label = "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function openHomeDialog(aURL)
|
function openHomeDialog(aURL)
|
||||||
{
|
{
|
||||||
|
@ -133,7 +128,7 @@ function openHomeDialog(aURL)
|
||||||
Services.prompt.BUTTON_POS_1),
|
Services.prompt.BUTTON_POS_1),
|
||||||
okButton, null, null, null,
|
okButton, null, null, null,
|
||||||
{value: false}) == 0)
|
{value: false}) == 0)
|
||||||
nsPreferences.setUnicharPref("browser.startup.homepage", aURL);
|
SetStringPref("browser.startup.homepage", aURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
var goButtonObserver = {
|
var goButtonObserver = {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче