2009-08-10 07:31:11 -04:00
var TreeStyleTabService = {
2008-11-09 23:48:11 -05:00
2007-10-21 04:16:10 -04:00
/* API */
2010-03-27 10:52:25 -04:00
changeTabbarPosition : function TSTService _changeTabbarPosition ( aNewPosition ) /* PUBLIC API (obsolete, for backward compatibility) */
2009-04-21 02:42:52 -04:00
{
2011-01-22 10:46:29 -05:00
this . position = aNewPosition ;
2009-04-21 02:42:52 -04:00
} ,
2010-03-27 10:52:25 -04:00
2011-01-22 10:46:29 -05:00
get position ( ) /* PUBLIC API */
2009-12-17 21:46:36 -05:00
{
2011-02-04 05:50:21 -05:00
return this . preInitialized && this . browser . treeStyleTab ?
this . browser . treeStyleTab . position :
this . utils . position ;
2009-12-17 21:46:36 -05:00
} ,
2011-01-22 10:46:29 -05:00
set position ( aValue )
2010-03-24 13:20:30 -04:00
{
if ( 'UndoTabService' in window && UndoTabService . isUndoable ( ) ) {
2011-01-22 10:46:29 -05:00
var current = this . utils . position ;
2010-01-13 02:06:50 -05:00
var self = this ;
UndoTabService . doOperation (
function ( ) {
2011-01-22 10:46:29 -05:00
self . utils . position = aValue ;
2010-03-24 13:20:30 -04:00
} ,
{
label : self . treeBundle . getString ( 'undo_changeTabbarPosition_label' ) ,
name : 'treestyletab-changeTabbarPosition' ,
data : {
oldPosition : current ,
newPosition : aValue
}
2010-01-13 02:06:50 -05:00
}
) ;
}
2011-01-22 10:46:29 -05:00
else {
this . utils . position = aValue ;
}
return aValue ;
} ,
2009-12-25 11:38:14 -05:00
2009-12-25 14:27:34 -05:00
undoChangeTabbarPosition : function TSTService _undoChangeTabbarPosition ( ) /* PUBLIC API */
2009-12-25 11:38:14 -05:00
{
2009-12-25 14:27:34 -05:00
return this . utils . undoChangeTabbarPosition ( ) ;
} ,
redoChangeTabbarPosition : function TSTService _redoChangeTabbarPosition ( ) /* PUBLIC API */
{
return this . utils . redoChangeTabbarPosition ( ) ;
2009-12-18 04:14:02 -05:00
} ,
2009-12-25 12:55:55 -05:00
get treeViewEnabled ( ) /* PUBLIC API */
{
return this . utils . treeViewEnabled ;
} ,
set treeViewEnabled ( aValue )
{
return this . utils . treeViewEnabled = aValue ;
} ,
2009-12-25 13:13:33 -05:00
get useTMPSessionAPI ( ) /* PUBLIC API */
{
return this . utils . useTMPSessionAPI ;
} ,
set useTMPSessionAPI ( aValue )
{
return this . utils . useTMPSessionAPI = aValue ;
} ,
2010-05-08 01:37:41 -04:00
get browser ( )
{
return 'SplitBrowser' in window ? window . SplitBrowser . activeBrowser :
window . gBrowser ;
} ,
2010-05-08 04:30:39 -04:00
get shouldApplyNewPref ( )
{
return window == this . topBrowserWindow && ! this . utils . inWindowDestoructionProcess ;
} ,
2007-10-30 08:58:09 -04:00
2007-11-14 14:34:36 -05:00
/* backward compatibility */
2009-12-25 03:34:52 -05:00
getTempTreeStyleTab : function TSTService _getTempTreeStyleTab ( aTabBrowser )
2007-11-14 14:34:36 -05:00
{
return aTabBrowser . treeStyleTab || new TreeStyleTabBrowser ( aTabBrowser ) ;
} ,
2009-12-25 03:34:52 -05:00
initTabAttributes : function TSTService _initTabAttributes ( aTab , aTabBrowser )
2007-11-14 14:34:36 -05:00
{
2007-11-17 08:32:41 -05:00
var b = aTabBrowser || this . getTabBrowserFromChild ( aTab ) ;
2007-11-14 14:34:36 -05:00
this . getTempTreeStyleTab ( b ) . initTabAttributes ( aTab ) ;
} ,
2009-12-25 03:34:52 -05:00
initTabContents : function TSTService _initTabContents ( aTab , aTabBrowser )
2007-11-14 14:34:36 -05:00
{
2007-11-17 08:32:41 -05:00
var b = aTabBrowser || this . getTabBrowserFromChild ( aTab ) ;
2007-11-14 14:34:36 -05:00
this . getTempTreeStyleTab ( b ) . initTabContents ( aTab ) ;
} ,
2009-12-25 03:34:52 -05:00
initTabContentsOrder : function TSTService _initTabContentsOrder ( aTab , aTabBrowser )
2007-11-14 14:34:36 -05:00
{
2007-11-17 08:32:41 -05:00
var b = aTabBrowser || this . getTabBrowserFromChild ( aTab ) ;
2007-11-14 14:34:36 -05:00
this . getTempTreeStyleTab ( b ) . initTabContentsOrder ( aTab ) ;
} ,
2007-10-16 13:22:28 -04:00
/* Utilities */
2008-03-09 01:36:52 -05:00
2009-12-25 03:34:52 -05:00
stopRendering : function TSTService _stopRendering ( )
2009-12-21 00:33:32 -05:00
{
2009-12-21 05:04:39 -05:00
window [ 'piro.sakura.ne.jp' ] . stopRendering . stop ( ) ;
2009-12-21 00:33:32 -05:00
} ,
2009-12-25 03:34:52 -05:00
startRendering : function TSTService _startRendering ( )
2009-12-21 00:33:32 -05:00
{
2009-12-21 05:04:39 -05:00
window [ 'piro.sakura.ne.jp' ] . stopRendering . start ( ) ;
2009-12-21 00:33:32 -05:00
} ,
2009-12-25 03:34:52 -05:00
getPropertyPixelValue : function TSTService _getPropertyPixelValue ( aElementOrStyle , aProp )
2009-04-07 12:09:17 -04:00
{
var style = aElementOrStyle instanceof Components . interfaces . nsIDOMCSSStyleDeclaration ?
aElementOrStyle :
window . getComputedStyle ( aElementOrStyle , null ) ;
return Number ( style . getPropertyValue ( aProp ) . replace ( /px$/ , '' ) ) ;
} ,
2010-04-21 07:43:13 -04:00
get isToolbarCustomizing ( )
{
2010-09-17 05:34:41 -04:00
var toolbox = window . gToolbox || window . gNavToolbox ;
return toolbox && toolbox . customizing ;
2010-04-21 07:43:13 -04:00
} ,
2010-04-22 04:12:31 -04:00
maxTabbarWidth : function TSTService _maxTabbarWidth ( aWidth , aTabBrowser )
{
aTabBrowser = aTabBrowser || this . browser ;
2010-09-13 05:47:04 -04:00
var windowWidth = window . outerWidth ;
var rootWidth = parseInt ( document . documentElement . getAttribute ( 'width' ) || 0 ) ;
var max = Math . max ( windowWidth , rootWidth ) ;
2010-09-12 23:54:04 -04:00
return Math . max ( 0 , Math . min ( aWidth , max * this . MAX _TABBAR _SIZE _RATIO ) ) ;
2010-04-22 04:12:31 -04:00
} ,
maxTabbarHeight : function TSTService _maxTabbarHeight ( aHeight , aTabBrowser )
{
aTabBrowser = aTabBrowser || this . browser ;
2010-09-13 05:47:04 -04:00
var windowHeight = window . outerHeight ;
var rootHeight = parseInt ( document . documentElement . getAttribute ( 'height' ) || 0 ) ;
var max = Math . max ( windowHeight , rootHeight ) ;
2010-09-12 23:54:04 -04:00
return Math . max ( 0 , Math . min ( aHeight , max * this . MAX _TABBAR _SIZE _RATIO ) ) ;
2010-04-22 04:12:31 -04:00
} ,
2010-12-09 01:05:46 -05:00
2010-12-09 01:18:37 -05:00
shouldOpenSearchResultAsChild : function TSTService _shouldOpenSearchResultAsChild ( aTerm )
2010-12-09 01:05:46 -05:00
{
2011-01-25 10:06:32 -05:00
var mode = this . getTreePref ( 'autoAttach.searchResult' ) ;
2011-01-05 21:15:56 -05:00
if ( mode == this . kSEARCH _RESULT _ATTACH _ALWAYS ) {
2010-12-09 01:19:38 -05:00
return true ;
2011-01-05 21:15:56 -05:00
}
else if ( ! aTerm || mode == this . kSEARCH _RESULT _DO _NOT _ATTACH ) {
2010-12-09 01:18:37 -05:00
return false ;
2011-01-05 21:15:56 -05:00
}
2010-12-09 01:18:37 -05:00
2010-12-09 01:05:46 -05:00
var w = document . commandDispatcher . focusedWindow ;
2010-12-09 01:18:37 -05:00
if ( ! w || w . top != this . browser . contentWindow )
w = this . browser . contentWindow ;
return ( function ( aWindow ) {
2010-12-09 09:33:04 -05:00
if ( ! aWindow || ! ( aWindow instanceof Components . interfaces . nsIDOMWindow ) )
return false ;
var selection = aWindow . getSelection ( ) ;
if ( selection && selection . toString ( ) == aTerm )
2010-12-09 01:18:37 -05:00
return true ;
2010-12-09 09:33:04 -05:00
return aWindow . frames ? Array . slice ( aWindow . frames ) . some ( arguments . callee ) : false ;
2010-12-09 01:18:37 -05:00
} ) ( w ) ;
2010-12-09 01:05:46 -05:00
} ,
2010-12-09 06:13:04 -05:00
kSEARCH _RESULT _DO _NOT _ATTACH : 0 ,
kSEARCH _RESULT _ATTACH _IF _SELECTED : 1 ,
kSEARCH _RESULT _ATTACH _ALWAYS : 2 ,
2009-07-22 00:25:39 -04:00
2007-10-16 13:22:28 -04:00
/* Initializing */
2008-11-09 23:48:11 -05:00
2009-12-25 03:34:52 -05:00
preInit : function TSTService _preInit ( )
2008-02-25 20:14:12 -05:00
{
2008-10-14 00:57:35 -04:00
if ( this . preInitialized ) return ;
this . preInitialized = true ;
2008-02-26 11:24:25 -05:00
window . removeEventListener ( 'DOMContentLoaded' , this , true ) ;
2010-09-12 22:17:38 -04:00
if ( location . href . indexOf ( 'chrome://browser/content/browser.xul' ) != 0 )
return ;
2008-02-25 20:14:12 -05:00
2008-11-09 23:48:11 -05:00
window . addEventListener ( 'SSTabRestoring' , this , true ) ;
2010-09-12 22:17:38 -04:00
var source = window . BrowserStartup . toSource ( ) ;
if ( source . indexOf ( '!MultipleTabService.tearOffSelectedTabsFromRemote()' ) > - 1 ) {
eval ( 'window.BrowserStartup = ' + source . replace (
'!MultipleTabService.tearOffSelectedTabsFromRemote()' ,
'!TreeStyleTabService.tearOffSubtreeFromRemote() && $&'
) ) ;
}
else if ( source . indexOf ( 'gBrowser.swapBrowsersAndCloseOther' ) > - 1 ) {
eval ( 'window.BrowserStartup = ' + source . replace (
'gBrowser.swapBrowsersAndCloseOther(gBrowser.selectedTab, uriToLoad);' ,
'if (!TreeStyleTabService.tearOffSubtreeFromRemote()) { $& }'
) ) ;
2008-12-01 03:30:36 -05:00
}
2008-12-02 23:57:40 -05:00
eval ( 'nsBrowserAccess.prototype.openURI = ' +
nsBrowserAccess . prototype . openURI . toSource ( ) . replace (
/(switch\s*\(aWhere\))/ ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [
2008-12-02 23:57:40 -05:00
if ( aOpener &&
aWhere == Components . interfaces . nsIBrowserDOMWindow . OPEN _NEWTAB ) {
TreeStyleTabService . readyToOpenChildTab ( aOpener ) ;
}
2009-03-26 11:30:00 -04:00
$1 ] ] >
2008-12-02 23:57:40 -05:00
)
) ;
2011-01-25 10:01:37 -05:00
if ( 'BrowserOpenTab' in window ) {
eval ( 'window.BrowserOpenTab = ' +
window . BrowserOpenTab . toSource ( ) . replace (
'gBrowser.loadOneTab(' ,
'gBrowser.treeStyleTab.onBeforeNewTabCommand(); $&'
)
) ;
}
2010-01-14 03:50:10 -05:00
if ( 'undoCloseTab' in window ) {
eval ( 'window.undoCloseTab = ' +
window . undoCloseTab . toSource ( ) . replace (
/(\btab\s*=\s*[^\.]+\.undoCloseTab\([^;]+\);)/ ,
< ! [ CDATA [
gBrowser . _ _treestyletab _ _readyToUndoCloseTab = true ;
$1
tab . _ _treestyletab _ _restoredByUndoCloseTab = true ;
delete gBrowser . _ _treestyletab _ _readyToUndoCloseTab ;
] ] >
)
) ;
}
2008-02-25 20:14:12 -05:00
this . overrideExtensionsPreInit ( ) ; // hacks.js
2009-07-06 11:36:43 -04:00
2009-07-27 03:22:56 -04:00
this . migratePrefs ( ) ;
} ,
preInitialized : false ,
2011-01-25 10:06:32 -05:00
kPREF _VERSION : 7 ,
2009-12-25 03:34:52 -05:00
migratePrefs : function TSTService _migratePrefs ( )
2009-07-27 03:22:56 -04:00
{
2009-07-07 20:09:13 -04:00
// migrate old prefs
2009-07-21 22:22:00 -04:00
var orientalPrefs = [ ] ;
2009-07-27 03:22:56 -04:00
switch ( this . getTreePref ( 'prefsVersion' ) )
2009-07-07 20:09:13 -04:00
{
case 0 :
2009-07-21 22:22:00 -04:00
orientalPrefs = orientalPrefs . concat ( [
2009-07-07 20:09:13 -04:00
'extensions.treestyletab.tabbar.fixed' ,
'extensions.treestyletab.enableSubtreeIndent' ,
'extensions.treestyletab.allowSubtreeCollapseExpand'
2009-07-21 22:22:00 -04:00
] ) ;
case 1 :
orientalPrefs = orientalPrefs . concat ( [
'extensions.treestyletab.tabbar.hideAlltabsButton'
] ) ;
2009-07-24 07:00:53 -04:00
case 2 :
if ( this . getTreePref ( 'urlbar.loadSameDomainToNewChildTab' ) !== null ) {
let value = this . getTreePref ( 'urlbar.loadSameDomainToNewChildTab' ) ;
this . setTreePref ( 'urlbar.loadSameDomainToNewTab' , value ) ;
this . setTreePref ( 'urlbar.loadSameDomainToNewTab.asChild' , value ) ;
if ( value ) this . setTreePref ( 'urlbar.loadDifferentDomainToNewTab' , value ) ;
2009-07-27 03:22:56 -04:00
this . clearTreePref ( 'urlbar.loadSameDomainToNewChildTab' ) ;
}
case 3 :
if ( this . getTreePref ( 'loadDroppedLinkToNewChildTab' ) !== null ) {
this . setTreePref ( 'dropLinksOnTab.behavior' ,
this . getTreePref ( 'loadDroppedLinkToNewChildTab.confirm' ) ?
this . kDROPLINK _ASK :
this . getTreePref ( 'loadDroppedLinkToNewChildTab' ) ?
this . kDROPLINK _NEWTAB :
this . kDROPLINK _LOAD
) ;
this . clearTreePref ( 'loadDroppedLinkToNewChildTab.confirm' ) ;
this . clearTreePref ( 'loadDroppedLinkToNewChildTab' ) ;
}
if ( this . getTreePref ( 'openGroupBookmarkAsTabSubTree' ) !== null ) {
let behavior = 0 ;
if ( this . getTreePref ( 'openGroupBookmarkAsTabSubTree.underParent' ) )
behavior += this . kGROUP _BOOKMARK _USE _DUMMY ;
if ( ! this . getTreePref ( 'openGroupBookmarkBehavior.confirm' ) ) {
2009-07-27 04:37:06 -04:00
behavior += (
this . getTreePref ( 'openGroupBookmarkAsTabSubTree' ) ?
this . kGROUP _BOOKMARK _SUBTREE :
this . getTreePref ( 'browser.tabs.loadFolderAndReplace' ) ?
this . kGROUP _BOOKMARK _REPLACE :
this . kGROUP _BOOKMARK _SEPARATE
) ;
2009-07-27 03:22:56 -04:00
}
this . setTreePref ( 'openGroupBookmark.behavior' , behavior ) ;
this . clearTreePref ( 'openGroupBookmarkBehavior.confirm' ) ;
this . clearTreePref ( 'openGroupBookmarkAsTabSubTree' ) ;
this . clearTreePref ( 'openGroupBookmarkAsTabSubTree.underParent' ) ;
2011-01-22 13:32:04 -05:00
this . setPref ( 'browser.tabs.loadFolderAndReplace' , ! ! ( behavior & this . kGROUP _BOOKMARK _REPLACE ) ) ;
2009-07-24 07:00:53 -04:00
}
2009-12-25 06:19:50 -05:00
case 4 :
[
2009-12-25 06:27:23 -05:00
'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect' ,
'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect.onCurrentTabRemove' ,
'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect.whileFocusMovingByShortcut' ,
'extensions.treestyletab.autoExpandSubTreeOnAppendChild' ,
'extensions.treestyletab.autoExpandSubTreeOnCollapsedChildFocused' ,
'extensions.treestyletab.collapseExpandSubTree.dblclick' ,
'extensions.treestyletab.createSubTree.underParent' ,
2009-12-25 06:19:50 -05:00
'extensions.treestyletab.show.context-item-reloadTabSubTree' ,
'extensions.treestyletab.show.context-item-removeTabSubTree' ,
'extensions.treestyletab.show.context-item-bookmarkTabSubTree' ,
'extensions.multipletab.show.multipletab-selection-item-removeTabSubTree' ,
'extensions.multipletab.show.multipletab-selection-item-createSubTree'
] . forEach ( function ( aPref ) {
var value = this . getPref ( aPref ) ;
if ( value === null ) return ;
this . setPref ( aPref . replace ( 'SubTree' , 'Subtree' ) , value ) ;
this . clearPref ( aPref ) ;
} , this ) ;
2010-07-29 22:39:51 -04:00
case 5 :
let ( behavior = this . getTreePref ( 'openGroupBookmark.behavior' ) ) {
behavior = behavior | 2048 ;
this . setTreePref ( 'openGroupBookmark.behavior' , behavior ) ;
}
2011-01-25 10:06:32 -05:00
case 6 :
let (
general = this . getTreePref ( 'autoAttachNewTabsAsChildren' ) ,
search = this . getTreePref ( 'autoAttachSearchResultAsChildren' )
) {
if ( general !== null )
this . setTreePref ( 'autoAttach' , general ) ;
if ( search !== null )
this . setTreePref ( 'autoAttach.searchResult' , search ) ;
}
2009-07-21 22:22:00 -04:00
default :
orientalPrefs . forEach ( function ( aPref ) {
2009-07-07 20:09:13 -04:00
let value = this . getPref ( aPref ) ;
if ( value === null ) return ;
this . setPref ( aPref + '.horizontal' , value ) ;
this . setPref ( aPref + '.vertical' , value ) ;
2009-07-21 22:22:00 -04:00
this . clearPref ( aPref ) ;
2009-07-07 20:09:13 -04:00
} , this ) ;
break ;
}
2009-07-27 03:22:56 -04:00
this . setTreePref ( 'prefsVersion' , this . kPREF _VERSION ) ;
2009-07-06 11:36:43 -04:00
} ,
2009-12-25 03:34:52 -05:00
init : function TSTService _init ( )
2007-10-16 13:22:28 -04:00
{
if ( ! ( 'gBrowser' in window ) ) return ;
2008-10-14 00:57:35 -04:00
if ( this . initialized ) return ;
this . initialized = true ;
if ( ! this . preInitialized ) {
this . preInit ( ) ;
}
2008-11-09 23:48:11 -05:00
window . removeEventListener ( 'SSTabRestoring' , this , true ) ;
2008-10-14 00:57:35 -04:00
2007-10-16 13:22:28 -04:00
window . removeEventListener ( 'load' , this , false ) ;
2008-02-22 00:01:35 -05:00
window . addEventListener ( 'unload' , this , false ) ;
2009-05-12 14:47:36 -04:00
document . addEventListener ( 'popupshowing' , this , false ) ;
2010-09-10 06:21:26 -04:00
document . addEventListener ( 'popuphiding' , this , true ) ;
2010-11-30 05:05:00 -05:00
document . addEventListener ( this . kEVENT _TYPE _TAB _COLLAPSED _STATE _CHANGED , this , false ) ;
document . addEventListener ( this . kEVENT _TYPE _TABBAR _POSITION _CHANGED , this , false ) ;
document . addEventListener ( this . kEVENT _TYPE _TABBAR _STATE _CHANGED , this , false ) ;
document . addEventListener ( this . kEVENT _TYPE _FOCUS _NEXT _TAB , this , false ) ;
2007-10-22 05:59:43 -04:00
2007-11-14 10:09:47 -05:00
var appcontent = document . getElementById ( 'appcontent' ) ;
appcontent . addEventListener ( 'SubBrowserAdded' , this , false ) ;
appcontent . addEventListener ( 'SubBrowserRemoveRequest' , this , false ) ;
2010-03-24 13:20:30 -04:00
2011-02-03 05:55:28 -05:00
var statusPanel = document . getElementById ( 'statusbar-display' ) ;
if ( statusPanel )
statusPanel . addEventListener ( 'DOMAttrModified' , this , false ) ;
2010-01-13 02:06:50 -05:00
window . addEventListener ( 'UIOperationHistoryUndo:TabbarOperations' , this , false ) ;
window . addEventListener ( 'UIOperationHistoryRedo:TabbarOperations' , this , false ) ;
2007-10-17 09:25:50 -04:00
2007-10-16 13:22:28 -04:00
this . addPrefListener ( this ) ;
2009-09-09 01:08:26 -04:00
this . initUninstallationListener ( ) ;
2009-09-09 00:45:54 -04:00
2008-02-25 20:14:12 -05:00
this . overrideExtensionsOnInitBefore ( ) ; // hacks.js
2007-10-21 11:02:58 -04:00
this . overrideGlobalFunctions ( ) ;
2007-10-16 13:22:28 -04:00
this . initTabBrowser ( gBrowser ) ;
2008-02-25 20:14:12 -05:00
this . overrideExtensionsOnInitAfter ( ) ; // hacks.js
2008-03-03 03:26:51 -05:00
2008-11-09 23:48:11 -05:00
this . processRestoredTabs ( ) ;
2010-05-15 10:05:02 -04:00
this . updateTabsOnTop ( ) ;
2008-11-09 23:48:11 -05:00
2009-07-07 04:30:30 -04:00
this . onPrefChange ( 'extensions.treestyletab.tabbar.autoHide.mode' ) ;
this . onPrefChange ( 'extensions.treestyletab.tabbar.style' ) ;
2009-12-25 06:27:23 -05:00
this . onPrefChange ( 'extensions.treestyletab.autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut' ) ;
2007-10-16 13:22:28 -04:00
} ,
2008-10-14 00:57:35 -04:00
initialized : false ,
2009-12-25 13:13:33 -05:00
initUninstallationListener : function TSTService _initUninstallationListener ( )
2009-09-09 00:45:54 -04:00
{
2010-11-17 11:08:40 -05:00
var namespace = { } ;
Components . utils . import (
2010-12-06 07:04:52 -05:00
'resource://treestyletab-modules/lib/prefs.js' ,
2010-11-17 11:08:40 -05:00
namespace
) ;
var prefs = namespace . prefs ;
namespace = void ( 0 ) ;
2009-09-09 00:45:54 -04:00
var restorePrefs = function ( ) {
if ( ! prefs ) return ;
[
'browser.tabs.loadFolderAndReplace' ,
2010-03-31 06:34:30 -04:00
'browser.tabs.insertRelatedAfterCurrent' ,
'extensions.stm.tabBarMultiRows' // Super Tab Mode
2009-09-09 00:45:54 -04:00
] . forEach ( function ( aPref ) {
var backup = prefs . getPref ( aPref + '.backup' ) ;
if ( backup === null ) return ;
2010-03-25 14:10:18 -04:00
prefs . setPref ( aPref + '.override' , backup ) ; // we have to set to ".override" pref, to avoid unexpectedly reset by the preference listener.
2009-09-09 00:45:54 -04:00
prefs . clearPref ( aPref + '.backup' ) ;
} ) ;
} ;
2009-09-09 01:08:26 -04:00
new window [ 'piro.sakura.ne.jp' ] . UninstallationListener ( {
id : 'treestyletab@piro.sakura.ne.jp' ,
2009-09-09 00:45:54 -04:00
onuninstalled : restorePrefs ,
ondisabled : restorePrefs
} ) ;
} ,
2009-12-25 13:13:33 -05:00
2009-12-25 03:34:52 -05:00
initTabBrowser : function TSTService _initTabBrowser ( aTabBrowser )
2007-10-16 13:22:28 -04:00
{
2007-11-14 14:34:36 -05:00
if ( aTabBrowser . localName != 'tabbrowser' ) return ;
aTabBrowser . treeStyleTab = new TreeStyleTabBrowser ( aTabBrowser ) ;
aTabBrowser . treeStyleTab . init ( ) ;
2007-10-16 13:22:28 -04:00
} ,
2007-10-19 01:27:06 -04:00
2009-12-25 03:34:52 -05:00
updateTabDNDObserver : function TSTService _updateTabDNDObserver ( aObserver )
2007-11-14 07:31:14 -05:00
{
2010-04-08 19:50:08 -04:00
var strip = this . getTabStrip ( aObserver ) ||
gBrowser . mStrip // fallback to the default strip, for Tab Mix Plus;
2010-03-27 10:52:25 -04:00
2010-03-27 11:09:35 -04:00
if ( aObserver . tabContainer &&
2010-08-07 12:15:07 -04:00
aObserver . tabContainer . tabbrowser == aObserver ) { // Firefox 4.0 or later
2010-03-27 11:09:35 -04:00
aObserver = aObserver . tabContainer ;
}
2010-11-29 19:12:22 -05:00
if ( '_setEffectAllowedForDataTransfer' in aObserver ) {
eval ( 'aObserver._setEffectAllowedForDataTransfer = ' +
aObserver . _setEffectAllowedForDataTransfer . toSource ( ) . replace (
2010-03-23 13:58:23 -04:00
'{' ,
2011-02-02 03:58:35 -05:00
'{ var TSTTabBrowser = this instanceof Ci.nsIDOMElement ? this : gBrowser ;'
2010-03-23 13:58:23 -04:00
) . replace (
/\.screenX/g , '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.positionProp]'
) . replace (
/\.width/g , '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.sizeProp]'
) . replace (
/(return (?:true|dt.effectAllowed = "copyMove");)/ ,
< ! [ CDATA [
2010-12-01 10:15:40 -05:00
if ( ! this . treeStyleTab . tabbarDNDObserver . canDropTab ( arguments [ 0 ] ) ) {
2010-11-29 21:00:09 -05:00
return dt . effectAllowed = "none" ;
2010-03-23 13:58:23 -04:00
}
$1
] ] >
2010-06-26 14:28:39 -04:00
) . replace (
'sourceNode.parentNode == this &&' ,
'$& TSTTabBrowser.treeStyleTab.getTabFromEvent(event) == sourceNode &&'
2008-10-01 21:32:31 -04:00
)
2010-03-23 13:58:23 -04:00
) ;
}
2010-03-24 13:20:30 -04:00
} ,
2010-03-24 13:57:49 -04:00
2009-12-25 03:34:52 -05:00
overrideGlobalFunctions : function TSTService _overrideGlobalFunctions ( )
2007-10-21 11:02:58 -04:00
{
2010-04-30 00:49:00 -04:00
window . _ _treestyletab _ _BrowserCustomizeToolbar = window . BrowserCustomizeToolbar ;
window . BrowserCustomizeToolbar = function ( ) {
TreeStyleTabService . destroyToolbarItems ( ) ;
window . _ _treestyletab _ _BrowserCustomizeToolbar . call ( window ) ;
} ;
2008-09-26 10:13:29 -04:00
2009-05-13 02:09:17 -04:00
let ( toolbox ) {
2009-07-24 04:11:05 -04:00
toolbox = document . getElementById ( 'navigator-toolbox' ) ;
2009-05-13 02:09:17 -04:00
if ( toolbox . customizeDone ) {
toolbox . _ _treestyletab _ _customizeDone = toolbox . customizeDone ;
toolbox . customizeDone = function ( aChanged ) {
this . _ _treestyletab _ _customizeDone ( aChanged ) ;
2010-04-30 00:49:00 -04:00
TreeStyleTabService . initToolbarItems ( ) ;
2009-05-13 02:09:17 -04:00
} ;
}
if ( 'BrowserToolboxCustomizeDone' in window ) {
window . _ _treestyletab _ _BrowserToolboxCustomizeDone = window . BrowserToolboxCustomizeDone ;
window . BrowserToolboxCustomizeDone = function ( aChanged ) {
window . _ _treestyletab _ _BrowserToolboxCustomizeDone . apply ( window , arguments ) ;
2010-04-30 00:49:00 -04:00
TreeStyleTabService . initToolbarItems ( ) ;
2009-05-13 02:09:17 -04:00
} ;
}
2010-04-30 00:49:00 -04:00
this . initToolbarItems ( ) ;
2009-05-13 02:09:17 -04:00
toolbox = null ;
2008-09-26 10:13:29 -04:00
}
2009-04-27 21:32:01 -04:00
2007-10-26 07:24:59 -04:00
2007-10-21 11:02:58 -04:00
eval ( 'nsContextMenu.prototype.openLinkInTab = ' +
nsContextMenu . prototype . openLinkInTab . toSource ( ) . replace (
'{' ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [ $ &
2008-02-26 20:26:38 -05:00
TreeStyleTabService . readyToOpenChildTab ( this . target . ownerDocument . defaultView ) ;
2009-03-26 11:30:00 -04:00
] ] >
2007-10-21 11:02:58 -04:00
)
) ;
eval ( 'nsContextMenu.prototype.openFrameInTab = ' +
nsContextMenu . prototype . openFrameInTab . toSource ( ) . replace (
'{' ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [ $ &
2008-02-26 20:26:38 -05:00
TreeStyleTabService . readyToOpenChildTab ( this . target . ownerDocument . defaultView ) ;
2009-03-26 11:30:00 -04:00
] ] >
2007-10-21 11:02:58 -04:00
)
) ;
2008-11-06 23:38:21 -05:00
var viewImageMethod = ( 'viewImage' in nsContextMenu . prototype ) ? 'viewImage' : 'viewMedia' ;
eval ( 'nsContextMenu.prototype.' + viewImageMethod + ' = ' +
nsContextMenu . prototype [ viewImageMethod ] . toSource ( ) . replace (
2007-10-22 18:45:35 -04:00
'openUILink(' ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [
2007-10-22 18:45:35 -04:00
if ( String ( whereToOpenLink ( e , false , true ) ) . indexOf ( 'tab' ) == 0 )
TreeStyleTabService . readyToOpenChildTab ( this . target . ownerDocument . defaultView ) ;
2009-03-26 11:30:00 -04:00
$ & ] ] >
2007-10-22 18:45:35 -04:00
)
) ;
eval ( 'nsContextMenu.prototype.viewBGImage = ' +
nsContextMenu . prototype . viewBGImage . toSource ( ) . replace (
'openUILink(' ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [
2007-10-22 18:45:35 -04:00
if ( String ( whereToOpenLink ( e , false , true ) ) . indexOf ( 'tab' ) == 0 )
TreeStyleTabService . readyToOpenChildTab ( this . target . ownerDocument . defaultView ) ;
2009-03-26 11:30:00 -04:00
$ & ] ] >
2007-10-22 18:45:35 -04:00
)
) ;
eval ( 'nsContextMenu.prototype.addDictionaries = ' +
nsContextMenu . prototype . addDictionaries . toSource ( ) . replace (
'openUILinkIn(' ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [
2007-10-22 18:45:35 -04:00
if ( where . indexOf ( 'tab' ) == 0 )
TreeStyleTabService . readyToOpenChildTab ( this . target . ownerDocument . defaultView ) ;
2009-03-26 11:30:00 -04:00
$ & ] ] >
2007-10-22 18:45:35 -04:00
)
) ;
2007-10-21 11:02:58 -04:00
2011-01-05 21:46:20 -05:00
if ( 'BrowserSearch' in window &&
'loadSearch' in BrowserSearch ) {
eval ( 'BrowserSearch.loadSearch = ' +
BrowserSearch . loadSearch . toSource ( ) . replace (
'if (useNewTab) {' ,
< ! [ CDATA [ $ &
if ( TreeStyleTabService . shouldOpenSearchResultAsChild ( arguments [ 0 ] ) )
TreeStyleTabService . readyToOpenChildTab ( ) ;
] ] >
)
) ;
}
2009-04-27 21:32:01 -04:00
this . _splitFunctionNames ( < ! [ CDATA [
window . duplicateTab . handleLinkClick
window . _ _treestyletab _ _highlander _ _origHandleLinkClick
window . _ _splitbrowser _ _handleLinkClick
window . _ _ctxextensions _ _handleLinkClick
window . handleLinkClick
] ] > ) . some ( function ( aFunc ) {
2009-05-13 02:09:17 -04:00
let source = this . _getFunctionSource ( aFunc ) ;
2009-04-28 00:55:59 -04:00
if ( ! source || ! /^\(?function handleLinkClick/ . test ( source ) )
2009-04-27 21:32:01 -04:00
return false ;
2010-11-29 19:42:22 -05:00
eval ( aFunc + ' = ' + source . replace ( // for Firefox 3.5 - Firefox 3.6
2009-04-27 21:32:01 -04:00
/(openNewTabWith\()/g ,
< ! [ CDATA [
2010-11-17 11:08:40 -05:00
if ( ! TreeStyleTabService . checkToOpenChildTab ( event . target . ownerDocument . defaultView ) )
TreeStyleTabService . readyToOpenChildTab ( event . target . ownerDocument . defaultView ) ;
2009-04-27 21:32:01 -04:00
$1 ] ] >
2010-10-24 22:36:47 -04:00
) . replace ( // for Firefox 4.0-
2011-01-04 20:35:11 -05:00
/(charset\s*:\s*doc\.characterSet\s*)/ ,
'$1, event : event, linkNode : linkNode'
2009-04-27 21:32:01 -04:00
) ) ;
2009-05-13 02:09:17 -04:00
source = null ;
2009-04-27 21:32:01 -04:00
return true ;
} , this ) ;
2010-10-24 22:36:47 -04:00
// for Firefox 4.0-
if ( 'openLinkIn' in window ) {
eval ( 'window.openLinkIn = ' +
window . openLinkIn . toSource ( ) . replace (
'browser.loadOneTab(' ,
< ! [ CDATA [
2010-10-25 20:35:09 -04:00
if ( params . linkNode &&
! TreeStyleTabService . checkToOpenChildTab ( params . linkNode . ownerDocument . defaultView ) )
2010-10-24 22:36:47 -04:00
TreeStyleTabService . readyToOpenChildTab ( params . linkNode . ownerDocument . defaultView ) ;
$ & ] ] > . toString ( )
)
) ;
}
2009-04-27 21:32:01 -04:00
this . _splitFunctionNames ( < ! [ CDATA [
window . permaTabs . utils . wrappedFunctions [ "window.contentAreaClick" ]
window . _ _contentAreaClick
window . _ _ctxextensions _ _contentAreaClick
window . contentAreaClick
] ] > ) . forEach ( function ( aFunc ) {
2009-05-13 02:09:17 -04:00
let source = this . _getFunctionSource ( aFunc ) ;
2009-04-28 00:55:59 -04:00
if ( ! source || ! /^\(?function contentAreaClick/ . test ( source ) )
2009-04-27 21:32:01 -04:00
return ;
eval ( aFunc + ' = ' + source . replace (
2010-09-18 11:42:11 -04:00
// for Tab Utilities, etc. Some addons insert openNewTabWith() to the function.
// (calls for the function is not included by Firefox default.)
/(openNewTabWith\()/g ,
< ! [ CDATA [
if ( ! TreeStyleTabService . checkToOpenChildTab ( event . target . ownerDocument . defaultView ) ) TreeStyleTabService . readyToOpenChildTab ( event . target . ownerDocument . defaultView ) ;
$1 ] ] >
2009-04-27 21:32:01 -04:00
) ) ;
2009-05-13 02:09:17 -04:00
source = null ;
2009-04-27 21:32:01 -04:00
} , this ) ;
this . _splitFunctionNames ( < ! [ CDATA [
window . duplicateTab . gotoHistoryIndex
window . duplicateTab . BrowserBack
window . duplicateTab . BrowserForward
window . _ _rewindforward _ _BrowserForward
window . _ _rewindforward _ _BrowserBack
window . gotoHistoryIndex
window . BrowserForward
window . BrowserBack
2010-09-20 07:01:20 -04:00
window . BrowserReloadOrDuplicate
2009-04-27 21:32:01 -04:00
] ] > ) . forEach ( function ( aFunc ) {
2009-05-13 02:09:17 -04:00
let source = this . _getFunctionSource ( aFunc ) ;
2009-04-28 00:55:59 -04:00
if ( ! source || ! /^\(?function (gotoHistoryIndex|BrowserForward|BrowserBack)/ . test ( source ) )
2009-04-27 21:32:01 -04:00
return ;
eval ( aFunc + ' = ' + source . replace (
2010-09-20 07:01:20 -04:00
/((?:openUILinkIn|duplicateTabIn)\()/g ,
2009-04-27 21:32:01 -04:00
< ! [ CDATA [
if ( where == 'tab' || where == 'tabshifted' )
TreeStyleTabService . readyToOpenChildTab ( ) ;
$1 ] ] >
) ) ;
2009-05-13 02:09:17 -04:00
source = null ;
2009-04-27 21:32:01 -04:00
} , this ) ;
this . _splitFunctionNames ( < ! [ CDATA [
permaTabs . utils . wrappedFunctions [ "window.BrowserHomeClick" ]
window . BrowserHomeClick
window . BrowserGoHome
] ] > ) . forEach ( function ( aFunc ) {
2009-05-13 02:09:17 -04:00
let source = this . _getFunctionSource ( aFunc ) ;
2009-04-28 00:55:59 -04:00
if ( ! source || ! /^\(?function (BrowserHomeClick|BrowserGoHome)/ . test ( source ) )
2009-04-27 21:32:01 -04:00
return ;
eval ( aFunc + ' = ' + source . replace (
'gBrowser.loadTabs(' ,
< ! [ CDATA [
TreeStyleTabService . readyToOpenNewTabGroup ( gBrowser ) ;
$ & ] ] >
) ) ;
2009-05-13 02:09:17 -04:00
source = null ;
2009-04-27 21:32:01 -04:00
} , this ) ;
2007-10-22 18:45:35 -04:00
eval ( 'FeedHandler.loadFeed = ' +
FeedHandler . loadFeed . toSource ( ) . replace (
'openUILink(' ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [
2007-10-22 18:45:35 -04:00
if ( String ( whereToOpenLink ( event , false , true ) ) . indexOf ( 'tab' ) == 0 )
TreeStyleTabService . readyToOpenChildTab ( gBrowser ) ;
2009-03-26 11:30:00 -04:00
$ & ] ] >
2007-10-22 18:45:35 -04:00
)
) ;
2008-06-17 07:57:29 -04:00
// Firefox 3 full screen
2009-07-30 20:02:01 -04:00
eval ( 'FullScreen._animateUp = ' +
FullScreen . _animateUp . toSource ( ) . replace (
2010-11-01 13:06:53 -04:00
// Firefox 3.6 or older
2010-03-30 22:21:18 -04:00
/(gBrowser\.mStrip\.boxObject\.height)/ ,
2011-01-22 10:46:29 -05:00
'((gBrowser.treeStyleTab.position != "top") ? 0 : $1)'
2009-07-30 20:02:01 -04:00
)
) ;
eval ( 'FullScreen.mouseoverToggle = ' +
2010-03-27 10:52:25 -04:00
FullScreen . mouseoverToggle . toSource ( ) . replace (
2010-08-07 12:15:07 -04:00
// Firefox 4.0 or later
2010-03-27 10:52:25 -04:00
'this._isChromeCollapsed = !aShow;' ,
2010-12-03 09:50:42 -05:00
'gBrowser.treeStyleTab.updateFloatingTabbar(gBrowser.treeStyleTab.kTABBAR_UPDATE_BY_FULLSCREEN); $&'
2010-03-27 10:52:25 -04:00
) . replace (
2010-03-27 09:07:31 -04:00
// Firefox 3.6 or older
2009-07-30 20:02:01 -04:00
'gBrowser.mStrip.setAttribute("moz-collapsed", !aShow);' ,
2011-01-22 10:46:29 -05:00
'if (gBrowser.treeStyleTab.position == "top") { $& }'
2009-07-30 20:02:01 -04:00
)
) ;
eval ( 'FullScreen.toggle = ' +
FullScreen . toggle . toSource ( ) . replace (
'{' ,
< ! [ CDATA [ {
var treeStyleTab = gBrowser . treeStyleTab ;
2011-01-22 10:46:29 -05:00
if ( treeStyleTab . position != 'top' ) {
2009-07-30 20:02:01 -04:00
if ( window . fullScreen )
2009-09-03 02:24:06 -04:00
treeStyleTab . autoHide . endForFullScreen ( ) ;
2009-07-30 20:02:01 -04:00
else
2009-09-03 02:24:06 -04:00
treeStyleTab . autoHide . startForFullScreen ( ) ;
2009-07-30 20:02:01 -04:00
}
] ] >
)
) ;
2009-08-25 03:20:56 -04:00
2010-03-28 14:22:15 -04:00
if ( 'PrintUtils' in window ) {
eval ( 'PrintUtils.printPreview = ' + PrintUtils . printPreview . toSource ( ) . replace (
'{' ,
'{ TreeStyleTabService.onPrintPreviewEnter();'
) ) ;
eval ( 'PrintUtils.exitPrintPreview = ' + PrintUtils . exitPrintPreview . toSource ( ) . replace (
2010-12-03 01:20:26 -05:00
'{' ,
'{ TreeStyleTabService.onPrintPreviewExit();'
2010-03-28 14:22:15 -04:00
) ) ;
}
2010-06-27 00:01:15 -04:00
if ( 'TabsOnTop' in window && TabsOnTop . syncCommand ) {
eval ( 'TabsOnTop.syncCommand = ' + TabsOnTop . syncCommand . toSource ( ) . replace (
/(\}\)?)$/ ,
'gBrowser.treeStyleTab.onTabsOnTopSyncCommand(enabled); $&'
) ) ;
}
2010-12-06 02:20:08 -05:00
if ( 'toggleSidebar' in window ) {
eval ( 'window.toggleSidebar = ' +
window . toggleSidebar . toSource ( ) . replace (
'{' ,
'{ gBrowser.treeStyleTab.updateFloatingTabbar(gBrowser.treeStyleTab.kTABBAR_UPDATE_BY_WINDOW_RESIZE);'
)
) ;
}
2007-10-21 11:02:58 -04:00
} ,
2009-12-25 03:34:52 -05:00
_splitFunctionNames : function TSTService _ _splitFunctionNames ( aString )
2009-04-27 21:32:01 -04:00
{
return String ( aString )
. split ( /\s+/ )
. map ( function ( aString ) {
return aString
. replace ( /\/\*.*\*\//g , '' )
. replace ( /\/\/.+$/ , '' )
. replace ( /^\s+|\s+$/g , '' ) ;
} ) ;
} ,
2009-12-25 03:34:52 -05:00
_getFunctionSource : function TSTService _ _getFunctionSource ( aFunc )
2009-04-27 21:32:01 -04:00
{
var func ;
try {
eval ( 'func = ' + aFunc ) ;
}
catch ( e ) {
return null ;
}
return func ? func . toSource ( ) : null ;
} ,
2008-09-26 10:13:29 -04:00
2010-04-30 00:49:00 -04:00
initToolbarItems : function TSTService _initToolbarItems ( )
2008-09-26 10:13:29 -04:00
{
2010-12-09 01:05:46 -05:00
var searchbar = document . getElementById ( 'searchbar' ) ;
if ( searchbar &&
searchbar . doSearch &&
searchbar . doSearch . toSource ( ) . toSource ( ) . indexOf ( 'TreeStyleTabService' ) < 0 ) {
eval ( 'searchbar.doSearch = ' + searchbar . doSearch . toSource ( ) . replace (
/(openUILinkIn\(.+?\);)/ ,
< ! [ CDATA [
2010-12-09 01:18:37 -05:00
if ( TreeStyleTabService . shouldOpenSearchResultAsChild ( arguments [ 0 ] ) )
2010-12-09 01:05:46 -05:00
TreeStyleTabService . readyToOpenChildTab ( ) ;
$1
TreeStyleTabService . stopToOpenChildTab ( ) ;
] ] > . toString ( )
) ) ;
}
2010-08-07 12:15:07 -04:00
// for Firefox 4.0 or later
2010-04-30 00:49:00 -04:00
this . updateAllTabsButton ( gBrowser ) ;
} ,
destroyToolbarItems : function TSTService _destroyToolbarItems ( )
{
2010-08-07 12:15:07 -04:00
// Firefox 4.0 or later (restore original position)
2010-04-30 00:49:00 -04:00
var allTabsButton = document . getElementById ( 'alltabs-button' ) ;
if ( allTabsButton && allTabsButton . hasChildNodes ( ) )
allTabsButton . firstChild . setAttribute ( 'position' , 'after_end' ) ;
} ,
updateAllTabsButton : function TSTService _updateAllTabsButton ( aTabBrowser )
{
aTabBrowser = aTabBrowser || this . browser ;
2010-08-07 12:15:07 -04:00
var allTabsButton = document . getElementById ( 'alltabs-button' ) || // Firefox 4.0 or later
2010-04-30 00:49:00 -04:00
document . getAnonymousElementByAttribute ( aTabBrowser . mTabContainer , 'class' , 'tabs-alltabs-button' ) || // Firefox 3.6 or older
( // Tab Mix Plus
this . getTreePref ( 'compatibility.TMP' ) &&
document . getAnonymousElementByAttribute ( aTabBrowser . mTabContainer , 'anonid' , 'alltabs-button' )
) ;
if ( allTabsButton && allTabsButton . hasChildNodes ( ) && aTabBrowser . treeStyleTab )
allTabsButton . firstChild . setAttribute ( 'position' , aTabBrowser . treeStyleTab . isVertical ? 'before_start' : 'after_end' ) ;
} ,
updateAllTabsPopup : function TSTService _updateAllTabsPopup ( aEvent )
{
if ( ! this . getTreePref ( 'enableSubtreeIndent.allTabsPopup' ) ) return ;
var items = Array . slice ( aEvent . originalTarget . childNodes ) ;
2010-04-30 00:49:51 -04:00
var firstItemIndex = 0 ;
2010-09-14 02:56:55 -04:00
// ignore menu items inserted by Weave (Firefox Sync), Tab Utilities, and others.
items . forEach ( function ( aItem , aIndex ) {
if (
aItem . getAttribute ( 'anonid' ) ||
aItem . id ||
aItem . hidden ||
aItem . localName != 'menuitem'
)
firstItemIndex = aIndex + 1 ;
} ) ;
items = items . slice ( firstItemIndex ) ;
2010-04-30 00:49:51 -04:00
2010-04-30 00:49:00 -04:00
var b = this . getTabBrowserFromChild ( aEvent . originalTarget ) || gBrowser ;
this . getTabsArray ( b ) . forEach ( function ( aTab , aIndex ) {
items [ aIndex ] . style . paddingLeft = aTab . getAttribute ( this . kNEST ) + 'em' ;
} , this ) ;
2008-09-26 10:13:29 -04:00
} ,
2011-02-03 05:55:28 -05:00
updateStatusPanel : function TSTService _updateStatusPanel ( aPanel )
{
2011-02-03 19:59:05 -05:00
if ( ! this . getTreePref ( 'autoRepositionStatusPanel' ) )
return ;
2011-02-03 05:55:28 -05:00
switch ( this . position )
{
case 'left' :
aPanel . setAttribute ( 'mirror' , true ) ;
break ;
case 'right' :
aPanel . removeAttribute ( 'mirror' ) ;
break ;
default :
break ;
}
} ,
2008-10-14 13:48:19 -04:00
2009-12-25 03:34:52 -05:00
destroy : function TSTService _destroy ( )
2007-10-16 13:22:28 -04:00
{
2010-05-08 04:30:39 -04:00
this . utils . inWindowDestoructionProcess = true ;
try {
window . removeEventListener ( 'unload' , this , false ) ;
2007-11-08 09:24:54 -05:00
2010-05-08 04:30:39 -04:00
gBrowser . treeStyleTab . saveCurrentState ( ) ;
this . destroyTabBrowser ( gBrowser ) ;
2007-10-16 13:22:28 -04:00
2010-05-08 04:30:39 -04:00
this . endListenKeyEventsFor ( this . LISTEN _FOR _AUTOHIDE ) ;
this . endListenKeyEventsFor ( this . LISTEN _FOR _AUTOEXPAND _BY _FOCUSCHANGE ) ;
2008-03-08 03:57:17 -05:00
2010-05-08 04:30:39 -04:00
document . removeEventListener ( 'popupshowing' , this , false ) ;
2010-09-10 06:21:26 -04:00
document . removeEventListener ( 'popuphiding' , this , true ) ;
2010-11-30 05:05:00 -05:00
document . removeEventListener ( this . kEVENT _TYPE _TAB _COLLAPSED _STATE _CHANGED , this , false ) ;
document . removeEventListener ( this . kEVENT _TYPE _TABBAR _POSITION _CHANGED , this , false ) ;
document . removeEventListener ( this . kEVENT _TYPE _TABBAR _STATE _CHANGED , this , false ) ;
document . removeEventListener ( this . kEVENT _TYPE _FOCUS _NEXT _TAB , this , false ) ;
2010-11-30 20:23:54 -05:00
this . _tabFocusAllowance . forEach ( function ( aListener ) {
2010-11-30 05:05:00 -05:00
window . removeEventListener ( this . kEVENT _TYPE _FOCUS _NEXT _TAB , aListener , false ) ;
} , this ) ;
2007-10-22 05:59:43 -04:00
2010-05-08 04:30:39 -04:00
var appcontent = document . getElementById ( 'appcontent' ) ;
appcontent . removeEventListener ( 'SubBrowserAdded' , this , false ) ;
appcontent . removeEventListener ( 'SubBrowserRemoveRequest' , this , false ) ;
2010-03-24 13:20:30 -04:00
2011-02-03 05:55:28 -05:00
var statusPanel = document . getElementById ( 'statusbar-display' ) ;
if ( statusPanel )
statusPanel . removeEventListener ( 'DOMAttrModified' , this , false ) ;
2010-05-08 04:30:39 -04:00
window . removeEventListener ( 'UIOperationHistoryUndo:TabbarOperations' , this , false ) ;
window . removeEventListener ( 'UIOperationHistoryRedo:TabbarOperations' , this , false ) ;
2007-10-16 13:22:28 -04:00
2010-05-08 04:30:39 -04:00
this . removePrefListener ( this ) ;
this . ObserverService . removeObserver ( this , 'sessionstore-windows-restored' ) ;
}
catch ( e ) {
throw e ;
}
finally {
this . utils . inWindowDestoructionProcess = false ;
}
2007-10-16 13:22:28 -04:00
} ,
2008-11-09 23:48:11 -05:00
2009-12-25 03:34:52 -05:00
destroyTabBrowser : function TSTService _destroyTabBrowser ( aTabBrowser )
2007-10-16 13:22:28 -04:00
{
2007-11-14 14:34:36 -05:00
if ( aTabBrowser . localName != 'tabbrowser' ) return ;
aTabBrowser . treeStyleTab . destroy ( ) ;
delete aTabBrowser . treeStyleTab ;
2007-10-16 13:22:28 -04:00
} ,
/* Event Handling */
2008-09-26 10:13:29 -04:00
2009-12-25 03:34:52 -05:00
handleEvent : function TSTService _handleEvent ( aEvent )
2007-10-16 13:22:28 -04:00
{
switch ( aEvent . type )
{
2008-02-25 20:14:12 -05:00
case 'DOMContentLoaded' :
2010-05-08 04:30:39 -04:00
return this . preInit ( ) ;
2008-02-25 20:14:12 -05:00
2007-10-16 13:22:28 -04:00
case 'load' :
2010-09-16 06:46:15 -04:00
return this . init ( ) ;
2007-10-16 13:22:28 -04:00
case 'unload' :
2010-05-08 04:30:39 -04:00
return this . destroy ( ) ;
2007-10-16 13:22:28 -04:00
2008-11-09 23:48:11 -05:00
case 'SSTabRestoring' :
2010-05-08 04:30:39 -04:00
return this . onTabRestored ( aEvent ) ;
2008-11-09 23:48:11 -05:00
2007-10-16 13:22:28 -04:00
case 'popupshowing' :
2010-09-10 06:21:26 -04:00
this . onPopupShown ( aEvent . originalTarget ) ;
2010-04-30 00:49:00 -04:00
if ( ( aEvent . originalTarget . getAttribute ( 'anonid' ) || aEvent . originalTarget . id ) == 'alltabs-popup' )
this . updateAllTabsPopup ( aEvent ) ;
2009-05-12 14:47:36 -04:00
return ;
case 'popuphiding' :
2010-09-10 06:21:26 -04:00
return this . onPopupHidden ( aEvent . originalTarget ) ;
2007-10-17 09:25:50 -04:00
2011-02-03 05:55:28 -05:00
case 'DOMAttrModified' :
if ( aEvent . attrName == 'label' )
this . updateStatusPanel ( aEvent . currentTarget ) ;
return ;
2010-11-30 05:05:00 -05:00
case this . kEVENT _TYPE _TAB _COLLAPSED _STATE _CHANGED :
2010-04-06 09:38:05 -04:00
return this . updateAeroPeekPreviews ( ) ;
2010-11-30 05:05:00 -05:00
case this . kEVENT _TYPE _TABBAR _POSITION _CHANGED :
case this . kEVENT _TYPE _TABBAR _STATE _CHANGED :
2010-05-15 10:05:02 -04:00
return this . updateTabsOnTop ( ) ;
2010-11-30 05:05:00 -05:00
case this . kEVENT _TYPE _FOCUS _NEXT _TAB :
return this . onFocusNextTab ( aEvent ) ;
2008-03-08 03:57:17 -05:00
case 'keydown' :
2010-05-08 04:30:39 -04:00
return this . onKeyDown ( aEvent ) ;
2008-03-08 03:57:17 -05:00
case 'keyup' :
case 'keypress' :
2010-05-08 04:30:39 -04:00
return this . onKeyRelease ( aEvent ) ;
2008-03-08 03:57:17 -05:00
2010-09-12 23:54:04 -04:00
case 'mousedown' :
return this . onTabbarResizeStart ( aEvent ) ;
case 'mouseup' :
return this . onTabbarResizeEnd ( aEvent ) ;
case 'mousemove' :
return this . onTabbarResizing ( aEvent ) ;
case 'dblclick' :
return this . onTabbarReset ( aEvent ) ;
2007-10-17 09:25:50 -04:00
case 'SubBrowserAdded' :
2010-05-08 04:30:39 -04:00
return this . initTabBrowser ( aEvent . originalTarget . browser ) ;
2007-10-17 09:25:50 -04:00
case 'SubBrowserRemoveRequest' :
2010-05-08 04:30:39 -04:00
return this . destroyTabBrowser ( aEvent . originalTarget . browser ) ;
2010-01-13 02:06:50 -05:00
case 'UIOperationHistoryUndo:TabbarOperations' :
switch ( aEvent . entry . name )
{
case 'treestyletab-changeTabbarPosition' :
2011-01-22 10:46:29 -05:00
this . position = aEvent . entry . data . oldPosition ;
return ;
case 'treestyletab-changeTabbarPosition-private' :
aEvent . entry . data . target . treeStyleTab . position = aEvent . entry . data . oldPosition ;
2010-01-13 02:06:50 -05:00
return ;
}
2010-05-08 04:30:39 -04:00
return ;
2010-01-13 02:06:50 -05:00
case 'UIOperationHistoryRedo:TabbarOperations' :
switch ( aEvent . entry . name )
{
case 'treestyletab-changeTabbarPosition' :
2011-01-22 10:46:29 -05:00
this . position = aEvent . entry . data . newPosition ;
return ;
case 'treestyletab-changeTabbarPosition-private' :
aEvent . entry . data . target . treeStyleTab . position = aEvent . entry . data . newPosition ;
2010-01-13 02:06:50 -05:00
return ;
}
2010-05-08 04:30:39 -04:00
return ;
2007-10-16 13:22:28 -04:00
}
} ,
2008-11-09 23:48:11 -05:00
2009-08-14 02:12:08 -04:00
keyEventListening : false ,
keyEventListeningFlags : 0 ,
LISTEN _FOR _AUTOHIDE : 1 ,
LISTEN _FOR _AUTOEXPAND _BY _FOCUSCHANGE : 2 ,
2009-12-25 03:34:52 -05:00
startListenKeyEventsFor : function TSTService _startListenKeyEventsFor ( aReason )
2009-08-14 02:12:08 -04:00
{
if ( this . keyEventListeningFlags & aReason ) return ;
if ( ! this . keyEventListening ) {
window . addEventListener ( 'keydown' , this , true ) ;
window . addEventListener ( 'keyup' , this , true ) ;
window . addEventListener ( 'keypress' , this , true ) ;
this . keyEventListening = true ;
}
this . keyEventListeningFlags |= aReason ;
} ,
2009-12-25 03:34:52 -05:00
endListenKeyEventsFor : function TSTService _endListenKeyEventsFor ( aReason )
2009-08-14 02:12:08 -04:00
{
if ( ! ( this . keyEventListeningFlags & aReason ) ) return ;
this . keyEventListeningFlags ^= aReason ;
if ( ! this . keyEventListeningFlags && this . keyEventListening ) {
window . removeEventListener ( 'keydown' , this , true ) ;
window . removeEventListener ( 'keyup' , this , true ) ;
2010-10-24 22:36:47 -04:00
2009-08-14 02:12:08 -04:00
window . removeEventListener ( 'keypress' , this , true ) ;
this . keyEventListening = false ;
}
} ,
2009-12-25 03:34:52 -05:00
onKeyDown : function TSTService _onKeyDown ( aEvent )
2008-03-08 03:57:17 -05:00
{
2010-09-15 06:41:52 -04:00
/ * *
* On Mac OS X , default accel key is the Command key ( metaKey ) , but
* Cmd - Tab is used to switch applications by the OS itself . So Firefox
* uses Ctrl - Tab to switch tabs on all platforms .
* /
// this.accelKeyPressed = this.isAccelKeyPressed(aEvent);
this . accelKeyPressed = aEvent . ctrlKey || aEvent . keyCode == Ci . nsIDOMKeyEvent . DOM _VK _CONTROL ;
2009-09-03 03:25:37 -04:00
2009-12-26 00:21:31 -05:00
var b = this . browser ;
2011-01-11 05:29:14 -05:00
var data = {
sourceEvent : aEvent
} ;
2010-12-20 06:54:42 -05:00
2011-01-11 05:29:14 -05:00
/* PUBLIC API */
this . fireDataContainerEvent ( this . kEVENT _TYPE _TAB _FOCUS _SWITCHING _KEY _DOWN , b , true , false , data ) ;
2010-12-20 06:54:42 -05:00
// for backward compatibility
2011-01-11 05:29:14 -05:00
this . fireDataContainerEvent ( this . kEVENT _TYPE _TAB _FOCUS _SWITCHING _KEY _DOWN . replace ( /^nsDOM/ , '' ) , b , true , false , data ) ;
2008-03-08 03:57:17 -05:00
} ,
2008-03-09 08:18:58 -04:00
accelKeyPressed : false ,
2008-03-08 05:07:28 -05:00
2009-12-25 03:34:52 -05:00
onKeyRelease : function TSTService _onKeyRelease ( aEvent )
2008-03-08 03:57:17 -05:00
{
var b = this . browser ;
if ( ! b || ! b . treeStyleTab ) return ;
var sv = b . treeStyleTab ;
var scrollDown ,
scrollUp ;
2010-09-15 06:41:52 -04:00
// this.accelKeyPressed = this.isAccelKeyPressed(aEvent);
this . accelKeyPressed = aEvent . ctrlKey || aEvent . keyCode == Ci . nsIDOMKeyEvent . DOM _VK _CONTROL ;
2008-03-09 08:34:10 -04:00
2009-05-12 14:21:44 -04:00
var standBy = scrollDown = scrollUp = ( ! aEvent . altKey && this . accelKeyPressed ) ;
2008-03-08 03:57:17 -05:00
scrollDown = scrollDown && (
! aEvent . shiftKey &&
(
aEvent . keyCode == aEvent . DOM _VK _TAB ||
aEvent . keyCode == aEvent . DOM _VK _PAGE _DOWN
)
) ;
scrollUp = scrollUp && (
aEvent . shiftKey ? ( aEvent . keyCode == aEvent . DOM _VK _TAB ) : ( aEvent . keyCode == aEvent . DOM _VK _PAGE _UP )
) ;
2009-11-09 10:07:14 -05:00
var onlyShiftKey = ( ! aEvent . shiftKey && aEvent . keyCode == 16 && ( aEvent . type == 'keyup' || aEvent . charCode == 0 ) ) ;
2009-09-03 03:25:37 -04:00
2011-01-11 05:29:14 -05:00
var data = {
scrollDown : scrollDown ,
scrollUp : scrollUp ,
standBy : standBy ,
onlyShiftKey : onlyShiftKey ,
sourceEvent : aEvent
} ;
2008-03-08 03:57:17 -05:00
if (
scrollDown ||
scrollUp ||
( // when you release "shift" key
2009-09-03 03:25:37 -04:00
standBy && onlyShiftKey
2008-03-08 03:57:17 -05:00
)
) {
2009-09-03 03:25:37 -04:00
/* PUBLIC API */
2011-01-11 05:29:14 -05:00
this . fireDataContainerEvent ( this . kEVENT _TYPE _TAB _FOCUS _SWITCHING _START , b , true , false , data ) ;
2011-01-10 23:20:01 -05:00
// for backward compatibility
2011-01-11 05:29:14 -05:00
this . fireDataContainerEvent ( this . kEVENT _TYPE _TAB _FOCUS _SWITCHING _START . replace ( /^nsDOM/ , '' ) , b , true , false , data ) ;
2008-03-08 03:57:17 -05:00
return ;
}
2009-08-14 02:12:08 -04:00
// when you just release accel key...
2009-09-03 03:25:37 -04:00
/* PUBLIC API */
let ( event ) {
2011-01-11 05:29:14 -05:00
this . fireDataContainerEvent ( this . kEVENT _TYPE _TAB _FOCUS _SWITCHING _END , b , true , false , data ) ;
2011-01-10 23:20:01 -05:00
// for backward compatibility
2011-01-11 05:29:14 -05:00
this . fireDataContainerEvent ( this . kEVENT _TYPE _TAB _FOCUS _SWITCHING _END . replace ( /^nsDOM/ , '' ) , b , true , false , data ) ;
2009-09-03 03:25:37 -04:00
}
2009-08-14 02:12:08 -04:00
if ( this . _tabShouldBeExpandedAfterKeyReleased ) {
let tab = this . _tabShouldBeExpandedAfterKeyReleased ;
if ( this . hasChildTabs ( tab ) &&
2009-10-25 22:36:42 -04:00
this . isSubtreeCollapsed ( tab ) ) {
2009-08-14 02:12:08 -04:00
this . getTabBrowserFromChild ( tab )
. treeStyleTab
. collapseExpandTreesIntelligentlyFor ( tab ) ;
}
}
this . _tabShouldBeExpandedAfterKeyReleased = null ;
2008-03-08 03:57:17 -05:00
} ,
2008-09-26 10:13:29 -04:00
2009-08-14 02:30:03 -04:00
get shouldListenKeyEventsForAutoExpandByFocusChange ( )
{
2009-08-14 10:51:01 -04:00
return ! this . ctrlTabPreviewsEnabled &&
2009-12-25 06:27:23 -05:00
! this . getTreePref ( 'autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut' ) &&
this . getTreePref ( 'autoCollapseExpandSubtreeOnSelect' ) ;
2009-08-14 02:30:03 -04:00
} ,
2009-08-14 10:51:01 -04:00
get ctrlTabPreviewsEnabled ( )
{
return 'allTabs' in window &&
this . getPref ( 'browser.ctrlTab.previews' ) ;
} ,
2009-09-03 02:24:06 -04:00
2010-09-12 23:54:04 -04:00
onTabbarResizeStart : function TSTService _onTabbarResizeStart ( aEvent )
2009-09-08 05:59:23 -04:00
{
2010-09-13 10:45:33 -04:00
if ( this . isEventFiredOnGrippy ( aEvent ) )
2010-09-12 23:54:04 -04:00
return ;
2010-09-10 06:21:26 -04:00
aEvent . stopPropagation ( ) ;
2010-09-12 23:54:04 -04:00
if ( 'setCapture' in aEvent . currentTarget )
aEvent . currentTarget . setCapture ( true ) ;
aEvent . currentTarget . addEventListener ( 'mousemove' , this , false ) ;
var b = this . getTabBrowserFromChild ( aEvent . currentTarget ) ;
var box = aEvent . currentTarget . id == 'treestyletab-tabbar-resizer-splitter' ?
this . getTabStrip ( b ) :
2010-09-13 10:45:33 -04:00
b . treeStyleTab . tabStripPlaceHolder || b . tabContainer ;
2010-09-12 23:54:04 -04:00
this . tabbarResizeStartWidth = box . boxObject . width ;
this . tabbarResizeStartHeight = box . boxObject . height ;
this . tabbarResizeStartX = aEvent . screenX ;
this . tabbarResizeStartY = aEvent . screenY ;
2010-09-10 06:21:26 -04:00
} ,
2010-09-13 04:01:30 -04:00
onTabbarResizeEnd : function TSTService _onTabbarResizeEnd ( aEvent )
2010-09-10 06:21:26 -04:00
{
2010-09-12 23:54:04 -04:00
if ( this . tabbarResizeStartWidth < 0 )
return ;
2010-09-10 06:21:26 -04:00
aEvent . stopPropagation ( ) ;
2010-09-12 23:54:04 -04:00
if ( 'releaseCapture' in aEvent . currentTarget )
aEvent . currentTarget . releaseCapture ( ) ;
aEvent . currentTarget . removeEventListener ( 'mousemove' , this , false ) ;
this . tabbarResizeStartWidth = - 1 ;
this . tabbarResizeStartHeight = - 1 ;
this . tabbarResizeStartX = - 1 ;
this . tabbarResizeStartY = - 1 ;
var b = this . getTabBrowserFromChild ( aEvent . currentTarget ) ;
2010-09-10 06:21:26 -04:00
} ,
2010-09-13 04:01:30 -04:00
onTabbarResizing : function TSTService _onTabbarResizing ( aEvent )
2010-09-10 06:21:26 -04:00
{
2010-09-12 23:54:04 -04:00
var target = aEvent . currentTarget ;
var b = this . getTabBrowserFromChild ( target ) ;
2010-09-10 06:21:26 -04:00
2010-09-12 23:54:04 -04:00
var expanded = target . id == 'treestyletab-tabbar-resizer-splitter' ;
if ( expanded )
aEvent . stopPropagation ( ) ;
var width = this . tabbarResizeStartWidth ;
var height = this . tabbarResizeStartHeight ;
2011-01-22 10:46:29 -05:00
var pos = b . treeStyleTab . position ;
2010-09-10 06:21:26 -04:00
if ( b . treeStyleTab . isVertical ) {
2010-09-12 23:54:04 -04:00
let delta = aEvent . screenX - this . tabbarResizeStartX ;
2010-09-10 06:21:26 -04:00
width += ( pos == 'left' ? delta : - delta ) ;
2010-09-12 23:54:04 -04:00
width = this . maxTabbarWidth ( width , b ) ;
if ( expanded || b . treeStyleTab . autoHide . expanded ) {
this . setTreePref ( 'tabbar.width' , width ) ;
if ( b . treeStyleTab . autoHide . mode == b . treeStyleTab . autoHide . kMODE _SHRINK &&
b . treeStyleTab . tabStripPlaceHolder )
b . treeStyleTab . tabStripPlaceHolder . setAttribute ( 'width' , this . getTreePref ( 'tabbar.shrunkenWidth' ) ) ;
}
else {
this . setTreePref ( 'tabbar.shrunkenWidth' , width ) ;
}
2010-09-10 06:21:26 -04:00
}
else {
2010-09-12 23:54:04 -04:00
let delta = aEvent . screenY - this . tabbarResizeStartY ;
2010-09-10 06:21:26 -04:00
height += ( pos == 'top' ? delta : - delta ) ;
2010-09-12 23:54:04 -04:00
this . setTreePref ( 'tabbar.height' , this . maxTabbarHeight ( height , b ) ) ;
2010-09-10 06:21:26 -04:00
}
2010-12-03 09:50:42 -05:00
b . treeStyleTab . updateFloatingTabbar ( this . kTABBAR _UPDATE _BY _TABBAR _RESIZE ) ;
2010-09-10 06:21:26 -04:00
} ,
2010-09-12 23:54:04 -04:00
tabbarResizeStartWidth : - 1 ,
tabbarResizeStartHeight : - 1 ,
tabbarResizeStartX : - 1 ,
tabbarResizeStartY : - 1 ,
onTabbarReset : function TSTService _onTabbarReset ( aEvent )
{
var b = this . getTabBrowserFromChild ( aEvent . currentTarget ) ;
if ( b ) {
b . treeStyleTab . resetTabbarSize ( ) ;
aEvent . stopPropagation ( ) ;
}
} ,
2010-09-10 06:21:26 -04:00
2010-12-01 10:15:40 -05:00
onFocusNextTab : function TSTService _onFocusNextTab ( aEvent )
2010-11-30 05:05:00 -05:00
{
2011-02-06 21:02:18 -05:00
var tab = aEvent . originalTarget ;
var b = this . getTabBrowserFromChild ( tab ) ;
2010-11-30 05:05:00 -05:00
if (
this . getPref ( 'browser.tabs.selectOwnerOnClose' ) &&
tab . owner &&
(
2011-02-06 21:02:18 -05:00
! b . _removingTabs ||
b . _removingTabs . indexOf ( tab . owner ) < 0
2010-11-30 05:05:00 -05:00
)
)
aEvent . preventDefault ( ) ;
} ,
2009-12-25 06:19:50 -05:00
showHideSubtreeMenuItem : function TSTService _showHideSubtreeMenuItem ( aMenuItem , aTabs )
2007-10-20 12:47:08 -04:00
{
2007-11-14 14:34:36 -05:00
if ( ! aMenuItem ||
aMenuItem . getAttribute ( 'hidden' ) == 'true' ||
! aTabs ||
! aTabs . length )
2007-11-12 10:29:12 -05:00
return ;
2007-10-20 12:47:08 -04:00
2009-12-25 06:19:50 -05:00
var hasSubtree = false ;
2007-11-14 14:34:36 -05:00
for ( var i = 0 , maxi = aTabs . length ; i < maxi ; i ++ )
2007-10-20 12:47:08 -04:00
{
2008-04-29 14:17:44 -04:00
if ( ! this . hasChildTabs ( aTabs [ i ] ) ) continue ;
2009-12-25 06:19:50 -05:00
hasSubtree = true ;
2007-10-20 12:47:08 -04:00
break ;
}
2009-12-25 06:19:50 -05:00
if ( hasSubtree )
2007-11-14 14:34:36 -05:00
aMenuItem . removeAttribute ( 'hidden' ) ;
else
aMenuItem . setAttribute ( 'hidden' , true ) ;
2007-10-20 12:47:08 -04:00
} ,
2009-12-25 06:36:22 -05:00
showHideSubTreeMenuItem : function ( ) { return this . showHideSubtreeMenuItem . apply ( this , arguments ) ; } , // obsolete, for backward compatibility
2009-05-13 02:09:17 -04:00
2010-04-06 09:38:05 -04:00
updateAeroPeekPreviews : function TSTService _updateAeroPeekPreviews ( )
{
if (
this . updateAeroPeekPreviewsTimer ||
2010-05-06 05:56:39 -04:00
! this . getPref ( 'browser.taskbar.previews.enable' ) ||
! this . getTreePref ( 'taskbarPreviews.hideCollapsedTabs' ) ||
2010-04-06 09:38:05 -04:00
! ( 'Win7Features' in window ) ||
! window . Win7Features ||
! this . AeroPeek ||
! this . AeroPeek . windows
)
return ;
this . updateAeroPeekPreviewsTimer = window . setTimeout ( function ( aSelf ) {
aSelf . updateAeroPeekPreviewsTimer = null ;
2010-04-06 09:59:13 -04:00
try {
aSelf . updateAeroPeekPreviewsInternal ( ) ;
}
catch ( e ) {
dump ( e + '\n' ) ;
aSelf . updateAeroPeekPreviews ( ) ;
}
} , 250 , this ) ;
2010-04-06 09:38:05 -04:00
} ,
updateAeroPeekPreviewsTimer : null ,
2010-04-22 04:12:31 -04:00
updateAeroPeekPreviewsInternal : function TSTService _updateAeroPeekPreviewsInternal ( )
2010-04-06 09:38:05 -04:00
{
2010-05-06 05:56:39 -04:00
if (
! this . getPref ( 'browser.taskbar.previews.enable' ) ||
! this . getTreePref ( 'taskbarPreviews.hideCollapsedTabs' )
)
return ;
2010-04-06 09:38:05 -04:00
this . AeroPeek . windows . some ( function ( aTabWindow ) {
if ( aTabWindow . win == window ) {
aTabWindow . previews . forEach ( function ( aPreview ) {
if ( ! aPreview ) return ;
var tab = aPreview . controller . wrappedJSObject . tab ;
2010-05-13 08:06:31 -04:00
aPreview . visible = ! this . isCollapsed ( tab ) ;
2010-04-06 09:38:05 -04:00
} , this ) ;
this . AeroPeek . checkPreviewCount ( ) ;
return true ;
}
return false ;
} , this ) ;
} ,
2010-05-15 10:05:02 -04:00
updateTabsOnTop : function TSTService _updateTabsOnTop ( )
{
if ( ! ( 'TabsOnTop' in window ) || ! ( 'enabled' in TabsOnTop ) )
return ;
if ( ! ( '_tabsOnTopDefaultState' in this ) )
this . _tabsOnTopDefaultState = TabsOnTop . enabled ;
2011-01-22 10:46:29 -05:00
if ( gBrowser . treeStyleTab . position != 'top' ||
2011-01-22 09:43:55 -05:00
! gBrowser . treeStyleTab . fixed ) {
2010-06-27 00:01:15 -04:00
if ( TabsOnTop . enabled )
TabsOnTop . enabled = false ;
2010-05-15 10:05:02 -04:00
}
else if ( '_tabsOnTopDefaultState' in this ) {
2010-06-27 00:01:15 -04:00
if ( TabsOnTop . enabled != this . _tabsOnTopDefaultState )
TabsOnTop . enabled = this . _tabsOnTopDefaultState ;
2010-05-15 10:05:02 -04:00
delete this . _tabsOnTopDefaultState ;
}
} ,
2010-09-10 06:21:26 -04:00
onPopupShown : function TSTService _onPopupShown ( aPopup )
{
if ( ! aPopup . boxObject ||
this . evaluateXPath (
'local-name() = "tooltip" or local-name() ="panel" or ' +
'parent::*/ancestor-or-self::*[local-name()="popup" or local-name()="menupopup"]' ,
2010-09-10 06:48:49 -04:00
aPopup ,
2010-09-10 06:21:26 -04:00
XPathResult . BOOLEAN _TYPE
2010-11-29 03:44:17 -05:00
2010-11-29 19:12:22 -05:00
2010-09-10 06:21:26 -04:00
) . booleanValue )
return ;
window . setTimeout ( function ( aSelf ) {
2010-09-10 09:06:43 -04:00
if ( ( ! aPopup . boxObject . width && ! aPopup . boxObject . height ) ||
aPopup . boxObject . popupState == 'closed' )
2010-09-10 06:21:26 -04:00
return ;
var id = aPopup . id ;
2010-10-13 11:18:04 -04:00
var item = id && document . getElementById ( id ) ? id : aPopup ;
2010-09-10 06:21:26 -04:00
var index = TreeStyleTabService . _shownPopups . indexOf ( item ) ;
if ( index < 0 )
TreeStyleTabService . _shownPopups . push ( item ) ;
} , 10 , this ) ;
} ,
onPopupHidden : function TSTService _onPopupHidden ( aPopup )
{
var id = aPopup . id ;
2010-10-13 11:18:04 -04:00
aPopup = id && document . getElementById ( id ) ? id : aPopup ;
2010-09-10 06:21:26 -04:00
var index = TreeStyleTabService . _shownPopups . indexOf ( aPopup ) ;
if ( index > - 1 )
TreeStyleTabService . _shownPopups . splice ( index , 1 ) ;
} ,
isPopupShown : function TSTService _isPopupShown ( )
{
TreeStyleTabService . _shownPopups = TreeStyleTabService . _shownPopups . filter ( function ( aItem ) {
if ( typeof aItem == 'string' )
aItem = document . getElementById ( aItem ) ;
2010-12-02 23:16:30 -05:00
return aItem && aItem . boxObject && ( ( aItem . boxObject . width || aItem . boxObject . height ) && aItem . state != 'closed' ) ;
2010-09-10 06:21:26 -04:00
} ) ;
return TreeStyleTabService . _shownPopups . length > 0 ;
} ,
_shownPopups : [ ] ,
2011-01-25 10:01:37 -05:00
onBeforeNewTabCommand : function TSTService _onBeforeNewTabCommand ( aTabBrowser )
{
var b = aTabBrowser || this . browser ;
switch ( this . getTreePref ( 'autoAttach.newTabCommand' ) )
{
case this . kNEWTAB _COMMAND _DO _NOT _ATTACH :
default :
break ;
case this . kNEWTAB _COMMAND _ATTACH _TO _CURRENT :
this . readyToOpenChildTab ( b . selectedTab ) ;
break ;
case this . kNEWTAB _COMMAND _ATTACH _TO _PARENT :
let parentTab = this . getParentTab ( b . selectedTab ) ;
if ( parentTab )
this . readyToOpenChildTab ( parentTab ) ;
break ;
}
} ,
kNEWTAB _COMMAND _DO _NOT _ATTACH : 0 ,
kNEWTAB _COMMAND _ATTACH _TO _CURRENT : 1 ,
kNEWTAB _COMMAND _ATTACH _TO _PARENT : 2 ,
2007-10-20 12:47:08 -04:00
2008-11-09 23:48:11 -05:00
/* Tree Style Tab<61> ̏<EFBFBD> <CC8F> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> s<EFBFBD> <73> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> O<EFBFBD> ɕ<EFBFBD> <C995> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ꂽ<EFBFBD> Z<EFBFBD> b<EFBFBD> V<EFBFBD> <56> <EFBFBD> <EFBFBD> <EFBFBD> ɂ <C982> <C282> ăc<C483> <63> <EFBFBD> [<5B> \<5C> <> <EFBFBD> <EFBFBD> */
_restoringTabs : [ ] ,
2009-12-25 03:34:52 -05:00
onTabRestored : function TSTService _onTabRestored ( aEvent )
2008-11-09 23:48:11 -05:00
{
this . _restoringTabs . push ( aEvent . originalTarget ) ;
} ,
2009-12-25 03:34:52 -05:00
processRestoredTabs : function TSTService _processRestoredTabs ( )
2008-11-09 23:48:11 -05:00
{
this . _restoringTabs . forEach ( function ( aTab ) {
try {
var b = this . getTabBrowserFromChild ( aTab ) ;
2009-08-26 05:33:54 -04:00
if ( b ) b . treeStyleTab . restoreStructure ( aTab , true ) ;
2008-11-09 23:48:11 -05:00
}
catch ( e ) {
}
} , this ) ;
this . _restoringTabs = [ ] ;
} ,
2007-11-14 14:34:36 -05:00
/* Commands */
2008-11-09 23:48:11 -05:00
2009-12-25 13:13:33 -05:00
setTabbarWidth : function TSTService _setTabbarWidth ( aWidth , aForceExpanded ) /* PUBLIC API */
{
gBrowser . treeStyleTab . autoHide . setWidth ( aWidth , aForceExpanded ) ;
} ,
setContentWidth : function TSTService _setContentWidth ( aWidth , aKeepWindowSize ) /* PUBLIC API */
{
var treeStyleTab = gBrowser . treeStyleTab ;
2010-03-23 09:33:00 -04:00
var strip = treeStyleTab . tabStrip ;
var tabbarWidth = treeStyleTab . splitterWidth + ( treeStyleTab . isVertical ? strip . boxObject . width : 0 ) ;
2009-12-25 13:13:33 -05:00
var contentWidth = gBrowser . boxObject . width - tabbarWidth ;
if ( aKeepWindowSize ||
window . fullScreen ||
window . windowState != Components . interfaces . nsIDOMChromeWindow . STATE _NORMAL ) {
this . setTabbarWidth ( Math . max ( 10 , gBrowser . boxObject . width - aWidth ) ) ;
}
else if ( tabbarWidth + aWidth <= screen . availWidth ) {
window . resizeBy ( aWidth - contentWidth , 0 ) ;
}
else {
window . resizeBy ( screen . availWidth - window . outerWidth , 0 ) ;
this . setTabbarWidth ( gBrowser . boxObject . width - aWidth ) ;
}
} ,
2010-12-09 01:05:46 -05:00
get autoHideWindow ( )
2010-12-06 08:31:58 -05:00
{
if ( ! this . _autoHideWindow ) {
let ns = { } ;
Components . utils . import ( 'resource://treestyletab-modules/autoHide.js' , ns ) ;
this . _autoHideWindow = new ns . AutoHideWindow ( window ) ;
}
return this . _autoHideWindow ;
} ,
2010-05-08 02:22:49 -04:00
toggleAutoHide : function TSTService _toggleAutoHide ( aTabBrowser ) /* PUBLIC API, for backward compatibility */
2009-12-25 13:13:33 -05:00
{
2010-12-06 08:31:58 -05:00
this . autoHideWindow . toggleMode ( aTabBrowser || this . browser ) ;
2009-12-25 13:13:33 -05:00
} ,
2010-05-08 02:22:49 -04:00
toggleFixed : function TSTService _toggleFixed ( aTabBrowser ) /* PUBLIC API */
2009-12-25 13:13:33 -05:00
{
2010-05-08 02:22:49 -04:00
var b = aTabBrowser || this . browser ;
var orient = b . treeStyleTab . isVertical ? 'vertical' : 'horizontal' ;
2009-12-25 13:13:33 -05:00
2010-05-08 02:22:49 -04:00
var newFixed = b . getAttribute ( this . kFIXED + '-' + orient ) != 'true' ;
2011-01-22 09:43:55 -05:00
this . setTabbrowserAttribute ( this . kFIXED + '-' + orient , newFixed || null , this . mTabBrowser ) ;
b . treeStyleTab . fixed = newFixed ;
2010-05-08 02:22:49 -04:00
this . setTreePref ( 'tabbar.fixed.' + orient , newFixed ) ;
b . treeStyleTab . updateTabbarState ( ) ;
2009-12-25 13:13:33 -05:00
} ,
2009-12-25 06:19:50 -05:00
removeTabSubtree : function TSTService _removeTabSubtree ( aTabOrTabs , aOnlyChildren )
2007-10-19 22:44:14 -04:00
{
2010-09-18 11:17:48 -04:00
var tabs = this . gatherSubtreeMemberTabs ( aTabOrTabs , aOnlyChildren ) ;
2009-06-17 04:59:18 -04:00
if ( ! this . warnAboutClosingTabs ( tabs . length ) )
2007-10-19 22:44:14 -04:00
return ;
2010-09-18 11:17:48 -04:00
if ( aOnlyChildren )
tabs = this . gatherSubtreeMemberTabs ( aTabOrTabs ) ;
2009-12-25 23:49:58 -05:00
this . splitTabsToSubtrees ( tabs ) . forEach ( function ( aTabs ) {
if ( ! this . fireTabSubtreeClosingEvent ( aTabs [ 0 ] , aTabs ) )
return ;
var b = this . getTabBrowserFromChild ( aTabs [ 0 ] ) ;
2009-12-27 06:22:44 -05:00
if ( aOnlyChildren )
aTabs = aTabs . slice ( 1 ) ;
if ( ! aTabs . length )
return ;
this . stopRendering ( ) ;
this . markAsClosedSet ( aTabs ) ;
for ( var i = aTabs . length - 1 ; i > - 1 ; i -- )
2009-12-25 23:49:58 -05:00
{
2010-08-08 05:42:47 -04:00
b . removeTab ( aTabs [ i ] , { animate : true } ) ;
2009-12-25 23:49:58 -05:00
}
2009-12-27 06:22:44 -05:00
this . startRendering ( ) ;
2009-12-25 23:49:58 -05:00
this . fireTabSubtreeClosedEvent ( b , aTabs [ 0 ] , aTabs )
} , this ) ;
2007-10-19 22:44:14 -04:00
} ,
2009-12-25 12:55:55 -05:00
removeTabSubTree : function ( ) { return this . removeTabSubtree . apply ( this , arguments ) ; } , // obsolete, for backward compatibility
2009-12-25 23:49:58 -05:00
fireTabSubtreeClosingEvent : function TSTService _fireTabSubtreeClosingEvent ( aParentTab , aClosedTabs )
{
2011-01-11 05:29:14 -05:00
var b = this . getTabBrowserFromChild ( aParentTab ) ;
var data = {
parent : aParentTab ,
tabs : aClosedTabs
} ;
var canClose = (
/* PUBLIC API */
this . fireDataContainerEvent ( this . kEVENT _TYPE _SUBTREE _CLOSING , b , true , true , data ) &&
// for backward compatibility
this . fireDataContainerEvent ( this . kEVENT _TYPE _SUBTREE _CLOSING . replace ( /^nsDOM/ , '' ) , b , true , true , data )
) ;
2010-12-20 06:54:42 -05:00
return canClose ;
2009-12-25 23:49:58 -05:00
} ,
fireTabSubtreeClosedEvent : function TSTService _fireTabSubtreeClosedEvent ( aTabBrowser , aParentTab , aClosedTabs )
{
2009-12-26 00:24:55 -05:00
aClosedTabs = aClosedTabs . filter ( function ( aTab ) { return ! aTab . parentNode ; } ) ;
2011-01-11 05:29:14 -05:00
var data = {
parent : aParentTab ,
tabs : aClosedTabs
} ;
2010-12-20 06:54:42 -05:00
2009-12-25 23:49:58 -05:00
/* PUBLIC API */
2011-01-11 05:29:14 -05:00
this . fireDataContainerEvent ( this . kEVENT _TYPE _SUBTREE _CLOSED , aTabBrowser , true , false , data ) ;
2010-12-20 06:54:42 -05:00
// for backward compatibility
2011-01-11 05:29:14 -05:00
this . fireDataContainerEvent ( this . kEVENT _TYPE _SUBTREE _CLOSED . replace ( /^nsDOM/ , '' ) , aTabBrowser , true , false , data ) ;
2009-12-25 23:49:58 -05:00
} ,
2009-12-25 12:55:55 -05:00
warnAboutClosingTabSubtreeOf : function TSTService _warnAboutClosingTabSubtreeOf ( aTab )
2009-12-18 00:52:47 -05:00
{
2009-12-25 06:19:50 -05:00
if ( ! this . shouldCloseTabSubtreeOf ( aTab ) )
2009-12-18 01:08:42 -05:00
return true ;
2009-12-18 00:52:47 -05:00
var tabs = [ aTab ] . concat ( this . getDescendantTabs ( aTab ) ) ;
return this . warnAboutClosingTabs ( tabs . length ) ;
} ,
2009-12-25 12:55:55 -05:00
warnAboutClosingTabSubTreeOf : function ( ) { return this . warnAboutClosingTabSubtreeOf . apply ( this , arguments ) ; } , // obsolete, for backward compatibility
warnAboutClosingTabs : function TSTService _warnAboutClosingTabs ( aTabsCount )
2009-06-17 04:59:18 -04:00
{
if (
aTabsCount <= 1 ||
2009-06-17 06:09:52 -04:00
! this . getPref ( 'browser.tabs.warnOnClose' )
2009-06-17 04:59:18 -04:00
)
return true ;
var checked = { value : true } ;
window . focus ( ) ;
2009-07-22 00:25:39 -04:00
var shouldClose = this . PromptService . confirmEx ( window ,
2009-06-17 04:59:18 -04:00
this . tabbrowserBundle . getString ( 'tabs.closeWarningTitle' ) ,
this . tabbrowserBundle . getFormattedString ( 'tabs.closeWarningMultipleTabs' , [ aTabsCount ] ) ,
2009-07-22 00:25:39 -04:00
( this . PromptService . BUTTON _TITLE _IS _STRING * this . PromptService . BUTTON _POS _0 ) +
( this . PromptService . BUTTON _TITLE _CANCEL * this . PromptService . BUTTON _POS _1 ) ,
2009-06-17 04:59:18 -04:00
this . tabbrowserBundle . getString ( 'tabs.closeButtonMultiple' ) ,
null , null ,
this . tabbrowserBundle . getString ( 'tabs.closeWarningPromptMe' ) ,
checked
) == 0 ;
if ( shouldClose && ! checked . value )
this . setPref ( 'browser.tabs.warnOnClose' , false ) ;
return shouldClose ;
} ,
2009-12-25 12:55:55 -05:00
2009-12-25 06:19:50 -05:00
reloadTabSubtree : function TSTService _reloadTabSubtree ( aTabOrTabs , aOnlyChildren )
2009-07-06 05:21:06 -04:00
{
2009-12-25 15:06:49 -05:00
var tabs = this . gatherSubtreeMemberTabs ( aTabOrTabs , aOnlyChildren ) ;
2009-07-06 05:21:06 -04:00
var b = this . getTabBrowserFromChild ( tabs [ 0 ] ) ;
for ( var i = tabs . length - 1 ; i > - 1 ; i -- )
{
b . reloadTab ( tabs [ i ] ) ;
}
} ,
2009-12-25 06:36:22 -05:00
reloadTabSubTree : function ( ) { return this . reloadTabSubtree . apply ( this , arguments ) ; } , // obsolete, for backward compatibility
2009-07-06 05:21:06 -04:00
2009-12-25 06:19:50 -05:00
createSubtree : function TSTService _createSubtree ( aTabs )
2009-07-23 11:34:28 -04:00
{
2009-07-23 12:14:45 -04:00
aTabs = this . getRootTabs ( aTabs ) ;
if ( ! aTabs . length ) return ;
2009-07-23 11:34:28 -04:00
var b = this . getTabBrowserFromChild ( aTabs [ 0 ] ) ;
2009-07-23 12:14:45 -04:00
2009-07-23 12:33:06 -04:00
var parent = this . getParentTab ( aTabs [ 0 ] ) ;
2009-07-23 12:51:48 -04:00
var next = aTabs [ 0 ] ;
2009-07-23 12:49:54 -04:00
while (
2009-07-23 12:51:48 -04:00
( next = this . getNextSiblingTab ( next ) ) &&
aTabs . indexOf ( next ) > - 1
2009-07-23 12:49:54 -04:00
) ;
2009-12-25 06:27:23 -05:00
var root = this . getTreePref ( 'createSubtree.underParent' ) ?
2009-07-24 03:09:29 -04:00
b . addTab ( this . getGroupTabURI ( ) ) :
aTabs . shift ( ) ;
2009-07-23 12:14:45 -04:00
window . setTimeout ( function ( aSelf ) {
aTabs . forEach ( function ( aTab ) {
b . treeStyleTab . attachTabTo ( aTab , root ) ;
2009-07-23 12:26:56 -04:00
b . treeStyleTab . collapseExpandTab ( aTab , false ) ;
2009-07-23 12:14:45 -04:00
} , aSelf ) ;
2009-07-23 12:49:54 -04:00
if ( parent ) {
b . treeStyleTab . attachTabTo ( root , parent , {
2009-07-23 12:51:48 -04:00
insertBefore : next
2009-07-23 12:49:54 -04:00
} ) ;
}
2009-07-23 12:51:48 -04:00
else if ( next ) {
2009-12-25 06:19:50 -05:00
b . treeStyleTab . moveTabSubtreeTo ( root , next . _tPos ) ;
2009-07-23 12:51:48 -04:00
}
2009-07-23 12:14:45 -04:00
} , 0 , this ) ;
} ,
2009-12-25 06:36:22 -05:00
createSubTree : function ( ) { return this . createSubtree . apply ( this , arguments ) ; } , // obsolete, for backward compatibility
2009-11-23 11:11:30 -05:00
2009-12-25 06:19:50 -05:00
canCreateSubtree : function TSTService _canCreateSubtree ( aTabs )
2009-07-23 12:14:45 -04:00
{
aTabs = this . getRootTabs ( aTabs ) ;
if ( aTabs . length < 2 ) return false ;
var lastParent = this . getParentTab ( aTabs [ 0 ] ) ;
for ( let i = 1 , maxi = aTabs . length - 1 ; i < maxi ; i ++ )
{
let parent = this . getParentTab ( aTabs [ i ] ) ;
if ( ! lastParent || parent != lastParent ) return true ;
lastParent = parent ;
}
2009-07-23 12:26:56 -04:00
return this . getChildTabs ( lastParent ) . length != aTabs . length ;
2009-07-23 12:14:45 -04:00
} ,
2009-12-25 06:36:22 -05:00
canCreateSubTree : function ( ) { return this . canCreateSubtree . apply ( this , arguments ) ; } , // obsolete, for backward compatibility
2009-11-23 11:11:30 -05:00
2009-12-25 03:34:52 -05:00
getRootTabs : function TSTService _getRootTabs ( aTabs )
2009-07-23 12:14:45 -04:00
{
var roots = [ ] ;
if ( ! aTabs || ! aTabs . length ) return roots ;
aTabs = this . cleanUpTabsArray ( aTabs ) ;
2009-07-23 11:34:28 -04:00
aTabs . forEach ( function ( aTab ) {
2009-07-23 12:14:45 -04:00
var parent = this . getParentTab ( aTab ) ;
if ( parent && aTabs . indexOf ( parent ) > - 1 ) return ;
roots . push ( aTab ) ;
2009-07-23 11:34:28 -04:00
} , this ) ;
2009-07-23 12:14:45 -04:00
return roots ;
2009-07-23 11:34:28 -04:00
} ,
2009-11-23 11:11:30 -05:00
2009-12-25 03:34:52 -05:00
collapseExpandAllSubtree : function TSTService _collapseExpandAllSubtree ( aCollapse )
2007-11-17 00:20:26 -05:00
{
this . ObserverService . notifyObservers (
window ,
2010-11-30 19:33:07 -05:00
this . kTOPIC _COLLAPSE _EXPAND _ALL ,
2007-11-17 00:20:26 -05:00
( aCollapse ? 'collapse' : 'open' )
) ;
} ,
2008-02-28 02:45:39 -05:00
2009-12-25 03:34:52 -05:00
promoteTab : function TSTService _promoteTab ( aTab ) /* PUBLIC API */
2009-12-18 04:05:41 -05:00
{
var b = this . getTabBrowserFromChild ( aTab ) ;
var sv = b . treeStyleTab ;
var parent = sv . getParentTab ( aTab ) ;
if ( ! parent ) return ;
var nextSibling = sv . getNextSiblingTab ( parent ) ;
var grandParent = sv . getParentTab ( parent ) ;
if ( grandParent ) {
sv . attachTabTo ( aTab , grandParent , {
insertBefore : nextSibling
} ) ;
}
else {
sv . partTab ( aTab ) ;
let index = nextSibling ? nextSibling . _tPos : b . mTabContainer . childNodes . length ;
if ( index > aTab . _tPos ) index -- ;
b . moveTabTo ( aTab , index ) ;
}
} ,
2009-12-25 12:55:55 -05:00
promoteCurrentTab : function TSTService _promoteCurrentTab ( ) /* PUBLIC API */
2009-12-18 04:05:41 -05:00
{
this . promoteTab ( this . browser . selectedTab ) ;
} ,
2009-12-25 12:55:55 -05:00
2009-12-25 03:34:52 -05:00
demoteTab : function TSTService _demoteTab ( aTab ) /* PUBLIC API */
2009-12-18 04:05:41 -05:00
{
var b = this . getTabBrowserFromChild ( aTab ) ;
var sv = b . treeStyleTab ;
var previous = this . getPreviousSiblingTab ( aTab ) ;
if ( previous )
sv . attachTabTo ( aTab , previous ) ;
} ,
2009-12-25 12:55:55 -05:00
demoteCurrentTab : function TSTService _demoteCurrentTab ( ) /* PUBLIC API */
2009-12-18 04:05:41 -05:00
{
this . demoteTab ( this . browser . selectedTab ) ;
} ,
2009-12-25 12:55:55 -05:00
2009-12-25 03:34:52 -05:00
expandTreeAfterKeyReleased : function TSTService _expandTreeAfterKeyReleased ( aTab )
2009-08-14 02:12:08 -04:00
{
2009-12-25 06:27:23 -05:00
if ( this . getTreePref ( 'autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut' ) ) return ;
2009-08-14 02:12:08 -04:00
this . _tabShouldBeExpandedAfterKeyReleased = aTab || null ;
} ,
_tabShouldBeExpandedAfterKeyReleased : null ,
2010-12-09 01:05:46 -05:00
removeAllTabsBut : function TSTService _removeAllTabsBut ( aTab )
2010-12-08 06:34:42 -05:00
{
var keepTabs = [ aTab ] . concat ( this . getDescendantTabs ( aTab ) ) ;
var b = this . getTabBrowserFromChild ( aTab ) ;
var closeTabs = this . getTabsArray ( b )
. filter ( function ( aTab ) {
return keepTabs . indexOf ( aTab ) < 0 ;
} ) ;
if ( ! this . warnAboutClosingTabs ( closeTabs . length ) )
return ;
this . stopRendering ( ) ;
this . markAsClosedSet ( closeTabs ) ;
closeTabs . reverse ( ) . forEach ( function ( aTab ) {
b . removeTab ( aTab ) ;
} ) ;
this . startRendering ( ) ;
} ,
2010-11-30 19:26:12 -05:00
// For backward compatibility. You should use DOM event to block TST's focus handling.
2009-12-25 03:34:52 -05:00
registerTabFocusAllowance : function TSTService _registerTabFocusAllowance ( aProcess ) /* PUBLIC API */
2008-03-02 13:16:57 -05:00
{
2010-11-30 05:05:00 -05:00
var listener = {
process : aProcess ,
handleEvent : function ( aEvent ) {
if ( ! this . process . call ( aEvent . target . treeStyleTab , aEvent . target ) )
aEvent . preventDefault ( ) ;
}
} ;
window . addEventListener ( this . kEVENT _TYPE _FOCUS _NEXT _TAB , listener , false ) ;
this . _tabFocusAllowance . push ( listener ) ;
2008-03-02 13:16:57 -05:00
} ,
_tabFocusAllowance : [ ] ,
2009-12-25 06:19:50 -05:00
tearOffSubtreeFromRemote : function TSTService _tearOffSubtreeFromRemote ( )
2008-12-01 03:30:36 -05:00
{
var remoteTab = window . arguments [ 0 ] ;
var remoteWindow = remoteTab . ownerDocument . defaultView ;
var remoteService = remoteWindow . TreeStyleTabService ;
var remoteMultipleTabService = remoteWindow . MultipleTabService ;
if ( remoteService . hasChildTabs ( remoteTab ) ||
2008-12-01 20:54:16 -05:00
( remoteMultipleTabService && remoteMultipleTabService . isSelected ( remoteTab ) ) ) {
2008-12-01 03:30:36 -05:00
var remoteBrowser = remoteService . getTabBrowserFromChild ( remoteTab ) ;
2010-12-01 19:00:39 -05:00
if ( remoteBrowser . treeStyleTab . tabbarDNDObserver . isDraggingAllTabs ( remoteTab ) ) {
2008-12-01 03:30:36 -05:00
window . close ( ) ;
}
else {
2008-12-01 04:14:05 -05:00
var actionInfo = {
action : this . kACTIONS _FOR _DESTINATION | this . kACTION _IMPORT
} ;
2008-12-01 03:30:36 -05:00
window . setTimeout ( function ( ) {
var blankTab = gBrowser . selectedTab ;
2010-12-01 19:00:39 -05:00
gBrowser . treeStyleTab . tabbarDNDObserver . performDrop ( actionInfo , remoteTab ) ;
2008-12-01 03:30:36 -05:00
window . setTimeout ( function ( ) {
gBrowser . removeTab ( blankTab ) ;
2009-05-13 02:09:17 -04:00
remoteTab = null ;
remoteBrowser = null ;
remoteWindow = null
remoteService = null ;
remoteMultipleTabService = null ;
2008-12-01 03:30:36 -05:00
} , 0 ) ;
} , 0 ) ;
}
return true ;
}
return false ;
} ,
2009-12-25 06:36:22 -05:00
tearOffSubTreeFromRemote : function ( ) { return this . tearOffSubtreeFromRemote . apply ( this , arguments ) ; } , // obsolete, for backward compatibility
2010-03-28 14:22:15 -04:00
onPrintPreviewEnter : function TSTService _onPrintPreviewEnter ( )
{
var event = document . createEvent ( 'Events' ) ;
2010-11-30 05:05:00 -05:00
event . initEvent ( this . kEVENT _TYPE _PRINT _PREVIEW _ENTERED , true , false ) ;
2010-03-28 14:22:15 -04:00
document . documentElement . dispatchEvent ( event ) ;
2010-12-20 06:54:42 -05:00
// for backward compatibility
2010-12-20 06:58:59 -05:00
event = document . createEvent ( 'Events' ) ;
2010-12-20 06:54:42 -05:00
event . initEvent ( this . kEVENT _TYPE _PRINT _PREVIEW _ENTERED . replace ( /^nsDOM/ , '' ) , true , false ) ;
document . documentElement . dispatchEvent ( event ) ;
2010-03-28 14:22:15 -04:00
} ,
onPrintPreviewExit : function TSTService _onPrintPreviewExit ( )
{
var event = document . createEvent ( 'Events' ) ;
2010-11-30 05:05:00 -05:00
event . initEvent ( this . kEVENT _TYPE _PRINT _PREVIEW _EXITED , true , false ) ;
2010-03-28 14:22:15 -04:00
document . documentElement . dispatchEvent ( event ) ;
2010-12-20 06:54:42 -05:00
// for backward compatibility
2010-12-20 06:58:59 -05:00
event = document . createEvent ( 'Events' ) ;
2010-12-20 06:54:42 -05:00
event . initEvent ( this . kEVENT _TYPE _PRINT _PREVIEW _EXITED . replace ( /^nsDOM/ , '' ) , true , false ) ;
document . documentElement . dispatchEvent ( event ) ;
2010-03-28 14:22:15 -04:00
} ,
2008-03-08 03:57:17 -05:00
2009-12-25 03:34:52 -05:00
observe : function TSTService _observe ( aSubject , aTopic , aData )
2009-07-03 05:58:34 -04:00
{
switch ( aTopic )
{
case 'nsPref:changed' :
this . onPrefChange ( aData ) ;
return ;
2009-08-26 05:33:54 -04:00
case 'sessionstore-windows-restored' :
2009-12-16 12:32:03 -05:00
if ( ! this . useTMPSessionAPI )
2010-01-29 02:54:17 -05:00
this . restoringTree = this . getRestoringTabsCount ( ) > 1 ;
2009-08-26 05:33:54 -04:00
return ;
2009-07-03 05:58:34 -04:00
}
} ,
2010-01-29 02:54:17 -05:00
restoringTree : false ,
2009-12-25 03:34:52 -05:00
getRestoringTabsCount : function TSTService _getRestoringTabsCount ( )
2009-10-25 13:31:47 -04:00
{
2010-09-14 03:39:17 -04:00
return this . getAllTabsArray ( this . browser )
2009-10-25 13:31:47 -04:00
. filter ( function ( aTab ) {
var owner = aTab . linkedBrowser ;
2010-01-28 11:33:00 -05:00
var data = owner . _ _SS _data || // Firefox 3.6-
owner . parentNode . _ _SS _data ; // -Firefox 3.5
2011-02-06 20:10:47 -05:00
return (
data &&
data . _tabStillLoading &&
! aTab . hasAttribute ( 'ontap' ) // if BarTab is installed, to-be-restored tab possibly has the value unexpectedly.
) ;
2009-10-25 13:31:47 -04:00
} ) . length ;
} ,
2009-07-03 05:58:34 -04:00
2007-10-16 13:22:28 -04:00
/* Pref Listener */
2008-03-08 05:07:28 -05:00
2008-03-03 03:26:51 -05:00
domains : [
'extensions.treestyletab' ,
2009-08-14 02:30:03 -04:00
'browser.ctrlTab.previews'
2008-03-03 03:26:51 -05:00
] ,
2007-10-16 13:22:28 -04:00
2009-12-25 03:34:52 -05:00
onPrefChange : function TSTService _onPrefChange ( aPrefName )
2007-10-16 13:22:28 -04:00
{
var value = this . getPref ( aPrefName ) ;
switch ( aPrefName )
{
2008-06-17 02:22:49 -04:00
case 'extensions.treestyletab.tabbar.autoHide.mode' :
2008-06-17 08:55:05 -04:00
// don't set on this time, because appearance of all tabbrowsers are not updated yet.
2009-09-03 02:24:06 -04:00
// this.autoHide.mode = this.getTreePref('tabbar.autoHide.mode');
2008-03-09 08:34:10 -04:00
case 'extensions.treestyletab.tabbar.autoShow.accelKeyDown' :
2008-03-08 03:57:17 -05:00
case 'extensions.treestyletab.tabbar.autoShow.tabSwitch' :
2008-03-09 08:34:10 -04:00
case 'extensions.treestyletab.tabbar.autoShow.feedback' :
2010-12-06 08:31:58 -05:00
this . autoHideWindow . updateKeyListeners ( window ) ;
2008-03-08 03:57:17 -05:00
break ;
2009-03-25 10:09:34 -04:00
case 'extensions.treestyletab.tabbar.style' :
case 'extensions.treestyletab.tabbar.position' :
this . preLoadImagesForStyle ( [
this . getPref ( 'extensions.treestyletab.tabbar.style' ) ,
2011-01-22 10:46:29 -05:00
this . position
2009-03-25 10:09:34 -04:00
] . join ( '-' ) ) ;
break ;
2009-08-14 02:36:59 -04:00
case 'browser.ctrlTab.previews' :
2010-12-06 08:31:58 -05:00
this . autoHideWindow . updateKeyListeners ( window ) ;
2009-12-25 06:27:23 -05:00
case 'extensions.treestyletab.autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut' :
case 'extensions.treestyletab.autoCollapseExpandSubtreeOnSelect' :
2009-08-14 02:36:59 -04:00
if ( this . shouldListenKeyEventsForAutoExpandByFocusChange )
2009-08-14 02:12:08 -04:00
this . startListenKeyEventsFor ( this . LISTEN _FOR _AUTOEXPAND _BY _FOCUSCHANGE ) ;
2009-08-14 02:36:59 -04:00
else
2009-08-14 02:12:08 -04:00
this . endListenKeyEventsFor ( this . LISTEN _FOR _AUTOEXPAND _BY _FOCUSCHANGE ) ;
break ;
2007-10-16 13:22:28 -04:00
default :
break ;
}
} ,
2010-03-27 10:52:25 -04:00
2007-10-16 13:22:28 -04:00
} ;
2010-03-27 10:52:25 -04:00
( function ( ) {
2009-12-25 11:38:14 -05:00
var namespace = { } ;
Components . utils . import (
2009-12-25 11:51:24 -05:00
'resource://treestyletab-modules/utils.js' ,
2009-12-25 11:43:16 -05:00
namespace
) ;
2009-12-25 11:51:24 -05:00
TreeStyleTabService . _ _proto _ _ = TreeStyleTabService . utils = namespace . TreeStyleTabUtils ;
TreeStyleTabService . utils . init ( ) ;
2009-12-25 11:38:14 -05:00
} ) ( ) ;
2007-11-17 00:20:26 -05:00