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 */
2007-11-08 08:21:13 -05:00
2009-12-25 03:34:52 -05: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
} ,
2009-12-17 21:46:36 -05:00
get currentTabbarPosition ( ) /* PUBLIC API */
{
2009-12-25 11:51:24 -05:00
return this . utils . currentTabbarPosition ;
2009-12-17 21:46:36 -05:00
} ,
2009-12-18 04:14:02 -05:00
set currentTabbarPosition ( aValue )
{
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 ;
} ,
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$/ , '' ) ) ;
} ,
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
)
) ;
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 ) ;
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 ) ;
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' ,
'browser.tabs.insertRelatedAfterCurrent'
] . forEach ( function ( aPref ) {
var backup = prefs . getPref ( aPref + '.backup' ) ;
if ( backup === null ) return ;
prefs . setPref ( aPref , backup ) ;
prefs . clearPref ( aPref + '.backup' ) ;
} ) ;
prefs = null ;
restorePrefs = null ;
} ;
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
{
2009-08-25 06:10:29 -04:00
if ( '_onDragStart' in aObserver ) { // Firefox 3.5 or later
2009-08-25 03:20:56 -04:00
eval ( 'aObserver._onDragStart = ' +
aObserver . _onDragStart . toSource ( ) . replace (
'if (target.localName == "tab"' ,
< ! [ CDATA [
2009-08-26 10:59:25 -04:00
if ( this . treeStyleTab . tabbarDNDObserver . canDragTabbar ( aEvent ) ) {
let sv = this . treeStyleTab ;
2009-08-25 03:20:56 -04:00
let dt = aEvent . dataTransfer ;
2009-08-26 10:59:25 -04:00
dt . mozSetDataAt (
sv . kDRAG _TYPE _TABBAR ,
aEvent . shiftKey ?
sv . kTABBAR _MOVE _FORCE :
sv . kTABBAR _MOVE _NORMAL ,
0
) ;
2009-08-25 03:20:56 -04:00
dt . mozCursor = 'move' ;
2009-09-03 23:12:38 -04:00
// let tabbar = this.mTabContainer;
// let 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 ) ;
2009-08-25 03:20:56 -04:00
aEvent . stopPropagation ( ) ;
2009-11-23 13:04:40 -05:00
this . treeStyleTab . tabbarDNDObserver . readyToStartDrag ( ) ;
2009-08-25 03:20:56 -04:00
}
else $ & ] ] >
)
) ;
}
else { // Firefox 3.0.x
2009-12-15 04:52:51 -05:00
eval ( 'aObserver.onDragStart = ' +
aObserver . onDragStart . toSource ( ) . replace ( // native
2009-08-25 03:20:56 -04:00
'aEvent.target.localName == "tab"' ,
2009-08-25 06:35:53 -04:00
< ! [ CDATA [
(
2009-08-26 10:59:25 -04:00
! this . treeStyleTab . tabbarDNDObserver . canDragTabbar ( aEvent ) &&
2009-08-25 06:35:53 -04:00
$ &
)
] ] >
2009-12-15 04:52:51 -05:00
)
) ;
2009-08-25 03:20:56 -04:00
}
2008-10-01 21:32:31 -04:00
var canDropFunctionName = '_setEffectAllowedForDataTransfer' in aObserver ?
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
2009-12-15 04:52:51 -05:00
eval ( 'aObserver.' + canDropFunctionName + ' = ' +
aObserver [ canDropFunctionName ] . toSource ( ) . replace (
2007-11-14 10:09:47 -05:00
'{' ,
'{ var TSTTabBrowser = this;'
) . replace (
2007-11-17 08:32:41 -05:00
/\.screenX/g , '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.positionProp]'
2007-11-14 07:31:14 -05:00
) . replace (
2007-11-17 08:32:41 -05:00
/\.width/g , '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.sizeProp]'
2007-11-14 07:31:14 -05:00
) . replace (
2008-12-01 20:54:16 -05:00
/(return (?:true|dt.effectAllowed = "copyMove");)/ ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [
2007-11-14 07:31:14 -05:00
if ( ! ( function ( aSelf ) {
try {
2008-10-17 08:35:55 -04:00
var node = TST _DRAGSESSION . sourceNode ;
var tab = TSTTabBrowser . treeStyleTab . getTabFromChild ( node ) ;
if ( ! node ||
! tab ||
tab . parentNode != aSelf . mTabContainer )
2007-11-14 07:31:14 -05:00
return true ;
2008-11-06 23:58:37 -05:00
tab = TSTTabBrowser . treeStyleTab . getTabFromEvent ( aEvent ) ;
2009-10-25 22:36:42 -04:00
if ( TreeStyleTabService . isCollapsed ( tab ) )
2007-11-14 07:31:14 -05:00
return false ;
2008-10-17 08:35:55 -04:00
var info = TSTTabBrowser . treeStyleTab . getDropAction ( aEvent , TST _DRAGSESSION ) ;
2007-11-14 07:31:14 -05:00
return info . canDrop ;
}
catch ( e ) {
dump ( 'TreeStyleTabService::canDrop\n' + e + '\n' ) ;
return false ;
}
2008-10-17 08:35:55 -04:00
} ) ( TSTTabBrowser ) ) {
2008-10-01 21:32:31 -04:00
return TST _DRAGDROP _DISALLOW _RETRUN _VALUE ;
2008-10-17 08:35:55 -04:00
}
2007-11-14 07:31:14 -05:00
$1
2009-03-26 11:30:00 -04:00
] ] >
2008-10-17 08:35:55 -04:00
) . replace (
/TST_DRAGSESSION/g ,
( canDropFunctionName == 'canDrop' ?
'aDragSession' :
'TSTTabBrowser.treeStyleTab.getCurrentDragSession()'
)
2008-10-01 21:32:31 -04:00
) . replace (
/TST_DRAGDROP_DISALLOW_RETRUN_VALUE/g ,
( canDropFunctionName == 'canDrop' ?
'false' :
'dt.effectAllowed = "none"'
)
2009-12-15 04:52:51 -05:00
)
) ;
2007-11-14 07:31:14 -05:00
2008-10-01 21:32:31 -04:00
var dragOverFunctionName = '_onDragOver' in aObserver ?
2009-08-25 06:10:29 -04:00
'_onDragOver' : // Firefox 3.5 or later
2008-10-01 21:32:31 -04:00
'onDragOver' ; // Firefox 3.0.x
eval ( 'aObserver.' + dragOverFunctionName + ' = ' +
aObserver [ dragOverFunctionName ] . toSource ( ) . replace (
2007-11-14 07:31:14 -05:00
'{' ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [
2007-11-14 07:31:14 -05:00
{
var TSTTabBrowser = this ;
if ( ( function ( aSelf ) {
try {
2009-04-07 05:33:47 -04:00
window [ 'piro.sakura.ne.jp' ] . autoScroll . processAutoScroll ( aEvent ) ;
2009-04-06 13:47:57 -04:00
2008-10-01 21:32:31 -04:00
var info = TSTTabBrowser . treeStyleTab . getDropAction ( aEvent , TST _DRAGSESSION ) ;
2007-11-14 07:31:14 -05:00
2009-12-16 09:56:50 -05:00
// auto-switch for staying on tabs (Firefox 3.0 or later)
if ( '_setEffectAllowedForDataTransfer' in aSelf &&
info . target &&
! info . target . selected &&
'mDragTime' in aSelf &&
'mDragOverDelay' in aSelf ) {
let effects = aSelf . _setEffectAllowedForDataTransfer ( aEvent ) ;
if ( effects == 'link' ) {
let now = Date . now ( ) ;
if ( ! aSelf . mDragTime )
aSelf . mDragTime = now ;
if ( now >= aSelf . mDragTime + aSelf . mDragOverDelay )
2009-12-16 11:05:05 -05:00
aSelf . selectedTab = info . target ;
2009-12-16 09:56:50 -05:00
}
}
2007-11-14 07:31:14 -05:00
if ( ! info . target || info . target != TreeStyleTabService . evaluateXPath (
'child::xul:tab[@' + TreeStyleTabService . kDROP _POSITION + ']' ,
aSelf . mTabContainer ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue )
2007-11-14 14:34:36 -05:00
TSTTabBrowser . treeStyleTab . clearDropPosition ( ) ;
2007-11-14 07:31:14 -05:00
2008-10-01 21:32:31 -04:00
if ( TST _DRAGDROP _DISALLOW _CHECK ) return true ;
2007-11-14 07:31:14 -05:00
info . target . setAttribute (
TreeStyleTabService . kDROP _POSITION ,
info . position == TreeStyleTabService . kDROP _BEFORE ? 'before' :
info . position == TreeStyleTabService . kDROP _AFTER ? 'after' :
'self'
) ;
aSelf . mTabDropIndicatorBar . setAttribute ( 'dragging' , ( info . position == TreeStyleTabService . kDROP _ON ) ? 'false' : 'true' ) ;
return ( info . position == TreeStyleTabService . kDROP _ON || aSelf . getAttribute ( TreeStyleTabService . kTABBAR _POSITION ) != 'top' )
}
catch ( e ) {
dump ( 'TreeStyleTabService::onDragOver\n' + e + '\n' ) ;
}
} ) ( TSTTabBrowser ) ) {
return ;
}
2009-03-26 11:30:00 -04:00
] ] >
2008-10-01 21:32:31 -04:00
) . replace (
/TST_DRAGSESSION/g ,
( canDropFunctionName == 'canDrop' ?
'aDragSession' :
'null'
)
) . replace (
/TST_DRAGDROP_DISALLOW_CHECK/g ,
( canDropFunctionName == 'canDrop' ?
'!aSelf.canDrop(aEvent, aDragSession)' :
2008-12-01 20:54:16 -05:00
'aSelf._setEffectAllowedForDataTransfer(aEvent) == "none"'
2008-10-01 21:32:31 -04:00
)
2007-11-14 07:31:14 -05:00
)
) ;
2008-10-01 21:32:31 -04:00
var dragExitFunctionName = '_onDragLeave' in aObserver ?
2009-08-25 06:10:29 -04:00
'_onDragLeave' : // Firefox 3.5 or later
2008-10-01 21:32:31 -04:00
'onDragExit' ; // Firefox 3.0.x
eval ( 'aObserver.' + dragExitFunctionName + ' = ' +
aObserver [ dragExitFunctionName ] . toSource ( ) . replace (
2007-11-14 07:31:14 -05:00
/(this.mTabDropIndicatorBar\.[^;]+;)/ ,
2007-11-14 14:34:36 -05:00
'$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 ?
2009-08-25 06:10:29 -04:00
'_onDrop' : // Firefox 3.5 or later
2008-10-01 21:32:31 -04:00
'onDrop' ; // Firefox 3.0.x
eval ( 'aObserver.' + dropFunctionName + ' = ' +
aObserver [ dropFunctionName ] . toSource ( ) . replace (
2007-11-14 07:31:14 -05:00
'{' ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [
2007-11-14 07:31:14 -05:00
{
var TSTTabBrowser = this ;
2007-11-14 14:34:36 -05:00
TSTTabBrowser . treeStyleTab . clearDropPosition ( ) ;
2008-10-01 21:32:31 -04:00
var dropActionInfo = TSTTabBrowser . treeStyleTab . getDropAction ( aEvent , TST _DRAGSESSION ) ;
2009-03-26 11:30:00 -04:00
] ] >
2009-08-25 06:10:29 -04:00
) . replace ( // Firefox 3.0.x, 3.5 or later
2008-10-01 21:32:31 -04:00
/(if \((accelKeyPressed|isCopy|dropEffect == "copy")\) {)/ ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [
2008-10-17 13:16:16 -04:00
if ( TSTTabBrowser . treeStyleTab . performDrop ( dropActionInfo , draggedTab ) )
2008-02-22 15:59:55 -05:00
return ;
2009-03-26 11:30:00 -04:00
$1 ] ] >
2008-02-22 15:59:55 -05:00
) . replace ( // Firefox 3, duplication of tab
2008-12-03 13:26:32 -05:00
/(this.selectedTab = newTab;)(\s*\})?/g ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [ $1 ;
2008-02-22 15:59:55 -05:00
if ( dropActionInfo . position == TreeStyleTabService . kDROP _ON )
TSTTabBrowser . treeStyleTab . attachTabTo ( newTab , dropActionInfo . target ) ;
2009-03-26 11:30:00 -04:00
$2 ] ] >
2008-02-24 03:11:17 -05:00
) . replace ( // Firefox 3, dragging tab from another window
'else if (draggedTab) {' ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [ $ &
2008-10-17 13:16:16 -04:00
if ( TSTTabBrowser . treeStyleTab . performDrop ( dropActionInfo , draggedTab ) )
2008-02-24 03:11:17 -05:00
return ;
2009-03-26 11:30:00 -04:00
] ] >
2007-11-14 07:31:14 -05:00
) . replace (
/(this.loadOneTab\([^;]+\));/ ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [
2008-10-17 13:16:16 -04:00
TSTTabBrowser . treeStyleTab . performDrop ( dropActionInfo , $1 ) ;
2007-11-14 07:31:14 -05:00
return ;
2009-03-26 11:30:00 -04:00
] ] >
2007-11-14 07:31:14 -05:00
) . replace (
'document.getBindingParent(aEvent.originalTarget).localName != "tab"' ,
'!TreeStyleTabService.getTabFromEvent(aEvent)'
) . replace (
'var tab = aEvent.target;' ,
2009-03-26 11:30:00 -04:00
< ! [ CDATA [ $ &
2009-07-22 00:25:39 -04:00
var loadDroppedLinkToNewChildTab = (
dropActionInfo . position != TreeStyleTabService . kDROP _ON ||
2009-12-15 03:33:03 -05:00
tab . getAttribute ( 'locked' ) == 'true' // Tab Mix Plus (or others)
2009-07-22 00:25:39 -04:00
) ;
if ( ! loadDroppedLinkToNewChildTab &&
dropActionInfo . position == TreeStyleTabService . kDROP _ON ) {
2009-07-27 03:22:56 -04:00
loadDroppedLinkToNewChildTab = TreeStyleTabService . dropLinksOnTabBehavior ( ) == TreeStyleTabService . kDROPLINK _NEWTAB ;
2009-07-22 00:25:39 -04:00
}
2007-11-14 07:31:14 -05:00
if (
2009-07-22 00:25:39 -04:00
loadDroppedLinkToNewChildTab ||
2009-12-15 03:33:03 -05:00
tab . getAttribute ( 'locked' ) == 'true' // Tab Mix Plus (or others)
2007-11-14 07:31:14 -05:00
) {
2008-10-17 13:16:16 -04:00
TSTTabBrowser . treeStyleTab . performDrop ( dropActionInfo , TSTTabBrowser . loadOneTab ( getShortcutOrURI ( url ) , null , null , null , bgLoad , false ) ) ;
2007-11-14 07:31:14 -05:00
return ;
}
2009-03-26 11:30:00 -04:00
] ] >
2008-10-01 21:32:31 -04:00
) . replace (
/TST_DRAGSESSION/g ,
( canDropFunctionName == 'canDrop' ?
'aDragSession' :
'TSTTabBrowser.treeStyleTab.getCurrentDragSession()'
)
2007-11-14 07:31:14 -05:00
)
) ;
} ,
2009-12-25 03:34:52 -05:00
overrideGlobalFunctions : function TSTService _overrideGlobalFunctions ( )
2007-10-21 11:02:58 -04:00
{
2008-09-26 10:13:29 -04:00
// window.__treestyletab__BrowserCustomizeToolbar = window.BrowserCustomizeToolbar;
// window.BrowserCustomizeToolbar = function() {
// TreeStyleTabService.destroyBar();
// window.__treestyletab__BrowserCustomizeToolbar.call(window);
// };
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 ) ;
TreeStyleTabService . initBar ( ) ;
} ;
}
if ( 'BrowserToolboxCustomizeDone' in window ) {
window . _ _treestyletab _ _BrowserToolboxCustomizeDone = window . BrowserToolboxCustomizeDone ;
window . BrowserToolboxCustomizeDone = function ( aChanged ) {
window . _ _treestyletab _ _BrowserToolboxCustomizeDone . apply ( window , arguments ) ;
TreeStyleTabService . initBar ( ) ;
} ;
}
this . initBar ( ) ;
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 [
TreeStyleTabService . checkReadyToOpenNewTab ( {
uri : href ,
external : {
newTab : TreeStyleTabService . getTreePref ( 'openOuterLinkInNewTab' ) || TreeStyleTabService . getTreePref ( 'openAnyLinkInNewTab' ) ,
forceChild : true
} ,
internal : {
newTab : TreeStyleTabService . getTreePref ( 'openAnyLinkInNewTab' )
} ,
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 )
) &&
2008-11-14 03:10:33 -05:00
TreeStyleTabService . checkReadyToOpenNewTab ( {
2009-04-27 21:32:01 -04:00
uri : wrapper . href ,
2008-11-14 03:10:33 -05:00
external : {
newTab : TreeStyleTabService . getTreePref ( 'openOuterLinkInNewTab' ) || TreeStyleTabService . getTreePref ( 'openAnyLinkInNewTab' ) ,
forceChild : true
} ,
internal : {
newTab : TreeStyleTabService . getTreePref ( 'openAnyLinkInNewTab' )
}
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 (
'gBrowser.mStrip.boxObject.height' ,
'((gBrowser.getAttribute(TreeStyleTabService.kTABBAR_POSITION) != "top") ? 0 : gBrowser.mStrip.boxObject.height)'
)
) ;
eval ( 'FullScreen.mouseoverToggle = ' +
FullScreen . mouseoverToggle . toSource ( ) . replace (
'gBrowser.mStrip.setAttribute("moz-collapsed", !aShow);' ,
'if (gBrowser.getAttribute(TreeStyleTabService.kTABBAR_POSITION) == "top") { $& }'
)
) ;
eval ( 'FullScreen.toggle = ' +
FullScreen . toggle . toSource ( ) . replace (
'{' ,
< ! [ CDATA [ {
var treeStyleTab = gBrowser . treeStyleTab ;
if ( gBrowser . getAttribute ( treeStyleTab . kTABBAR _POSITION ) != 'top' ) {
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
2009-09-03 12:20:53 -04:00
if ( window . contentAreaDNDObserver &&
! ( 'getSupportedFlavours' in contentAreaDNDObserver ) ) { // Firefox 3.6 or later
2009-08-25 03:20:56 -04:00
eval ( 'contentAreaDNDObserver.onDrop = ' +
contentAreaDNDObserver . onDrop . toSource ( ) . replace (
'var types = aEvent.dataTransfer.types;' ,
2009-08-25 04:35:05 -04:00
< ! [ CDATA [ $ &
2009-08-25 06:35:53 -04:00
if ( gBrowser . treeStyleTab . panelDNDObserver . canDrop ( aEvent , gBrowser . treeStyleTab . getCurrentDragSession ( ) ) ) {
return gBrowser . treeStyleTab . panelDNDObserver . onDrop ( aEvent , null , gBrowser . treeStyleTab . getCurrentDragSession ( ) ) ;
2009-08-25 04:35:05 -04:00
}
] ] >
)
) ;
2009-08-25 03:20:56 -04:00
}
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
2009-12-25 03:34:52 -05:00
initBar : function TSTService _initBar ( )
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 ;
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
{
2007-11-14 14:34:36 -05:00
window . removeEventListener ( 'unload' , this , false ) ;
2007-11-08 09:24:54 -05:00
2009-04-08 05:44:44 -04:00
window [ 'piro.sakura.ne.jp' ] . animationManager . stop ( ) ;
2007-10-16 13:22:28 -04:00
this . destroyTabBrowser ( gBrowser ) ;
2009-08-14 02:12:08 -04:00
this . endListenKeyEventsFor ( this . LISTEN _FOR _AUTOHIDE ) ;
this . endListenKeyEventsFor ( this . LISTEN _FOR _AUTOEXPAND _BY _FOCUSCHANGE ) ;
2008-03-08 03:57:17 -05:00
2009-05-12 14:47:36 -04:00
document . removeEventListener ( 'popupshowing' , this , false ) ;
document . removeEventListener ( 'popuphiding' , this , false ) ;
2007-10-22 05:59:43 -04:00
2007-11-14 10:09:47 -05:00
var appcontent = document . getElementById ( 'appcontent' ) ;
appcontent . removeEventListener ( 'SubBrowserAdded' , this , false ) ;
appcontent . removeEventListener ( 'SubBrowserRemoveRequest' , this , false ) ;
2007-10-16 13:22:28 -04:00
this . removePrefListener ( this ) ;
2009-08-26 05:33:54 -04:00
this . ObserverService . removeObserver ( this , 'sessionstore-windows-restored' ) ;
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' :
this . preInit ( ) ;
return ;
2007-10-16 13:22:28 -04:00
case 'load' :
2007-11-14 14:34:36 -05:00
this . init ( ) ;
2007-10-18 13:11:03 -04:00
return ;
2007-10-16 13:22:28 -04:00
case 'unload' :
this . destroy ( ) ;
2007-10-18 13:11:03 -04:00
return ;
2007-10-16 13:22:28 -04:00
2008-11-09 23:48:11 -05:00
case 'SSTabRestoring' :
this . onTabRestored ( aEvent ) ;
return ;
2007-10-16 13:22:28 -04:00
case 'popupshowing' :
2009-05-14 13:47:55 -04:00
if ( ! 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 ) ;
}
2009-05-12 14:47:36 -04:00
return ;
case 'popuphiding' :
2009-05-14 13:47:55 -04:00
if ( ! 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
2008-03-08 03:57:17 -05:00
case 'keydown' :
this . onKeyDown ( aEvent ) ;
return ;
case 'keyup' :
case 'keypress' :
this . onKeyRelease ( aEvent ) ;
return ;
2007-10-17 09:25:50 -04:00
case 'SubBrowserAdded' :
this . initTabBrowser ( aEvent . originalTarget . browser ) ;
2007-10-18 13:11:03 -04:00
return ;
2007-10-17 09:25:50 -04:00
case 'SubBrowserRemoveRequest' :
this . destroyTabBrowser ( aEvent . originalTarget . browser ) ;
2007-10-18 13:11:03 -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 ) ;
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 ;
var event = b . ownerDocument . createEvent ( 'UIEvents' ) ;
event . initEvent ( 'TreeStyleTabFocusSwitchingKeyDown' , true , false , b . ownerDocument . defaultView , aEvent . keyCode ) ;
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:21:31 -05:00
let event = b . ownerDocument . createEvent ( 'UIEvents' ) ;
event . initEvent ( 'TreeStyleTabFocusSwitchingStart' , true , false , b . ownerDocument . defaultView , aEvent . keyCode ) ;
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:21:31 -05:00
event = document . createEvent ( 'UIEvents' ) ;
event . initEvent ( 'TreeStyleTabFocusSwitchingEnd' , true , false , b . ownerDocument . defaultView , aEvent . keyCode ) ;
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 ) ;
2009-09-08 05:59:23 -04:00
window . setTimeout ( function ( aSelf ) {
if ( ! b . treeStyleTab . clickedOnTabbarResizerGrippy ) {
if ( ! b . treeStyleTab . isVertical ) {
aSelf . setTreePref ( 'tabbar.height' , b . mStrip . boxObject . height ) ;
}
else {
if ( ! b . treeStyleTab . autoHide . expanded )
aSelf . setTreePref ( 'tabbar.shrunkenWidth' , b . mStrip . boxObject . width ) ;
else
aSelf . setTreePref ( 'tabbar.width' , b . mStrip . boxObject . width ) ;
}
}
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 ;
} ,
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 ;
var tabbarWidth = treeStyleTab . splitterWidth + ( treeStyleTab . isVertical ? gBrowser . mStrip . boxObject . width : 0 ) ;
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 ) ;
}
} ,
toggleAutoHide : function TSTService _toggleAutoHide ( )
{
TreeStyleTabBrowserAutoHide . toggleMode ( ) ;
} ,
toggleFixed : function TSTService _toggleFixed ( )
{
var pos = this . currentTabbarPosition ;
var isVertical = ( pos == 'left' || pos == 'right' ) ;
var orient = isVertical ? 'vertical' : 'horizontal' ;
var pref = 'tabbar.fixed.' + orient ;
this . setTreePref ( pref , ! this . getTreePref ( pref ) ) ;
if ( ! this . getTreePref ( 'tabbar.syncRelatedPrefsForDynamicPosition' ) ) return ;
if ( ! isVertical )
this . setTreePref ( 'enableSubtreeIndent.horizontal' , ! this . getTreePref ( pref ) ) ;
} ,
2009-12-25 06:19:50 -05:00
removeTabSubtree : function TSTService _removeTabSubtree ( aTabOrTabs , aOnlyChildren )
2007-10-19 22:44:14 -04:00
{
2009-12-25 15:06:49 -05: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 ;
2009-12-25 23:49:58 -05:00
this . splitTabsToSubtrees ( tabs ) . forEach ( function ( aTabs ) {
if ( ! this . fireTabSubtreeClosingEvent ( aTabs [ 0 ] , aTabs ) )
return ;
this . markAsClosedSet ( aTabs ) ;
var b = this . getTabBrowserFromChild ( aTabs [ 0 ] ) ;
for ( var i = tabs . length - 1 ; i > - 1 ; i -- )
{
b . removeTab ( aTabs [ i ] ) ;
}
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
splitTabsToSubtrees : function TSTService _splitTabsToSubtrees ( aTabs ) /* PUBLIC API */
{
var groups = [ ] ;
var group = [ ] ;
this . cleanUpTabsArray ( aTabs )
. forEach ( function ( aTab ) {
var parent = this . getParentTab ( aTab ) ;
if ( group . indexOf ( parent ) < 0 ) {
groups . push ( group ) ;
group = [ aTab ] ;
}
else {
group . push ( aTab ) ;
}
} , this ) ;
groups . push ( group ) ;
return groups ;
} ,
fireTabSubtreeClosingEvent : function TSTService _fireTabSubtreeClosingEvent ( aParentTab , aClosedTabs )
{
/* PUBLIC API */
2009-12-26 00:21:31 -05:00
var event = aParentTab . ownerDocument . createEvent ( 'UIEvents' ) ;
event . initEvent ( 'TreeStyleTabSubtreeClosing' , true , true , aParentTab . ownerDocument . defaultView , aClosedTabs . length ) ;
2009-12-25 23:49:58 -05:00
event . parent = aParentTab ;
event . tabs = aClosedTabs ;
this . getTabBrowserFromChild ( aParentTab ) . dispatchEvent ( event ) ;
return ! event . getPreventDefault ( ) ;
} ,
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:21:31 -05:00
var event = aTabBrowser . ownerDocument . createEvent ( 'UIEvents' ) ;
event . initEvent ( 'TreeStyleTabSubtreeClosed' , true , false , aTabBrowser . ownerDocument . defaultView , aClosedTabs . length ) ;
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
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 )
this . restoringWindow = this . getRestoringTabsCount ( ) > 1 ;
2009-08-26 05:33:54 -04:00
return ;
2009-07-03 05:58:34 -04:00
}
} ,
2009-10-25 13:58:26 -04:00
restoringWindow : 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 ;
var data = owner . parentNode . _ _SS _data ;
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 ;
}
} ,
} ;
2009-12-25 11:38:14 -05:00
( function ( ) {
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