Bug 465186 - When detaching a tab, open the new window at the drop location. r=dao/smaug

--HG--
extra : rebase_source : 8145e9a0fcc4bf96fc5f66c2fdbbad13ca25c90e
This commit is contained in:
Jezreel Ng 2011-07-04 12:51:47 +02:00
Родитель 82f7b47d00
Коммит 08e9ef88ed
2 изменённых файлов: 56 добавлений и 4 удалений

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

@ -2005,13 +2005,18 @@
in the current window, in which case this will do nothing. -->
<method name="replaceTabWithWindow">
<parameter name="aTab"/>
<parameter name="aOptions"/>
<body>
<![CDATA[
if (this.tabs.length == 1)
return null;
var options = "chrome,dialog=no,all";
for (var name in aOptions)
options += "," + name + "=" + aOptions[name];
// tell a new window to take the "dropped" tab
return window.openDialog(getBrowserURL(), "_blank", "dialog=no,all", aTab);
return window.openDialog(getBrowserURL(), "_blank", options, aTab);
]]>
</body>
</method>
@ -3298,6 +3303,16 @@
let canvas = tabPreviews.capture(tab, false);
dt.setDragImage(canvas, 0, 0);
let bo = this.mTabstrip.boxObject;
let paddingStart = this.mTabstrip.scrollboxPaddingStart;
// _dragOffset[X|Y] give the coordinates that the mouse should be
// positioned relative to the corner of the new window created upon
// dragend such that the mouse appears to have the same position
// relative to the corner of the dragged tab.
tab._dragOffsetX = event.screenX - tab.boxObject.screenX + paddingStart + bo.screenX - window.screenX;
tab._dragOffsetY = event.screenY - tab.boxObject.screenY + bo.screenY - window.screenY;
event.stopPropagation();
]]></handler>
@ -3477,6 +3492,11 @@
}
}
}
// these offsets are only used in dragend, but we need to free them here
// as well
delete draggedTab._dragOffsetX;
delete draggedTab._dragOffsetY;
]]></handler>
<handler event="dragend"><![CDATA[
@ -3491,6 +3511,7 @@
// Disable detach within the browser toolbox
var eX = event.screenX;
var eY = event.screenY;
var wX = window.screenX;
// check if the drop point is horizontally within the window
if (eX > wX && eX < (wX + window.outerWidth)) {
@ -3498,13 +3519,43 @@
// also avoid detaching if the the tab was dropped too close to
// the tabbar (half a tab)
let endScreenY = bo.screenY + 1.5 * bo.height;
let eY = event.screenY;
if (eY < endScreenY && eY > window.screenY)
return;
}
var draggedTab = dt.mozGetDataAt(TAB_DROP_TYPE, 0);
this.tabbrowser.replaceTabWithWindow(draggedTab);
// screen.availLeft et. al. only check the screen that this window is on,
// but we want to look at the screen the tab is being dropped onto.
var sm = Cc["@mozilla.org/gfx/screenmanager;1"].
getService(Ci.nsIScreenManager);
var whichScreen = sm.screenForRect(eX, eY, 1, 1);
var sX = {}, sY = {}, sW = {}, sH = {};
whichScreen.GetAvailRect(sX, sY, sW, sH);
// ensure new window entirely within screen
var winWidth = Math.min(window.outerWidth, sW.value);
var winHeight = Math.min(window.outerHeight, sH.value);
var aLeft = Math.min(Math.max(eX - draggedTab._dragOffsetX, sX.value), sX.value + sW.value - winWidth);
var aTop = Math.min(Math.max(eY - draggedTab._dragOffsetY, sY.value), sY.value + sH.value - winHeight);
delete draggedTab._dragOffsetX;
delete draggedTab._dragOffsetY;
if (this.tabbrowser.tabs.length == 1) {
// resize _before_ move to ensure the window fits the new screen. if
// the window is too large for its screen, the window manager may do
// automatic repositioning.
window.resizeTo(winWidth, winHeight);
window.moveTo(aLeft, aTop);
window.focus();
}
else
this.tabbrowser.replaceTabWithWindow(draggedTab, { screenX: aLeft,
screenY: aTop,
#ifndef XP_WIN
outerWidth: winWidth,
outerHeight: winHeight
#endif
});
event.stopPropagation();
]]></handler>

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

@ -2579,7 +2579,8 @@ nsGlobalWindow::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
} else if (msg == NS_MOUSE_BUTTON_DOWN &&
NS_IS_TRUSTED_EVENT(aVisitor.mEvent)) {
gMouseDown = PR_TRUE;
} else if (msg == NS_MOUSE_BUTTON_UP &&
} else if ((msg == NS_MOUSE_BUTTON_UP ||
msg == NS_DRAGDROP_END) &&
NS_IS_TRUSTED_EVENT(aVisitor.mEvent)) {
gMouseDown = PR_FALSE;
if (gDragServiceDisabled) {