Bug 475066 - dragging a tab out of the browser window doesn't detach. r=mconnor

This commit is contained in:
Asaf Romano 2009-02-19 14:00:05 +02:00
Родитель 60e23d37dd
Коммит bd65821a6a
5 изменённых файлов: 48 добавлений и 12 удалений

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

@ -4909,7 +4909,7 @@ var contentAreaDNDObserver = {
var dragType = aXferData.flavour.contentType;
var dragData = aXferData.data;
if (dragType == "application/x-moz-tabbrowser-tab") {
if (dragType == TAB_DROP_TYPE) {
// If the tab was dragged from some other tab bar, its own dragend
// handler will take care of detaching the tab
if (dragData instanceof XULElement && dragData.localName == "tab" &&
@ -4958,7 +4958,7 @@ var contentAreaDNDObserver = {
getSupportedFlavours: function ()
{
var flavourSet = new FlavourSet();
flavourSet.appendFlavour("application/x-moz-tabbrowser-tab");
flavourSet.appendFlavour(TAB_DROP_TYPE);
flavourSet.appendFlavour("text/x-moz-url");
flavourSet.appendFlavour("text/plain");
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");

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

@ -1912,10 +1912,13 @@
if (target.localName == "tab" &&
aEvent.originalTarget.localName != "toolbarbutton") {
var dt = aEvent.dataTransfer;
dt.mozSetDataAt("application/x-moz-tabbrowser-tab", target, 0);
dt.mozSetDataAt(TAB_DROP_TYPE, target, 0);
var uri = this.getBrowserForTab(aEvent.target).currentURI;
var spec = uri ? uri.spec : "about:blank";
dt.mozSetDataAt("text/x-moz-url", spec + "\n" + aEvent.target.label, 0);
// We must not set text/x-moz-url data, otherwise trying to deatch
// the tab by dropping it on the desktop would result in an
// "internet shortcut"
dt.mozSetDataAt("text/plain", spec, 0);
var canvas = tabPreviews.capture(target, false);
@ -1947,8 +1950,8 @@
var types = dt.mozTypesAt(0);
var sourceNode = null;
// tabs are always added as the first type
if (types[0] == "application/x-moz-tabbrowser-tab") {
var sourceNode = dt.mozGetDataAt("application/x-moz-tabbrowser-tab", 0);
if (types[0] == TAB_DROP_TYPE) {
var sourceNode = dt.mozGetDataAt(TAB_DROP_TYPE, 0);
if (sourceNode instanceof XULElement &&
sourceNode.localName == "tab" &&
(sourceNode.parentNode == this.mTabContainer ||
@ -2086,7 +2089,7 @@
var dropEffect = dt.dropEffect;
var draggedTab;
if (dropEffect != "link") { // copy or move
draggedTab = dt.mozGetDataAt("application/x-moz-tabbrowser-tab", 0);
draggedTab = dt.mozGetDataAt(TAB_DROP_TYPE, 0);
// not our drop then
if (!draggedTab)
return;
@ -2209,7 +2212,7 @@
// 2. Drop on some other tabbar
// 3. Drop on text fields (even outside our window)
if (dt.dropEffect == "none") {
var draggedTab = dt.mozGetDataAt("application/x-moz-tabbrowser-tab", 0);
var draggedTab = dt.mozGetDataAt(TAB_DROP_TYPE, 0);
this.replaceTabWithWindow(draggedTab);
}
aEvent.stopPropagation();

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

@ -42,6 +42,8 @@
* for shared application glue for the Communicator suite of applications
**/
var TAB_DROP_TYPE = "application/x-moz-tabbrowser-tab";
var gBidiUI = false;
function getBrowserURL()

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

@ -1335,6 +1335,19 @@ var PlacesControllerDragHelper = {
var data = dt.mozGetDataAt(flavor, i);
// urls can be dropped on any insertionpoint
// XXXmano: // Remember: this method is called for each dragover event!
// Thus we shouldn't use unwrapNodes here at all if possible.
// I think it would be OK to accept bogus data here (e.g. text which was
// somehow wrapped as TAB_DROP_TYPE, this is not in our control, and
// will just case the actual drop to be a no-op), and only rule out valid
// expected cases, which are either unsupported flavors, or items which
// cannot be dropped in the current insertionpoint. The last case will
// likely force us to use unwrapNodes for the private data types of
// places.
if (flavor == TAB_DROP_TYPE)
continue;
try {
var dragged = PlacesUtils.unwrapNodes(data, flavor)[0];
} catch (e) {
@ -1363,6 +1376,7 @@ var PlacesControllerDragHelper = {
return true;
},
/**
* Determines if a node can be moved.
*
@ -1444,8 +1458,22 @@ var PlacesControllerDragHelper = {
return false;
var data = dt.mozGetDataAt(flavor, i);
// There's only ever one in the D&D case.
var unwrapped = PlacesUtils.unwrapNodes(data, flavor)[0];
var unwrapped;
if (flavor != TAB_DROP_TYPE) {
// There's only ever one in the D&D case.
unwrapped = PlacesUtils.unwrapNodes(data, flavor)[0];
}
else if (data instanceof XULElement && data.localName == "tab" &&
data.ownerDocument.defaultView instanceof ChromeWindow) {
var uri = data.linkedBrowser.currentURI;
var spec = uri ? uri.spec : "about:blank";
var title = data.label;
unwrapped = { uri: spec,
title: data.label,
type: PlacesUtils.TYPE_X_MOZ_URL};
}
else
throw("bogus data was passed as a tab")
var index = insertionPoint.index;
@ -1494,10 +1522,12 @@ var PlacesControllerDragHelper = {
PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR,
PlacesUtils.TYPE_X_MOZ_PLACE],
// The order matters.
GENERIC_VIEW_DROP_TYPES: [PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER,
PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR,
PlacesUtils.TYPE_X_MOZ_PLACE,
PlacesUtils.TYPE_X_MOZ_URL,
TAB_DROP_TYPE,
PlacesUtils.TYPE_UNICODE],
/**

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

@ -386,8 +386,9 @@ var PlacesUIUtils = {
break;
default:
if (type == PlacesUtils.TYPE_X_MOZ_URL ||
type == PlacesUtils.TYPE_UNICODE) {
var title = (type == PlacesUtils.TYPE_X_MOZ_URL) ? data.title :
type == PlacesUtils.TYPE_UNICODE ||
type == TAB_DROP_TYPE) {
var title = (type != PlacesUtils.TYPE_UNICODE) ? data.title :
data.uri;
return this.ptm.createItem(PlacesUtils._uri(data.uri),
container, index, title);