diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index 8ce920fa..fe05f761 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -343,6 +343,10 @@ var TreeStyleTabService = { updateTabDNDObserver : function TSTService_updateTabDNDObserver(aObserver) { + if (aObserver.tabContainer && + aObserver.tabContainer.tabbrowser == aObserver) + aObserver = aObserver.tabContainer; + if ('_onDragStart' in aObserver) { // Firefox 3.5 or later eval('aObserver._onDragStart = '+ aObserver._onDragStart.toSource().replace( @@ -355,7 +359,7 @@ var TreeStyleTabService = { ) ); } - else { // Firefox 3.0.x + else if ('onDragStart' in aObserver) { // Firefox 3.0.x eval('aObserver.onDragStart = '+ aObserver.onDragStart.toSource().replace( // native 'aEvent.target.localName == "tab"', @@ -372,122 +376,130 @@ var TreeStyleTabService = { var canDropFunctionName = '_setEffectAllowedForDataTransfer' in aObserver ? '_setEffectAllowedForDataTransfer' : // Firefox 3.5 or later 'canDrop' ; // Firefox 3.0.x - eval('aObserver.'+canDropFunctionName+' = '+ - aObserver[canDropFunctionName].toSource().replace( - '{', - '{ var TSTTabBrowser = this;' - ).replace( - /\.screenX/g, '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.positionProp]' - ).replace( - /\.width/g, '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.sizeProp]' - ).replace( - /(return (?:true|dt.effectAllowed = "copyMove");)/, - - ).replace( - /TST_DRAGDROP_DISALLOW_RETRUN_VALUE/g, - (canDropFunctionName == 'canDrop' ? - 'false' : - 'dt.effectAllowed = "none"' + if (canDropFunctionName in aObserver) { + eval('aObserver.'+canDropFunctionName+' = '+ + aObserver[canDropFunctionName].toSource().replace( + '{', + '{ var TSTTabBrowser = this;' + ).replace( + /\.screenX/g, '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.positionProp]' + ).replace( + /\.width/g, '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.sizeProp]' + ).replace( + /(return (?:true|dt.effectAllowed = "copyMove");)/, + + ).replace( + /TST_DRAGDROP_DISALLOW_RETRUN_VALUE/g, + (canDropFunctionName == 'canDrop' ? + 'false' : + 'dt.effectAllowed = "none"' + ) ) - ) - ); + ); + } var dragOverFunctionName = '_onDragOver' in aObserver ? '_onDragOver' : // Firefox 3.5 or later 'onDragOver' ; // Firefox 3.0.x - eval('aObserver.'+dragOverFunctionName+' = '+ - aObserver[dragOverFunctionName].toSource().replace( - '{', - - ) - ); + if (dragOverFunctionName in aObserver) { + eval('aObserver.'+dragOverFunctionName+' = '+ + aObserver[dragOverFunctionName].toSource().replace( + '{', + + ) + ); + } var dragExitFunctionName = '_onDragLeave' in aObserver ? '_onDragLeave' : // Firefox 3.5 or later 'onDragExit' ; // Firefox 3.0.x - eval('aObserver.'+dragExitFunctionName+' = '+ - aObserver[dragExitFunctionName].toSource().replace( - /(this.mTabDropIndicatorBar\.[^;]+;)/, - '$1; this.treeStyleTab.clearDropPosition();' - ) - ); + if (dragExitFunctionName in aObserver) { + eval('aObserver.'+dragExitFunctionName+' = '+ + aObserver[dragExitFunctionName].toSource().replace( + /(this.mTabDropIndicatorBar\.[^;]+;)/, + '$1; this.treeStyleTab.clearDropPosition();' + ) + ); + } var dropFunctionName = '_onDrop' in aObserver ? '_onDrop' : // Firefox 3.5 or later 'onDrop' ; // Firefox 3.0.x - eval('aObserver.'+dropFunctionName+' = '+ - aObserver[dropFunctionName].toSource().replace( - '{', - - ).replace( // Firefox 3.0.x, 3.5 or later - /(if \((accelKeyPressed|isCopy|dropEffect == "copy")\) {)/, - + ).replace( // Firefox 3.0.x, 3.5 or later + /(if \((accelKeyPressed|isCopy|dropEffect == "copy")\) {)/, + + ).replace( // Firefox 3, duplication of tab + /(this.selectedTab = newTab;)(\s*\})?/g, + + ).replace( // Firefox 3, dragging tab from another window + 'else if (draggedTab) {', + + ).replace( + /(this.loadOneTab\([^;]+\));/, + - ).replace( // Firefox 3, duplication of tab - /(this.selectedTab = newTab;)(\s*\})?/g, - - ).replace( // Firefox 3, dragging tab from another window - 'else if (draggedTab) {', - - ).replace( - /(this.loadOneTab\([^;]+\));/, - - ).replace( - 'document.getBindingParent(aEvent.originalTarget).localName != "tab"', - '!TreeStyleTabService.getTabFromEvent(aEvent)' - ).replace( - 'var tab = aEvent.target;', - + ).replace( + 'document.getBindingParent(aEvent.originalTarget).localName != "tab"', + '!TreeStyleTabService.getTabFromEvent(aEvent)' + ).replace( + 'var tab = aEvent.target;', + - ).replace( - /TST_DRAGSESSION/g, - (canDropFunctionName == 'canDrop' ? - 'aDragSession' : - 'TSTTabBrowser.treeStyleTab.getCurrentDragSession()' + ) { + TSTTabBrowser.treeStyleTab.performDrop(dropActionInfo, TSTTabBrowser.loadOneTab(getShortcutOrURI(url), null, null, null, bgLoad, false)); + return; + } + ]]> + ).replace( + /TST_DRAGSESSION/g, + (canDropFunctionName == 'canDrop' ? + 'aDragSession' : + 'TSTTabBrowser.treeStyleTab.getCurrentDragSession()' + ) ) - ) - ); + ); + } }, onTabbarDragStart : function TSTService_onTabbarDragStart(aEvent, aTabBrowser) { diff --git a/content/treestyletab/treestyletabbrowser.js b/content/treestyletab/treestyletabbrowser.js index ed974377..277775c5 100644 --- a/content/treestyletab/treestyletabbrowser.js +++ b/content/treestyletab/treestyletabbrowser.js @@ -158,6 +158,7 @@ TreeStyleTabBrowser.prototype = { this.stopRendering(); var b = this.mTabBrowser; + b.tabContainer.treeStyleTab = this; this._tabsCache = {}; @@ -171,7 +172,7 @@ TreeStyleTabBrowser.prototype = { if (!toggler) { toggler = document.createElement('spacer'); toggler.setAttribute('class', this.kTABBAR_TOGGLER); - this.tabStrip.parentNode.insertBefore(toggler, this.tabStrip); + b.mTabBox.insertBefore(toggler, b.mTabBox.firstChild); } } @@ -350,13 +351,24 @@ TreeStyleTabBrowser.prototype = { this.updateTabDNDObserver(b); - eval('b.getNewIndex = '+ - b.getNewIndex.toSource().replace( - /\.screenX/g, '[this.treeStyleTab.positionProp]' - ).replace( - /\.width/g, '[this.treeStyleTab.sizeProp]' - ) - ); + if (b.tabContainer && '_getDropIndex' in b.tabContainer) { // Firefox 3.7 or later + eval('b.tabContainer._getDropIndex = '+ + b.tabContainer._getDropIndex.toSource().replace( + /\.screenX/g, '[this.treeStyleTab.positionProp]' + ).replace( + /\.width/g, '[this.treeStyleTab.sizeProp]' + ) + ); + } + else if ('getNewIndex' in b) { // Firefox 3.6 or older + eval('b.getNewIndex = '+ + b.getNewIndex.toSource().replace( + /\.screenX/g, '[this.treeStyleTab.positionProp]' + ).replace( + /\.width/g, '[this.treeStyleTab.sizeProp]' + ) + ); + } eval('b.moveTabForward = '+ b.moveTabForward.toSource().replace( @@ -416,6 +428,7 @@ TreeStyleTabBrowser.prototype = { ) ); +/* if ('' in b) { // Firefox 3.7- eval('b._handleKeyEvent = '+ b._handleKeyEvent.toSource().replace( @@ -445,7 +458,7 @@ TreeStyleTabBrowser.prototype = { ) ); } - else if ('_keyEventHandler' in b) { // -Firefox 3.6 + else */if ('_keyEventHandler' in b) { // Firefox 3.6 or older eval('b._keyEventHandler.handleEvent = '+ b._keyEventHandler.handleEvent.toSource().replace( 'this.tabbrowser.moveTabOver(aEvent);', @@ -510,12 +523,14 @@ TreeStyleTabBrowser.prototype = { ) ); - eval('b.onTabBarDblClick = '+ - b.onTabBarDblClick.toSource().replace( - 'aEvent.originalTarget.localName == "box"', - '/^(box|(arrow)?scrollbox|tabs)$/.test(aEvent.originalTarget.localName)' - ) - ); + if ('onTabBarDblClick' in b) { // Firefox 3.6 or older + eval('b.onTabBarDblClick = '+ + b.onTabBarDblClick.toSource().replace( + 'aEvent.originalTarget.localName == "box"', + '/^(box|(arrow)?scrollbox|tabs)$/.test(aEvent.originalTarget.localName)' + ) + ); + } if ('_onDragEnd' in b) { eval('b._onDragEnd = '+b._onDragEnd.toSource().replace( @@ -569,7 +584,8 @@ TreeStyleTabBrowser.prototype = { this.onPrefChange('extensions.treestyletab.tabbar.invertTabContents'); this.onPrefChange('extensions.treestyletab.tabbar.invertClosebox'); - var tabContextMenu = document.getAnonymousElementByAttribute(b, 'anonid', 'tabContextMenu'); + var tabContextMenu = document.getAnonymousElementByAttribute(b, 'anonid', 'tabContextMenu') || + document.getAnonymousElementByAttribute(b.tabContainer, 'anonid', 'tabContextMenu'); tabContextMenu.addEventListener('popupshowing', this, false); if (!('MultipleTabService' in window)) { window.setTimeout(function(aSelf, aTabBrowser, aPopup) { @@ -855,6 +871,7 @@ TreeStyleTabBrowser.prototype = { var strip = this.tabStrip; var splitter = this._ensureNewSplitter(); var toggler = document.getAnonymousElementByAttribute(b, 'class', this.kTABBAR_TOGGLER); + var indicator = b.mTabDropIndicatorBar || b.tabContainer._tabDropIndicator; // Tab Mix Plus var scrollFrame, newTabBox, tabBarMode; @@ -939,7 +956,7 @@ TreeStyleTabBrowser.prototype = { unexpectedly becomes 0 on the startup. so, we have to set the width again. */ strip.setAttribute('width', aSelf.getTreePref('tabbar.width')); - aTabBrowser.mTabDropIndicatorBar.setAttribute('ordinal', 1); + indicator.setAttribute('ordinal', 1); strip.setAttribute('ordinal', 30); aSplitter.setAttribute('ordinal', 20); aToggler.setAttribute('ordinal', 40); @@ -952,7 +969,7 @@ TreeStyleTabBrowser.prototype = { this.setTabbarAttribute(this.kTAB_INVERTED, null, b); this.indentTarget = 'left'; delayedPostProcess = function(aSelf, aTabBrowser, aSplitter, aToggler) { - aTabBrowser.mTabDropIndicatorBar.setAttribute('ordinal', 1); + indicator.setAttribute('ordinal', 1); strip.setAttribute('ordinal', 10); aSplitter.setAttribute('ordinal', 20); aToggler.setAttribute('ordinal', 5); @@ -998,7 +1015,7 @@ TreeStyleTabBrowser.prototype = { this.setTabbarAttribute(this.kTABBAR_POSITION, 'bottom', b); this.indentTarget = 'bottom'; delayedPostProcess = function(aSelf, aTabBrowser, aSplitter, aToggler) { - aTabBrowser.mTabDropIndicatorBar.setAttribute('ordinal', 1); + indicator.setAttribute('ordinal', 1); strip.setAttribute('ordinal', 30); aSplitter.setAttribute('ordinal', 20); aToggler.setAttribute('ordinal', 40); @@ -1009,7 +1026,7 @@ TreeStyleTabBrowser.prototype = { this.setTabbarAttribute(this.kTABBAR_POSITION, 'top', b); this.indentTarget = 'top'; delayedPostProcess = function(aSelf, aTabBrowser, aSplitter, aToggler) { - aTabBrowser.mTabDropIndicatorBar.setAttribute('ordinal', 1); + indicator.setAttribute('ordinal', 1); strip.setAttribute('ordinal', 10); aSplitter.setAttribute('ordinal', 20); aToggler.setAttribute('ordinal', 5); @@ -1158,6 +1175,7 @@ TreeStyleTabBrowser.prototype = { delete this._autoHide; var b = this.mTabBrowser; + delete b.tabContainer.treeStyleTab; this.getTabsArray(b).forEach(function(aTab) { this.destroyTab(aTab); diff --git a/modules/utils.js b/modules/utils.js index e8327ac6..2baac84b 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -789,14 +789,18 @@ var TreeStyleTabUtils = { getTabBrowserFromChild : function TSTUtils_getTabBrowserFromChild(aTabBrowserChild) { - if (!aTabBrowserChild) return null; + if (!aTabBrowserChild) + return null; - if (aTabBrowserChild.__treestyletab__linkedTabBrowser) + if (aTabBrowserChild.__treestyletab__linkedTabBrowser) // tab return aTabBrowserChild.__treestyletab__linkedTabBrowser; - if (aTabBrowserChild.localName == 'tabbrowser') + if (aTabBrowserChild.localName == 'tabbrowser') // itself return aTabBrowserChild; + if (aTabBrowserChild.tabbrowser) // tabs, Firefox 3.7 or later + return aTabBrowserChild.tabbrowser; + var b = this.evaluateXPath( 'ancestor::xul:tabbrowser | '+ 'ancestor::xul:tabs[@tabbrowser]',