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
{
2009-12-18 04:14:02 -05:00
this . currentTabbarPosition = aNewPosition ;
2009-04-21 02:42:52 -04:00
} ,
2010-03-27 10:52:25 -04:00
2009-12-17 21:46:36 -05:00
get currentTabbarPosition ( ) /* PUBLIC API */
{
2010-05-08 01:37:41 -04:00
return this . browser . getAttribute ( this . kTABBAR _POSITION ) ||
this . utils . currentTabbarPosition ;
2009-12-17 21:46:36 -05:00
} ,
2009-12-18 04:14:02 -05:00
set currentTabbarPosition ( aValue )
2010-03-24 13:20:30 -04:00
{
if ( 'UndoTabService' in window && UndoTabService . isUndoable ( ) ) {
var current = this . utils . currentTabbarPosition ;
2010-01-13 02:06:50 -05:00
var self = this ;
UndoTabService . doOperation (
function ( ) {
self . utils . currentTabbarPosition = 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
}
) ;
}
2009-12-25 11:51:24 -05:00
return this . utils . currentTabbarPosition = 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 ( )
{
return window . gToolbox && gToolbox . customizing ;
} ,
2010-04-22 04:12:31 -04:00
maxTabbarWidth : function TSTService _maxTabbarWidth ( aWidth , aTabBrowser )
{
aTabBrowser = aTabBrowser || this . browser ;
2010-04-22 05:05:15 -04:00
var max = Math . max ( window . outerWidth , parseInt ( document . documentElement . getAttribute ( 'width' ) || 0 ) ) ;
2010-04-22 05:38:46 -04:00
return 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-04-22 05:05:15 -04:00
var max = Math . max ( window . outerHeight , parseInt ( document . documentElement . getAttribute ( 'height' ) || 0 ) ) ;
2010-04-22 05:38:46 -04:00
return Math . min ( aHeight , max * this . MAX _TABBAR _SIZE _RATIO ) ;
2010-04-22 04:12:31 -04:00
} ,
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 ) ;
2008-02-25 20:14:12 -05:00
if ( ! document . getElementById ( 'content' ) ) return ;
2008-11-09 23:48:11 -05:00
window . addEventListener ( 'SSTabRestoring' , this , true ) ;
2008-12-01 03:30:36 -05:00
if ( 'swapBrowsersAndCloseOther' in document . getElementById ( 'content' ) ) {
var source = window . BrowserStartup . toSource ( ) ;
if ( source . indexOf ( '!MultipleTabService.tearOffSelectedTabsFromRemote()' ) > - 1 ) {
eval ( 'window.BrowserStartup = ' + source . replace (
'!MultipleTabService.tearOffSelectedTabsFromRemote()' ,
2009-12-25 06:19:50 -05:00
'!TreeStyleTabService.tearOffSubtreeFromRemote() && $&'
2008-12-01 03:30:36 -05:00
) ) ;
}
else {
eval ( 'window.BrowserStartup = ' + source . replace (
'gBrowser.swapBrowsersAndCloseOther(gBrowser.selectedTab, uriToLoad);' ,
2009-12-25 06:19:50 -05:00
'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
)
) ;
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
this . registerTabFocusAllowance ( this . defaultTabFocusAllowance ) ;
2009-07-07 20:09:13 -04:00
2009-07-27 03:22:56 -04:00
this . migratePrefs ( ) ;
} ,
preInitialized : false ,
2009-12-25 03:34:52 -05:00
defaultTabFocusAllowance : function TSTService _defaultTabFocusAllowance ( aBrowser )
2009-07-27 03:22:56 -04:00
{
var tab = aBrowser . selectedTab ;
return (
! this . getPref ( 'browser.tabs.selectOwnerOnClose' ) ||
! tab . owner ||
(
aBrowser . _removingTabs &&
aBrowser . _removingTabs . indexOf ( tab . owner ) > - 1
)
) ;
} ,
2009-12-25 06:19:50 -05:00
kPREF _VERSION : 5 ,
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' ) ;
this . setPref ( 'browser.tabs.loadFolderAndReplace' , behavior & this . kGROUP _BOOKMARK _REPLACE ? true : false ) ;
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 ) ;
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 ) ;
document . addEventListener ( 'popuphiding' , this , false ) ;
2010-04-06 09:38:05 -04:00
document . addEventListener ( 'TreeStyleTabCollapsedStateChange' , 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
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 ( ) ;
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
{
var prefs = window [ 'piro.sakura.ne.jp' ] . prefs ;
var restorePrefs = function ( ) {
if ( ! prefs ) return ;
[
'browser.link.open_newwindow.restriction' ,
'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 &&
aObserver . tabContainer . tabbrowser == aObserver ) { // Firefox 3.7 or later
aObserver = aObserver . tabContainer ;
strip . addEventListener ( 'drop' , this , true ) ;
strip . addEventListener ( 'dragend' , this , true ) ;
}
2010-03-27 10:52:25 -04:00
// Firefox 3.5 or later
var useHTML5Events = '_setEffectAllowedForDataTransfer' in aObserver ;
if ( useHTML5Events ) {
strip . addEventListener ( 'dragstart' , this , true ) ;
strip . addEventListener ( 'dragover' , this , true ) ;
strip . addEventListener ( 'dragleave' , this , true ) ;
}
var canDropFunctionName = useHTML5Events ?
2009-08-25 06:10:29 -04:00
'_setEffectAllowedForDataTransfer' : // Firefox 3.5 or later
2008-10-01 21:32:31 -04:00
'canDrop' ; // Firefox 3.0.x
2010-03-23 13:58:23 -04:00
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");)/ ,
< ! [ CDATA [
2010-03-24 13:20:30 -04:00
if ( ! this . treeStyleTab . checkCanTabDrop ( arguments [ 0 ] , this ) ) {
2010-03-23 13:58:23 -04:00
return TST _DRAGDROP _DISALLOW _RETRUN _VALUE ;
}
$1
] ] >
) . replace (
/TST_DRAGDROP_DISALLOW_RETRUN_VALUE/g ,
( canDropFunctionName == 'canDrop' ?
'false' :
'dt.effectAllowed = "none"'
)
2008-10-01 21:32:31 -04:00
)
2010-03-23 13:58:23 -04:00
) ;
}
2007-11-14 07:31:14 -05:00
2010-03-27 10:52:25 -04:00
if ( 'onDragStart' in aObserver ) { // Firefox 3.0.x
2010-03-24 13:20:30 -04:00
eval ( 'aObserver.onDragStart = ' +
2010-03-27 10:52:25 -04:00
aObserver . onDragStart . toSource ( ) . replace (
2010-03-24 13:20:30 -04:00
'aEvent.target.localName == "tab"' ,
< ! [ CDATA [
(
! this . treeStyleTab . tabbarDNDObserver . canDragTabbar ( aEvent ) &&
$ &
)
] ] >
)
) ;
}
2010-03-27 10:52:25 -04:00
if ( 'onDragOver' in aObserver ) { // Firefox 3.0.x
eval ( 'aObserver.onDragOver = ' +
aObserver . onDragOver . toSource ( ) . replace (
2010-03-23 13:58:23 -04:00
'{' ,
2010-03-27 10:52:25 -04:00
< ! [ CDATA [ $ &
if ( this . treeStyleTab . processTabDragOverEvent ( aEvent , this ) )
2010-03-23 13:58:23 -04:00
return ;
] ] >
)
) ;
}
2007-11-14 07:31:14 -05:00
2010-03-27 10:52:25 -04:00
if ( 'onDragExit' in aObserver ) { // Firefox 3.0.x
eval ( 'aObserver.onDragExit = ' +
aObserver . onDragExit . toSource ( ) . replace (
2010-03-23 13:58:23 -04:00
/(this.mTabDropIndicatorBar\.[^;]+;)/ ,
'$1; this.treeStyleTab.clearDropPosition();'
)
) ;
}
2007-11-14 07:31:14 -05:00
2008-10-01 21:32:31 -04:00
var dropFunctionName = '_onDrop' in aObserver ?
2010-03-27 10:52:25 -04:00
'_onDrop' : // Firefox 3.5 - 3.6
2008-10-01 21:32:31 -04:00
'onDrop' ; // Firefox 3.0.x
2010-03-23 13:58:23 -04:00
if ( dropFunctionName in aObserver ) {
eval ( 'aObserver.' + dropFunctionName + ' = ' +
aObserver [ dropFunctionName ] . toSource ( ) . replace (
'{' ,
< ! [ CDATA [
{
var TSTTabBrowser = this ;
TSTTabBrowser . treeStyleTab . clearDropPosition ( ) ;
var dropActionInfo = TSTTabBrowser . treeStyleTab . getDropAction ( aEvent , TST _DRAGSESSION ) ;
] ] >
) . replace ( // Firefox 3.0.x, 3.5 or later
/(if \((accelKeyPressed|isCopy|dropEffect == "copy")\) {)/ ,
< ! [ CDATA [
if ( TSTTabBrowser . treeStyleTab . performDrop ( dropActionInfo , draggedTab ) )
return ;
$1 ] ] >
) . replace ( // Firefox 3, duplication of tab
/(this.selectedTab = newTab;)(\s*\})?/g ,
< ! [ CDATA [ $1 ;
if ( dropActionInfo . position == TreeStyleTabService . kDROP _ON )
TSTTabBrowser . treeStyleTab . attachTabTo ( newTab , dropActionInfo . target ) ;
$2 ] ] >
) . replace ( // Firefox 3, dragging tab from another window
'else if (draggedTab) {' ,
< ! [ CDATA [ $ &
if ( TSTTabBrowser . treeStyleTab . performDrop ( dropActionInfo , draggedTab ) )
return ;
] ] >
) . replace (
/(this.loadOneTab\([^;]+\));/ ,
< ! [ CDATA [
TSTTabBrowser . treeStyleTab . performDrop ( dropActionInfo , $1 ) ;
2008-02-24 03:11:17 -05:00
return ;
2010-03-23 13:58:23 -04:00
] ] >
) . replace (
'document.getBindingParent(aEvent.originalTarget).localName != "tab"' ,
'!TreeStyleTabService.getTabFromEvent(aEvent)'
) . replace (
'var tab = aEvent.target;' ,
< ! [ CDATA [ $ &
2010-03-31 07:08:46 -04:00
let locked = (
tab . getAttribute ( 'locked' ) == 'true' || // Tab Mix Plus and others
tab . getAttribute ( 'isPageLocked' ) == 'true' // Super Tab Mode
) ;
2010-03-23 13:58:23 -04:00
var loadDroppedLinkToNewChildTab = (
dropActionInfo . position != TreeStyleTabService . kDROP _ON ||
2010-03-31 07:08:46 -04:00
locked
2010-03-23 13:58:23 -04:00
) ;
if ( ! loadDroppedLinkToNewChildTab &&
dropActionInfo . position == TreeStyleTabService . kDROP _ON ) {
loadDroppedLinkToNewChildTab = TreeStyleTabService . dropLinksOnTabBehavior ( ) == TreeStyleTabService . kDROPLINK _NEWTAB ;
}
2010-03-31 07:08:46 -04:00
if ( loadDroppedLinkToNewChildTab || locked ) {
2010-03-23 13:58:23 -04:00
TSTTabBrowser . treeStyleTab . performDrop ( dropActionInfo , TSTTabBrowser . loadOneTab ( getShortcutOrURI ( url ) , null , null , null , bgLoad , false ) ) ;
return ;
}
] ] >
) . replace (
/TST_DRAGSESSION/g ,
( canDropFunctionName == 'canDrop' ?
'aDragSession' :
'TSTTabBrowser.treeStyleTab.getCurrentDragSession()'
)
2008-10-01 21:32:31 -04:00
)
2010-03-23 13:58:23 -04:00
) ;
}
2010-03-25 06:53:39 -04:00
2010-03-27 10:52:25 -04:00
if ( '_onDragEnd' in aObserver ) { // Firefox 3.5 - 3.6
2010-03-25 08:56:49 -04:00
eval ( 'aObserver._onDragEnd = ' + aObserver . _onDragEnd . toSource ( ) . replace (
2010-03-25 06:53:39 -04:00
/([^\{\}\(\);]*this\.replaceTabWithWindow\()/ ,
'if (this.treeStyleTab.isDraggingAllTabs(draggedTab)) return; $1'
) . replace (
'{' ,
'{ var treeStyleTab = this.treeStyleTab;'
) . replace (
/window\.screenX/g , 'gBrowser.boxObject.screenX'
) . replace (
/window\.outerWidth/g , 'gBrowser.boxObject.width'
) . replace (
/\.screenX/g , '[treeStyleTab.positionProp]'
) . replace (
/\.width/g , '[treeStyleTab.sizeProp]'
) . replace (
/\.screenY/g , '[treeStyleTab.invertedPositionProp]'
) . replace (
/\.height/g , '[treeStyleTab.invertedSizeProp]'
) ) ;
}
2007-11-14 07:31:14 -05:00
} ,
2010-03-24 13:20:30 -04:00
destroyTabDNDObserver : function TSTService _destroyTabDNDObserver ( aObserver )
{
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 &&
aObserver . tabContainer . tabbrowser == aObserver ) { // Firefox 3.7 or later
2010-03-27 10:52:25 -04:00
strip . removeEventListener ( 'dragstart' , this , true ) ;
strip . removeEventListener ( 'dragover' , this , true ) ;
strip . removeEventListener ( 'dragleave' , this , true ) ;
}
2010-03-27 11:09:35 -04:00
// Firefox 3.5 or later
var useHTML5Events = '_setEffectAllowedForDataTransfer' in aObserver ;
if ( useHTML5Events ) {
2010-03-27 10:52:25 -04:00
strip . removeEventListener ( 'dragstart' , this , true ) ;
strip . removeEventListener ( 'dragover' , this , true ) ;
strip . removeEventListener ( 'dragleave' , this , true ) ;
2010-03-24 13:20:30 -04:00
}
} ,
2010-03-27 10:52:25 -04:00
checkCanTabDrop : function TSTService _checkCanTabDrop ( aEvent , aTabBrowser )
{
try {
var session = this . getCurrentDragSession ( ) ;
var node = session . sourceNode ;
var tab = this . getTabFromChild ( node ) ;
if ( ! node ||
! tab ||
tab . parentNode != aTabBrowser . mTabContainer )
return true ;
tab = this . getTabFromEvent ( aEvent ) ;
if ( this . isCollapsed ( tab ) )
return false ;
var info = this . getDropAction ( aEvent , session ) ;
return info . canDrop ;
}
catch ( e ) {
dump ( 'TreeStyleTabService::canDrop\n' + e + '\n' ) ;
return false ;
}
} ,
onTabDragStart : function TSTService _onTabDragStart ( aEvent )
{
var b = this . getTabBrowserFromChild ( aEvent . currentTarget ) ;
if ( b . treeStyleTab . tabbarDNDObserver . canDragTabbar ( aEvent ) )
b . treeStyleTab . onTabbarDragStart ( aEvent , b ) ;
} ,
2010-03-24 13:20:30 -04:00
onTabbarDragStart : function TSTService _onTabbarDragStart ( aEvent , aTabBrowser )
2010-02-05 04:36:25 -05:00
{
var dt = aEvent . dataTransfer ;
dt . mozSetDataAt (
this . kDRAG _TYPE _TABBAR ,
aEvent . shiftKey ?
this . kTABBAR _MOVE _FORCE :
this . kTABBAR _MOVE _NORMAL ,
0
) ;
dt . mozCursor = 'move' ;
// var tabbar = aTabBrowser.mTabContainer;
// var box = tabbar.boxObject;
// dt.setDragImage(
// tabbar,
// aEvent.screenX - box.screenX,
// aEvent.screenY - box.screenY
// );
// no feedback image, because it's annoying...
dt . setDragImage ( new Image ( ) , 0 , 0 ) ;
aEvent . stopPropagation ( ) ;
aTabBrowser . treeStyleTab . tabbarDNDObserver . readyToStartDrag ( ) ;
} ,
2010-03-27 10:52:25 -04:00
onTabDragOver : function TSTService _onTabDragOver ( aEvent )
2010-02-05 04:36:25 -05:00
{
2010-03-27 10:52:25 -04:00
var b = this . getTabBrowserFromChild ( aEvent . currentTarget ) ;
if ( b . treeStyleTab . processTabDragOverEvent ( aEvent , b ) ) {
aEvent . stopPropagation ( ) ;
aEvent . preventDefault ( ) ; // this is required to override default dragover actions!
}
2010-02-05 04:36:25 -05:00
} ,
2010-03-27 10:52:25 -04:00
2010-03-24 13:20:30 -04:00
processTabDragOverEvent : function TSTService _processTabDragOverEvent ( aEvent , aTabBrowser )
2010-02-05 04:36:25 -05:00
{
try {
var session = this . getCurrentDragSession ( ) ;
2010-04-21 07:43:13 -04:00
// don't touch to drag & drop of customizable toolbar items
if ( this . isToolbarCustomizing && ! this . getTabFromChild ( session . sourceNode ) )
return false ;
2010-02-05 04:36:25 -05:00
window [ 'piro.sakura.ne.jp' ] . autoScroll . processAutoScroll ( aEvent ) ;
var info = this . getDropAction ( aEvent , session ) ;
2010-03-24 13:20:30 -04:00
var setEffectAllowedFunc ;
2010-03-24 13:57:49 -04:00
var observer = aTabBrowser ;
2010-03-24 13:20:30 -04:00
if ( aTabBrowser . _setEffectAllowedForDataTransfer ) {
setEffectAllowedFunc = function ( aEvent ) {
return aTabBrowser . _setEffectAllowedForDataTransfer ( aEvent ) ;
} ;
}
else if ( aTabBrowser . tabContainer &&
2010-03-24 13:57:49 -04:00
aTabBrowser . tabContainer . _setEffectAllowedForDataTransfer ) {
observer = aTabBrowser . tabContainer ;
2010-03-24 13:20:30 -04:00
setEffectAllowedFunc = function ( aEvent ) {
return aTabBrowser . tabContainer . _setEffectAllowedForDataTransfer ( aEvent ) ;
} ;
}
2010-03-27 10:52:25 -04:00
// auto-switch for staying on tabs (Firefox 3.0 or later)
2010-03-24 13:57:49 -04:00
if (
setEffectAllowedFunc &&
2010-04-27 00:32:23 -04:00
info . position == this . kDROP _ON &&
2010-02-05 04:36:25 -05:00
info . target &&
! info . target . selected &&
2010-03-24 13:57:49 -04:00
(
2010-04-22 04:50:23 -04:00
( 'mDragTime' in observer && 'mDragOverDelay' in observer ) || // Firefox 3.6
2010-03-27 10:52:25 -04:00
( '_dragTime' in observer && '_dragOverDelay' in observer ) // Firefox 3.7 or later
2010-03-24 13:57:49 -04:00
)
) {
let time = observer . mDragTime || observer . _dragTime || 0 ;
let delay = observer . mDragOverDelay || observer . _dragOverDelay || 0 ;
2010-03-24 13:20:30 -04:00
let effects = setEffectAllowedFunc ( aEvent ) ;
2010-02-05 04:36:25 -05:00
if ( effects == 'link' ) {
let now = Date . now ( ) ;
2010-03-24 13:57:49 -04:00
if ( ! time ) {
2010-04-22 06:50:14 -04:00
time = now ;
2010-03-24 13:57:49 -04:00
if ( 'mDragTime' in observer )
2010-04-22 06:50:14 -04:00
observer . mDragTime = time ;
2010-03-24 13:57:49 -04:00
else
2010-04-22 06:50:14 -04:00
observer . _dragTime = time ;
2010-03-24 13:57:49 -04:00
}
if ( now >= time + delay )
2010-02-05 04:36:25 -05:00
aTabBrowser . selectedTab = info . target ;
}
}
if ( ! info . target || info . target != this . evaluateXPath (
'child::xul:tab[@' + this . kDROP _POSITION + ']' ,
aTabBrowser . mTabContainer ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue )
this . clearDropPosition ( ) ;
2010-03-24 13:20:30 -04:00
if ( setEffectAllowedFunc ?
( setEffectAllowedFunc ( aEvent ) == 'none' ) :
2010-02-05 04:36:25 -05:00
! aTabBrowser . canDrop ( aEvent , session )
)
return true ;
info . target . setAttribute (
this . kDROP _POSITION ,
info . position == this . kDROP _BEFORE ? 'before' :
info . position == this . kDROP _AFTER ? 'after' :
'self'
) ;
2010-03-24 13:20:30 -04:00
var indicator = aTabBrowser . mTabDropIndicatorBar || aTabBrowser . tabContainer . _tabDropIndicator ;
indicator . setAttribute ( 'dragging' , ( info . position == this . kDROP _ON ) ? 'false' : 'true' ) ;
2010-05-08 01:37:41 -04:00
return ( info . position == this . kDROP _ON || aTabBrowser . treeStyleTab . currentTabbarPosition != 'top' )
2010-02-05 04:36:25 -05:00
}
catch ( e ) {
dump ( 'TreeStyleTabService::onDragOver\n' + e + '\n' ) ;
}
} ,
2010-03-27 10:52:25 -04:00
onTabDragLeave : function TSTService _onTabDragLeave ( aEvent )
2010-03-24 13:20:30 -04:00
{
2010-03-27 10:52:25 -04:00
var b = this . getTabBrowserFromChild ( aEvent . currentTarget ) ;
2010-03-24 13:20:30 -04:00
var tabbarFromEvent = this . getTabbarFromChild ( aEvent . relatedTarget ) ;
if ( ! tabbarFromEvent )
2010-03-27 10:52:25 -04:00
b . treeStyleTab . clearDropPosition ( ) ;
2010-03-24 13:20:30 -04:00
} ,
2010-03-24 13:57:49 -04:00
2010-03-27 10:52:25 -04:00
onTabDrop : function TSTService _onTabDrop ( aEvent )
2010-03-24 13:57:49 -04:00
{
2010-03-28 14:22:15 -04:00
var b = this . getTabBrowserFromChild ( aEvent . currentTarget ) ;
var tabbar = b . mTabContainer ;
2010-03-24 13:57:49 -04:00
var sv = b . treeStyleTab ;
var dt = aEvent . dataTransfer ;
sv . clearDropPosition ( ) ;
var dropActionInfo = sv . getDropAction ( aEvent , sv . getCurrentDragSession ( ) ) ;
var draggedTab ;
if ( dt . dropEffect != 'link' ) {
draggedTab = dt . mozGetDataAt ( TAB _DROP _TYPE , 0 ) ;
if ( ! draggedTab ) {
aEvent . stopPropagation ( ) ;
return ;
}
}
2010-03-24 14:21:32 -04:00
if ( draggedTab && sv . performDrop ( dropActionInfo , draggedTab ) ) {
2010-03-24 13:57:49 -04:00
aEvent . stopPropagation ( ) ;
return ;
}
2010-03-24 14:21:32 -04:00
// duplicating of tabs
2010-03-24 13:57:49 -04:00
if (
2010-03-24 14:21:32 -04:00
draggedTab &&
2010-03-24 13:57:49 -04:00
(
dt . dropEffect == 'copy' ||
2010-03-27 11:03:39 -04:00
this . getTabBrowserFromChild ( draggedTab ) != b
2010-03-24 13:57:49 -04:00
) &&
dropActionInfo . position == sv . kDROP _ON
) {
2010-03-27 11:03:39 -04:00
var beforeTabs = Array . slice ( b . mTabContainer . childNodes ) ;
2010-03-24 13:57:49 -04:00
window . setTimeout ( function ( ) {
2010-03-27 11:03:39 -04:00
var newTabs = Array . slice ( b . mTabContainer . childNodes ) . filter ( function ( aTab ) {
2010-03-24 13:57:49 -04:00
return beforeTabs . indexOf ( aTab ) < 0 ;
2010-03-28 14:22:15 -04:00
} ) ;
2010-03-27 11:03:39 -04:00
if ( newTabs . length )
sv . attachTabTo ( newTabs [ 0 ] , dropActionInfo . target ) ;
2010-03-24 13:57:49 -04:00
} , 0 ) ;
2010-03-24 14:21:32 -04:00
return ;
}
2010-03-27 10:52:25 -04:00
// dropping of urls
2010-03-24 14:22:28 -04:00
if ( ! draggedTab ) {
2010-03-27 10:52:25 -04:00
aEvent . stopPropagation ( ) ;
2010-03-24 14:24:09 -04:00
let url ;
2010-03-24 14:22:28 -04:00
for ( let i = 0 ; i < tabbar . _supportedLinkDropTypes . length ; i ++ ) {
let dataType = tabbar . _supportedLinkDropTypes [ i ] ;
let isURLList = dataType == 'text/uri-list' ;
let urlData = dt . mozGetDataAt ( isURLList ? 'URL' : dataType , 0 ) ;
if ( urlData ) {
url = transferUtils . retrieveURLFromData ( urlData , isURLList ? 'text/plain' : dataType ) ;
break ;
}
2010-03-24 14:21:32 -04:00
}
2010-03-24 14:22:28 -04:00
if ( ! url || ! url . length || url . indexOf ( ' ' , 0 ) != - 1 || /^\s*(javascript|data):/ . test ( url ) )
return ;
2010-03-24 14:21:32 -04:00
2010-03-24 14:22:28 -04:00
nsDragAndDrop . dragDropSecurityCheck ( aEvent , sv . getCurrentDragSession ( ) , url ) ;
2010-03-24 14:21:32 -04:00
2010-03-24 14:24:09 -04:00
let bgLoad = this . getPref ( 'browser.tabs.loadInBackground' ) ;
2010-03-24 14:22:28 -04:00
if ( aEvent . shiftKey ) bgLoad = ! bgLoad ;
2010-03-24 14:21:32 -04:00
2010-03-24 14:24:09 -04:00
let tab = sv . getTabFromEvent ( aEvent ) ;
2010-03-24 14:22:28 -04:00
if ( ! tab || dt . dropEffect == 'copy' ) {
sv . performDrop ( dropActionInfo , b . loadOneTab ( getShortcutOrURI ( url ) , { inBackground : bgLoad } ) ) ;
}
else {
2010-03-31 07:08:46 -04:00
let locked = (
tab . getAttribute ( 'locked' ) == 'true' || // Tab Mix Plus and others
tab . getAttribute ( 'isPageLocked' ) == 'true' // Super Tab Mode
) ;
2010-03-24 14:22:28 -04:00
let loadDroppedLinkToNewChildTab = dropActionInfo . position != sv . kDROP _ON || locked ;
if ( ! loadDroppedLinkToNewChildTab &&
dropActionInfo . position == sv . kDROP _ON )
loadDroppedLinkToNewChildTab = sv . dropLinksOnTabBehavior ( ) == sv . kDROPLINK _NEWTAB ;
try {
if ( loadDroppedLinkToNewChildTab || locked ) {
sv . performDrop ( dropActionInfo , b . loadOneTab ( getShortcutOrURI ( url ) , { inBackground : bgLoad } ) ) ;
}
else {
tab . linkedBrowser . loadURI ( getShortcutOrURI ( url ) ) ;
if ( ! bgLoad )
b . selectedTab = tab ;
}
2010-03-24 14:21:32 -04:00
}
2010-03-24 14:22:28 -04:00
catch ( e ) {
2010-03-24 14:21:32 -04:00
}
}
2010-03-24 13:57:49 -04:00
}
} ,
2010-03-25 06:53:39 -04:00
2010-03-27 10:52:25 -04:00
onTabDragEnd : function TSTService _onTabDragEnd ( aEvent )
2010-03-25 06:53:39 -04:00
{
2010-03-28 14:22:15 -04:00
var b = this . getTabBrowserFromChild ( aEvent . currentTarget ) ;
var tabbar = b . mTabContainer ;
2010-03-25 06:53:39 -04:00
var sv = b . treeStyleTab ;
var dt = aEvent . dataTransfer ;
2010-03-25 07:49:37 -04:00
sv . clearDropPosition ( ) ;
2010-03-25 08:56:49 -04:00
if (
dt . mozUserCancelled ||
dt . dropEffect != 'none' ||
tabbar . hasAttribute ( this . kDROP _POSITION ) // ignore dragging of the tabbar itself
)
2010-03-25 07:29:00 -04:00
return ;
// prevent handling of this event by the default handler
aEvent . stopPropagation ( ) ;
2010-03-25 07:49:37 -04:00
var eX = aEvent . screenX ;
var eY = aEvent . screenY ;
var x , y , w , h ;
// ignore drop on the toolbox
x = window . screenX ;
y = window . screenY ;
w = window . outerWidth ;
h = document . getElementById ( 'navigator-toolbox' ) . boxObject . height ;
if ( eX > x && eX < x + w && eY > y && eY < y + h )
return ;
// ignore drop near the tab bar
var box = tabbar . boxObject ;
var ignoreArea = Math . max ( 16 , parseInt ( tabbar . firstChild . boxObject . height / 2 ) ) ;
x = box . screenX - ( sv . isVertical ? ignoreArea : 0 ) ;
y = box . screenY - ignoreArea ;
w = box . width + ( sv . isVertical ? ignoreArea + ignoreArea : 0 ) ;
h = box . height + ignoreArea + ignoreArea ;
if ( eX > x && eX < x + w && eY > y && eY < y + h )
return ;
2010-03-25 07:29:00 -04:00
var draggedTab = dt . mozGetDataAt ( TAB _DROP _TYPE , 0 ) ;
if ( sv . isDraggingAllTabs ( draggedTab ) )
return ;
b . replaceTabWithWindow ( draggedTab ) ;
2010-03-25 06:53:39 -04:00
} ,
2010-03-27 10:52:25 -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
this . _splitFunctionNames ( < ! [ CDATA [
window . permaTabs . utils . wrappedFunctions [ "window.BrowserLoadURL" ]
window . BrowserLoadURL
] ] > ) . 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 BrowserLoadURL/ . test ( source ) )
2008-09-26 10:13:29 -04:00
return ;
2009-04-27 21:32:01 -04:00
eval ( aFunc + ' = ' + source . replace (
2008-09-26 10:13:29 -04:00
'aTriggeringEvent && aTriggeringEvent.altKey' ,
'TreeStyleTabService.checkReadyToOpenNewTabOnLocationBar(url, $&)'
) ) ;
2009-05-13 02:09:17 -04:00
source = null ;
2009-04-27 21:32:01 -04:00
} , this ) ;
2007-10-21 11:50:11 -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
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 ;
eval ( aFunc + ' = ' + source . replace (
/(openNewTabWith\()/g ,
< ! [ CDATA [
if ( ! TreeStyleTabService . checkToOpenChildTab ( event . target . ownerDocument . defaultView ) ) TreeStyleTabService . readyToOpenChildTab ( event . target . ownerDocument . defaultView ) ;
$1 ] ] >
) . replace (
/(event.ctrlKey|event.metaKey)/ ,
< ! [ CDATA [
2010-04-22 21:15:23 -04:00
TreeStyleTabService . checkReadyToOpenNewTabFromLink ( {
link : ( linkNode || { href : href } ) ,
2009-04-27 21:32:01 -04:00
modifier : $1 ,
invert : TreeStyleTabService . getTreePref ( 'link.invertDefaultBehavior' )
2009-09-08 22:57:30 -04:00
} ) ?
2009-09-15 07:48:44 -04:00
(
( TreeStyleTabService . isNewTabAction ( event ) ? null : TreeStyleTabService . readyToOpenDivertedTab ( ) ) ,
true
) :
2009-09-08 22:57:30 -04:00
( TreeStyleTabService . readyToOpenChildTab ( ) , false )
2009-04-27 21:32:01 -04:00
] ] >
) . replace (
/ * <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 郊 <EFBFBD> <EFBFBD> <EFBFBD> N <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ^ <EFBFBD> u <EFBFBD> <EFBFBD> <EFBFBD> J <EFBFBD> <EFBFBD> <EFBFBD> ݒ <EFBFBD> <EFBFBD> ̎ <EFBFBD> <EFBFBD> Ɂ A <EFBFBD> A <EFBFBD> N <EFBFBD> Z <EFBFBD> <EFBFBD> <EFBFBD> L <EFBFBD> [ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ă <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ꍇ <EFBFBD> <EFBFBD>
<EFBFBD> <EFBFBD> <EFBFBD> ] <EFBFBD> <EFBFBD> <EFBFBD> ꂽ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> i <EFBFBD> ʏ <EFBFBD> <EFBFBD> ̃ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> N <EFBFBD> ǂݍ <EFBFBD> <EFBFBD> ݁ j <EFBFBD> <EFBFBD> <EFBFBD> s <EFBFBD> <EFBFBD> * /
'return false;case 1:' ,
< ! [ CDATA [
2009-12-15 03:33:03 -05:00
if ( ( // do nothing for Tab Mix Plus
! TreeStyleTabService . getTreePref ( 'compatibility.TMP' ) ||
! ( 'TMP_contentAreaClick' in window )
) &&
2009-04-27 21:32:01 -04:00
TreeStyleTabService . checkToOpenChildTab ( ) ) {
TreeStyleTabService . stopToOpenChildTab ( ) ;
if ( TreeStyleTabService . isAccelKeyPressed ( event ) ) {
if ( linkNode )
urlSecurityCheck ( href ,
'nodePrincipal' in linkNode . ownerDocument ?
linkNode . ownerDocument . nodePrincipal :
linkNode . ownerDocument . location . href
) ;
var postData = { } ;
href = getShortcutOrURI ( href , postData ) ;
if ( ! href ) return false ;
loadURI ( href , null , postData . value , false ) ;
}
}
return false ;
case 1 :
] ] >
) ) ;
2009-05-13 02:09:17 -04:00
source = null ;
2009-04-27 21:32:01 -04:00
return true ;
} , this ) ;
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 (
/((openWebPanel\([^\;]+\);|PlacesUIUtils.showMinimalAddBookmarkUI\([^;]+\);)event.preventDefault\(\);return false;\})/ ,
< ! [ CDATA [
$1
2009-12-15 03:33:03 -05:00
else if (
( // do nothing for Tab Mix Plus
! TreeStyleTabService . getTreePref ( 'compatibility.TMP' ) ||
! ( 'TMP_contentAreaClick' in window )
) &&
2010-04-22 21:15:23 -04:00
TreeStyleTabService . checkReadyToOpenNewTabFromLink ( wrapper )
2009-12-15 03:33:03 -05:00
) {
2009-04-27 21:32:01 -04:00
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
handleLinkClick ( event , wrapper . href , linkNode ) ;
return true ;
}
] ] >
) ) ;
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
] ] > ) . 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 (
/(openUILinkIn\()/g ,
< ! [ 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-03-30 22:21:18 -04:00
/(gBrowser\.mStrip\.boxObject\.height)/ ,
2010-05-08 01:37:41 -04:00
'((gBrowser.treeStyleTab.currentTabbarPosition != "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-03-27 09:07:31 -04:00
// Firefox 3.7 or later
2010-03-27 10:52:25 -04:00
'allFSToolbars[i].setAttribute("moz-collapsed", !aShow);' ,
2010-05-08 01:37:41 -04:00
'if (allFSToolbars[i].id != "TabsToolbar" || gBrowser.treeStyleTab.currentTabbarPosition == "top") { $& }'
2010-03-27 10:52:25 -04:00
) . replace (
// Firefox 3.7 or later
'this._isChromeCollapsed = !aShow;' ,
2010-03-27 09:07:31 -04:00
'gBrowser.treeStyleTab.updateFloatingTabbar(); $&'
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);' ,
2010-05-08 01:37:41 -04:00
'if (gBrowser.treeStyleTab.currentTabbarPosition == "top") { $& }'
2009-07-30 20:02:01 -04:00
)
) ;
eval ( 'FullScreen.toggle = ' +
FullScreen . toggle . toSource ( ) . replace (
'{' ,
< ! [ CDATA [ {
var treeStyleTab = gBrowser . treeStyleTab ;
2010-05-08 01:37:41 -04:00
if ( treeStyleTab . currentTabbarPosition != '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 (
/(\}\)?)$/ ,
'TreeStyleTabService.onPrintPreviewExit(); $1'
) ) ;
}
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
{
var bar = document . getElementById ( 'urlbar' ) ;
if ( ! bar ) return ;
var source ;
if (
'handleCommand' in bar &&
( source = bar . handleCommand . toSource ( ) ) &&
source . indexOf ( 'TreeStyleTabService' ) < 0
) {
eval ( 'bar.handleCommand = ' + source . replace (
'aTriggeringEvent && aTriggeringEvent.altKey' ,
'TreeStyleTabService.checkReadyToOpenNewTabOnLocationBar(url, $&)'
) ) ;
}
2009-05-13 02:09:17 -04:00
bar = null ;
source = null ;
2010-04-30 00:49:00 -04:00
// for Firefox 3.7 or later
this . updateAllTabsButton ( gBrowser ) ;
} ,
destroyToolbarItems : function TSTService _destroyToolbarItems ( )
{
// Firefox 3.7 or later (restore original position)
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 ;
var allTabsButton = document . getElementById ( 'alltabs-button' ) || // Firefox 3.7 or later
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 ;
// ignore menu items inserted by Weave
if ( items . some ( function ( aItem , aIndex ) {
if ( ( aItem . getAttribute ( 'anonid' ) || aItem . id ) == 'sync-tabs-sep' ) {
firstItemIndex = aIndex + 1 ;
return true ;
}
return false ;
} ) ) {
items = items . slice ( firstItemIndex ) ;
}
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
} ,
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
window [ 'piro.sakura.ne.jp' ] . animationManager . stop ( ) ;
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 ) ;
document . removeEventListener ( 'popuphiding' , this , false ) ;
document . removeEventListener ( 'TreeStyleTabCollapsedStateChange' , this , false ) ;
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
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-05-08 04:30:39 -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-02-09 18:11:02 -05:00
if ( aEvent . originalTarget . boxObject &&
! this . evaluateXPath (
2009-05-14 13:47:21 -04:00
'local-name() = "tooltip" or local-name() ="panel" or ' +
2009-05-12 14:47:36 -04:00
'parent::*/ancestor-or-self::*[local-name()="popup" or local-name()="menupopup"]' ,
aEvent . originalTarget ,
XPathResult . BOOLEAN _TYPE
2009-05-14 13:59:16 -04:00
) . booleanValue ) {
2009-05-12 14:47:36 -04:00
this . popupMenuShown = true ;
2009-05-14 13:59:16 -04:00
window . setTimeout ( function ( aSelf , aPopup ) {
if ( ! aPopup . boxObject . width || ! aPopup . boxObject . height )
aSelf . popupMenuShown = false ;
} , 10 , this , 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-02-09 18:11:02 -05:00
if ( aEvent . originalTarget . boxObject &&
! this . evaluateXPath (
2009-05-14 13:47:21 -04:00
'local-name() = "tooltip" or local-name() ="panel" or ' +
2009-05-12 14:47:36 -04:00
'parent::*/ancestor-or-self::*[local-name()="popup" or local-name()="menupopup"]' ,
aEvent . originalTarget ,
XPathResult . BOOLEAN _TYPE
2009-05-14 13:59:16 -04:00
) . booleanValue ) {
2009-05-12 14:47:36 -04:00
this . popupMenuShown = false ;
2009-05-14 13:59:16 -04:00
}
2007-10-18 13:11:03 -04:00
return ;
2007-10-17 09:25:50 -04:00
2010-04-06 09:38:05 -04:00
case 'TreeStyleTabCollapsedStateChange' :
return this . updateAeroPeekPreviews ( ) ;
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
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' :
this . currentTabbarPosition = aEvent . entry . data . oldPosition ;
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' :
this . currentTabbarPosition = aEvent . entry . data . newPosition ;
return ;
}
2010-05-08 04:30:39 -04:00
return ;
2010-03-24 13:20:30 -04:00
2010-03-27 10:52:25 -04:00
// Firefox 3.5 or later
case 'dragstart' : return this . onTabDragStart ( aEvent ) ;
case 'dragover' : return this . onTabDragOver ( aEvent ) ;
case 'dragleave' : return this . onTabDragLeave ( aEvent ) ;
// Firefox 3.7 or later
case 'drop' : return this . onTabDrop ( aEvent ) ;
case 'dragend' : return this . onTabDragEnd ( aEvent ) ;
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 ) ;
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
{
2008-10-17 08:35:55 -04:00
this . accelKeyPressed = this . isAccelKeyPressed ( aEvent ) ;
2009-09-03 03:25:37 -04:00
/* PUBLIC API */
2009-12-26 00:21:31 -05:00
var b = this . browser ;
2009-12-26 00:38:38 -05:00
var event = b . ownerDocument . createEvent ( 'Events' ) ;
event . initEvent ( 'TreeStyleTabFocusSwitchingKeyDown' , true , false ) ;
2009-09-03 03:25:37 -04:00
event . sourceEvent = aEvent ;
2009-12-26 00:21:31 -05:00
b . dispatchEvent ( event ) ;
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 ;
2008-10-17 08:35:55 -04:00
this . accelKeyPressed = this . isAccelKeyPressed ( aEvent ) ;
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
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 */
2009-12-26 00:38:38 -05:00
let event = b . ownerDocument . createEvent ( 'Events' ) ;
event . initEvent ( 'TreeStyleTabFocusSwitchingStart' , true , false ) ;
2009-09-03 03:25:37 -04:00
event . scrollDown = scrollDown ;
event . scrollUp = scrollUp ;
event . standBy = standBy ;
event . onlyShiftKey = onlyShiftKey ;
event . sourceEvent = aEvent ;
b . dispatchEvent ( event ) ;
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 ) {
2009-12-26 00:38:38 -05:00
event = document . createEvent ( 'Events' ) ;
event . initEvent ( 'TreeStyleTabFocusSwitchingEnd' , true , false ) ;
2009-09-03 03:25:37 -04:00
event . scrollDown = scrollDown ;
event . scrollUp = scrollUp ;
event . standBy = standBy ;
event . onlyShiftKey = onlyShiftKey ;
event . sourceEvent = aEvent ;
b . dispatchEvent ( event ) ;
}
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
2009-12-25 03:34:52 -05:00
onTabbarResized : function TSTService _onTabbarResized ( aEvent )
2007-10-16 13:22:28 -04:00
{
2008-06-17 02:22:49 -04:00
var b = this . getTabBrowserFromChild ( aEvent . currentTarget ) ;
2010-03-25 23:17:16 -04:00
var box = ( b . treeStyleTab . tabStripPlaceHolder || this . getTabStrip ( b ) ) . boxObject ;
2009-09-08 05:59:23 -04:00
window . setTimeout ( function ( aSelf ) {
if ( ! b . treeStyleTab . clickedOnTabbarResizerGrippy ) {
if ( ! b . treeStyleTab . isVertical ) {
2010-04-22 04:12:31 -04:00
aSelf . setTreePref ( 'tabbar.height' , aSelf . maxTabbarHeight ( box . height , b ) ) ;
2009-09-08 05:59:23 -04:00
}
else {
if ( ! b . treeStyleTab . autoHide . expanded )
2010-04-22 04:12:31 -04:00
aSelf . setTreePref ( 'tabbar.shrunkenWidth' , aSelf . maxTabbarWidth ( box . width , b ) ) ;
2009-09-08 05:59:23 -04:00
else
2010-04-22 04:12:31 -04:00
aSelf . setTreePref ( 'tabbar.width' , aSelf . maxTabbarWidth ( box . width , b ) ) ;
2009-09-08 05:59:23 -04:00
}
}
2010-03-25 06:04:47 -04:00
b . treeStyleTab . updateFloatingTabbar ( ) ;
2009-09-08 05:59:23 -04:00
b . treeStyleTab . clickedOnTabbarResizerGrippy = false ;
} , 10 , this ) ;
} ,
2009-12-25 03:34:52 -05:00
onTabbarResizerClick : function TSTService _onTabbarResizerClick ( aEvent )
2009-09-08 05:59:23 -04:00
{
var b = this . getTabBrowserFromChild ( aEvent . currentTarget ) ;
b . treeStyleTab . clickedOnTabbarResizerGrippy = this . evaluateXPath (
'ancestor-or-self::xul:grippy' ,
aEvent . originalTarget ,
XPathResult . BOOLEAN _TYPE
) . booleanValue ;
2007-10-16 13:22:28 -04:00
} ,
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
2009-12-25 03:34:52 -05:00
handleTooltip : function TSTService _handleTooltip ( aEvent , aTab )
2009-07-31 03:02:13 -04:00
{
var label ;
2009-10-25 22:36:42 -04:00
var collapsed = this . isSubtreeCollapsed ( aTab ) ;
2009-07-31 03:02:13 -04:00
2009-07-31 03:10:30 -04:00
var base = parseInt ( aTab . getAttribute ( this . kNEST ) || 0 ) ;
2009-07-31 06:11:01 -04:00
var descendant = this . getDescendantTabs ( aTab ) ;
2009-08-11 03:18:50 -04:00
var indentPart = ' ' ;
2009-12-17 10:20:55 -05:00
var tree = ( this . getTreePref ( 'tooltip.includeChildren' ) && descendant . length ) ?
2009-08-09 23:15:15 -04:00
[ aTab ] . concat ( descendant )
2009-07-31 03:02:13 -04:00
. map ( function ( aTab ) {
2009-08-11 03:18:50 -04:00
let label = aTab . getAttribute ( 'label' ) ;
let indent = '' ;
2009-07-31 03:02:13 -04:00
let nest = parseInt ( aTab . getAttribute ( this . kNEST ) || 0 ) - base ;
for ( let i = 0 ; i < nest ; i ++ )
{
2009-08-11 03:18:50 -04:00
indent += indentPart ;
2009-07-31 03:02:13 -04:00
}
2009-08-11 03:18:50 -04:00
return this . treeBundle . getFormattedString ( 'tooltip.item.label' , [ label , indent ] ) ;
2009-07-31 03:02:13 -04:00
} , this )
2009-08-09 23:15:15 -04:00
. join ( '\n' ) :
null ;
2009-07-31 03:02:13 -04:00
2009-07-31 06:09:11 -04:00
if ( 'mOverCloseButton' in aTab && aTab . mOverCloseButton ) {
2009-07-31 06:11:01 -04:00
if ( descendant . length &&
( collapsed || this . getTreePref ( 'closeParentBehavior' ) == this . CLOSE _PARENT _BEHAVIOR _CLOSE ) ) {
2009-08-10 22:30:29 -04:00
label = this . treeBundle . getString ( 'tooltip.closeTree' ) ;
2009-07-31 06:09:11 -04:00
}
}
else if ( aTab . getAttribute ( this . kTWISTY _HOVER ) == 'true' ) {
2009-07-31 03:02:13 -04:00
let key = collapsed ?
'tooltip.expandSubtree' :
'tooltip.collapseSubtree' ;
2009-07-31 03:10:30 -04:00
label = tree || aTab . getAttribute ( 'label' ) ;
2009-07-31 03:02:13 -04:00
label = label ?
2009-08-10 22:30:29 -04:00
this . treeBundle . getFormattedString ( key + '.labeled' , [ label ] ) :
this . treeBundle . getString ( key ) ;
2009-07-31 03:02:13 -04:00
}
2009-07-31 03:10:30 -04:00
else if ( collapsed ) {
label = tree ;
}
2009-07-31 03:02:13 -04:00
if ( label )
aEvent . target . setAttribute ( 'label' , label ) ;
return label ;
} ,
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 ) ;
} ,
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-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-05-08 02:22:49 -04:00
TreeStyleTabBrowserAutoHide . 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' ;
this . setTabbrowserAttribute ( this . kFIXED + '-' + orient , newFixed ? 'true' : null , b ) ;
this . setTreePref ( 'tabbar.fixed.' + orient , newFixed ) ;
b . treeStyleTab . updateTabbarState ( ) ;
2009-12-25 13:13:33 -05:00
if ( ! this . getTreePref ( 'tabbar.syncRelatedPrefsForDynamicPosition' ) ) return ;
if ( ! isVertical )
2010-05-08 02:22:49 -04:00
this . setTreePref ( 'enableSubtreeIndent.horizontal' , ! this . getTreePref ( 'tabbar.fixed.' + orient ) ) ;
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
{
2009-12-27 06:22:44 -05:00
var tabs = this . gatherSubtreeMemberTabs ( aTabOrTabs ) ;
2009-06-17 04:59:18 -04:00
if ( ! this . warnAboutClosingTabs ( tabs . length ) )
2007-10-19 22:44:14 -04:00
return ;
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
{
b . removeTab ( aTabs [ i ] ) ;
}
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 )
{
/* PUBLIC API */
2009-12-26 03:00:12 -05:00
var event = aParentTab . ownerDocument . createEvent ( 'Events' ) ;
event . initEvent ( 'TreeStyleTabSubtreeClosing' , true , true ) ;
2009-12-25 23:49:58 -05:00
event . parent = aParentTab ;
event . tabs = aClosedTabs ;
2010-01-09 16:08:11 -05:00
return this . getTabBrowserFromChild ( aParentTab ) . dispatchEvent ( event ) ;
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 ; } ) ;
2009-12-25 23:49:58 -05:00
/* PUBLIC API */
2009-12-26 00:38:38 -05:00
var event = aTabBrowser . ownerDocument . createEvent ( 'Events' ) ;
event . initEvent ( 'TreeStyleTabSubtreeClosed' , true , false ) ;
2009-12-25 23:49:58 -05:00
event . parent = aParentTab ;
2009-12-26 00:24:55 -05:00
event . tabs = aClosedTabs ;
2009-12-25 23:49:58 -05:00
aTabBrowser . dispatchEvent ( event ) ;
} ,
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 ,
'TreeStyleTab:collapseExpandAllSubtree' ,
( 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 ,
2009-12-25 03:34:52 -05:00
registerTabFocusAllowance : function TSTService _registerTabFocusAllowance ( aProcess ) /* PUBLIC API */
2008-03-02 13:16:57 -05:00
{
this . _tabFocusAllowance . push ( aProcess ) ;
} ,
_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 ) ;
2008-12-01 04:14:05 -05:00
if ( remoteBrowser . treeStyleTab . 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 ;
gBrowser . treeStyleTab . performDrop ( actionInfo , remoteTab ) ;
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' ) ;
event . initEvent ( 'TreeStyleTabPrintPreviewEntered' , true , false ) ;
document . documentElement . dispatchEvent ( event ) ;
} ,
onPrintPreviewExit : function TSTService _onPrintPreviewExit ( )
{
var event = document . createEvent ( 'Events' ) ;
event . initEvent ( 'TreeStyleTabPrintPreviewExited' , true , false ) ;
document . documentElement . dispatchEvent ( event ) ;
} ,
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
{
return this . getTabsArray ( this . browser )
. 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
2009-10-25 13:31:47 -04:00
return data && data . _tabStillLoading ;
} ) . 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' :
2009-09-03 02:24:06 -04:00
TreeStyleTabBrowserAutoHide . updateKeyListeners ( ) ;
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' ) ,
2009-12-17 21:46:36 -05:00
this . currentTabbarPosition
2009-03-25 10:09:34 -04:00
] . join ( '-' ) ) ;
break ;
2009-08-14 02:36:59 -04:00
case 'browser.ctrlTab.previews' :
2009-09-03 02:24:06 -04:00
TreeStyleTabBrowserAutoHide . updateKeyListeners ( ) ;
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
} ) ( ) ;
2008-02-26 11:24:25 -05:00
window . addEventListener ( 'DOMContentLoaded' , TreeStyleTabService , true ) ;
2007-10-16 13:22:28 -04:00
window . addEventListener ( 'load' , TreeStyleTabService , false ) ;
2009-08-26 05:33:54 -04:00
TreeStyleTabService . ObserverService . addObserver ( TreeStyleTabService , 'sessionstore-windows-restored' , false ) ;
2007-11-17 00:20:26 -05:00