2010-12-06 07:04:52 -05:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Tree Style Tab.
|
|
|
|
*
|
2012-10-13 14:31:06 -04:00
|
|
|
* The Initial Developer of the Original Code is YUKI "Piro" Hiroshi.
|
2013-01-05 21:47:50 -05:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010-2013
|
2010-12-06 07:04:52 -05:00
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
2012-10-13 14:31:06 -04:00
|
|
|
* Contributor(s): YUKI "Piro" Hiroshi <piro.outsider.reflex@gmail.com>
|
2010-12-06 07:04:52 -05:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ******/
|
|
|
|
|
2011-01-22 09:43:55 -05:00
|
|
|
const EXPORTED_SYMBOLS = ['TabbarDNDObserver'];
|
2010-12-06 07:04:52 -05:00
|
|
|
|
2012-05-01 14:27:30 -04:00
|
|
|
const DEBUG = false;
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
2013-01-05 21:47:50 -05:00
|
|
|
const Cu = Components.utils;
|
2010-12-06 07:04:52 -05:00
|
|
|
|
2013-01-05 21:47:50 -05:00
|
|
|
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
|
|
|
Cu.import('resource://gre/modules/Services.jsm');
|
2012-08-13 01:58:40 -04:00
|
|
|
|
2012-11-11 08:48:42 -05:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'utils', 'resource://treestyletab-modules/utils.js', 'TreeStyleTabUtils');
|
2012-10-19 08:38:35 -04:00
|
|
|
|
2013-01-05 21:47:50 -05:00
|
|
|
XPCOMUtils.defineLazyGetter(this, 'window', function() {
|
|
|
|
Cu.import('resource://treestyletab-modules/lib/namespace.jsm');
|
|
|
|
return getNamespaceFor('piro.sakura.ne.jp');
|
|
|
|
});
|
|
|
|
XPCOMUtils.defineLazyGetter(this, 'prefs', function() {
|
|
|
|
Cu.import('resource://treestyletab-modules/lib/prefs.js');
|
|
|
|
return window['piro.sakura.ne.jp'].prefs;
|
|
|
|
});
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
const TAB_DROP_TYPE = 'application/x-moz-tabbrowser-tab';
|
|
|
|
|
|
|
|
const SSS = Cc['@mozilla.org/content/style-sheet-service;1']
|
|
|
|
.getService(Ci.nsIStyleSheetService);
|
|
|
|
const SecMan = Cc['@mozilla.org/scriptsecuritymanager;1']
|
|
|
|
.getService(Ci.nsIScriptSecurityManager);
|
2012-09-17 11:49:12 -04:00
|
|
|
|
2010-12-06 08:31:58 -05:00
|
|
|
function TabbarDNDObserver(aTabBrowser)
|
2009-09-02 21:26:38 -04:00
|
|
|
{
|
2010-12-06 08:31:58 -05:00
|
|
|
this.init(aTabBrowser);
|
2009-09-02 21:26:38 -04:00
|
|
|
}
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
TabbarDNDObserver.prototype = {
|
2009-09-03 02:20:45 -04:00
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
readyToStartTabbarDrag : function TabbarDND_readyToStartTabbarDrag()
|
2009-09-02 21:26:38 -04:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sheet = this.treeStyleTab.makeURIFromSpec('chrome://treestyletab/content/hide-embed.css');
|
|
|
|
if (!SSS.sheetRegistered(sheet, SSS.AGENT_SHEET))
|
|
|
|
SSS.loadAndRegisterSheet(sheet, SSS.AGENT_SHEET);
|
2010-12-01 10:15:40 -05:00
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
readyToEndTabbarDrag : function TabbarDND_readyToEndTabbarDrag()
|
2010-12-01 10:15:40 -05:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sheet = this.treeStyleTab.makeURIFromSpec('chrome://treestyletab/content/hide-embed.css');
|
|
|
|
if (SSS.sheetRegistered(sheet, SSS.AGENT_SHEET))
|
|
|
|
SSS.unregisterSheet(sheet, SSS.AGENT_SHEET);
|
2010-12-01 10:15:40 -05:00
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
canDragTabbar : function TabbarDND_canDragTabbar(aEvent)
|
2010-12-01 10:15:40 -05:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
2009-09-03 04:24:22 -04:00
|
|
|
|
2010-04-21 07:03:05 -04:00
|
|
|
if (
|
|
|
|
sv.evaluateXPath(
|
2009-09-03 14:06:23 -04:00
|
|
|
'ancestor-or-self::*[contains(" scrollbar popup menupopup panel tooltip ", concat(" ", local-name(), " "))]',
|
2009-09-03 04:24:22 -04:00
|
|
|
aEvent.originalTarget,
|
2010-12-06 07:04:52 -05:00
|
|
|
Ci.nsIDOMXPathResult.BOOLEAN_TYPE
|
2010-04-21 07:03:05 -04:00
|
|
|
).booleanValue ||
|
2010-04-21 07:43:13 -04:00
|
|
|
sv.isToolbarCustomizing
|
2010-04-21 07:03:05 -04:00
|
|
|
)
|
2009-09-03 04:24:22 -04:00
|
|
|
return false;
|
|
|
|
|
2009-09-02 21:26:38 -04:00
|
|
|
var tab = sv.getTabFromEvent(aEvent);
|
|
|
|
var tabbar = sv.getTabbarFromEvent(aEvent);
|
2009-09-03 21:42:32 -04:00
|
|
|
var canDrag = (
|
2009-09-02 21:26:38 -04:00
|
|
|
(tab ? aEvent.shiftKey : tabbar ) &&
|
|
|
|
(
|
|
|
|
aEvent.shiftKey ||
|
2010-12-06 07:04:52 -05:00
|
|
|
sv.browser.getAttribute(sv.kFIXED) != 'true'
|
2009-09-02 21:26:38 -04:00
|
|
|
)
|
|
|
|
);
|
2009-09-03 21:42:32 -04:00
|
|
|
|
|
|
|
if (canDrag && !aEvent.shiftKey) {
|
2012-10-23 12:43:56 -04:00
|
|
|
let insensitiveArea = utils.getTreePref('tabbar.fixed.insensitiveArea');
|
2009-09-03 21:42:32 -04:00
|
|
|
let box = tabbar.boxObject;
|
2011-01-22 10:46:29 -05:00
|
|
|
switch (sv.position)
|
2009-09-03 21:42:32 -04:00
|
|
|
{
|
|
|
|
case 'right':
|
|
|
|
if (aEvent.screenX < box.screenX + insensitiveArea)
|
|
|
|
canDrag = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'left':
|
|
|
|
if (aEvent.screenX > box.screenX + box.width - insensitiveArea)
|
|
|
|
canDrag = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case 'top':
|
|
|
|
if (aEvent.screenY > box.screenY + box.height - insensitiveArea)
|
|
|
|
canDrag = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'bottom':
|
|
|
|
if (aEvent.screenY < box.screenY + insensitiveArea)
|
|
|
|
canDrag = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return canDrag;
|
2009-09-02 21:26:38 -04:00
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
canDrop : function TabbarDND_canDrop(aEvent)
|
2009-11-23 13:04:40 -05:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
2010-12-01 10:15:40 -05:00
|
|
|
var tooltip = sv.tabStrip.firstChild;
|
|
|
|
if (tooltip &&
|
|
|
|
tooltip.localName == 'tooltip' &&
|
|
|
|
tooltip.popupBoxObject.popupState != 'closed')
|
|
|
|
tooltip.hidePopup();
|
|
|
|
|
2010-12-01 19:00:39 -05:00
|
|
|
var dropAction = this.getDropAction(aEvent);
|
2010-12-01 10:15:40 -05:00
|
|
|
if ('dataTransfer' in aEvent) {
|
|
|
|
var dt = aEvent.dataTransfer;
|
2010-12-01 19:00:39 -05:00
|
|
|
if (dropAction.action & sv.kACTION_NEWTAB) {
|
2010-12-01 10:15:40 -05:00
|
|
|
dt.effectAllowed = dt.dropEffect = (
|
|
|
|
!dropAction.source ? 'link' :
|
|
|
|
sv.isCopyAction(aEvent) ? 'copy' :
|
|
|
|
'move'
|
|
|
|
);
|
2009-11-23 13:04:40 -05:00
|
|
|
}
|
|
|
|
}
|
2010-12-01 10:15:40 -05:00
|
|
|
return dropAction.canDrop;
|
2009-11-23 13:04:40 -05:00
|
|
|
},
|
2010-12-01 10:15:40 -05:00
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
canDropTab : function TabbarDND_canDropTab(aEvent)
|
2009-11-23 13:04:40 -05:00
|
|
|
{
|
2010-12-01 10:15:40 -05:00
|
|
|
try{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
|
|
|
var b = this.browser;
|
2010-12-01 10:15:40 -05:00
|
|
|
|
2010-12-01 19:02:27 -05:00
|
|
|
var session = sv.currentDragSession;
|
2010-12-01 10:15:40 -05:00
|
|
|
var node = session.sourceNode;
|
|
|
|
var tab = sv.getTabFromChild(node);
|
|
|
|
if (!node ||
|
|
|
|
!tab ||
|
|
|
|
tab.parentNode != b.mTabContainer)
|
|
|
|
return true;
|
|
|
|
|
2011-11-05 06:50:30 -04:00
|
|
|
tab = sv.getTabFromEvent(aEvent) || sv.getTabFromTabbarEvent(aEvent);
|
2010-12-01 10:15:40 -05:00
|
|
|
if (sv.isCollapsed(tab))
|
|
|
|
return false;
|
|
|
|
|
2010-12-01 19:00:39 -05:00
|
|
|
var info = this.getDropAction(aEvent, session);
|
2010-12-01 10:15:40 -05:00
|
|
|
return info.canDrop;
|
|
|
|
}
|
|
|
|
catch(e) {
|
2010-12-06 07:04:52 -05:00
|
|
|
dump('TabbarDND::canDrop\n'+e+'\n');
|
2010-12-01 10:15:40 -05:00
|
|
|
return false;
|
|
|
|
}
|
2009-11-23 13:04:40 -05:00
|
|
|
},
|
2010-12-01 10:15:40 -05:00
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
getDropAction : function TabbarDND_getDropAction(aEvent, aDragSession)
|
2010-12-01 19:00:39 -05:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
|
|
|
var b = this.browser;
|
2010-12-01 19:00:39 -05:00
|
|
|
|
|
|
|
if (!aDragSession)
|
2010-12-01 19:02:27 -05:00
|
|
|
aDragSession = sv.currentDragSession;
|
2010-12-01 19:00:39 -05:00
|
|
|
|
|
|
|
var tab = aDragSession ? sv.getTabFromChild(aDragSession.sourceNode) : null ;
|
|
|
|
sv.ensureTabInitialized(tab);
|
|
|
|
|
|
|
|
var info = this.getDropActionInternal(aEvent, tab);
|
|
|
|
info.canDrop = true;
|
|
|
|
info.source = tab;
|
|
|
|
if (tab) {
|
|
|
|
var isCopy = sv.isCopyAction(aEvent);
|
|
|
|
if (isCopy && 'duplicateTab' in b) {
|
|
|
|
info.action |= sv.kACTION_DUPLICATE;
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
!isCopy &&
|
|
|
|
sv.getTabBrowserFromChild(tab) != b &&
|
|
|
|
(
|
2011-01-19 11:31:22 -05:00
|
|
|
('duplicateTab' in b)
|
2010-12-01 19:00:39 -05:00
|
|
|
)
|
|
|
|
) {
|
|
|
|
info.action |= sv.kACTION_IMPORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.action & sv.kACTIONS_FOR_DESTINATION) {
|
|
|
|
if (info.action & sv.kACTION_MOVE) info.action ^= sv.kACTION_MOVE;
|
|
|
|
if (info.action & sv.kACTION_STAY) info.action ^= sv.kACTION_STAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.action & sv.kACTION_ATTACH) {
|
|
|
|
if (info.parent == tab) {
|
|
|
|
info.canDrop = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var orig = tab;
|
|
|
|
tab = info.target;
|
|
|
|
while (tab = sv.getParentTab(tab))
|
|
|
|
{
|
|
|
|
if (tab != orig) continue;
|
|
|
|
info.canDrop = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-23 14:30:01 -04:00
|
|
|
|
2011-05-16 13:23:38 -04:00
|
|
|
var isInverted = sv.isVertical ? false : b.ownerDocument.defaultView.getComputedStyle(b.parentNode, null).direction == 'rtl';
|
2011-03-23 14:30:01 -04:00
|
|
|
if (
|
|
|
|
info.target &&
|
|
|
|
(
|
|
|
|
info.target.hidden ||
|
2011-05-16 13:23:38 -04:00
|
|
|
(
|
|
|
|
sv.isCollapsed(info.target) &&
|
|
|
|
info.position != (isInverted ? sv.kDROP_BEFORE : sv.kDROP_AFTER )
|
|
|
|
)
|
2011-03-23 14:30:01 -04:00
|
|
|
)
|
|
|
|
)
|
|
|
|
info.canDrop = false;
|
|
|
|
|
2010-12-01 19:00:39 -05:00
|
|
|
return info;
|
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
getDropActionInternal : function TabbarDND_getDropActionInternal(aEvent, aSourceTab)
|
2010-12-01 19:00:39 -05:00
|
|
|
{
|
2012-05-01 14:27:30 -04:00
|
|
|
if (DEBUG) dump('getDropActionInternal: start\n');
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
|
|
|
var b = this.browser;
|
|
|
|
var d = this.document;
|
2010-12-01 19:00:39 -05:00
|
|
|
|
2011-11-05 06:50:30 -04:00
|
|
|
var tab = sv.getTabFromEvent(aEvent) || sv.getTabFromTabbarEvent(aEvent) || aEvent.target;
|
2012-09-23 02:43:49 -04:00
|
|
|
var tabs = sv.getTabs(b);
|
2010-12-06 22:40:41 -05:00
|
|
|
var firstTab = sv.getFirstNormalTab(b) || tabs[0];
|
2011-05-16 13:23:38 -04:00
|
|
|
var lastTabIndex = tabs.length - 1;
|
2010-12-06 07:04:52 -05:00
|
|
|
var isInverted = sv.isVertical ? false : b.ownerDocument.defaultView.getComputedStyle(b.parentNode, null).direction == 'rtl';
|
2010-12-01 19:00:39 -05:00
|
|
|
var info = {
|
|
|
|
target : null,
|
|
|
|
position : null,
|
|
|
|
action : null,
|
|
|
|
parent : null,
|
|
|
|
insertBefore : null,
|
|
|
|
event : aEvent
|
|
|
|
};
|
|
|
|
|
2012-10-12 13:09:34 -04:00
|
|
|
let draggedTab = aEvent.dataTransfer && aEvent.dataTransfer.mozGetDataAt(TAB_DROP_TYPE, 0);
|
2012-12-20 23:55:32 -05:00
|
|
|
if (draggedTab && draggedTab._dragData) {
|
2012-12-03 11:40:31 -05:00
|
|
|
let sameTypeUndraggedTabs = tabs.filter(function(aTab) {
|
|
|
|
return !aTab._dragData && aTab.pinned == draggedTab.pinned;
|
2012-11-29 13:03:59 -05:00
|
|
|
});
|
2012-12-03 11:40:31 -05:00
|
|
|
tab = draggedTab.pinned ?
|
|
|
|
// pinned tabs cannot be dropped to another pinned tab, so
|
|
|
|
// we can use the drop position calculated by "_animateTabMove()".
|
|
|
|
tabs[draggedTab._dragData.animDropIndex] :
|
|
|
|
// otherwise, we have to find "drop target" tab from screen coordinates.
|
|
|
|
sv.getTabFromCoordinates(aEvent, sameTypeUndraggedTabs) ||
|
2012-12-03 12:04:06 -05:00
|
|
|
tabs[draggedTab._dragData.animDropIndex] ;
|
2012-10-12 13:09:34 -04:00
|
|
|
}
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
var isTabMoveFromOtherWindow = aSourceTab && aSourceTab.ownerDocument != d;
|
|
|
|
var isNewTabAction = !aSourceTab || aSourceTab.ownerDocument != d;
|
2010-12-01 19:00:39 -05:00
|
|
|
|
2012-11-29 13:03:59 -05:00
|
|
|
if (!tab || tab.localName != 'tab') {
|
2012-05-01 14:27:30 -04:00
|
|
|
if (DEBUG) dump(' not on a tab\n');
|
2011-05-16 13:23:38 -04:00
|
|
|
let action = isTabMoveFromOtherWindow ? sv.kACTION_STAY : (sv.kACTION_MOVE | sv.kACTION_PART) ;
|
2010-12-01 19:00:39 -05:00
|
|
|
if (isNewTabAction) action |= sv.kACTION_NEWTAB;
|
2012-10-12 11:37:03 -04:00
|
|
|
if (aEvent[sv.screenPositionProp] < sv.getTabActualScreenPosition(firstTab)) {
|
2012-05-01 14:27:30 -04:00
|
|
|
if (DEBUG) dump(' above the first tab\n');
|
2010-12-01 19:00:39 -05:00
|
|
|
info.target = info.parent = info.insertBefore = firstTab;
|
|
|
|
info.position = isInverted ? sv.kDROP_AFTER : sv.kDROP_BEFORE ;
|
|
|
|
info.action = action;
|
|
|
|
return info;
|
|
|
|
}
|
2012-10-12 11:37:03 -04:00
|
|
|
else if (aEvent[sv.screenPositionProp] > sv.getTabActualScreenPosition(tabs[lastTabIndex]) + tabs[lastTabIndex].boxObject[sv.sizeProp]) {
|
2012-05-01 14:27:30 -04:00
|
|
|
if (DEBUG) dump(' below the last tab\n');
|
2010-12-01 19:00:39 -05:00
|
|
|
info.target = info.parent = tabs[lastTabIndex];
|
|
|
|
info.position = isInverted ? sv.kDROP_BEFORE : sv.kDROP_AFTER ;
|
|
|
|
info.action = action;
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let index = b.getNewIndex ?
|
|
|
|
b.getNewIndex(aEvent) :
|
|
|
|
b.tabContainer._getDropIndex(aEvent) ;
|
2012-05-01 14:27:30 -04:00
|
|
|
if (DEBUG) dump(' on the tab '+index+'\n');
|
2012-11-29 13:03:59 -05:00
|
|
|
info.target = tab = tabs[Math.min(index, lastTabIndex)];
|
2012-05-01 14:27:30 -04:00
|
|
|
if (DEBUG) dump(' info.target = '+info.target._tPos+'\n');
|
2010-12-01 19:00:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-05-01 14:27:30 -04:00
|
|
|
if (DEBUG) dump(' on the tab '+tab._tPos+'\n');
|
2010-12-01 19:00:39 -05:00
|
|
|
sv.ensureTabInitialized(tab);
|
|
|
|
info.target = tab;
|
|
|
|
}
|
|
|
|
|
2011-03-18 16:14:17 -04:00
|
|
|
/**
|
|
|
|
* Basically, tabs should have three areas for dropping of items:
|
|
|
|
* [start][center][end], but, pinned tabs couldn't have its tree.
|
|
|
|
* So, if a tab is dragged and the target tab is pinned, then, we
|
|
|
|
* have to ignore the [center] area.
|
|
|
|
*/
|
|
|
|
var pinned = tab.getAttribute('pinned') == 'true';
|
|
|
|
var dropAreasCount = (aSourceTab && pinned) ? 2 : 3 ;
|
2011-05-26 13:31:44 -04:00
|
|
|
var screenPositionProp = sv.isVertical && pinned ? sv.invertedScreenPositionProp : sv.screenPositionProp ;
|
2011-03-18 16:14:17 -04:00
|
|
|
var sizeProp = sv.isVertical && pinned ? sv.invertedSizeProp : sv.sizeProp ;
|
2012-10-12 11:37:03 -04:00
|
|
|
var boxPos = sv.getTabActualScreenPosition(tab);
|
2011-03-18 16:14:17 -04:00
|
|
|
var boxUnit = Math.round(tab.boxObject[sizeProp] / dropAreasCount);
|
2012-10-12 14:16:08 -04:00
|
|
|
var eventPosition = aEvent[screenPositionProp];
|
|
|
|
// if (this.window['piro.sakura.ne.jp'].tabsDragUtils
|
|
|
|
// .canAnimateDraggedTabs(aEvent)) {
|
|
|
|
// eventPosition = Math.round(sv.getTabActualScreenPosition(draggedTab) + (tab.boxObject[sizeProp] / 2))
|
|
|
|
// }
|
|
|
|
if (eventPosition < boxPos + boxUnit) {
|
2010-12-01 19:00:39 -05:00
|
|
|
info.position = isInverted ? sv.kDROP_AFTER : sv.kDROP_BEFORE ;
|
|
|
|
}
|
2012-10-12 14:16:08 -04:00
|
|
|
else if (dropAreasCount == 2 || eventPosition > boxPos + boxUnit + boxUnit) {
|
2010-12-01 19:00:39 -05:00
|
|
|
info.position = isInverted ? sv.kDROP_BEFORE : sv.kDROP_AFTER ;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
info.position = sv.kDROP_ON;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (info.position)
|
|
|
|
{
|
|
|
|
case sv.kDROP_ON:
|
2012-05-01 14:27:30 -04:00
|
|
|
if (DEBUG) dump(' position = on the tab\n');
|
2011-03-18 16:14:17 -04:00
|
|
|
var visible = sv.getNextVisibleTab(tab);
|
2010-12-01 19:00:39 -05:00
|
|
|
info.action = sv.kACTION_STAY | sv.kACTION_ATTACH;
|
|
|
|
info.parent = tab;
|
2012-10-23 12:43:56 -04:00
|
|
|
info.insertBefore = utils.getTreePref('insertNewChildAt') == sv.kINSERT_FISRT ?
|
2010-12-01 19:00:39 -05:00
|
|
|
(sv.getFirstChildTab(tab) || visible) :
|
2012-05-01 14:27:30 -04:00
|
|
|
(sv.getNextSiblingTab(tab) || sv.getNextTab(sv.getLastDescendantTab(tab) || tab));
|
|
|
|
if (DEBUG && info.insertBefore) dump(' insertBefore = '+info.insertBefore._tPos+'\n');
|
2010-12-01 19:00:39 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sv.kDROP_BEFORE:
|
2012-05-01 14:27:30 -04:00
|
|
|
if (DEBUG) dump(' position = before the tab\n');
|
2010-12-01 19:00:39 -05:00
|
|
|
/*
|
2012-08-28 08:52:13 -04:00
|
|
|
[TARGET ] ↑detach from parent, and move
|
2010-12-01 19:00:39 -05:00
|
|
|
|
|
|
|
[ ]
|
2012-08-28 08:52:13 -04:00
|
|
|
[TARGET ] ↑attach to the parent of the target, and move
|
2010-12-01 19:00:39 -05:00
|
|
|
|
|
|
|
[ ]
|
2012-08-28 08:52:13 -04:00
|
|
|
[TARGET ] ↑attach to the parent of the target, and move
|
2010-12-01 19:00:39 -05:00
|
|
|
|
|
|
|
[ ]
|
2012-08-28 08:52:13 -04:00
|
|
|
[TARGET] ↑attach to the parent of the target (previous tab), and move
|
2010-12-01 19:00:39 -05:00
|
|
|
*/
|
|
|
|
var prevTab = sv.getPreviousVisibleTab(tab);
|
|
|
|
if (!prevTab) {
|
2012-08-02 13:41:47 -04:00
|
|
|
// allow to drop pinned tab to beside of another pinned tab
|
|
|
|
if (aSourceTab && aSourceTab.getAttribute('pinned') == 'true') {
|
|
|
|
info.action = sv.kACTION_MOVE;
|
|
|
|
info.insertBefore = tab;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
info.action = sv.kACTION_MOVE | sv.kACTION_PART;
|
|
|
|
info.insertBefore = firstTab;
|
|
|
|
}
|
2010-12-01 19:00:39 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
var prevLevel = Number(prevTab.getAttribute(sv.kNEST));
|
|
|
|
var targetNest = Number(tab.getAttribute(sv.kNEST));
|
|
|
|
info.parent = (prevLevel < targetNest) ? prevTab : sv.getParentTab(tab) ;
|
|
|
|
info.action = sv.kACTION_MOVE | (info.parent ? sv.kACTION_ATTACH : sv.kACTION_PART );
|
|
|
|
info.insertBefore = tab;
|
|
|
|
}
|
2012-05-01 14:27:30 -04:00
|
|
|
if (DEBUG && info.insertBefore) dump(' insertBefore = '+info.insertBefore._tPos+'\n');
|
2010-12-01 19:00:39 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sv.kDROP_AFTER:
|
2012-05-01 14:27:30 -04:00
|
|
|
if (DEBUG) dump(' position = after the tab\n');
|
2010-12-01 19:00:39 -05:00
|
|
|
/*
|
2012-08-28 08:52:13 -04:00
|
|
|
[TARGET ] ↓if the target has a parent, attach to it and and move
|
2010-12-01 19:00:39 -05:00
|
|
|
|
2012-08-28 08:52:13 -04:00
|
|
|
[TARGET] ↓attach to the parent of the target, and move
|
2010-12-01 19:00:39 -05:00
|
|
|
[ ]
|
|
|
|
|
2012-08-28 08:52:13 -04:00
|
|
|
[TARGET ] ↓attach to the parent of the target, and move
|
2010-12-01 19:00:39 -05:00
|
|
|
[ ]
|
|
|
|
|
2012-08-28 08:52:13 -04:00
|
|
|
[TARGET ] ↓attach to the target, and move
|
2010-12-01 19:00:39 -05:00
|
|
|
[ ]
|
|
|
|
*/
|
|
|
|
var nextTab = sv.getNextVisibleTab(tab);
|
|
|
|
if (!nextTab) {
|
|
|
|
info.action = sv.kACTION_MOVE | sv.kACTION_ATTACH;
|
|
|
|
info.parent = sv.getParentTab(tab);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var targetNest = Number(tab.getAttribute(sv.kNEST));
|
|
|
|
var nextLevel = Number(nextTab.getAttribute(sv.kNEST));
|
|
|
|
info.parent = (targetNest < nextLevel) ? tab : sv.getParentTab(tab) ;
|
|
|
|
info.action = sv.kACTION_MOVE | (info.parent ? sv.kACTION_ATTACH : sv.kACTION_PART );
|
|
|
|
info.insertBefore = nextTab;
|
|
|
|
/*
|
2012-08-28 08:52:13 -04:00
|
|
|
[TARGET ] ↓attach dragged tab to the parent of the target as its next sibling
|
2010-12-01 19:00:39 -05:00
|
|
|
[DRAGGED]
|
|
|
|
*/
|
2012-02-28 11:50:24 -05:00
|
|
|
if (aSourceTab == nextTab) {
|
2010-12-01 19:00:39 -05:00
|
|
|
info.action = sv.kACTION_MOVE | sv.kACTION_ATTACH;
|
|
|
|
info.parent = sv.getParentTab(tab);
|
2012-08-03 13:35:44 -04:00
|
|
|
info.insertBefore = sv.getNextSiblingTab(tab) || sv.getNextTab(nextTab);
|
2010-12-01 19:00:39 -05:00
|
|
|
}
|
|
|
|
}
|
2012-05-01 14:27:30 -04:00
|
|
|
if (DEBUG && info.insertBefore) dump(' insertBefore = '+info.insertBefore._tPos+'\n');
|
2010-12-01 19:00:39 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-05-25 23:17:48 -04:00
|
|
|
if (isNewTabAction) info.action |= sv.kACTION_NEWTAB;
|
2010-12-01 19:00:39 -05:00
|
|
|
|
|
|
|
return info;
|
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
performDrop : function TabbarDND_performDrop(aInfo, aDraggedTab)
|
2010-12-01 19:00:39 -05:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
|
|
|
var b = this.browser;
|
|
|
|
var w = this.window;
|
2010-12-01 19:00:39 -05:00
|
|
|
|
2012-11-29 13:03:59 -05:00
|
|
|
var tabsInfo = this.getDraggedTabsInfoFromOneTab(aDraggedTab, aInfo);
|
2010-12-01 19:00:39 -05:00
|
|
|
if (!tabsInfo.draggedTab) return false;
|
|
|
|
|
2011-06-15 04:38:14 -04:00
|
|
|
var sourceWindow = aDraggedTab.ownerDocument.defaultView;
|
|
|
|
var sourceBrowser = sourceWindow.TreeStyleTabService.getTabBrowserFromChild(aDraggedTab);
|
|
|
|
var sourceService = sourceBrowser.treeStyleTab;
|
|
|
|
|
2010-12-01 19:00:39 -05:00
|
|
|
aDraggedTab = tabsInfo.draggedTab;
|
|
|
|
var draggedTabs = tabsInfo.draggedTabs;
|
2011-06-15 04:38:14 -04:00
|
|
|
var draggedRoots = sourceService.collectRootTabs(tabsInfo.draggedTabs);
|
2010-12-01 19:00:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
var targetBrowser = b;
|
2012-09-23 02:43:49 -04:00
|
|
|
var tabs = sv.getTabs(targetBrowser);
|
2010-12-01 19:00:39 -05:00
|
|
|
|
|
|
|
var draggedWholeTree = [].concat(draggedRoots);
|
2012-02-04 16:31:03 -05:00
|
|
|
for (let i = 0, maxi = draggedRoots.length; i < maxi; i++)
|
2011-05-16 20:24:19 -04:00
|
|
|
{
|
2012-02-04 16:31:03 -05:00
|
|
|
let root = draggedRoots[i];
|
2011-06-15 04:38:14 -04:00
|
|
|
let tabs = sourceService.getDescendantTabs(root);
|
2012-02-04 16:31:03 -05:00
|
|
|
for (let i = 0, maxi = tabs.length; i < maxi; i++)
|
2011-05-16 20:24:19 -04:00
|
|
|
{
|
2012-02-04 16:31:03 -05:00
|
|
|
let tab = tabs[i];
|
2011-05-16 20:24:19 -04:00
|
|
|
if (draggedWholeTree.indexOf(tab) < 0)
|
|
|
|
draggedWholeTree.push(tab);
|
|
|
|
}
|
|
|
|
}
|
2011-04-07 23:15:42 -04:00
|
|
|
|
|
|
|
var selectedTabs = draggedTabs.filter(function(aTab) {
|
|
|
|
return aTab.getAttribute('multiselected') == 'true';
|
|
|
|
});
|
|
|
|
if (draggedWholeTree.length != selectedTabs.length &&
|
|
|
|
selectedTabs.length) {
|
|
|
|
draggedTabs = draggedRoots = selectedTabs;
|
2011-06-15 04:38:14 -04:00
|
|
|
if (aInfo.action & sv.kACTIONS_FOR_SOURCE)
|
2011-12-06 20:18:05 -05:00
|
|
|
sourceService.detachTabs(selectedTabs);
|
2011-04-07 23:15:42 -04:00
|
|
|
}
|
|
|
|
|
2010-12-01 19:00:39 -05:00
|
|
|
while (aInfo.insertBefore && draggedWholeTree.indexOf(aInfo.insertBefore) > -1)
|
|
|
|
{
|
|
|
|
aInfo.insertBefore = sv.getNextTab(aInfo.insertBefore);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aInfo.action & sv.kACTIONS_FOR_SOURCE) {
|
|
|
|
if (aInfo.action & sv.kACTION_PART) {
|
2011-12-06 20:18:05 -05:00
|
|
|
this.detachTabsOnDrop(draggedRoots);
|
2010-12-01 19:00:39 -05:00
|
|
|
}
|
|
|
|
else if (aInfo.action & sv.kACTION_ATTACH) {
|
|
|
|
this.attachTabsOnDrop(draggedRoots, aInfo.parent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( // if this move will cause no change...
|
|
|
|
sourceBrowser == targetBrowser &&
|
2011-06-15 04:38:14 -04:00
|
|
|
sourceService.getNextVisibleTab(draggedTabs[draggedTabs.length-1]) == aInfo.insertBefore
|
2010-12-01 19:00:39 -05:00
|
|
|
) {
|
|
|
|
// then, do nothing
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-15 04:38:14 -04:00
|
|
|
var treeStructure = sourceService.getTreeStructureFromTabs(draggedTabs);
|
2010-12-01 19:00:39 -05:00
|
|
|
|
2011-06-16 12:59:57 -04:00
|
|
|
var newTabs = sv.moveTabsInternal(draggedTabs, {
|
2011-06-15 05:13:23 -04:00
|
|
|
duplicate : aInfo.action & sv.kACTION_DUPLICATE,
|
|
|
|
insertBefore : aInfo.insertBefore
|
|
|
|
});
|
2010-12-01 19:00:39 -05:00
|
|
|
|
2011-06-15 04:38:14 -04:00
|
|
|
if (newTabs.length && aInfo.action & sv.kACTION_ATTACH)
|
|
|
|
this.attachTabsOnDrop(
|
|
|
|
newTabs.filter(function(aTab, aIndex) {
|
|
|
|
return treeStructure[aIndex] == -1;
|
|
|
|
}),
|
|
|
|
aInfo.parent
|
|
|
|
);
|
2010-12-01 19:00:39 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2012-11-29 13:03:59 -05:00
|
|
|
getDraggedTabsInfoFromOneTab : function TabbarDND_getDraggedTabsInfoFromOneTab(aTab, aInfo)
|
2010-12-01 19:00:39 -05:00
|
|
|
{
|
2012-11-29 13:03:59 -05:00
|
|
|
aInfo = aInfo || {};
|
2012-07-28 22:11:41 -04:00
|
|
|
if (aInfo.draggedTabsInfo)
|
|
|
|
return aInfo.draggedTabsInfo;
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
2011-06-15 04:38:14 -04:00
|
|
|
var sourceWindow = aTab.ownerDocument.defaultView;
|
|
|
|
var sourceBrowser = sourceWindow.TreeStyleTabService.getTabBrowserFromChild(aTab);
|
|
|
|
var sourceService = sourceBrowser.treeStyleTab;
|
2010-12-01 19:00:39 -05:00
|
|
|
|
2011-06-15 04:38:14 -04:00
|
|
|
aTab = sourceService.getTabFromChild(aTab);
|
2011-02-09 18:58:28 -05:00
|
|
|
if (!aTab || !aTab.parentNode) // ignore removed tabs!
|
2010-12-01 19:00:39 -05:00
|
|
|
return {
|
|
|
|
draggedTab : null,
|
|
|
|
draggedTabs : [],
|
|
|
|
isMultipleMove : false
|
|
|
|
};
|
|
|
|
|
2011-06-15 04:38:14 -04:00
|
|
|
var draggedTabs = sourceWindow['piro.sakura.ne.jp'].tabsDragUtils.getSelectedTabs(aTab || sourceBrowser || aInfo.event);
|
2010-12-01 19:00:39 -05:00
|
|
|
var isMultipleMove = false;
|
|
|
|
|
|
|
|
if (draggedTabs.length > 1) {
|
|
|
|
isMultipleMove = true;
|
|
|
|
}
|
|
|
|
else if (aInfo.action & sv.kACTIONS_FOR_DESTINATION) {
|
2011-06-15 04:38:14 -04:00
|
|
|
draggedTabs = [aTab].concat(sourceService.getDescendantTabs(aTab));
|
2010-12-01 19:00:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
draggedTab : aTab,
|
|
|
|
draggedTabs : draggedTabs,
|
|
|
|
isMultipleMove : isMultipleMove
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
attachTabsOnDrop : function TabbarDND_attachTabsOnDrop(aTabs, aParent)
|
2010-12-01 19:00:39 -05:00
|
|
|
{
|
2011-06-15 04:38:14 -04:00
|
|
|
var b = aTabs[0].ownerDocument.defaultView.TreeStyleTabService.getTabBrowserFromChild(aTabs[0]);
|
|
|
|
var sv = b.treeStyleTab;
|
2010-12-01 19:00:39 -05:00
|
|
|
|
|
|
|
b.movingSelectedTabs = true; // Multiple Tab Handler
|
2012-02-04 16:31:03 -05:00
|
|
|
for (let i = 0, maxi = aTabs.length; i < maxi; i++)
|
2012-02-04 13:15:38 -05:00
|
|
|
{
|
2012-02-04 16:31:03 -05:00
|
|
|
let tab = aTabs[i];
|
2012-02-04 13:15:38 -05:00
|
|
|
if (!tab.parentNode) continue; // ignore removed tabs
|
2010-12-01 19:00:39 -05:00
|
|
|
if (aParent)
|
2012-02-04 13:15:38 -05:00
|
|
|
sv.attachTabTo(tab, aParent);
|
2010-12-01 19:00:39 -05:00
|
|
|
else
|
2012-02-04 13:15:38 -05:00
|
|
|
sv.detachTab(tab);
|
|
|
|
sv.collapseExpandTab(tab, false);
|
|
|
|
}
|
2010-12-01 19:00:39 -05:00
|
|
|
b.movingSelectedTabs = false; // Multiple Tab Handler
|
|
|
|
},
|
|
|
|
|
2011-12-06 20:18:05 -05:00
|
|
|
detachTabsOnDrop : function TabbarDND_detachTabsOnDrop(aTabs)
|
2010-12-01 19:00:39 -05:00
|
|
|
{
|
2011-06-15 04:38:14 -04:00
|
|
|
var b = aTabs[0].ownerDocument.defaultView.TreeStyleTabService.getTabBrowserFromChild(aTabs[0]);
|
|
|
|
var sv = b.treeStyleTab;
|
2010-12-01 19:00:39 -05:00
|
|
|
|
|
|
|
b.movingSelectedTabs = true; // Multiple Tab Handler
|
2012-02-04 16:31:03 -05:00
|
|
|
for (let i = 0, maxi = aTabs.length; i < maxi; i++)
|
2012-02-04 13:15:38 -05:00
|
|
|
{
|
2012-02-04 16:31:03 -05:00
|
|
|
let tab = aTabs[i];
|
2012-02-04 13:15:38 -05:00
|
|
|
if (!tab.parentNode) continue; // ignore removed tabs
|
|
|
|
sv.detachTab(tab);
|
|
|
|
sv.collapseExpandTab(tab, false);
|
|
|
|
}
|
2010-12-01 19:00:39 -05:00
|
|
|
b.movingSelectedTabs = false; // Multiple Tab Handler
|
|
|
|
},
|
|
|
|
|
2012-08-29 16:41:25 -04:00
|
|
|
clearDropPosition : function TabbarDND_clearDropPosition(aOnFinish)
|
2010-12-01 19:00:39 -05:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
|
|
|
var b = this.browser;
|
2012-08-29 16:28:03 -04:00
|
|
|
|
2012-08-29 16:41:25 -04:00
|
|
|
b.visibleTabs.forEach(function(aTab) {
|
|
|
|
if (aTab.hasAttribute(sv.kDROP_POSITION))
|
|
|
|
aTab.removeAttribute(sv.kDROP_POSITION)
|
|
|
|
|
|
|
|
// clear drop position preview on Firefox 17 and later
|
2012-10-12 14:05:48 -04:00
|
|
|
if (aOnFinish) {
|
|
|
|
aTab.style.transform = '';
|
2012-10-12 14:16:08 -04:00
|
|
|
if ('__treestyletab__opacityBeforeDragged' in aTab) {
|
2012-10-12 14:05:48 -04:00
|
|
|
aTab.style.opacity = aTab.__treestyletab__opacityBeforeDragged;
|
|
|
|
delete aTab.__treestyletab__opacityBeforeDragged;
|
|
|
|
}
|
|
|
|
}
|
2012-08-29 16:28:03 -04:00
|
|
|
});
|
2012-08-29 16:41:25 -04:00
|
|
|
|
|
|
|
if (aOnFinish)
|
|
|
|
this.browser.mTabContainer.removeAttribute('movingtab')
|
2010-12-01 19:00:39 -05:00
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
isDraggingAllTabs : function TabbarDND_isDraggingAllTabs(aTab, aTabs)
|
2010-12-01 19:00:39 -05:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
|
|
|
var b = this.browser;
|
2010-12-01 19:00:39 -05:00
|
|
|
|
|
|
|
var actionInfo = {
|
|
|
|
action : sv.kACTIONS_FOR_DESTINATION | sv.kACTION_IMPORT
|
|
|
|
};
|
2012-11-29 13:03:59 -05:00
|
|
|
var tabsInfo = this.getDraggedTabsInfoFromOneTab(aTab, actionInfo);
|
2012-09-23 02:43:49 -04:00
|
|
|
return tabsInfo.draggedTabs.length == (aTabs || sv.getAllTabs(b)).length;
|
2010-12-01 19:00:39 -05:00
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
isDraggingAllCurrentTabs : function TabbarDND_isDraggingAllCurrentTabs(aTab)
|
2010-12-01 19:00:39 -05:00
|
|
|
{
|
2012-09-23 02:43:49 -04:00
|
|
|
return this.isDraggingAllTabs(aTab, this.treeStyleTab.getTabs(this.treeStyleTab.browser));
|
2010-12-01 19:00:39 -05:00
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
handleEvent : function TabbarDND_handleEvent(aEvent)
|
2010-12-01 18:12:57 -05:00
|
|
|
{
|
2012-01-13 03:38:12 -05:00
|
|
|
// ignore drag and drop while toolbar customization
|
2011-02-19 06:27:30 -05:00
|
|
|
if (this.treeStyleTab.isToolbarCustomizing)
|
|
|
|
return;
|
|
|
|
|
2010-12-01 18:12:57 -05:00
|
|
|
switch (aEvent.type)
|
|
|
|
{
|
|
|
|
case 'dragstart': return this.onDragStart(aEvent);
|
|
|
|
case 'dragenter': return this.onDragEnter(aEvent);
|
|
|
|
case 'dragleave': return this.onDragLeave(aEvent);
|
|
|
|
case 'dragend': return this.onDragEnd(aEvent);
|
|
|
|
case 'dragover': return this.onDragOver(aEvent);
|
|
|
|
case 'drop': return this.onDrop(aEvent);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
onDragStart : function TabbarDND_onDragStart(aEvent)
|
2009-11-23 13:04:40 -05:00
|
|
|
{
|
2010-12-01 10:15:40 -05:00
|
|
|
if (this.canDragTabbar(aEvent))
|
|
|
|
return this.onTabbarDragStart(aEvent);
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
var tab = this.treeStyleTab.getTabFromEvent(aEvent);
|
2010-12-01 10:15:40 -05:00
|
|
|
if (tab)
|
|
|
|
return this.onTabDragStart(aEvent, tab);
|
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
onTabDragStart : function TabbarDND_onTabDragStart(aEvent, aTab)
|
2010-12-01 10:15:40 -05:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
|
|
|
var w = this.window;
|
2010-12-01 10:15:40 -05:00
|
|
|
var actionInfo = {
|
|
|
|
action : sv.kACTIONS_FOR_DESTINATION | sv.kACTION_MOVE,
|
|
|
|
event : aEvent
|
|
|
|
};
|
2012-11-29 13:03:59 -05:00
|
|
|
var tabsInfo = this.getDraggedTabsInfoFromOneTab(aTab, actionInfo);
|
2010-12-20 01:46:38 -05:00
|
|
|
if (
|
2011-04-26 13:44:19 -04:00
|
|
|
tabsInfo.draggedTabs.length <= 1 ||
|
|
|
|
Array.some(tabsInfo.draggedTabs, function(aTab) {
|
2011-06-01 20:27:18 -04:00
|
|
|
return aTab.getAttribute('multiselected') == 'true'; // if multiselected, it should be handled by other addons (like Multiple Tab Handler)
|
2011-04-26 13:44:19 -04:00
|
|
|
})
|
2010-12-20 02:24:47 -05:00
|
|
|
)
|
2011-04-26 13:44:19 -04:00
|
|
|
return;
|
2010-12-20 01:46:38 -05:00
|
|
|
|
|
|
|
w['piro.sakura.ne.jp'].tabsDragUtils.startTabsDrag(aEvent, tabsInfo.draggedTabs);
|
2009-11-23 13:04:40 -05:00
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
onTabbarDragStart : function TabbarDND_onTabbarDragStart(aEvent)
|
2010-12-01 10:15:40 -05:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
2010-12-01 10:15:40 -05:00
|
|
|
var dt = aEvent.dataTransfer;
|
|
|
|
dt.mozSetDataAt(
|
|
|
|
sv.kDRAG_TYPE_TABBAR,
|
|
|
|
aEvent.shiftKey ?
|
|
|
|
sv.kTABBAR_MOVE_FORCE :
|
|
|
|
sv.kTABBAR_MOVE_NORMAL,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
dt.mozCursor = 'move';
|
2010-12-06 07:04:52 -05:00
|
|
|
// var tabbar = sv.browser.mTabContainer;
|
2010-12-01 10:15:40 -05:00
|
|
|
// var box = tabbar.boxObject;
|
|
|
|
// dt.setDragImage(
|
|
|
|
// tabbar,
|
|
|
|
// aEvent.screenX - box.screenX,
|
|
|
|
// aEvent.screenY - box.screenY
|
|
|
|
// );
|
|
|
|
// no feedback image, because it's annoying...
|
2010-12-06 07:04:52 -05:00
|
|
|
dt.setDragImage(new this.window.Image(), 0, 0);
|
2010-12-01 10:15:40 -05:00
|
|
|
aEvent.stopPropagation();
|
|
|
|
this.readyToStartTabbarDrag();
|
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
onDragEnter : function TabbarDND_onDragEnter(aEvent)
|
2009-09-02 21:26:38 -04:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
|
|
|
var w = this.window;
|
2010-12-01 10:15:40 -05:00
|
|
|
|
2010-06-13 08:21:49 -04:00
|
|
|
var dt = aEvent.dataTransfer;
|
2010-12-01 10:15:40 -05:00
|
|
|
if (!this.canDrop(aEvent)) {
|
|
|
|
dt.effectAllowed = dt.dropEffect = 'none';
|
|
|
|
return;
|
|
|
|
}
|
2010-06-13 08:21:49 -04:00
|
|
|
|
2009-09-02 21:26:38 -04:00
|
|
|
var tab = aEvent.target;
|
|
|
|
if (tab.localName != 'tab' ||
|
2012-10-23 12:43:56 -04:00
|
|
|
!utils.getTreePref('autoExpand.enabled'))
|
2009-09-02 21:26:38 -04:00
|
|
|
return;
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
w.clearTimeout(this.mAutoExpandTimer);
|
2011-03-23 14:30:01 -04:00
|
|
|
w.clearTimeout(this.mAutoExpandTimerNext);
|
2010-06-13 08:21:49 -04:00
|
|
|
|
|
|
|
var sourceNode = dt.getData(sv.kDRAG_TYPE_TABBAR+'-node');
|
2010-12-01 10:15:40 -05:00
|
|
|
if (aEvent.target == sourceNode)
|
|
|
|
return;
|
2010-06-13 08:21:49 -04:00
|
|
|
|
2012-08-29 20:43:23 -04:00
|
|
|
var draggedTab = dt.mozGetDataAt(TAB_DROP_TYPE, 0);
|
|
|
|
this.mAutoExpandTimerNext = w.setTimeout(function(aSelf, aTarget, aDragged) {
|
2011-03-23 14:30:01 -04:00
|
|
|
aSelf.mAutoExpandTimerNext = null;
|
|
|
|
aSelf.mAutoExpandTimer = w.setTimeout(
|
|
|
|
function() {
|
|
|
|
let tab = sv.getTabById(aTarget);
|
|
|
|
if (tab &&
|
|
|
|
sv.shouldTabAutoExpanded(tab) &&
|
|
|
|
tab.getAttribute(sv.kDROP_POSITION) == 'self') {
|
2012-10-13 14:47:34 -04:00
|
|
|
let draggedTab = aDragged && sv.getTabById(aDragged);
|
2012-10-23 12:43:56 -04:00
|
|
|
if (utils.getTreePref('autoExpand.intelligently')) {
|
2011-03-23 14:30:01 -04:00
|
|
|
sv.collapseExpandTreesIntelligentlyFor(tab);
|
2012-10-13 14:47:34 -04:00
|
|
|
if (draggedTab)
|
|
|
|
aSelf.updateDragData(draggedTab);
|
2011-03-23 14:30:01 -04:00
|
|
|
}
|
|
|
|
else {
|
2012-08-29 17:10:47 -04:00
|
|
|
if (aSelf.mAutoExpandedTabs.indexOf(aTarget) < 0)
|
|
|
|
aSelf.mAutoExpandedTabs.push(aTarget);
|
2011-03-23 14:30:01 -04:00
|
|
|
sv.collapseExpandSubtree(tab, false);
|
2012-10-13 14:47:34 -04:00
|
|
|
if (draggedTab)
|
|
|
|
aSelf.updateDragData(draggedTab);
|
2011-03-23 14:30:01 -04:00
|
|
|
}
|
2009-09-02 21:26:38 -04:00
|
|
|
}
|
2011-03-23 14:30:01 -04:00
|
|
|
},
|
2012-10-23 12:43:56 -04:00
|
|
|
utils.getTreePref('autoExpand.delay')
|
2011-03-23 14:30:01 -04:00
|
|
|
);
|
2012-10-13 14:47:34 -04:00
|
|
|
}, 0, this, tab.getAttribute(sv.kID), draggedTab && draggedTab.getAttribute(sv.kID));
|
2009-09-02 21:26:38 -04:00
|
|
|
|
|
|
|
tab = null;
|
|
|
|
},
|
2012-08-29 20:43:23 -04:00
|
|
|
updateDragData : function TabbarDND_updateDragData(aTab)
|
|
|
|
{
|
|
|
|
if (!aTab || !aTab._dragData) return;
|
|
|
|
var sv = this.treeStyleTab;
|
2012-10-12 13:18:16 -04:00
|
|
|
var data = aTab._dragData;
|
|
|
|
var offsetX = sv.getXOffsetOfTab(aTab);
|
|
|
|
var offsetY = sv.getYOffsetOfTab(aTab);
|
|
|
|
if ('offsetX' in data) data.offsetX += offsetX;
|
|
|
|
if ('screenX' in data) data.screenX += offsetX;
|
|
|
|
if ('offsetY' in data) data.offsetY += offsetY;
|
|
|
|
if ('screenY' in data) data.screenY += offsetY;
|
2012-08-29 20:43:23 -04:00
|
|
|
},
|
2009-09-02 21:26:38 -04:00
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
onDragLeave : function TabbarDND_onDragLeave(aEvent)
|
2009-09-02 21:26:38 -04:00
|
|
|
{
|
2011-05-27 20:18:44 -04:00
|
|
|
this.clearDropPosition();
|
2010-06-13 08:21:49 -04:00
|
|
|
|
2011-05-27 20:18:44 -04:00
|
|
|
this.window.clearTimeout(this.mAutoExpandTimer);
|
2009-09-02 21:26:38 -04:00
|
|
|
this.mAutoExpandTimer = null;
|
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
onDragEnd : function TabbarDND_onDragEnd(aEvent)
|
2009-09-02 21:26:38 -04:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
2010-06-13 08:21:49 -04:00
|
|
|
var dt = aEvent.dataTransfer;
|
2010-12-01 10:15:40 -05:00
|
|
|
if (dt.getData(sv.kDRAG_TYPE_TABBAR))
|
|
|
|
this.onTabbarDragEnd(aEvent);
|
|
|
|
else
|
|
|
|
this.onTabDragEnd(aEvent);
|
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
onTabDragEnd : function TabbarDND_onTabDragEnd(aEvent)
|
2010-12-01 10:15:40 -05:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
|
|
|
var b = this.browser;
|
|
|
|
var d = this.document;
|
|
|
|
var w = this.window;
|
2010-12-01 10:15:40 -05:00
|
|
|
|
|
|
|
var tabbar = b.mTabContainer;
|
|
|
|
var strip = sv.tabStrip;
|
|
|
|
var dt = aEvent.dataTransfer;
|
|
|
|
|
2012-08-29 16:41:25 -04:00
|
|
|
this.clearDropPosition(true);
|
2012-08-29 17:10:47 -04:00
|
|
|
this.collapseAutoExpandedTabs();
|
2010-12-01 10:15:40 -05:00
|
|
|
|
|
|
|
if (dt.mozUserCancelled || dt.dropEffect != 'none')
|
|
|
|
return;
|
2010-06-13 08:21:49 -04:00
|
|
|
|
2010-12-01 10:15:40 -05:00
|
|
|
// prevent handling of this event by the default handler
|
|
|
|
aEvent.stopPropagation();
|
2011-02-08 12:56:33 -05:00
|
|
|
aEvent.preventDefault();
|
2010-12-01 10:15:40 -05:00
|
|
|
|
|
|
|
var eX = aEvent.screenX;
|
|
|
|
var eY = aEvent.screenY;
|
|
|
|
var x, y, w, h;
|
|
|
|
|
|
|
|
// ignore drop on the toolbox
|
2010-12-06 07:04:52 -05:00
|
|
|
x = w.screenX;
|
|
|
|
y = w.screenY;
|
|
|
|
w = w.outerWidth;
|
|
|
|
h = d.getElementById('navigator-toolbox').boxObject.height;
|
2010-12-01 10:15:40 -05:00
|
|
|
if (eX > x && eX < x + w && eY > y && eY < y + h)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// ignore drop near the tab bar
|
|
|
|
var box = strip.boxObject;
|
|
|
|
var ignoreArea = Math.max(16, parseInt(sv.getFirstNormalTab(b).boxObject.height / 2));
|
|
|
|
x = box.screenX - (sv.isVertical ? ignoreArea : 0 );
|
|
|
|
y = box.screenY - ignoreArea;
|
|
|
|
w = box.width + (sv.isVertical ? ignoreArea + ignoreArea : 0 );
|
|
|
|
h = box.height + ignoreArea + ignoreArea;
|
|
|
|
if (eX > x && eX < x + w && eY > y && eY < y + h)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var draggedTab = dt.mozGetDataAt(TAB_DROP_TYPE, 0);
|
2010-12-01 19:00:39 -05:00
|
|
|
if (this.isDraggingAllCurrentTabs(draggedTab))
|
2010-12-01 10:15:40 -05:00
|
|
|
return;
|
|
|
|
|
2012-02-04 17:50:26 -05:00
|
|
|
if (aEvent.ctrlKey || aEvent.metaKey)
|
|
|
|
draggedTab.__treestyletab__toBeDuplicated = true;
|
|
|
|
|
2010-12-01 10:15:40 -05:00
|
|
|
b.replaceTabWithWindow(draggedTab);
|
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
onTabbarDragEnd : function TabbarDND_onTabbarDragEnd(aEvent)
|
2010-12-01 10:15:40 -05:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var w = this.window;
|
|
|
|
w.setTimeout(function(aSelf) {
|
2010-12-01 10:15:40 -05:00
|
|
|
aSelf.readyToEndTabbarDrag();
|
2010-12-06 07:04:52 -05:00
|
|
|
aSelf.treeStyleTab.removeTabbrowserAttribute(aSelf.treeStyleTab.kDROP_POSITION);
|
2009-11-23 13:04:40 -05:00
|
|
|
}, 10, this);
|
2009-09-02 21:26:38 -04:00
|
|
|
aEvent.stopPropagation();
|
2010-06-13 08:21:49 -04:00
|
|
|
aEvent.preventDefault();
|
2009-09-02 21:26:38 -04:00
|
|
|
},
|
2010-12-01 10:15:40 -05:00
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
onDragOver : function TabbarDND_onDragOver(aEvent)
|
2009-09-02 21:26:38 -04:00
|
|
|
{
|
2010-12-01 10:15:40 -05:00
|
|
|
if (this.onTabDragOver(aEvent)) {
|
|
|
|
aEvent.stopPropagation();
|
|
|
|
aEvent.preventDefault(); // this is required to override default dragover actions!
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
onTabDragOver : function TabbarDND_onTabDragOver(aEvent)
|
2010-12-01 10:15:40 -05:00
|
|
|
{
|
|
|
|
try{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
|
|
|
var b = this.browser;
|
2012-08-29 16:28:03 -04:00
|
|
|
var tabbar = b.mTabContainer;
|
2010-06-13 08:21:49 -04:00
|
|
|
|
2010-12-01 19:02:27 -05:00
|
|
|
var session = sv.currentDragSession;
|
2010-12-02 12:38:15 -05:00
|
|
|
if (sv.isToolbarCustomizing)
|
2010-12-01 10:15:40 -05:00
|
|
|
return false;
|
|
|
|
|
|
|
|
sv.autoScroll.processAutoScroll(aEvent);
|
|
|
|
|
2012-10-12 13:09:34 -04:00
|
|
|
let draggedTab = aEvent.dataTransfer && aEvent.dataTransfer.mozGetDataAt(TAB_DROP_TYPE, 0);
|
|
|
|
let dragOverTab = sv.getTabFromEvent(aEvent) || sv.getTabFromTabbarEvent(aEvent) || aEvent.target;
|
2012-10-12 11:37:03 -04:00
|
|
|
b.ownerDocument.defaultView['piro.sakura.ne.jp'].tabsDragUtils
|
2012-11-28 04:48:05 -05:00
|
|
|
.processTabsDragging(aEvent, {
|
|
|
|
canDropOnSelf : !dragOverTab || !dragOverTab.pinned,
|
|
|
|
isVertical : (
|
|
|
|
b.ownerDocument.defaultView['piro.sakura.ne.jp'].tabsDragUtils.isVertical(b.tabContainer) &&
|
2012-12-03 10:28:23 -05:00
|
|
|
(
|
|
|
|
!draggedTab.pinned ||
|
|
|
|
!utils.getTreePref('pinnedTab.faviconized')
|
|
|
|
)
|
2012-11-28 04:48:05 -05:00
|
|
|
)
|
|
|
|
});
|
2012-10-12 11:37:03 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* We must calculate drop action after tabsDragUtils.processTabsDragging(),
|
|
|
|
* because the drop position depends on tabs' actual
|
|
|
|
* positions (which can be changed by animation effects.)
|
|
|
|
*/
|
2010-12-01 19:00:39 -05:00
|
|
|
var info = this.getDropAction(aEvent, session);
|
2010-12-01 10:15:40 -05:00
|
|
|
|
|
|
|
var observer = b;
|
2012-01-13 11:30:06 -05:00
|
|
|
if (b.tabContainer && b.tabContainer._setEffectAllowedForDataTransfer)
|
2010-12-01 10:15:40 -05:00
|
|
|
observer = b.tabContainer;
|
|
|
|
|
2012-01-13 03:38:12 -05:00
|
|
|
// auto-switch for staying on tabs
|
2010-12-01 10:15:40 -05:00
|
|
|
if (
|
|
|
|
info.position == sv.kDROP_ON &&
|
|
|
|
info.target &&
|
|
|
|
!info.target.selected &&
|
2012-01-13 03:38:12 -05:00
|
|
|
'_dragTime' in observer && '_dragOverDelay' in observer
|
2010-12-01 10:15:40 -05:00
|
|
|
) {
|
|
|
|
let time = observer.mDragTime || observer._dragTime || 0;
|
|
|
|
let delay = observer.mDragOverDelay || observer._dragOverDelay || 0;
|
|
|
|
let effects = observer._setEffectAllowedForDataTransfer(aEvent);
|
|
|
|
if (effects == 'link') {
|
|
|
|
let now = Date.now();
|
|
|
|
if (!time) {
|
|
|
|
time = now;
|
|
|
|
if ('mDragTime' in observer)
|
|
|
|
observer.mDragTime = time;
|
|
|
|
else
|
|
|
|
observer._dragTime = time;
|
|
|
|
}
|
|
|
|
if (now >= time + delay)
|
2010-12-02 12:38:15 -05:00
|
|
|
b.selectedTab = info.target;
|
2010-12-01 10:15:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
!info.canDrop ||
|
|
|
|
observer._setEffectAllowedForDataTransfer(aEvent) == 'none'
|
|
|
|
) {
|
|
|
|
aEvent.dataTransfer.effectAllowed = "none";
|
2012-08-29 16:28:03 -04:00
|
|
|
this.clearDropPosition();
|
2010-12-01 10:15:40 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-16 13:23:38 -04:00
|
|
|
let indicatorTab = info.target;
|
|
|
|
if (sv.isCollapsed(info.target)) {
|
|
|
|
let tab = indicatorTab;
|
|
|
|
while ((tab = sv.getPreviousTab(tab)) && sv.isCollapsed(tab)) {}
|
|
|
|
if (tab) indicatorTab = tab;
|
|
|
|
}
|
|
|
|
|
2012-08-29 16:41:25 -04:00
|
|
|
let dropPosition = info.position == sv.kDROP_BEFORE ? 'before' :
|
|
|
|
info.position == sv.kDROP_AFTER ? 'after' :
|
|
|
|
'self';
|
2012-08-29 17:02:37 -04:00
|
|
|
if (indicatorTab != draggedTab &&
|
|
|
|
indicatorTab.getAttribute(sv.kDROP_POSITION) != dropPosition) {
|
2012-08-28 09:11:06 -04:00
|
|
|
this.clearDropPosition();
|
2012-08-29 16:41:25 -04:00
|
|
|
indicatorTab.setAttribute(sv.kDROP_POSITION, dropPosition);
|
2012-10-11 07:03:40 -04:00
|
|
|
if (b.ownerDocument.defaultView['piro.sakura.ne.jp'].tabsDragUtils
|
2012-10-12 11:37:03 -04:00
|
|
|
.canAnimateDraggedTabs(aEvent)) { // Firefox 17 and later
|
2012-10-12 13:56:02 -04:00
|
|
|
let newOpacity = dropPosition == 'self' ? 0.5 : '' ; // to prevent the dragged tab hides the drop target itself
|
|
|
|
this.window['piro.sakura.ne.jp'].tabsDragUtils.getDraggedTabs(aEvent).forEach(function(aTab) {
|
2012-10-12 14:05:48 -04:00
|
|
|
if (!('__treestyletab__opacityBeforeDragged' in aTab))
|
|
|
|
aTab.__treestyletab__opacityBeforeDragged = aTab.style.opacity || '';
|
2012-10-12 13:56:02 -04:00
|
|
|
aTab.style.opacity = newOpacity;
|
|
|
|
});
|
2012-08-29 16:28:03 -04:00
|
|
|
}
|
2012-08-28 09:11:06 -04:00
|
|
|
}
|
|
|
|
|
2011-01-19 05:03:40 -05:00
|
|
|
|
2010-12-01 10:15:40 -05:00
|
|
|
var indicator = b.mTabDropIndicatorBar || b.tabContainer._tabDropIndicator;
|
2011-03-30 03:18:23 -04:00
|
|
|
indicator.setAttribute('dragging', (info.position == sv.kDROP_ON || sv.isVertical) ? 'false' : 'true' );
|
2011-01-19 05:03:40 -05:00
|
|
|
if (sv.isVertical)
|
|
|
|
indicator.collapsed = true;
|
|
|
|
|
2011-01-22 10:46:29 -05:00
|
|
|
return (info.position == sv.kDROP_ON || sv.position != 'top')
|
2010-12-01 10:15:40 -05:00
|
|
|
}
|
|
|
|
catch(e) {
|
2010-12-06 07:04:52 -05:00
|
|
|
dump('TabbarDND::onDragOver\n'+e+'\n');
|
2010-12-01 10:15:40 -05:00
|
|
|
}
|
2009-09-02 21:26:38 -04:00
|
|
|
},
|
2010-12-01 10:15:40 -05:00
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
onDrop : function TabbarDND_onDrop(aEvent)
|
2009-09-02 21:26:38 -04:00
|
|
|
{
|
2010-12-01 10:15:40 -05:00
|
|
|
this.onTabDrop(aEvent);
|
2012-08-29 17:10:47 -04:00
|
|
|
this.collapseAutoExpandedTabs();
|
|
|
|
},
|
|
|
|
collapseAutoExpandedTabs : function TabbarDND_collapseAutoExpandedTabs()
|
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
2010-12-01 10:15:40 -05:00
|
|
|
if (this.mAutoExpandedTabs.length) {
|
2012-10-23 12:43:56 -04:00
|
|
|
if (utils.getTreePref('autoExpand.collapseFinally')) {
|
2012-02-04 16:31:03 -05:00
|
|
|
for (let i = 0, maxi = this.mAutoExpandedTabs.length; i < maxi; i++)
|
2012-02-04 13:15:38 -05:00
|
|
|
{
|
2012-02-04 16:31:03 -05:00
|
|
|
sv.collapseExpandSubtree(sv.getTabById(this.mAutoExpandedTabs[i]), true, true);
|
2012-02-04 13:15:38 -05:00
|
|
|
}
|
2010-12-01 10:15:40 -05:00
|
|
|
}
|
|
|
|
this.mAutoExpandedTabs = [];
|
2009-09-02 21:26:38 -04:00
|
|
|
}
|
|
|
|
},
|
2010-12-01 10:15:40 -05:00
|
|
|
|
|
|
|
onTabDrop : function TSTService_onTabDrop(aEvent)
|
2009-09-02 21:26:38 -04:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var sv = this.treeStyleTab;
|
|
|
|
var b = this.browser;
|
|
|
|
var w = this.window;
|
2009-09-02 21:26:38 -04:00
|
|
|
|
2010-12-01 10:15:40 -05:00
|
|
|
var tabbar = b.mTabContainer;
|
|
|
|
var dt = aEvent.dataTransfer;
|
|
|
|
|
2012-10-12 11:37:03 -04:00
|
|
|
/**
|
|
|
|
* We must calculate drop action before clearing "dragging"
|
|
|
|
* state, because the drop position depends on tabs' actual
|
|
|
|
* positions (they are applied only while tab dragging.)
|
|
|
|
*/
|
|
|
|
var session = sv.currentDragSession;
|
|
|
|
var dropActionInfo = this.getDropAction(aEvent, session);
|
|
|
|
|
2012-08-29 16:41:25 -04:00
|
|
|
this.clearDropPosition(true);
|
2012-01-13 11:30:06 -05:00
|
|
|
if (tabbar._tabDropIndicator)
|
2010-12-01 10:15:40 -05:00
|
|
|
tabbar._tabDropIndicator.collapsed = true;
|
|
|
|
|
2012-10-12 13:43:34 -04:00
|
|
|
var draggedTab = dt.mozGetDataAt(TAB_DROP_TYPE, 0);
|
|
|
|
if (dt.dropEffect != 'link' && !draggedTab) {
|
|
|
|
aEvent.stopPropagation();
|
|
|
|
return;
|
2010-12-01 10:15:40 -05:00
|
|
|
}
|
|
|
|
|
2012-08-29 16:48:28 -04:00
|
|
|
var sourceBrowser = sv.getTabBrowserFromChild(draggedTab);
|
|
|
|
if (draggedTab && sourceBrowser != b)
|
|
|
|
sourceBrowser.treeStyleTab.tabbarDNDObserver.clearDropPosition(true);
|
|
|
|
|
2010-12-01 19:00:39 -05:00
|
|
|
if (draggedTab && this.performDrop(dropActionInfo, draggedTab)) {
|
2010-12-01 10:15:40 -05:00
|
|
|
aEvent.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// duplicating of tabs
|
|
|
|
if (
|
|
|
|
draggedTab &&
|
|
|
|
(
|
|
|
|
dt.dropEffect == 'copy' ||
|
2012-08-29 16:48:28 -04:00
|
|
|
sourceBrowser != b
|
2010-12-01 10:15:40 -05:00
|
|
|
) &&
|
|
|
|
dropActionInfo.position == sv.kDROP_ON
|
|
|
|
) {
|
|
|
|
var beforeTabs = Array.slice(b.mTabContainer.childNodes);
|
2010-12-06 07:04:52 -05:00
|
|
|
w.setTimeout(function() {
|
2010-12-01 10:15:40 -05:00
|
|
|
var newTabs = Array.slice(b.mTabContainer.childNodes).filter(function(aTab) {
|
|
|
|
return beforeTabs.indexOf(aTab) < 0;
|
|
|
|
});
|
|
|
|
if (newTabs.length)
|
|
|
|
sv.attachTabTo(newTabs[0], dropActionInfo.target);
|
|
|
|
}, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-28 15:08:57 -04:00
|
|
|
if (!draggedTab)
|
|
|
|
this.handleLinksOrBookmarks(aEvent, dropActionInfo);
|
|
|
|
},
|
|
|
|
handleLinksOrBookmarks : function TabbarDND_handleLinksOrBookmarks(aEvent, aDropActionInfo)
|
|
|
|
{
|
|
|
|
aEvent.stopPropagation();
|
2010-12-01 10:15:40 -05:00
|
|
|
|
2012-07-28 15:08:57 -04:00
|
|
|
var uris = this.retrieveURLsFromDataTransfer(aEvent.dataTransfer);
|
|
|
|
uris.forEach(function(aURI) {
|
|
|
|
if (aURI.indexOf(this.BOOKMARK_FOLDER) != 0)
|
2012-08-29 05:16:42 -04:00
|
|
|
this.securityCheck(aURI, aEvent);
|
2012-07-28 15:08:57 -04:00
|
|
|
}, this);
|
2010-12-01 10:15:40 -05:00
|
|
|
|
2012-07-28 15:08:57 -04:00
|
|
|
var sv = this.treeStyleTab;
|
|
|
|
var b = this.browser;
|
|
|
|
var w = this.window;
|
2012-07-28 22:11:41 -04:00
|
|
|
var self = this;
|
2010-12-01 10:15:40 -05:00
|
|
|
|
2013-01-05 21:47:50 -05:00
|
|
|
let bgLoad = prefs.getPref('browser.tabs.loadInBackground');
|
2012-07-28 15:08:57 -04:00
|
|
|
if (aEvent.shiftKey) bgLoad = !bgLoad;
|
|
|
|
|
|
|
|
let tab = sv.getTabFromEvent(aEvent);
|
|
|
|
if (
|
|
|
|
!tab ||
|
|
|
|
aEvent.dataTransfer.dropEffect == 'copy' ||
|
|
|
|
uris.length > 1 ||
|
|
|
|
uris[0].indexOf(this.BOOKMARK_FOLDER) == 0
|
|
|
|
) {
|
|
|
|
uris.reverse().forEach(function(aURI) {
|
|
|
|
if (aURI.indexOf(this.BOOKMARK_FOLDER) == 0) {
|
2012-07-28 22:11:41 -04:00
|
|
|
let newTabs = sv.getNewTabsWithOperation(function() {
|
|
|
|
var data = aURI.replace(self.BOOKMARK_FOLDER, '');
|
|
|
|
data = JSON.parse(data);
|
|
|
|
w.PlacesUIUtils._openTabset(data.children, { type : 'drop' }, w, data.title);
|
|
|
|
}, b);
|
|
|
|
aDropActionInfo.draggedTabsInfo = {
|
|
|
|
draggedTabs : newTabs,
|
|
|
|
draggedTab : newTabs[0],
|
|
|
|
isMultipleMove : newTabs.length > 1
|
|
|
|
};
|
|
|
|
this.performDrop(aDropActionInfo, newTabs[0]);
|
2012-07-28 15:08:57 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aURI = w.getShortcutOrURI(aURI);
|
|
|
|
this.performDrop(aDropActionInfo, b.loadOneTab(aURI, { inBackground: bgLoad }));
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let locked = (
|
|
|
|
tab.getAttribute('locked') == 'true' || // Tab Mix Plus and others
|
|
|
|
tab.getAttribute('isPageLocked') == 'true' // Super Tab Mode
|
|
|
|
);
|
|
|
|
let loadDroppedLinkToNewChildTab = aDropActionInfo.position != sv.kDROP_ON || locked;
|
|
|
|
if (!loadDroppedLinkToNewChildTab &&
|
|
|
|
aDropActionInfo.position == sv.kDROP_ON)
|
|
|
|
loadDroppedLinkToNewChildTab = sv.dropLinksOnTabBehavior() == sv.kDROPLINK_NEWTAB;
|
|
|
|
|
|
|
|
try {
|
|
|
|
let uri = w.getShortcutOrURI(uris[0]);
|
|
|
|
if (loadDroppedLinkToNewChildTab || locked) {
|
|
|
|
this.performDrop(aDropActionInfo, b.loadOneTab(uri, { inBackground: bgLoad }));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tab.linkedBrowser.loadURI(uri);
|
|
|
|
if (!bgLoad)
|
|
|
|
b.selectedTab = tab;
|
2010-12-01 10:15:40 -05:00
|
|
|
}
|
|
|
|
}
|
2012-07-28 15:08:57 -04:00
|
|
|
catch(e) {
|
2010-12-01 10:15:40 -05:00
|
|
|
}
|
2012-07-28 15:08:57 -04:00
|
|
|
}
|
|
|
|
},
|
2012-08-29 05:16:42 -04:00
|
|
|
securityCheck : function TabbarDND_securityCheck(aURI, aEvent)
|
2012-07-28 15:08:57 -04:00
|
|
|
{
|
2012-09-01 09:01:38 -04:00
|
|
|
// See dragDropSecurityCheck() in chrome://global/content/nsDragAndDrop.js
|
2012-07-28 15:08:57 -04:00
|
|
|
let session = this.treeStyleTab.currentDragSession;
|
2012-09-01 09:01:38 -04:00
|
|
|
if (!session) { //TODO: use some fake nodePrincipal?
|
|
|
|
aEvent.stopPropagation();
|
2012-08-29 06:23:05 -04:00
|
|
|
throw 'Drop of ' + aURI + ' denied: no drag session.';
|
2012-09-01 09:01:38 -04:00
|
|
|
}
|
2012-09-01 09:16:19 -04:00
|
|
|
let normalizedURI;
|
|
|
|
try {
|
|
|
|
normalizedURI = this.treeStyleTab.makeURIFromSpec(aURI);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
}
|
2012-09-01 09:01:38 -04:00
|
|
|
if (!normalizedURI)
|
|
|
|
return;
|
|
|
|
let sourceDoc = session.sourceDocument;
|
2012-10-13 14:54:46 -04:00
|
|
|
let sourceURI = sourceDoc ? sourceDoc.documentURI : 'file:///' ;
|
2012-10-12 15:18:59 -04:00
|
|
|
let principal = sourceDoc ?
|
2012-10-13 14:54:46 -04:00
|
|
|
sourceDoc.nodePrincipal :
|
|
|
|
SecMan.getSimpleCodebasePrincipal ? // this method isn't there on Firefox 16 and olders!
|
|
|
|
SecMan.getSimpleCodebasePrincipal(Services.io.newURI(sourceURI, null, null)) :
|
|
|
|
null ;
|
2012-09-01 09:01:38 -04:00
|
|
|
try {
|
2012-10-13 14:54:46 -04:00
|
|
|
if (principal)
|
|
|
|
SecMan.checkLoadURIStrWithPrincipal(principal, normalizedURI.spec, Ci.nsIScriptSecurityManager.STANDARD);
|
|
|
|
else
|
|
|
|
SecMan.checkLoadURIStr(sourceURI, normalizedURI.spec, Ci.nsIScriptSecurityManager.STANDARD);
|
2012-09-01 09:01:38 -04:00
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
aEvent.stopPropagation();
|
|
|
|
throw 'Drop of ' + aURI + ' denied.';
|
2009-09-02 21:26:38 -04:00
|
|
|
}
|
|
|
|
},
|
2010-12-01 10:15:40 -05:00
|
|
|
|
2011-06-14 11:29:36 -04:00
|
|
|
retrieveURLsFromDataTransfer : function TSTService_retrieveURLsFromDataTransfer(aDataTransfer)
|
2010-12-01 10:15:40 -05:00
|
|
|
{
|
2011-06-14 11:34:08 -04:00
|
|
|
var urls = [];
|
2011-06-14 11:29:36 -04:00
|
|
|
var types = [
|
2012-07-28 13:32:57 -04:00
|
|
|
'text/x-moz-place',
|
2011-06-14 11:29:36 -04:00
|
|
|
'text/uri-list',
|
|
|
|
'text/x-moz-text-internal',
|
|
|
|
'text/x-moz-url',
|
|
|
|
'text/plain',
|
|
|
|
'application/x-moz-file'
|
|
|
|
];
|
2010-12-01 10:15:40 -05:00
|
|
|
for (let i = 0; i < types.length; i++) {
|
|
|
|
let dataType = types[i];
|
2011-06-14 11:29:36 -04:00
|
|
|
for (let i = 0, maxi = aDataTransfer.mozItemCount; i < maxi; i++)
|
|
|
|
{
|
|
|
|
let urlData = aDataTransfer.mozGetDataAt(dataType, i);
|
|
|
|
if (urlData) {
|
|
|
|
urls = urls.concat(this.retrieveURLsFromData(urlData, dataType));
|
|
|
|
}
|
2010-12-01 10:15:40 -05:00
|
|
|
}
|
2011-06-14 11:29:36 -04:00
|
|
|
if (urls.length)
|
|
|
|
break;
|
2010-12-01 10:15:40 -05:00
|
|
|
}
|
2012-07-28 15:08:57 -04:00
|
|
|
return urls.filter(function(aURI) {
|
|
|
|
return aURI &&
|
|
|
|
aURI.length &&
|
|
|
|
aURI.indexOf(this.BOOKMARK_FOLDER) == 0 ||
|
|
|
|
(
|
|
|
|
aURI.indexOf(' ', 0) == -1 &&
|
|
|
|
!/^\s*(javascript|data):/.test(aURI)
|
|
|
|
);
|
|
|
|
}, this);
|
2010-12-01 10:15:40 -05:00
|
|
|
},
|
2012-07-28 15:08:57 -04:00
|
|
|
BOOKMARK_FOLDER: 'x-moz-place:',
|
2011-06-14 11:29:36 -04:00
|
|
|
retrieveURLsFromData : function TSTService_retrieveURLsFromData(aData, aType)
|
2010-12-01 10:15:40 -05:00
|
|
|
{
|
|
|
|
switch (aType)
|
|
|
|
{
|
2012-07-28 13:32:57 -04:00
|
|
|
case 'text/x-moz-place':
|
2012-07-28 15:08:57 -04:00
|
|
|
let (uri = JSON.parse(aData).uri) {
|
|
|
|
if (uri)
|
|
|
|
return uri;
|
|
|
|
else
|
|
|
|
return this.BOOKMARK_FOLDER+aData;
|
|
|
|
}
|
2012-07-28 13:32:57 -04:00
|
|
|
|
2011-06-14 11:29:36 -04:00
|
|
|
case 'text/uri-list':
|
|
|
|
return aData.replace(/\r/g, '\n')
|
|
|
|
.replace(/^\#.+$/gim, '')
|
|
|
|
.replace(/\n\n+/g, '\n')
|
|
|
|
.split('\n');
|
|
|
|
|
2010-12-01 10:15:40 -05:00
|
|
|
case 'text/unicode':
|
|
|
|
case 'text/plain':
|
|
|
|
case 'text/x-moz-text-internal':
|
2011-06-14 11:29:36 -04:00
|
|
|
return [aData.replace(/^\s+|\s+$/g, '')];
|
2010-12-01 10:15:40 -05:00
|
|
|
|
|
|
|
case 'text/x-moz-url':
|
2011-06-14 11:29:36 -04:00
|
|
|
return [((aData instanceof Ci.nsISupportsString) ? aData.toString() : aData)
|
|
|
|
.split('\n')[0]];
|
2010-12-01 10:15:40 -05:00
|
|
|
|
|
|
|
case 'application/x-moz-file':
|
2012-09-17 11:49:12 -04:00
|
|
|
let fileHandler = Services.io.getProtocolHandler('file')
|
2010-12-06 07:04:52 -05:00
|
|
|
.QueryInterface(Ci.nsIFileProtocolHandler);
|
2011-06-14 11:29:36 -04:00
|
|
|
return [fileHandler.getURLSpecFromFile(aData)];
|
2010-12-01 10:15:40 -05:00
|
|
|
}
|
2011-06-14 11:29:36 -04:00
|
|
|
return [];
|
2010-12-01 10:15:40 -05:00
|
|
|
},
|
2010-12-01 18:12:57 -05:00
|
|
|
|
2010-12-06 08:31:58 -05:00
|
|
|
init : function TabbarDND_init(aTabBrowser)
|
2010-12-01 18:12:57 -05:00
|
|
|
{
|
2010-12-06 08:31:58 -05:00
|
|
|
this.browser = aTabBrowser;
|
|
|
|
this.document = aTabBrowser.ownerDocument;
|
2010-12-06 07:04:52 -05:00
|
|
|
this.window = this.document.defaultView;
|
2010-12-06 08:31:58 -05:00
|
|
|
this.treeStyleTab = aTabBrowser.treeStyleTab;
|
2010-12-06 07:04:52 -05:00
|
|
|
|
2010-12-01 18:12:57 -05:00
|
|
|
this.mAutoExpandTimer = null;
|
2011-03-23 14:30:01 -04:00
|
|
|
this.mAutoExpandTimerNext = null;
|
2010-12-01 18:12:57 -05:00
|
|
|
this.mAutoExpandedTabs = [];
|
2011-01-22 09:43:55 -05:00
|
|
|
this.startListenEvents();
|
|
|
|
},
|
|
|
|
|
|
|
|
startListenEvents : function TabbarDND_startListenEvents()
|
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var strip = this.treeStyleTab.tabStrip;
|
2010-12-01 18:12:57 -05:00
|
|
|
strip.addEventListener('dragstart', this, true);
|
|
|
|
strip.addEventListener('dragover', this, true);
|
|
|
|
strip.addEventListener('dragenter', this, false);
|
|
|
|
strip.addEventListener('dragleave', this, false);
|
2011-02-08 12:56:33 -05:00
|
|
|
strip.addEventListener('dragend', this, true);
|
2010-12-01 18:12:57 -05:00
|
|
|
strip.addEventListener('drop', this, true);
|
|
|
|
},
|
2011-01-22 09:43:55 -05:00
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
destroy : function TabbarDND_destroy()
|
2011-01-22 09:43:55 -05:00
|
|
|
{
|
|
|
|
this.endListenEvents();
|
|
|
|
|
|
|
|
delete this.treeStyleTab;
|
|
|
|
delete this.browser;
|
|
|
|
delete this.document;
|
|
|
|
delete this.window;
|
|
|
|
},
|
|
|
|
|
|
|
|
endListenEvents : function TabbarDND_endListenEvents()
|
2009-09-02 21:42:04 -04:00
|
|
|
{
|
2010-12-06 07:04:52 -05:00
|
|
|
var strip = this.treeStyleTab.tabStrip;
|
2010-12-01 18:12:57 -05:00
|
|
|
strip.removeEventListener('dragstart', this, true);
|
|
|
|
strip.removeEventListener('dragover', this, true);
|
|
|
|
strip.removeEventListener('dragenter', this, false);
|
|
|
|
strip.removeEventListener('dragleave', this, false);
|
2011-02-08 12:56:33 -05:00
|
|
|
strip.removeEventListener('dragend', this, true);
|
2010-12-01 18:12:57 -05:00
|
|
|
strip.removeEventListener('drop', this, true);
|
2009-09-02 21:26:38 -04:00
|
|
|
}
|
2011-01-22 09:43:55 -05:00
|
|
|
|
2009-09-02 21:26:38 -04:00
|
|
|
};
|
|
|
|
|