Firefox 3.5以降ではなるべく新しい方のやり方を使うように

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@6475 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2010-03-27 14:52:25 +00:00
parent 7e7fde7227
commit 967308c2e7
2 changed files with 117 additions and 117 deletions

View File

@ -341,17 +341,24 @@ var TreeStyleTabService = {
updateTabDNDObserver : function TSTService_updateTabDNDObserver(aObserver) updateTabDNDObserver : function TSTService_updateTabDNDObserver(aObserver)
{ {
var strip = this.getTabStrip(aObserver);
// Firefox 3.5 or later
var useHTML5Events = '_setEffectAllowedForDataTransfer' in aObserver;
if (useHTML5Events) {
strip.addEventListener('dragstart', this, true);
strip.addEventListener('dragover', this, true);
strip.addEventListener('dragleave', this, true);
}
if (aObserver.tabContainer && if (aObserver.tabContainer &&
aObserver.tabContainer.tabbrowser == aObserver) { // Firefox 3.7 or later aObserver.tabContainer.tabbrowser == aObserver) { // Firefox 3.7 or later
aObserver = aObserver.tabContainer; aObserver = aObserver.tabContainer;
aObserver.addEventListener('dragstart', this, true); strip.addEventListener('drop', this, true);
aObserver.addEventListener('dragover', this, true); strip.addEventListener('dragend', this, true);
aObserver.addEventListener('dragleave', this, true);
aObserver.addEventListener('drop', this, true);
aObserver.addEventListener('dragend', this, true);
} }
var canDropFunctionName = '_setEffectAllowedForDataTransfer' in aObserver ? var canDropFunctionName = useHTML5Events ?
'_setEffectAllowedForDataTransfer' : // Firefox 3.5 or later '_setEffectAllowedForDataTransfer' : // Firefox 3.5 or later
'canDrop' ; // Firefox 3.0.x 'canDrop' ; // Firefox 3.0.x
if (canDropFunctionName in aObserver) { if (canDropFunctionName in aObserver) {
@ -381,21 +388,9 @@ var TreeStyleTabService = {
); );
} }
if ('_onDragStart' in aObserver) { // Firefox 3.5 - 3.6 if ('onDragStart' in aObserver) { // Firefox 3.0.x
eval('aObserver._onDragStart = '+
aObserver._onDragStart.toSource().replace(
'if (target.localName == "tab"',
<![CDATA[
if (this.treeStyleTab.tabbarDNDObserver.canDragTabbar(aEvent)) {
this.treeStyleTab.onTabbarDragStart(aEvent, this);
}
else $&]]>
)
);
}
else if ('onDragStart' in aObserver) { // Firefox 3.0.x
eval('aObserver.onDragStart = '+ eval('aObserver.onDragStart = '+
aObserver.onDragStart.toSource().replace( // native aObserver.onDragStart.toSource().replace(
'aEvent.target.localName == "tab"', 'aEvent.target.localName == "tab"',
<![CDATA[ <![CDATA[
( (
@ -407,29 +402,21 @@ var TreeStyleTabService = {
); );
} }
var dragOverFunctionName = '_onDragOver' in aObserver ? if ('onDragOver' in aObserver) { // Firefox 3.0.x
'_onDragOver' : // Firefox 3.5 - 3.6 eval('aObserver.onDragOver = '+
'onDragOver' ; // Firefox 3.0.x aObserver.onDragOver.toSource().replace(
if (dragOverFunctionName in aObserver) {
eval('aObserver.'+dragOverFunctionName+' = '+
aObserver[dragOverFunctionName].toSource().replace(
'{', '{',
<![CDATA[ <![CDATA[$&
{ if (this.treeStyleTab.processTabDragOverEvent(aEvent, this))
if (this.treeStyleTab.processTabDragOverEvent(aEvent, this)) {
return; return;
}
]]> ]]>
) )
); );
} }
var dragExitFunctionName = '_onDragLeave' in aObserver ? if ('onDragExit' in aObserver) { // Firefox 3.0.x
'_onDragLeave' : // Firefox 3.5 - 3.6 eval('aObserver.onDragExit = '+
'onDragExit' ; // Firefox 3.0.x aObserver.onDragExit.toSource().replace(
if (dragExitFunctionName in aObserver) {
eval('aObserver.'+dragExitFunctionName+' = '+
aObserver[dragExitFunctionName].toSource().replace(
/(this.mTabDropIndicatorBar\.[^;]+;)/, /(this.mTabDropIndicatorBar\.[^;]+;)/,
'$1; this.treeStyleTab.clearDropPosition();' '$1; this.treeStyleTab.clearDropPosition();'
) )
@ -437,7 +424,7 @@ var TreeStyleTabService = {
} }
var dropFunctionName = '_onDrop' in aObserver ? var dropFunctionName = '_onDrop' in aObserver ?
'_onDrop' : // Firefox 3.5 or later '_onDrop' : // Firefox 3.5 - 3.6
'onDrop' ; // Firefox 3.0.x 'onDrop' ; // Firefox 3.0.x
if (dropFunctionName in aObserver) { if (dropFunctionName in aObserver) {
eval('aObserver.'+dropFunctionName+' = '+ eval('aObserver.'+dropFunctionName+' = '+
@ -505,7 +492,7 @@ var TreeStyleTabService = {
); );
} }
if ('_onDragEnd' in aObserver) { // Firefox 3.6 or older if ('_onDragEnd' in aObserver) { // Firefox 3.5 - 3.6
eval('aObserver._onDragEnd = '+aObserver._onDragEnd.toSource().replace( eval('aObserver._onDragEnd = '+aObserver._onDragEnd.toSource().replace(
/([^\{\}\(\);]*this\.replaceTabWithWindow\()/, /([^\{\}\(\);]*this\.replaceTabWithWindow\()/,
'if (this.treeStyleTab.isDraggingAllTabs(draggedTab)) return; $1' 'if (this.treeStyleTab.isDraggingAllTabs(draggedTab)) return; $1'
@ -529,41 +516,24 @@ var TreeStyleTabService = {
}, },
destroyTabDNDObserver : function TSTService_destroyTabDNDObserver(aObserver) destroyTabDNDObserver : function TSTService_destroyTabDNDObserver(aObserver)
{ {
var strip = this.getTabStrip(aObserver);
// Firefox 3.5 or later
var useHTML5Events = '_setEffectAllowedForDataTransfer' in aObserver;
if (useHTML5Events) {
strip.removeEventListener('dragstart', this, true);
strip.removeEventListener('dragover', this, true);
strip.removeEventListener('dragleave', this, true);
}
if (aObserver.tabContainer && if (aObserver.tabContainer &&
aObserver.tabContainer.tabbrowser == aObserver) { // Firefox 3.7 or later aObserver.tabContainer.tabbrowser == aObserver) { // Firefox 3.7 or later
aObserver = aObserver.tabContainer; strip.removeEventListener('dragstart', this, true);
aObserver.removeEventListener('dragstart', this, true); strip.removeEventListener('dragover', this, true);
aObserver.removeEventListener('dragover', this, true); strip.removeEventListener('dragleave', this, true);
aObserver.removeEventListener('dragleave', this, true);
aObserver.removeEventListener('drop', this, true);
aObserver.removeEventListener('dragend', this, true);
} }
}, },
onTabbarDragStart : function TSTService_onTabbarDragStart(aEvent, aTabBrowser)
{
var dt = aEvent.dataTransfer;
dt.mozSetDataAt(
this.kDRAG_TYPE_TABBAR,
aEvent.shiftKey ?
this.kTABBAR_MOVE_FORCE :
this.kTABBAR_MOVE_NORMAL,
0
);
dt.mozCursor = 'move';
// var tabbar = aTabBrowser.mTabContainer;
// var box = tabbar.boxObject;
// dt.setDragImage(
// tabbar,
// aEvent.screenX - box.screenX,
// aEvent.screenY - box.screenY
// );
// no feedback image, because it's annoying...
dt.setDragImage(new Image(), 0, 0);
aEvent.stopPropagation();
aTabBrowser.treeStyleTab.tabbarDNDObserver.readyToStartDrag();
},
checkCanTabDrop : function TSTService_checkCanTabDrop(aEvent, aTabBrowser) checkCanTabDrop : function TSTService_checkCanTabDrop(aEvent, aTabBrowser)
{ {
try{ try{
@ -588,6 +558,46 @@ catch(e) {
} }
}, },
onTabDragStart : function TSTService_onTabDragStart(aEvent)
{
var b = this.getTabBrowserFromChild(aEvent.currentTarget);
if (b.treeStyleTab.tabbarDNDObserver.canDragTabbar(aEvent))
b.treeStyleTab.onTabbarDragStart(aEvent, b);
},
onTabbarDragStart : function TSTService_onTabbarDragStart(aEvent, aTabBrowser)
{
var dt = aEvent.dataTransfer;
dt.mozSetDataAt(
this.kDRAG_TYPE_TABBAR,
aEvent.shiftKey ?
this.kTABBAR_MOVE_FORCE :
this.kTABBAR_MOVE_NORMAL,
0
);
dt.mozCursor = 'move';
// var tabbar = aTabBrowser.mTabContainer;
// var box = tabbar.boxObject;
// dt.setDragImage(
// tabbar,
// aEvent.screenX - box.screenX,
// aEvent.screenY - box.screenY
// );
// no feedback image, because it's annoying...
dt.setDragImage(new Image(), 0, 0);
aEvent.stopPropagation();
aTabBrowser.treeStyleTab.tabbarDNDObserver.readyToStartDrag();
},
onTabDragOver : function TSTService_onTabDragOver(aEvent)
{
var b = this.getTabBrowserFromChild(aEvent.currentTarget);
if (b.treeStyleTab.processTabDragOverEvent(aEvent, b)) {
aEvent.stopPropagation();
aEvent.preventDefault(); // this is required to override default dragover actions!
}
},
processTabDragOverEvent : function TSTService_processTabDragOverEvent(aEvent, aTabBrowser) processTabDragOverEvent : function TSTService_processTabDragOverEvent(aEvent, aTabBrowser)
{ {
try{ try{
@ -596,7 +606,6 @@ try{
var info = this.getDropAction(aEvent, session); var info = this.getDropAction(aEvent, session);
// auto-switch for staying on tabs (Firefox 3.0 or later)
var setEffectAllowedFunc; var setEffectAllowedFunc;
var observer = aTabBrowser; var observer = aTabBrowser;
if (aTabBrowser._setEffectAllowedForDataTransfer) { if (aTabBrowser._setEffectAllowedForDataTransfer) {
@ -612,13 +621,14 @@ try{
}; };
} }
// auto-switch for staying on tabs (Firefox 3.0 or later)
if ( if (
setEffectAllowedFunc && setEffectAllowedFunc &&
info.target && info.target &&
!info.target.selected && !info.target.selected &&
( (
('mDragTime' in observer && 'mDragOverDelay' in observer) || ('mDragTime' in observer && 'mDragOverDelay' in observer) || // Firefox 3.6 or older
('_dragTime' in observer && '_dragOverDelay' in observer) ('_dragTime' in observer && '_dragOverDelay' in observer) // Firefox 3.7 or later
) )
) { ) {
let time = observer.mDragTime || observer._dragTime || 0; let time = observer.mDragTime || observer._dragTime || 0;
@ -665,33 +675,15 @@ catch(e) {
} }
}, },
/* tab DND listening for Firefox 3.7 or later */ onTabDragLeave : function TSTService_onTabDragLeave(aEvent)
onTabDNDObserverDragStart : function TSTService_onTabDNDObserverDragStart(aEvent)
{ {
var tabbar = aEvent.currentTarget; var b = this.getTabBrowserFromChild(aEvent.currentTarget);
if (tabbar.treeStyleTab.tabbarDNDObserver.canDragTabbar(aEvent))
tabbar.treeStyleTab.onTabbarDragStart(aEvent, tabbar.tabbrowser);
},
onTabDNDObserverDragOver : function TSTService_onTabDNDObserverDragOver(aEvent)
{
var tabbar = aEvent.currentTarget;
if (tabbar.treeStyleTab.processTabDragOverEvent(aEvent, tabbar.tabbrowser)) {
aEvent.stopPropagation();
aEvent.preventDefault(); // this is required to override default dragover actions!
}
},
onTabDNDObserverDragLeave : function TSTService_onTabDNDObserverDragLeave(aEvent)
{
var tabbar = aEvent.currentTarget;
var tabbarFromEvent = this.getTabbarFromChild(aEvent.relatedTarget); var tabbarFromEvent = this.getTabbarFromChild(aEvent.relatedTarget);
if (!tabbarFromEvent) if (!tabbarFromEvent)
tabbar.treeStyleTab.clearDropPosition(); b.treeStyleTab.clearDropPosition();
}, },
onTabDNDObserverDrop : function TSTService_onTabDNDObserverDrop(aEvent) onTabDrop : function TSTService_onTabDrop(aEvent)
{ {
var tabbar = aEvent.currentTarget; var tabbar = aEvent.currentTarget;
var b = tabbar.tabbrowser; var b = tabbar.tabbrowser;
@ -738,8 +730,10 @@ catch(e) {
return; return;
} }
if (!draggedTab) {
// dropping of urls // dropping of urls
if (!draggedTab) {
aEvent.stopPropagation();
let url; let url;
for (let i = 0; i < tabbar._supportedLinkDropTypes.length; i++) { for (let i = 0; i < tabbar._supportedLinkDropTypes.length; i++) {
let dataType = tabbar._supportedLinkDropTypes[i]; let dataType = tabbar._supportedLinkDropTypes[i];
@ -783,11 +777,10 @@ catch(e) {
catch(e) { catch(e) {
} }
} }
aEvent.stopPropagation();
} }
}, },
onTabDNDObserverDragEnd : function TSTService_onTabDNDObserverDragEnd(aEvent) onTabDragEnd : function TSTService_onTabDragEnd(aEvent)
{ {
var tabbar = aEvent.currentTarget; var tabbar = aEvent.currentTarget;
var b = tabbar.tabbrowser; var b = tabbar.tabbrowser;
@ -1289,12 +1282,13 @@ catch(e) {
return; return;
} }
// tab drag drop listeners for Firefox 3.7 or later // Firefox 3.5 or later
case 'dragstart': return this.onTabDNDObserverDragStart(aEvent); case 'dragstart': return this.onTabDragStart(aEvent);
case 'dragover': return this.onTabDNDObserverDragOver(aEvent); case 'dragover': return this.onTabDragOver(aEvent);
case 'dragleave': return this.onTabDNDObserverDragLeave(aEvent); case 'dragleave': return this.onTabDragLeave(aEvent);
case 'drop': return this.onTabDNDObserverDrop(aEvent); // Firefox 3.7 or later
case 'dragend': return this.onTabDNDObserverDragEnd(aEvent); case 'drop': return this.onTabDrop(aEvent);
case 'dragend': return this.onTabDragEnd(aEvent);
} }
}, },

View File

@ -662,6 +662,9 @@ var TreeStyleTabUtils = {
getTabStrip : function TSTUtils_getTabStrip(aTabBrowser) getTabStrip : function TSTUtils_getTabStrip(aTabBrowser)
{ {
if (!(aTabBrowser instanceof Ci.nsIDOMElement))
return null;
var strip = aTabBrowser.mStrip; var strip = aTabBrowser.mStrip;
return (strip && strip.localName == 'hbox') ? return (strip && strip.localName == 'hbox') ?
strip : strip :
@ -810,6 +813,9 @@ var TreeStyleTabUtils = {
if (aTabBrowserChild.tabbrowser) // tabs, Firefox 3.7 or later if (aTabBrowserChild.tabbrowser) // tabs, Firefox 3.7 or later
return aTabBrowserChild.tabbrowser; return aTabBrowserChild.tabbrowser;
if (aTabBrowserChild.id == 'TabsToolbar') // tabs toolbar, Firefox 3.7 or later
return aTabBrowserChild.getElementsByTagName('tabs')[0].tabbrowser;
var b = this.evaluateXPath( var b = this.evaluateXPath(
'ancestor::xul:tabbrowser | '+ 'ancestor::xul:tabbrowser | '+
'ancestor::xul:tabs[@tabbrowser]', 'ancestor::xul:tabs[@tabbrowser]',