タブのドロップのハンドリング

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@6429 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2010-03-24 17:57:49 +00:00
parent 0b0de3ebaa
commit dc66e92627

View File

@ -349,6 +349,7 @@ var TreeStyleTabService = {
aObserver.addEventListener('dragstart', this, true); aObserver.addEventListener('dragstart', this, true);
aObserver.addEventListener('dragover', this, true); aObserver.addEventListener('dragover', this, true);
aObserver.addEventListener('dragleave', this, true); aObserver.addEventListener('dragleave', this, true);
aObserver.addEventListener('drop', this, true);
} }
var canDropFunctionName = '_setEffectAllowedForDataTransfer' in aObserver ? var canDropFunctionName = '_setEffectAllowedForDataTransfer' in aObserver ?
@ -513,6 +514,7 @@ var TreeStyleTabService = {
aObserver.removeEventListener('dragstart', this, true); aObserver.removeEventListener('dragstart', this, true);
aObserver.removeEventListener('dragover', this, true); aObserver.removeEventListener('dragover', this, true);
aObserver.removeEventListener('dragleave', this, true); aObserver.removeEventListener('dragleave', this, true);
aObserver.removeEventListener('drop', this, true);
} }
}, },
@ -574,29 +576,41 @@ try{
// auto-switch for staying on tabs (Firefox 3.0 or later) // auto-switch for staying on tabs (Firefox 3.0 or later)
var setEffectAllowedFunc; var setEffectAllowedFunc;
var observer = aTabBrowser;
if (aTabBrowser._setEffectAllowedForDataTransfer) { if (aTabBrowser._setEffectAllowedForDataTransfer) {
setEffectAllowedFunc = function(aEvent) { setEffectAllowedFunc = function(aEvent) {
return aTabBrowser._setEffectAllowedForDataTransfer(aEvent); return aTabBrowser._setEffectAllowedForDataTransfer(aEvent);
}; };
} }
else if (aTabBrowser.tabContainer && else if (aTabBrowser.tabContainer &&
aTabBrowser.tabContainer._setEffectAllowedForDataTransfer) { aTabBrowser.tabContainer._setEffectAllowedForDataTransfer) {
observer = aTabBrowser.tabContainer;
setEffectAllowedFunc = function(aEvent) { setEffectAllowedFunc = function(aEvent) {
return aTabBrowser.tabContainer._setEffectAllowedForDataTransfer(aEvent); return aTabBrowser.tabContainer._setEffectAllowedForDataTransfer(aEvent);
}; };
} }
if (setEffectAllowedFunc && if (
setEffectAllowedFunc &&
info.target && info.target &&
!info.target.selected && !info.target.selected &&
'mDragTime' in aTabBrowser && (
'mDragOverDelay' in aTabBrowser) { ('mDragTime' in observer && 'mDragOverDelay' in observer) ||
('_dragTime' in observer && '_dragOverDelay' in observer)
)
) {
let time = observer.mDragTime || observer._dragTime || 0;
let delay = observer.mDragOverDelay || observer._dragOverDelay || 0;
let effects = setEffectAllowedFunc(aEvent); let effects = setEffectAllowedFunc(aEvent);
if (effects == 'link') { if (effects == 'link') {
let now = Date.now(); let now = Date.now();
if (!aTabBrowser.mDragTime) if (!time) {
aTabBrowser.mDragTime = now; if ('mDragTime' in observer)
if (now >= aTabBrowser.mDragTime + aTabBrowser.mDragOverDelay) observer.mDragTime = now;
else
observer._dragTime = now;
}
if (now >= time + delay)
aTabBrowser.selectedTab = info.target; aTabBrowser.selectedTab = info.target;
} }
} }
@ -653,6 +667,51 @@ catch(e) {
tabbar.treeStyleTab.clearDropPosition(); tabbar.treeStyleTab.clearDropPosition();
}, },
onTabDNDObserverDrop : function TSTService_onTabDNDObserverDrop(aEvent)
{
var tabbar = aEvent.currentTarget;
var b = tabbar.tabbrowser;
var sv = b.treeStyleTab;
var dt = aEvent.dataTransfer;
sv.clearDropPosition();
var dropActionInfo = sv.getDropAction(aEvent, sv.getCurrentDragSession());
var draggedTab;
if (dt.dropEffect != 'link') {
draggedTab = dt.mozGetDataAt(TAB_DROP_TYPE, 0);
if (!draggedTab) {
aEvent.stopPropagation();
return;
}
}
if (sv.performDrop(dropActionInfo, draggedTab)) {
aEvent.stopPropagation();
return;
}
if (
(
dt.dropEffect == 'copy' ||
draggedTab.parentNode != tabbar
) &&
dropActionInfo.position == sv.kDROP_ON
) {
var beforeTabs = Array.slice(b.tabs);
window.setTimeout(function() {
var afterTabs = Array.slice(b.tabs);
var newTabs = afterTabs.filter(function(aTab) {
return beforeTabs.indexOf(aTab) < 0;
});
newTabs.forEach(function(aTab) {
sv.attachTabTo(aTab, dropActionInfo.target);
});
}, 0);
}
},
overrideGlobalFunctions : function TSTService_overrideGlobalFunctions() overrideGlobalFunctions : function TSTService_overrideGlobalFunctions()
{ {
// window.__treestyletab__BrowserCustomizeToolbar = window.BrowserCustomizeToolbar; // window.__treestyletab__BrowserCustomizeToolbar = window.BrowserCustomizeToolbar;
@ -1102,6 +1161,7 @@ catch(e) {
case 'dragstart': return this.onTabDNDObserverDragStart(aEvent); case 'dragstart': return this.onTabDNDObserverDragStart(aEvent);
case 'dragover': return this.onTabDNDObserverDragOver(aEvent); case 'dragover': return this.onTabDNDObserverDragOver(aEvent);
case 'dragleave': return this.onTabDNDObserverDragLeave(aEvent); case 'dragleave': return this.onTabDNDObserverDragLeave(aEvent);
case 'drop': return this.onTabDNDObserverDrop(aEvent);
} }
}, },