Bug 773983 - Switch to new drag and drop api for urlbar proxyIcon r=neil

This commit is contained in:
Ian Neal 2012-07-16 16:00:03 +01:00
Родитель 639881ec83
Коммит d314abc13b
3 изменённых файлов: 29 добавлений и 29 удалений

Просмотреть файл

@ -2269,15 +2269,6 @@ function SetPageProxyState(aState, aURI)
} }
} }
function PageProxyDragGesture(aEvent)
{
if (gProxyButton.getAttribute("pageproxystate") == "valid") {
nsDragAndDrop.startDrag(aEvent, proxyIconDNDObserver);
return true;
}
return false;
}
function handlePageProxyClick(aEvent) function handlePageProxyClick(aEvent)
{ {
switch (aEvent.button) { switch (aEvent.button) {

Просмотреть файл

@ -280,12 +280,11 @@
</box> </box>
<deck id="page-proxy-deck" <deck id="page-proxy-deck"
class="urlbar-icons" class="urlbar-icons"
ondragstart="proxyIconDNDObserver.onDragStart(event);"
onclick="handlePageProxyClick(event);"> onclick="handlePageProxyClick(event);">
<image id="page-proxy-button" <image id="page-proxy-button"
ondraggesture="PageProxyDragGesture(event);"
tooltiptext="&proxyIcon.tooltip;"/> tooltiptext="&proxyIcon.tooltip;"/>
<image id="page-proxy-favicon" validate="never" <image id="page-proxy-favicon" validate="never"
ondraggesture="PageProxyDragGesture(event);"
onload="this.parentNode.selectedIndex = 1; onload="this.parentNode.selectedIndex = 1;
event.stopPropagation();" event.stopPropagation();"
onerror="gBrowser.addToMissedIconCache(this.src);" onerror="gBrowser.addToMissedIconCache(this.src);"

Просмотреть файл

@ -40,26 +40,36 @@ var RDFUtils = {
} }
} }
var proxyIconDNDObserver = { function htmlEscape(aString)
onDragStart: function (aEvent, aXferData, aDragAction) {
{ return aString.replace(/&/g, "&amp;")
var urlBar = document.getElementById("urlbar"); .replace(/>/g, "&gt;")
.replace(/</g, "&lt;")
// XXX - do we want to allow the user to set a blank page to their homepage? .replace(/"/g, "&quot;")
// if so then we want to modify this a little to set about:blank as .replace(/'/g, "&apos;");
// the homepage in the event of an empty urlbar.
if (!urlBar.value) return;
var urlString = urlBar.value + "\n" + window.content.document.title;
var htmlString = "<a href=\"" + urlBar.value + "\">" + urlBar.value + "</a>";
aXferData.data = new TransferData();
aXferData.data.addDataForFlavour("text/x-moz-url", urlString);
aXferData.data.addDataForFlavour("text/unicode", urlBar.value);
aXferData.data.addDataForFlavour("text/html", htmlString);
}
} }
function BeginDragLink(aEvent, aHref, aTitle)
{
var dt = aEvent.dataTransfer;
dt.setData("text/x-moz-url", aHref + "\n" + aTitle);
dt.setData("text/uri-list", aHref);
dt.setData("text/html", "<a href=\"" + htmlEscape(aHref) +
"\">" + htmlEscape(aTitle) + "</a>");
dt.setData("text/plain", aHref);
}
var proxyIconDNDObserver = {
onDragStart: function (aEvent)
{
if (gProxyButton.getAttribute("pageproxystate") != "valid")
return;
BeginDragLink(aEvent, window.content.location.href,
window.content.document.title);
}
};
var homeButtonObserver = { var homeButtonObserver = {
onDragStart: function (aEvent, aXferData, aDragAction) onDragStart: function (aEvent, aXferData, aDragAction)
{ {