2009-08-10 07:31:11 -04:00
var TreeStyleTabService = {
2009-04-26 22:18:17 -04:00
/* attributes */
2007-10-23 02:05:44 -04:00
kID : 'treestyletab-id' ,
kCHILDREN : 'treestyletab-children' ,
kPARENT : 'treestyletab-parent' ,
2007-11-26 16:17:46 -05:00
kANCESTOR : 'treestyletab-ancestors' ,
2009-04-26 22:18:17 -04:00
kNEST : 'treestyletab-nest' ,
2007-10-23 02:05:44 -04:00
kINSERT _BEFORE : 'treestyletab-insert-before' ,
2009-04-26 22:18:17 -04:00
2007-10-23 02:05:44 -04:00
kSUBTREE _COLLAPSED : 'treestyletab-subtree-collapsed' ,
kCOLLAPSED : 'treestyletab-collapsed' ,
2009-04-07 13:14:09 -04:00
kCOLLAPSED _DONE : 'treestyletab-collapsed-done' ,
kCOLLAPSING : 'treestyletab-collapsing' ,
2009-04-26 22:18:17 -04:00
kALLOW _COLLAPSE : 'treestyletab-allow-subtree-collapse' ,
2009-04-08 11:00:21 -04:00
kX _OFFSET : 'treestyletab-x-offset' ,
kY _OFFSET : 'treestyletab-y-offset' ,
2009-04-26 22:18:17 -04:00
2007-10-23 02:05:44 -04:00
kTABBAR _POSITION : 'treestyletab-tabbar-position' ,
2007-10-26 08:56:04 -04:00
kMODE : 'treestyletab-mode' ,
2009-05-11 03:19:37 -04:00
2008-12-01 22:50:34 -05:00
kHIDE _NEWTAB : 'treestyletab-hide-newtab-button' ,
2007-11-09 00:48:39 -05:00
kHIDE _ALLTABS : 'treestyletab-hide-alltabs-button' ,
2007-10-23 02:05:44 -04:00
kSTYLE : 'treestyletab-style' ,
kFIRSTTAB _BORDER : 'treestyletab-firsttab-border' ,
2007-11-08 08:21:13 -05:00
kAUTOHIDE : 'treestyletab-tabbar-autohide' ,
2008-02-22 12:55:35 -05:00
kFIXED : 'treestyletab-tabbar-fixed' ,
2008-03-09 23:51:21 -04:00
kRESIZING : 'treestyletab-tabbar-resizing' ,
kTRANSPARENT : 'treestyletab-tabbar-transparent' ,
2009-05-11 04:22:16 -04:00
kINDENTED : 'treestyletab-tabs-indented' ,
2007-10-18 13:11:03 -04:00
2009-05-11 03:19:37 -04:00
kTAB _INVERTED : 'treestyletab-tab-inverted' ,
kTAB _CONTENTS _INVERTED : 'treestyletab-tab-contents-inverted' ,
kCLOSEBOX _INVERTED : 'treestyletab-closebox-inverted' ,
kSCROLLBAR _INVERTED : 'treestyletab-scrollbar-inverted' ,
2009-04-26 22:18:17 -04:00
kTWISTY _HOVER : 'treestyletab-twisty-hover' ,
kTWISTY _STYLE : 'treestyletab-twisty-style' ,
kDROP _POSITION : 'treestyletab-drop-position' ,
2009-08-25 03:20:56 -04:00
kDRAG _TYPE _TABBAR : 'application/x-moz-tabbrowser-tabbar' ,
2009-04-26 22:18:17 -04:00
/* classes */
2007-10-20 02:12:22 -04:00
kTWISTY : 'treestyletab-twisty' ,
kTWISTY _CONTAINER : 'treestyletab-twisty-container' ,
kDROP _MARKER : 'treestyletab-drop-marker' ,
kDROP _MARKER _CONTAINER : 'treestyletab-drop-marker-container' ,
kCOUNTER : 'treestyletab-counter' ,
kCOUNTER _CONTAINER : 'treestyletab-counter-container' ,
2009-04-08 05:16:39 -04:00
kSPLITTER : 'treestyletab-splitter' ,
2009-03-29 17:03:58 -04:00
kTABBAR _TOGGLER : 'treestyletab-tabbar-toggler' ,
2007-10-16 13:22:28 -04:00
2007-10-19 22:44:14 -04:00
kMENUITEM _REMOVESUBTREE _SELECTION : 'multipletab-selection-item-removeTabSubTree' ,
2007-10-19 01:27:06 -04:00
2007-10-18 23:05:36 -04:00
kFOCUS _ALL : 0 ,
kFOCUS _VISIBLE : 1 ,
2007-10-19 22:44:14 -04:00
kDROP _BEFORE : - 1 ,
kDROP _ON : 0 ,
kDROP _AFTER : 1 ,
2009-03-29 15:02:06 -04:00
kACTION _MOVE : 1 << 0 ,
kACTION _STAY : 1 << 1 ,
kACTION _DUPLICATE : 1 << 2 ,
kACTION _IMPORT : 1 << 3 ,
kACTION _NEWTAB : 1 << 4 ,
kACTION _ATTACH : 1 << 10 ,
kACTION _PART : 1 << 11 ,
kACTIONS _FOR _SOURCE : ( 1 << 0 ) | ( 1 << 1 ) ,
kACTIONS _FOR _DESTINATION : ( 1 << 2 ) | ( 1 << 3 ) ,
kTABBAR _TOP : 1 << 0 ,
kTABBAR _BOTTOM : 1 << 1 ,
kTABBAR _LEFT : 1 << 2 ,
kTABBAR _RIGHT : 1 << 3 ,
kTABBAR _HORIZONTAL : ( 1 << 0 ) | ( 1 << 1 ) ,
kTABBAR _VERTICAL : ( 1 << 2 ) | ( 1 << 3 ) ,
2007-10-20 06:24:36 -04:00
2008-06-17 02:22:49 -04:00
kAUTOHIDE _MODE _DISABLED : 0 ,
kAUTOHIDE _MODE _HIDE : 1 ,
kAUTOHIDE _MODE _SHRINK : 2 ,
2008-06-17 06:16:57 -04:00
get autoHideMode ( )
{
if ( this . _autoHideMode == this . kAUTOHIDE _MODE _SHRINK &&
this . getTreePref ( 'tabbar.position' ) != 'left' &&
this . getTreePref ( 'tabbar.position' ) != 'right' )
return this . kAUTOHIDE _MODE _HIDE ;
return this . _autoHideMode ;
} ,
set autoHideMode ( aValue )
{
this . _autoHideMode = aValue ;
return aValue ;
} ,
_autoHideMode : 0 ,
2008-06-17 02:22:49 -04:00
2008-03-08 03:57:17 -05:00
kSHOWN _BY _UNKNOWN : 0 ,
2009-03-29 15:02:06 -04:00
kSHOWN _BY _SHORTCUT : 1 << 0 ,
kSHOWN _BY _MOUSEMOVE : 1 << 1 ,
2009-04-08 05:16:39 -04:00
kSHOWN _BY _FEEDBACK : 1 << 2 ,
2009-03-29 15:06:25 -04:00
kKEEP _SHOWN _ON _MOUSEOVER : ( 1 << 0 ) | ( 1 << 1 ) | ( 1 << 2 ) ,
2008-09-26 10:13:29 -04:00
kTRANSPARENT _NONE : 0 ,
kTRANSPARENT _PART : 1 ,
kTRANSPARENT _FULL : 2 ,
kTRANSPARENT _STYLE : [ 'none' , 'part' , 'full' ] ,
2008-03-08 03:57:17 -05:00
2007-10-30 20:38:37 -04:00
kINSERT _FISRT : 0 ,
kINSERT _LAST : 1 ,
2009-04-07 13:14:09 -04:00
baseIndent : 12 ,
2008-12-03 08:17:40 -05:00
shouldDetectClickOnIndentSpaces : true ,
2009-04-07 13:14:09 -04:00
2009-04-09 21:32:03 -04:00
smoothScrollEnabled : true ,
smoothScrollDuration : 150 ,
2009-04-08 12:00:51 -04:00
2009-04-07 12:09:17 -04:00
animationEnabled : true ,
2009-04-09 21:32:03 -04:00
indentDuration : 200 ,
collapseDuration : 150 ,
2007-11-08 22:10:10 -05:00
2007-10-16 13:22:28 -04:00
NSResolver : {
lookupNamespaceURI : function ( aPrefix )
{
switch ( aPrefix )
{
case 'xul' :
return 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul' ;
case 'html' :
case 'xhtml' :
return 'http://www.w3.org/1999/xhtml' ;
case 'xlink' :
return 'http://www.w3.org/1999/xlink' ;
default :
return '' ;
}
}
} ,
get SessionStore ( ) {
if ( ! this . _SessionStore ) {
2008-02-22 00:01:35 -05:00
this . _SessionStore = Components
. classes [ '@mozilla.org/browser/sessionstore;1' ]
. getService ( Components . interfaces . nsISessionStore ) ;
2007-10-16 13:22:28 -04:00
}
return this . _SessionStore ;
} ,
_SessionStore : null ,
2007-10-20 04:22:42 -04:00
get ObserverService ( ) {
if ( ! this . _ObserverService ) {
2008-02-22 00:01:35 -05:00
this . _ObserverService = Components
. classes [ '@mozilla.org/observer-service;1' ]
. getService ( Components . interfaces . nsIObserverService ) ;
2007-10-20 04:22:42 -04:00
}
return this . _ObserverService ;
} ,
_ObserverService : null ,
2007-10-22 05:59:43 -04:00
get IOService ( ) {
if ( ! this . _IOService ) {
2008-02-22 00:01:35 -05:00
this . _IOService = Components
. classes [ '@mozilla.org/network/io-service;1' ]
. getService ( Components . interfaces . nsIIOService ) ;
2007-10-22 05:59:43 -04:00
}
return this . _IOService ;
} ,
_IOService : null ,
2007-11-09 00:20:32 -05:00
2008-02-22 00:01:35 -05:00
get WindowMediator ( ) {
if ( ! this . _WindowMediator ) {
this . _WindowMediator = Components
. classes [ '@mozilla.org/appshell/window-mediator;1' ]
. getService ( Components . interfaces . nsIWindowMediator ) ;
}
return this . _WindowMediator ;
} ,
_WindowMediator : null ,
2009-04-27 21:56:56 -04:00
get EffectiveTLD ( )
{
if ( ! ( '_EffectiveTLD' in this ) ) {
this . _EffectiveTLD = 'nsIEffectiveTLDService' in Components . interfaces ?
Components
. classes [ '@mozilla.org/network/effective-tld-service;1' ]
. getService ( Components . interfaces . nsIEffectiveTLDService ) :
null ;
}
return this . _EffectiveTLD ;
} ,
// _EffectiveTLD : null,
2009-07-22 00:25:39 -04:00
get PromptService ( )
{
if ( ! this . _PromptService ) {
this . _PromptService = Components
. classes [ '@mozilla.org/embedcomp/prompt-service;1' ]
. getService ( Components . interfaces . nsIPromptService ) ;
}
return this . _PromptService ;
} ,
_PromptService : null ,
2007-11-09 00:20:32 -05:00
get XULAppInfo ( ) {
if ( ! this . _XULAppInfo ) {
2009-04-21 02:10:26 -04:00
this . _XULAppInfo = Components
. classes [ '@mozilla.org/xre/app-info;1' ]
. getService ( Components . interfaces . nsIXULAppInfo ) ;
2007-11-09 00:20:32 -05:00
}
return this . _XULAppInfo ;
} ,
_XULAppInfo : null ,
2009-04-21 02:10:26 -04:00
get Comparator ( ) {
if ( ! this . _Comparator ) {
this . _Comparator = Components
. classes [ '@mozilla.org/xpcom/version-comparator;1' ]
. getService ( Components . interfaces . nsIVersionComparator ) ;
}
return this . _Comparator ;
} ,
_Comparator : null ,
2007-11-30 14:22:34 -05:00
2009-08-10 22:30:29 -04:00
get treeBundle ( ) {
return window [ 'piro.sakura.ne.jp' ]
. stringBundle
. get ( 'chrome://treestyletab/locale/treestyletab.properties' ) ;
2007-11-30 14:22:34 -05:00
} ,
2009-06-17 04:59:18 -04:00
get tabbrowserBundle ( ) {
2009-08-10 22:30:29 -04:00
return window [ 'piro.sakura.ne.jp' ]
. stringBundle
. get ( 'chrome://browser/locale/tabbrowser.properties' ) ;
2009-06-17 04:59:18 -04:00
} ,
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-05-15 11:51:12 -04:00
readyToOpenChildTab : function ( aFrameOrTabBrowser , aMultiple , aInsertBefore ) /* PUBLIC API */
2007-10-21 04:16:10 -04:00
{
2008-02-27 19:07:51 -05:00
if ( ! this . getTreePref ( 'autoAttachNewTabsAsChildren' ) ) return ;
2007-10-21 04:16:10 -04:00
var frame = this . getFrameFromTabBrowserElements ( aFrameOrTabBrowser ) ;
if ( ! frame ) return ;
2007-10-23 00:33:46 -04:00
var ownerBrowser = this . getTabBrowserFromFrame ( frame ) ;
2009-03-31 14:25:49 -04:00
var parentTab = this . getTabFromFrame ( frame , ownerBrowser ) ;
ownerBrowser . treeStyleTab . ensureTabInitialized ( parentTab ) ;
var parentId = parentTab . getAttribute ( this . kID ) ;
var refId = null ;
if ( aInsertBefore ) {
ownerBrowser . treeStyleTab . ensureTabInitialized ( parentTab ) ;
refId = aInsertBefore . getAttribute ( this . kID ) ;
}
2007-11-14 14:34:36 -05:00
ownerBrowser . treeStyleTab . readyToAttachNewTab = true ;
ownerBrowser . treeStyleTab . readyToAttachMultiple = aMultiple || false ;
ownerBrowser . treeStyleTab . multipleCount = 0 ;
2009-03-31 14:25:49 -04:00
ownerBrowser . treeStyleTab . parentTab = parentId ;
ownerBrowser . treeStyleTab . insertBefore = refId ;
2007-10-21 04:16:10 -04:00
} ,
2009-07-30 03:56:11 -04:00
readyToOpenNewTabGroup : function ( aFrameOrTabBrowser , aTreeStructure ) /* PUBLIC API */
2007-10-21 20:40:04 -04:00
{
2008-02-27 19:07:51 -05:00
if ( ! this . getTreePref ( 'autoAttachNewTabsAsChildren' ) ) return ;
2007-10-21 20:40:04 -04:00
var frame = this . getFrameFromTabBrowserElements ( aFrameOrTabBrowser ) ;
if ( ! frame ) return ;
this . stopToOpenChildTab ( frame ) ;
2007-10-23 00:33:46 -04:00
var ownerBrowser = this . getTabBrowserFromFrame ( frame ) ;
2007-11-14 14:34:36 -05:00
ownerBrowser . treeStyleTab . readyToAttachNewTabGroup = true ;
ownerBrowser . treeStyleTab . readyToAttachMultiple = true ;
ownerBrowser . treeStyleTab . multipleCount = 0 ;
2009-07-30 03:56:11 -04:00
ownerBrowser . treeStyleTab . treeStructure = aTreeStructure ;
2007-10-21 20:40:04 -04:00
} ,
2009-05-15 11:51:12 -04:00
stopToOpenChildTab : function ( aFrameOrTabBrowser ) /* PUBLIC API */
2007-10-21 04:16:10 -04:00
{
var frame = this . getFrameFromTabBrowserElements ( aFrameOrTabBrowser ) ;
if ( ! frame ) return ;
2007-10-23 00:33:46 -04:00
var ownerBrowser = this . getTabBrowserFromFrame ( frame ) ;
2007-11-14 14:34:36 -05:00
ownerBrowser . treeStyleTab . readyToAttachNewTab = false ;
ownerBrowser . treeStyleTab . readyToAttachNewTabGroup = false ;
ownerBrowser . treeStyleTab . readyToAttachMultiple = false ;
ownerBrowser . treeStyleTab . multipleCount = 0 ;
ownerBrowser . treeStyleTab . parentTab = null ;
ownerBrowser . treeStyleTab . insertBefore = null ;
2009-07-30 03:56:11 -04:00
ownerBrowser . treeStyleTab . treeStructure = null ;
2007-10-21 04:16:10 -04:00
} ,
2009-05-15 11:51:12 -04:00
checkToOpenChildTab : function ( aFrameOrTabBrowser ) /* PUBLIC API */
2007-10-21 04:16:10 -04:00
{
var frame = this . getFrameFromTabBrowserElements ( aFrameOrTabBrowser ) ;
if ( ! frame ) return false ;
2007-10-23 00:33:46 -04:00
var ownerBrowser = this . getTabBrowserFromFrame ( frame ) ;
2007-11-14 14:34:36 -05:00
return ownerBrowser . treeStyleTab . readyToAttachNewTab || ownerBrowser . treeStyleTab . readyToAttachNewTabGroup ? true : false ;
2007-10-21 04:16:10 -04:00
} ,
2007-10-28 12:07:10 -04:00
2007-10-29 11:49:00 -04:00
checkReadyToOpenNewTab : function ( aInfo )
2007-10-28 12:07:10 -04:00
{
2007-10-29 10:52:52 -04:00
/ *
<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ̐ <EFBFBD> <EFBFBD> <EFBFBD>
<EFBFBD> E <EFBFBD> <EFBFBD> <EFBFBD> ݂ ̃ T <EFBFBD> C <EFBFBD> g <EFBFBD> ƈقȂ <EFBFBD> <EFBFBD> T <EFBFBD> C <EFBFBD> g <EFBFBD> <EFBFBD> <EFBFBD> ǂݍ <EFBFBD> <EFBFBD> ޏꍇ <EFBFBD> Ƀ ^ <EFBFBD> u <EFBFBD> <EFBFBD> <EFBFBD> J <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> F
<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ɉ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ȃ <EFBFBD> <EFBFBD> B <EFBFBD> V <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> J <EFBFBD> <EFBFBD> <EFBFBD> ^ <EFBFBD> u <EFBFBD> <EFBFBD> <EFBFBD> q <EFBFBD> ^ <EFBFBD> u <EFBFBD> ɂ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ꍇ <EFBFBD> ͕ ʓr
readyToOpenChildTab <EFBFBD> <EFBFBD> <EFBFBD> g <EFBFBD> <EFBFBD> <EFBFBD> B
<EFBFBD> E <EFBFBD> <EFBFBD> <EFBFBD> ݂ ̃ T <EFBFBD> C <EFBFBD> g <EFBFBD> Ɠ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> T <EFBFBD> C <EFBFBD> g <EFBFBD> ̃ y <EFBFBD> [ <EFBFBD> W <EFBFBD> <EFBFBD> <EFBFBD> ǂݍ <EFBFBD> <EFBFBD> ޏꍇ <EFBFBD> Ƀ ^ <EFBFBD> u <EFBFBD> <EFBFBD> <EFBFBD> J <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> F
<EFBFBD> <EFBFBD> <EFBFBD> e <EFBFBD> ̃ ^ <EFBFBD> u <EFBFBD> ͓ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> T <EFBFBD> C <EFBFBD> g <EFBFBD> <EFBFBD> <EFBFBD> H
No <EFBFBD> F <EFBFBD> q <EFBFBD> ^ <EFBFBD> u <EFBFBD> <EFBFBD> <EFBFBD> J <EFBFBD> <EFBFBD>
Yes <EFBFBD> F <EFBFBD> Z <EFBFBD> <EFBFBD> <EFBFBD> Ƃ <EFBFBD> <EFBFBD> ă ^ <EFBFBD> u <EFBFBD> <EFBFBD> <EFBFBD> J <EFBFBD> <EFBFBD> <EFBFBD> B <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> A <EFBFBD> <EFBFBD> <EFBFBD> ̃ ^ <EFBFBD> u <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ̃ ^ <EFBFBD> u <EFBFBD> ͂ <EFBFBD> <EFBFBD> ׂ <EFBFBD>
<EFBFBD> <EFBFBD> <EFBFBD> ݂ ̃ ^ <EFBFBD> u <EFBFBD> Ǝ <EFBFBD> <EFBFBD> ̌ Z <EFBFBD> <EFBFBD> <EFBFBD> ^ <EFBFBD> u <EFBFBD> Ƃ ̊ ԂɊJ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> A <EFBFBD> <EFBFBD> <EFBFBD> z <EFBFBD> T <EFBFBD> u <EFBFBD> c <EFBFBD> <EFBFBD> <EFBFBD> [ <EFBFBD> ƂȂ <EFBFBD> <EFBFBD> B
<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ݂ ̃ ^ <EFBFBD> u <EFBFBD> Ɂ u_ _treestyletab _ _next <EFBFBD> v <EFBFBD> v <EFBFBD> <EFBFBD> <EFBFBD> p <EFBFBD> e <EFBFBD> B <EFBFBD> <EFBFBD>
<EFBFBD> <EFBFBD> <EFBFBD> 邩 <EFBFBD> H
Yes <EFBFBD> F _ _treestyletab _ _next <EFBFBD> Ŏ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ꂽ <EFBFBD> ^ <EFBFBD> u <EFBFBD> ̒ <EFBFBD> <EFBFBD> O <EFBFBD> <EFBFBD>
<EFBFBD> V <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Z <EFBFBD> <EFBFBD> <EFBFBD> ^ <EFBFBD> u <EFBFBD> <EFBFBD> <EFBFBD> } <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> B
No <EFBFBD> F <EFBFBD> <EFBFBD> <EFBFBD> ݂ ̃ ^ <EFBFBD> u <EFBFBD> ̎ <EFBFBD> <EFBFBD> ̌ Z <EFBFBD> <EFBFBD> <EFBFBD> ^ <EFBFBD> u <EFBFBD> <EFBFBD> ID <EFBFBD> <EFBFBD> _ _treestyletab _ _next
<EFBFBD> v <EFBFBD> <EFBFBD> <EFBFBD> p <EFBFBD> e <EFBFBD> B <EFBFBD> ɕێ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> A <EFBFBD> <EFBFBD> <EFBFBD> z <EFBFBD> ̎ q <EFBFBD> ^ <EFBFBD> u <EFBFBD> <EFBFBD> <EFBFBD> } <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʒu <EFBFBD> <EFBFBD>
<EFBFBD> <EFBFBD> Ƃ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> B
* /
2007-10-28 14:03:24 -04:00
var info = aInfo || { uri : '' } ;
if ( /^javascript:/ . test ( info . uri ) ) return false ;
2007-10-29 11:22:50 -04:00
var frame = this . getFrameFromTabBrowserElements ( info . target ) ;
if ( ! frame ) return false ;
2007-10-28 13:16:48 -04:00
var external = info . external || { } ;
var internal = info . internal || { } ;
2007-11-14 14:34:36 -05:00
var b = this . getTabBrowserFromFrame ( frame ) ;
var nextTab = b . treeStyleTab . getNextSiblingTab ( currentTab ) ;
2009-04-28 04:25:14 -04:00
var targetHost = this . _getDomainFromURI ( info . uri ) ;
2007-10-29 10:52:52 -04:00
var currentTab = this . getTabFromFrame ( frame ) ;
2007-10-28 12:07:10 -04:00
var currentURI = frame . location . href ;
2009-04-28 04:25:14 -04:00
var currentHost = this . _getDomainFromURI ( currentURI ) ;
2007-11-14 14:34:36 -05:00
var parentTab = b . treeStyleTab . getParentTab ( currentTab ) ;
2007-10-28 12:07:10 -04:00
var parentURI = parentTab ? parentTab . linkedBrowser . currentURI : null ;
2009-04-28 03:30:54 -04:00
var parentHost = this . _getDomainFromURI ( parentURI ) ;
2009-04-27 21:56:56 -04:00
2007-10-29 11:49:00 -04:00
var openTab = false ;
var parent = null ;
var insertBefore = null ;
if ( info . modifier ) openTab = true ;
if (
internal . newTab &&
currentHost == targetHost &&
currentURI != 'about:blank' &&
currentURI . split ( '#' ) [ 0 ] != info . uri . split ( '#' ) [ 0 ]
) {
openTab = info . modifier && info . invert ? ! openTab : true ;
2009-07-24 07:00:53 -04:00
parent = ( 'forceChild' in internal && ! internal . forceChild ) ? null :
( parentHost == targetHost && ! internal . forceChild ) ? parentTab :
frame ;
2007-10-30 20:38:37 -04:00
insertBefore = parentHost == targetHost && ! internal . forceChild &&
( this . getTreePref ( 'insertNewChildAt' ) == this . kINSERT _FIRST ?
nextTab :
(
2007-11-14 14:34:36 -05:00
b . treeStyleTab . getTabById ( currentTab . _ _treestyletab _ _next ) ||
2007-10-30 20:38:37 -04:00
( nextTab ? ( currentTab . _ _treestyletab _ _next = nextTab . getAttribute ( this . kID ) , nextTab ) : null )
)
) ;
2007-10-29 11:49:00 -04:00
}
else if (
external . newTab &&
currentHost != targetHost &&
currentURI != 'about:blank'
) {
openTab = info . modifier && info . invert ? ! openTab : true ;
if ( external . forceChild ) {
parent = frame ;
}
}
if ( openTab && parent ) {
this . readyToOpenChildTab ( parent , false , insertBefore ) ;
}
return openTab ;
2007-10-28 12:07:10 -04:00
} ,
2008-09-26 10:13:29 -04:00
checkReadyToOpenNewTabOnLocationBar : function ( aURI , aModifier )
{
return this . checkReadyToOpenNewTab ( {
uri : aURI ,
external : {
newTab : this . getTreePref ( 'urlbar.loadDifferentDomainToNewTab' ) ,
forceChild : this . getTreePref ( 'urlbar.loadDifferentDomainToNewTab.asChild' )
} ,
2009-07-24 07:00:53 -04:00
internal : {
newTab : this . getTreePref ( 'urlbar.loadSameDomainToNewTab' ) ,
forceChild : this . getTreePref ( 'urlbar.loadSameDomainToNewTab.asChild' )
} ,
2008-09-26 10:13:29 -04:00
modifier : aModifier ,
invert : this . getTreePref ( 'urlbar.invertDefaultBehavior' )
} ) ;
} ,
2009-04-28 03:20:39 -04:00
_getDomainFromURI : function ( aURI )
{
2009-04-28 03:30:54 -04:00
if ( ! aURI ) return null ;
2009-04-28 04:25:14 -04:00
2009-04-28 03:30:54 -04:00
if ( this . getTreePref ( 'useEffectiveTLD' ) && this . EffectiveTLD ) {
2009-04-28 03:20:39 -04:00
try {
2009-04-28 04:25:14 -04:00
var uri = aURI ;
if ( ! ( uri instanceof Ci . nsIURI ) ) uri = this . makeURIFromSpec ( uri ) ;
var domain = this . EffectiveTLD . getBaseDomain ( uri , 0 ) ;
if ( domain ) return domain ;
2009-04-28 03:20:39 -04:00
}
catch ( e ) {
}
}
2009-04-28 04:25:14 -04:00
var str = aURI ;
if ( str instanceof Ci . nsIURI ) str = aURI . spec ;
2009-04-28 04:25:38 -04:00
return /^\w+:\/\/([^:\/]+)/ . test ( getShortcutOrURI ( str ) ) ?
2009-04-28 04:25:14 -04:00
RegExp . $1 :
null ;
2009-04-28 03:20:39 -04:00
} ,
2009-04-21 02:42:52 -04:00
2009-05-15 11:51:12 -04:00
setTabbarWidth : function ( aWidth , aForceExpanded ) /* PUBLIC API */
2009-04-21 02:42:52 -04:00
{
var treeStyleTab = gBrowser . treeStyleTab ;
if ( aForceExpanded ||
treeStyleTab . autoHideShown ||
treeStyleTab . autoHideMode != this . kAUTOHIDE _MODE _SHRINK )
this . setTreePref ( 'tabbar.width' , aWidth ) ;
else
this . setTreePref ( 'tabbar.shrunkenWidth' , aWidth ) ;
} ,
2009-05-15 11:51:12 -04:00
setContentWidth : function ( aWidth , aKeepWindowSize ) /* PUBLIC API */
2009-04-21 02:42:52 -04:00
{
var treeStyleTab = gBrowser . treeStyleTab ;
var tabbarWidth = treeStyleTab . splitterWidth + ( treeStyleTab . isVertical ? gBrowser . mStrip . boxObject . width : 0 ) ;
var contentWidth = gBrowser . boxObject . width - tabbarWidth ;
2009-04-21 02:45:00 -04:00
if ( aKeepWindowSize ||
window . fullScreen ||
window . windowState != Components . interfaces . nsIDOMChromeWindow . STATE _NORMAL ) {
2009-04-21 02:42:52 -04:00
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 ( )
{
this . setTreePref ( 'tabbar.autoHide.mode' ,
this . getTreePref ( 'tabbar.autoHide.mode' ) == this . kAUTOHIDE _MODE _DISABLED ?
this . getTreePref ( 'tabbar.autoHide.mode.toggle' ) :
this . kAUTOHIDE _MODE _DISABLED
) ;
} ,
toggleFixed : function ( )
{
2009-07-07 11:34:14 -04:00
var pos = this . getTreePref ( 'tabbar.position' ) ;
2009-07-07 12:00:42 -04:00
var isVertical = ( pos == 'left' || pos == 'right' ) ;
var pref = isVertical ? 'tabbar.fixed.vertical' : 'tabbar.fixed.horizontal' ;
2009-07-07 11:34:14 -04:00
this . setTreePref ( pref , ! this . getTreePref ( pref ) ) ;
2009-07-07 20:21:39 -04:00
2009-07-07 21:23:57 -04:00
if ( ! this . getTreePref ( 'tabbar.syncRelatedPrefsForDynamicPosition' ) ) return ;
2009-07-07 20:21:39 -04:00
if ( ! isVertical )
this . setTreePref ( 'enableSubtreeIndent.horizontal' , ! this . getTreePref ( pref ) ) ;
2009-04-21 02:42:52 -04:00
} ,
2009-05-15 11:51:12 -04:00
changeTabbarPosition : function ( aNewPosition ) /* PUBLIC API */
2009-04-21 02:42:52 -04:00
{
if ( ! aNewPosition || ! /^(top|bottom|left|right)$/i . test ( aNewPosition ) )
aNewPosition = 'top' ;
aNewPosition = aNewPosition . toLowerCase ( ) ;
this . setTreePref ( 'tabbar.position' , aNewPosition ) ;
} ,
2007-10-30 08:58:09 -04:00
2007-11-14 14:34:36 -05:00
/* backward compatibility */
getTempTreeStyleTab : function ( aTabBrowser )
{
return aTabBrowser . treeStyleTab || new TreeStyleTabBrowser ( aTabBrowser ) ;
} ,
initTabAttributes : function ( aTab , aTabBrowser )
{
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 ) ;
} ,
initTabContents : function ( aTab , aTabBrowser )
{
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 ) ;
} ,
initTabContentsOrder : function ( aTab , aTabBrowser )
{
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
2007-10-26 05:36:45 -04:00
isEventFiredOnTwisty : function ( aEvent )
2007-10-16 13:22:28 -04:00
{
var tab = this . getTabFromEvent ( aEvent ) ;
2009-05-08 02:04:22 -04:00
if ( ! tab || ! this . hasChildTabs ( tab ) ) return false ;
2007-10-16 13:22:28 -04:00
2009-05-08 02:04:22 -04:00
var expression = 'ancestor-or-self::*[@class="' + this . kTWISTY + '"]' ;
if ( this . canExpandTwistyArea ( this . getTabBrowserFromChild ( tab ) ) )
expression += ' | ancestor-or-self::*[@class="tab-icon" and ancestor::xul:tabbrowser[@' + this . kMODE + '="vertical"]]' ;
return this . evaluateXPath (
expression ,
2007-10-26 05:36:45 -04:00
aEvent . originalTarget || aEvent . target ,
2009-04-26 22:18:17 -04:00
XPathResult . BOOLEAN _TYPE
) . booleanValue ;
2007-10-18 13:11:03 -04:00
} ,
2009-05-08 02:04:22 -04:00
canExpandTwistyArea : function ( aTabBrowser )
{
return (
this . expandTwistyArea &&
this . _expandTwistyAreaAllowance . every ( function ( aFunc ) {
2009-07-06 11:36:43 -04:00
return aFunc . call ( this , aTabBrowser ) ;
} , this )
2009-05-08 02:04:22 -04:00
) ;
} ,
expandTwistyArea : true ,
2007-10-18 14:20:54 -04:00
2009-07-31 06:09:11 -04:00
isEventFiredOnClosebox : function ( aEvent )
{
var tab = this . getTabFromEvent ( aEvent ) ;
if ( ! tab || ! this . hasChildTabs ( tab ) ) return false ;
return this . evaluateXPath (
'ancestor-or-self::*[contains(concat(" ", normalize-space(@class), " "), " tab-close-button ")]' ,
aEvent . originalTarget || aEvent . target ,
XPathResult . BOOLEAN _TYPE
) . booleanValue ;
} ,
2008-12-14 21:59:51 -05:00
isEventFiredOnClickable : function ( aEvent )
{
return this . evaluateXPath (
2008-12-17 18:41:39 -05:00
'ancestor-or-self::*[contains(" button toolbarbutton scrollbar popup menupopup tooltip ", concat(" ", local-name(), " "))]' ,
2008-12-14 21:59:51 -05:00
aEvent . originalTarget ,
2009-04-26 22:18:17 -04:00
XPathResult . BOOLEAN _TYPE
) . booleanValue ;
2008-12-14 21:59:51 -05:00
} ,
2008-10-17 08:35:55 -04:00
isAccelKeyPressed : function ( aEvent )
{
2009-05-12 14:21:44 -04:00
var isMac = navigator . platform . toLowerCase ( ) . indexOf ( 'mac' ) > - 1 ;
var nsIDOMKeyEvent = Components . interfaces . nsIDOMKeyEvent ;
if ( // this is releasing of the accel key!
( aEvent . type == 'keyup' ) &&
( aEvent . keyCode == ( isMac ? nsIDOMKeyEvent . DOM _VK _META : nsIDOMKeyEvent . DOM _VK _CONTROL ) )
) {
return false ;
}
return isMac ?
( aEvent . metaKey || ( aEvent . keyCode == nsIDOMKeyEvent . DOM _VK _META ) ) :
( aEvent . ctrlKey || ( aEvent . keyCode == nsIDOMKeyEvent . DOM _VK _CONTROL ) ) ;
2008-10-17 08:35:55 -04:00
} ,
2008-02-22 00:01:35 -05:00
get browserWindow ( )
{
return this . WindowMediator . getMostRecentWindow ( 'navigator:browser' ) ;
} ,
2007-10-16 13:22:28 -04:00
get browser ( )
{
2008-02-22 00:01:35 -05:00
var w = this . browserWindow ;
return ! w ? null :
2008-02-22 00:04:35 -05:00
'SplitBrowser' in w ? w . SplitBrowser . activeBrowser :
2008-02-22 00:01:35 -05:00
w . gBrowser ;
2007-10-16 13:22:28 -04:00
} ,
2007-10-18 23:05:36 -04:00
evaluateXPath : function ( aExpression , aContext , aType )
{
if ( ! aType ) aType = XPathResult . ORDERED _NODE _SNAPSHOT _TYPE ;
try {
2008-10-17 08:35:55 -04:00
var xpathResult = ( aContext . ownerDocument || aContext || document ) . evaluate (
2007-10-18 23:05:36 -04:00
aExpression ,
2008-10-17 08:35:55 -04:00
( aContext || document ) ,
2007-10-18 23:05:36 -04:00
this . NSResolver ,
aType ,
null
) ;
}
catch ( e ) {
return {
singleNodeValue : null ,
snapshotLength : 0 ,
snapshotItem : function ( ) {
return null
}
} ;
}
return xpathResult ;
} ,
2007-10-16 13:22:28 -04:00
getArrayFromXPathResult : function ( aXPathResult )
{
var max = aXPathResult . snapshotLength ;
var array = new Array ( max ) ;
if ( ! max ) return array ;
for ( var i = 0 ; i < max ; i ++ )
{
array [ i ] = aXPathResult . snapshotItem ( i ) ;
}
return array ;
} ,
2009-03-31 00:45:00 -04:00
getBoxObjectFor : function ( aNode )
{
2009-03-31 03:40:29 -04:00
return window [ 'piro.sakura.ne.jp' ] . boxObject . getBoxObjectFor ( aNode ) ;
2009-03-31 00:45:00 -04:00
} ,
2007-10-16 13:22:28 -04:00
getTabFromEvent : function ( aEvent )
{
2008-10-17 08:35:55 -04:00
return this . getTabFromChild ( aEvent . originalTarget || aEvent . target ) ;
2007-10-16 13:22:28 -04:00
} ,
2007-10-17 12:07:43 -04:00
getTabFromFrame : function ( aFrame , aTabBrowser )
{
var b = aTabBrowser || this . browser ;
var docShell = aFrame . top
. QueryInterface ( Components . interfaces . nsIInterfaceRequestor )
. getInterface ( Components . interfaces . nsIWebNavigation )
. QueryInterface ( Components . interfaces . nsIDocShell ) ;
2009-01-24 00:39:22 -05:00
var tabs = this . getTabs ( b ) ;
var tab ;
for ( var i = 0 , maxi = tabs . snapshotLength ; i < maxi ; i ++ )
2007-10-17 12:07:43 -04:00
{
2009-01-24 00:39:22 -05:00
tab = tabs . snapshotItem ( i ) ;
if ( tab . linkedBrowser . docShell == docShell )
return tab ;
2007-10-17 12:07:43 -04:00
}
return null ;
} ,
2008-10-17 08:35:55 -04:00
getTabFromChild : function ( aTab )
{
return this . evaluateXPath (
'ancestor-or-self::xul:tab[ancestor::xul:tabbrowser]' ,
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
} ,
2009-08-25 03:20:56 -04:00
getTabbarFromEvent : function ( aEvent )
{
return this . evaluateXPath (
'ancestor-or-self::*[contains(concat(" ", normalize-space(@class), " "), " tabbrowser-strip ")]' ,
aEvent . originalTarget || aEvent . target ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
} ,
2007-11-17 08:32:41 -05:00
getTabBrowserFromChild : function ( aTab )
2007-10-16 13:22:28 -04:00
{
2007-10-17 12:07:43 -04:00
if ( ! aTab ) return null ;
2007-10-16 13:22:28 -04:00
if ( aTab . _ _treestyletab _ _linkedTabBrowser )
return aTab . _ _treestyletab _ _linkedTabBrowser ;
2007-10-26 06:25:59 -04:00
return this . evaluateXPath (
'ancestor-or-self::xul:tabbrowser' ,
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
2007-10-16 13:22:28 -04:00
} ,
2007-10-23 00:33:46 -04:00
getTabBrowserFromFrame : function ( aFrame )
{
2008-02-22 00:01:35 -05:00
var w = this . browserWindow ;
return ! w ? null :
( 'SplitBrowser' in w ) ? this . getTabBrowserFromChild ( w . SplitBrowser . getSubBrowserAndBrowserFromFrame ( aFrame . top ) . browser ) :
this . browser ;
2007-10-23 00:33:46 -04:00
} ,
2007-10-23 04:19:32 -04:00
2007-10-21 04:16:10 -04:00
getFrameFromTabBrowserElements : function ( aFrameOrTabBrowser )
{
var frame = aFrameOrTabBrowser ;
if ( frame == '[object XULElement]' ) {
if ( frame . localName == 'tab' ) {
frame = frame . linkedBrowser . contentWindow ;
}
else if ( frame . localName == 'browser' ) {
frame = frame . contentWindow ;
}
else {
2007-11-17 08:32:41 -05:00
frame = this . getTabBrowserFromChild ( frame ) ;
2007-10-21 04:16:10 -04:00
if ( ! frame ) return null ;
frame = frame . contentWindow ;
}
}
if ( ! frame )
frame = this . browser . contentWindow ;
return frame ;
} ,
2007-10-21 11:02:58 -04:00
2007-11-17 07:50:36 -05:00
makeNewId : function ( )
{
return 'tab-<' + Date . now ( ) + '-' + parseInt ( Math . random ( ) * 65000 ) + '>' ;
} ,
2007-11-17 07:59:48 -05:00
2007-10-22 05:59:43 -04:00
makeURIFromSpec : function ( aURI )
{
var newURI ;
aURI = aURI || '' ;
if ( aURI && String ( aURI ) . indexOf ( 'file:' ) == 0 ) {
var fileHandler = this . IOService . getProtocolHandler ( 'file' ) . QueryInterface ( Components . interfaces . nsIFileProtocolHandler ) ;
var tempLocalFile = fileHandler . getFileFromURLSpec ( aURI ) ;
newURI = this . IOService . newFileURI ( tempLocalFile ) ;
}
else {
newURI = this . IOService . newURI ( aURI , null , null ) ;
}
return newURI ;
} ,
2007-11-12 11:31:00 -05:00
2009-04-07 12:09:17 -04:00
getPropertyPixelValue : function ( aElementOrStyle , aProp )
{
var style = aElementOrStyle instanceof Components . interfaces . nsIDOMCSSStyleDeclaration ?
aElementOrStyle :
window . getComputedStyle ( aElementOrStyle , null ) ;
return Number ( style . getPropertyValue ( aProp ) . replace ( /px$/ , '' ) ) ;
} ,
2009-06-18 04:45:48 -04:00
getGroupTabURI : function ( aTitle )
{
2009-07-23 11:34:28 -04:00
return 'about:treestyletab-group' + ( aTitle === void ( 0 ) ? '' : '?' + encodeURIComponent ( aTitle ) ) ;
2009-06-17 12:49:18 -04:00
} ,
2007-11-17 07:59:48 -05:00
/* get tab(s) */
2008-02-22 12:55:35 -05:00
2007-11-17 07:59:48 -05:00
getTabById : function ( aId , aTabBrowserChildren )
{
if ( ! aId ) return null ;
2007-11-17 08:32:41 -05:00
var b = aTabBrowserChildren ? this . getTabBrowserFromChild ( aTabBrowserChildren ) : null ;
2007-11-17 07:59:48 -05:00
if ( ! b ) b = this . browser ;
return this . evaluateXPath (
'descendant::xul:tab[@' + this . kID + ' = "' + aId + '"]' ,
b . mTabContainer ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
} ,
2008-02-22 12:55:35 -05:00
2009-01-26 01:37:29 -05:00
getTabs : function ( aTabBrowser )
{
return this . evaluateXPath (
'descendant::xul:tab' ,
aTabBrowser . mTabContainer
) ;
} ,
getTabsArray : function ( aTabBrowser )
{
var tabs = this . getTabs ( aTabBrowser ) ;
var array = [ ] ;
for ( var i = 0 , maxi = tabs . snapshotLength ; i < maxi ; i ++ )
{
array . push ( tabs . snapshotItem ( i ) ) ;
}
return array ;
} ,
2009-01-26 01:39:51 -05:00
getFirstTab : function ( aTabBrowser )
{
return this . evaluateXPath (
'descendant::xul:tab[1]' ,
aTabBrowser . mTabContainer ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
} ,
2009-01-26 01:37:29 -05:00
getLastTab : function ( aTabBrowser )
{
return this . evaluateXPath (
'descendant::xul:tab[last()]' ,
aTabBrowser . mTabContainer ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
} ,
2009-01-24 00:39:22 -05:00
getNextTab : function ( aTab )
{
2009-07-08 06:40:51 -04:00
if ( ! aTab ) return null ;
2009-01-26 01:13:37 -05:00
return this . evaluateXPath (
'following-sibling::xul:tab[1]' ,
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
2009-01-24 00:39:22 -05:00
} ,
getPreviousTab : function ( aTab )
{
2009-07-08 06:40:51 -04:00
if ( ! aTab ) return null ;
2009-01-26 01:13:37 -05:00
return this . evaluateXPath (
'preceding-sibling::xul:tab[1]' ,
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
2009-01-24 00:39:22 -05:00
} ,
2007-11-17 07:59:48 -05:00
getNextVisibleTab : function ( aTab )
{
2009-07-08 06:40:51 -04:00
if ( ! aTab ) return null ;
2009-01-26 01:13:37 -05:00
return this . evaluateXPath (
'following-sibling::xul:tab[not(@' + this . kCOLLAPSED + '="true")][1]' ,
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
2007-11-17 07:59:48 -05:00
} ,
getPreviousVisibleTab : function ( aTab )
{
2009-07-08 06:40:51 -04:00
if ( ! aTab ) return null ;
2009-01-26 01:13:37 -05:00
return this . evaluateXPath (
'preceding-sibling::xul:tab[not(@' + this . kCOLLAPSED + '="true")][1]' ,
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
2007-11-17 07:59:48 -05:00
} ,
2007-11-26 17:43:50 -05:00
2008-02-22 01:58:50 -05:00
getLastVisibleTab : function ( aTab )
{
2009-07-08 06:40:51 -04:00
if ( ! aTab ) return null ;
2009-01-26 01:13:37 -05:00
return this . evaluateXPath (
'child::xul:tab[not(@' + this . kCOLLAPSED + '="true")][last()]' ,
aTab . parentNode ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
2008-02-22 01:58:50 -05:00
} ,
getVisibleTabs : function ( aTab )
{
var xpathResult = this . evaluateXPath (
'child::xul:tab[not(@' + this . kCOLLAPSED + '="true")]' ,
aTab . parentNode
) ;
return xpathResult ;
} ,
2007-11-26 17:43:50 -05:00
getVisibleIndex : function ( aTab )
{
2009-07-08 06:40:51 -04:00
if ( ! aTab || aTab . getAttribute ( this . kCOLLAPSED ) == 'true' ) return - 1 ;
2007-11-26 17:43:50 -05:00
return this . evaluateXPath (
2009-01-26 01:13:37 -05:00
'count(preceding-sibling::xul:tab[not(@' + this . kCOLLAPSED + '="true")])' ,
aTab ,
XPathResult . NUMBER _TYPE
) . numberValue ;
2007-11-26 17:43:50 -05:00
} ,
2008-03-09 01:36:52 -05:00
2007-11-17 07:59:48 -05:00
/* tree manipulations */
2008-02-22 12:55:35 -05:00
2009-05-15 11:51:12 -04:00
get rootTabs ( ) /* PUBLIC API */
2007-11-17 07:59:48 -05:00
{
return this . getArrayFromXPathResult (
this . evaluateXPath (
'child::xul:tab[not(@' + this . kNEST + ') or @' + this . kNEST + '="0" or @' + this . kNEST + '=""]' ,
this . browser . mTabContainer
)
) ;
} ,
2009-05-15 11:51:12 -04:00
getParentTab : function ( aTab ) /* PUBLIC API */
2007-11-17 07:59:48 -05:00
{
if ( ! aTab ) return null ;
var id = aTab . getAttribute ( this . kID ) ;
if ( ! id ) return null ; // not initialized yet
return this . evaluateXPath (
2008-02-22 16:09:09 -05:00
'parent::*/child::xul:tab[contains(concat("|", @' + this . kCHILDREN + ', "|"), "|' + id + '|")]' ,
2007-11-17 07:59:48 -05:00
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
} ,
2009-05-15 11:51:12 -04:00
getRootTab : function ( aTab ) /* PUBLIC API */
2007-11-17 07:59:48 -05:00
{
var parent = aTab ;
var root = aTab ;
while ( parent = this . getParentTab ( parent ) )
{
root = parent ;
}
return root ;
} ,
2009-05-15 11:51:12 -04:00
getNextSiblingTab : function ( aTab ) /* PUBLIC API */
2007-11-17 07:59:48 -05:00
{
if ( ! aTab ) return null ;
var parentTab = this . getParentTab ( aTab ) ;
if ( ! parentTab ) {
var next = aTab ;
do {
next = next . nextSibling ;
}
2009-01-24 00:39:22 -05:00
while ( next &&
next . nodeType == Node . ELEMENT _NODE &&
this . getParentTab ( next ) ) ;
2007-11-17 07:59:48 -05:00
return next ;
}
var children = parentTab . getAttribute ( this . kCHILDREN ) ;
if ( children ) {
var list = ( '|' + children ) . split ( '|' + aTab . getAttribute ( this . kID ) ) [ 1 ] . split ( '|' ) ;
for ( var i = 0 , maxi = list . length ; i < maxi ; i ++ )
{
var firstChild = this . getTabById ( list [ i ] , aTab ) ;
if ( firstChild ) return firstChild ;
}
}
return null ;
} ,
2009-05-15 11:51:12 -04:00
getPreviousSiblingTab : function ( aTab ) /* PUBLIC API */
2007-11-17 07:59:48 -05:00
{
if ( ! aTab ) return null ;
var parentTab = this . getParentTab ( aTab ) ;
if ( ! parentTab ) {
var prev = aTab ;
do {
prev = prev . previousSibling ;
}
2009-01-24 00:39:22 -05:00
while ( prev &&
prev . nodeType == Node . ELEMENT _NODE &&
this . getParentTab ( prev ) ) ;
2007-11-17 07:59:48 -05:00
return prev ;
}
var children = parentTab . getAttribute ( this . kCHILDREN ) ;
if ( children ) {
var list = ( '|' + children ) . split ( '|' + aTab . getAttribute ( this . kID ) ) [ 0 ] . split ( '|' ) ;
for ( var i = list . length - 1 ; i > - 1 ; i -- )
{
var lastChild = this . getTabById ( list [ i ] , aTab ) ;
if ( lastChild ) return lastChild ;
}
}
return null ;
} ,
2009-05-15 11:51:12 -04:00
getChildTabs : function ( aTab , aAllTabsArray ) /* PUBLIC API */
2007-11-17 07:59:48 -05:00
{
var tabs = [ ] ;
2009-07-24 03:09:29 -04:00
if ( ! aTab ) return tabs ;
2007-11-17 07:59:48 -05:00
var children = aTab . getAttribute ( this . kCHILDREN ) ;
if ( ! children ) return tabs ;
if ( aAllTabsArray ) tabs = aAllTabsArray ;
var list = children . split ( '|' ) ;
var tab ;
for ( var i = 0 , maxi = list . length ; i < maxi ; i ++ )
{
tab = this . getTabById ( list [ i ] , aTab ) ;
if ( ! tab ) continue ;
tabs . push ( tab ) ;
if ( aAllTabsArray )
this . getChildTabs ( tab , tabs ) ;
}
return tabs ;
} ,
2009-05-15 11:51:12 -04:00
hasChildTabs : function ( aTab ) /* PUBLIC API */
2008-04-29 14:17:44 -04:00
{
if ( ! aTab ) return false ;
return aTab . hasAttribute ( this . kCHILDREN ) ;
} ,
2009-05-15 11:51:12 -04:00
getDescendantTabs : function ( aTab ) /* PUBLIC API */
2007-11-17 07:59:48 -05:00
{
var tabs = [ ] ;
this . getChildTabs ( aTab , tabs ) ;
return tabs ;
} ,
2009-05-15 11:51:12 -04:00
getFirstChildTab : function ( aTab ) /* PUBLIC API */
2007-11-17 07:59:48 -05:00
{
if ( ! aTab ) return null ;
var children = aTab . getAttribute ( this . kCHILDREN ) ;
var firstChild = null ;
if ( children ) {
var list = children . split ( '|' ) ;
for ( var i = 0 , maxi = list . length ; i < maxi ; i ++ )
{
firstChild = this . getTabById ( list [ i ] , aTab ) ;
if ( firstChild ) break ;
}
}
return firstChild ;
} ,
2009-05-15 11:51:12 -04:00
getLastChildTab : function ( aTab ) /* PUBLIC API */
2007-11-17 07:59:48 -05:00
{
if ( ! aTab ) return null ;
var children = aTab . getAttribute ( this . kCHILDREN ) ;
var lastChild = null ;
if ( children ) {
var list = children . split ( '|' ) ;
for ( var i = list . length - 1 ; i > - 1 ; i -- )
{
lastChild = this . getTabById ( list [ i ] , aTab ) ;
if ( lastChild ) break ;
}
}
return lastChild ;
} ,
2007-11-26 17:43:50 -05:00
2009-05-15 11:51:12 -04:00
getLastDescendantTab : function ( aTab ) /* PUBLIC API */
2009-03-16 10:35:30 -04:00
{
if ( ! aTab ) return null ;
var tabs = this . getDescendantTabs ( aTab ) ;
return tabs . length ? tabs [ tabs . length - 1 ] : null ;
} ,
2007-11-26 17:43:50 -05:00
getChildIndex : function ( aTab , aParent )
{
var parent = this . getParentTab ( aTab ) ;
2007-11-26 18:51:26 -05:00
if ( ! aParent || ! parent || aParent != parent ) {
2007-11-26 18:00:30 -05:00
parent = aTab ;
2007-11-26 17:43:50 -05:00
while ( parent && parent != aParent )
{
aTab = parent ;
parent = this . getParentTab ( parent ) ;
}
if ( parent != aParent )
return - 1 ;
aParent = parent ;
}
if ( aParent ) {
var children = aParent . getAttribute ( this . kCHILDREN ) ;
var list = children . split ( '|' ) ;
var id = aTab . getAttribute ( this . kID ) ;
for ( var i = 0 , maxi = list . length ; i < maxi ; i ++ )
{
if ( list [ i ] == id ) return i ;
}
return - 1 ;
}
else {
var tabs = this . rootTabs ;
for ( var i = 0 , maxi = tabs . length ; i < maxi ; i ++ )
{
if ( tabs [ i ] == aTab ) return i ;
}
}
} ,
2009-04-08 11:16:34 -04:00
getXOffsetOfTab : function ( aTab )
{
return this . evaluateXPath (
2009-04-08 11:20:34 -04:00
'sum((self::* | preceding-sibling::xul:tab[not(@' + this . kCOLLAPSED + '="true")])/attribute::' + this . kX _OFFSET + ')' ,
2009-04-08 11:16:34 -04:00
aTab ,
XPathResult . NUMBER _TYPE
) . numberValue ;
} ,
getYOffsetOfTab : function ( aTab )
{
return this . evaluateXPath (
2009-04-08 11:20:34 -04:00
'sum((self::* | preceding-sibling::xul:tab[not(@' + this . kCOLLAPSED + '="true")])/attribute::' + this . kY _OFFSET + ')' ,
2009-04-08 11:16:34 -04:00
aTab ,
XPathResult . NUMBER _TYPE
) . numberValue ;
} ,
2009-07-05 23:07:44 -04:00
2009-07-08 21:58:57 -04:00
isGroupTab : function ( aTab , aLazyCheck )
2009-07-05 23:07:44 -04:00
{
return (
2009-07-08 21:58:57 -04:00
( aLazyCheck || aTab . linkedBrowser . sessionHistory . count == 1 ) &&
2009-07-05 23:07:44 -04:00
aTab . linkedBrowser . currentURI . spec . indexOf ( 'about:treestyletab-group' ) > - 1
) ;
} ,
2007-11-14 14:34:36 -05:00
2007-11-17 07:59:48 -05:00
/* Session Store API */
getTabValue : function ( aTab , aKey )
{
2009-03-16 09:43:06 -04:00
var value = '' ;
2007-11-17 07:59:48 -05:00
try {
value = this . SessionStore . getTabValue ( aTab , aKey ) ;
}
catch ( e ) {
}
2008-06-20 01:57:38 -04:00
if ( this . useTMPSessionAPI ) {
var TMPValue = aTab . getAttribute ( this . kTMP _SESSION _DATA _PREFIX + aKey ) ;
if ( TMPValue ) value = TMPValue ;
}
2007-11-17 07:59:48 -05:00
return value ;
} ,
setTabValue : function ( aTab , aKey , aValue )
{
2008-06-20 01:57:38 -04:00
if ( ! aValue ) return this . deleteTabValue ( aTab , aKey ) ;
2007-11-17 07:59:48 -05:00
aTab . setAttribute ( aKey , aValue ) ;
try {
this . SessionStore . setTabValue ( aTab , aKey , aValue ) ;
}
catch ( e ) {
}
2008-06-20 01:57:38 -04:00
if ( this . useTMPSessionAPI )
aTab . setAttribute ( this . kTMP _SESSION _DATA _PREFIX + aKey , aValue ) ;
2007-11-17 07:59:48 -05:00
return aValue ;
} ,
deleteTabValue : function ( aTab , aKey )
{
aTab . removeAttribute ( aKey ) ;
try {
this . SessionStore . deleteTabValue ( aTab , aKey ) ;
}
catch ( e ) {
}
2008-06-20 01:57:38 -04:00
if ( this . useTMPSessionAPI )
aTab . removeAttribute ( this . kTMP _SESSION _DATA _PREFIX + aKey ) ;
2007-11-17 07:59:48 -05:00
} ,
2008-06-20 01:57:38 -04:00
2008-09-26 10:13:29 -04:00
useTMPSessionAPI : false ,
2008-06-20 01:57:38 -04:00
kTMP _SESSION _DATA _PREFIX : 'tmp-session-data-' ,
2009-07-22 00:25:39 -04:00
2009-07-27 03:22:56 -04:00
dropLinksOnTabBehavior : function ( )
2009-07-22 00:25:39 -04:00
{
2009-07-27 03:22:56 -04:00
var behavior = this . getTreePref ( 'dropLinksOnTab.behavior' ) ;
if ( behavior & this . kDROPLINK _FIXED ) return behavior ;
2009-07-22 00:25:39 -04:00
var checked = { value : false } ;
var newChildTab = this . PromptService . confirmEx ( window ,
2009-08-10 22:30:29 -04:00
this . treeBundle . getString ( 'dropLinkOnTab.title' ) ,
this . treeBundle . getString ( 'dropLinkOnTab.text' ) ,
2009-07-22 00:25:39 -04:00
( this . PromptService . BUTTON _TITLE _IS _STRING * this . PromptService . BUTTON _POS _0 ) +
( this . PromptService . BUTTON _TITLE _IS _STRING * this . PromptService . BUTTON _POS _1 ) ,
2009-08-10 22:30:29 -04:00
this . treeBundle . getString ( 'dropLinkOnTab.openNewChildTab' ) ,
this . treeBundle . getString ( 'dropLinkOnTab.loadInTheTab' ) ,
2009-07-22 00:25:39 -04:00
null ,
2009-08-10 22:30:29 -04:00
this . treeBundle . getString ( 'dropLinkOnTab.never' ) ,
2009-07-22 00:25:39 -04:00
checked
2009-07-22 01:24:37 -04:00
) == 0 ;
2009-07-27 03:22:56 -04:00
behavior = newChildTab ? this . kDROPLINK _NEWTAB : this . kDROPLINK _LOAD ;
if ( checked . value )
this . setTreePref ( 'dropLinksOnTab.behavior' , behavior ) ;
return behavior
2009-07-22 00:25:39 -04:00
} ,
2009-07-27 03:22:56 -04:00
kDROPLINK _ASK : 0 ,
kDROPLINK _FIXED : 1 + 2 ,
kDROPLINK _LOAD : 1 ,
kDROPLINK _NEWTAB : 2 ,
2009-07-22 00:51:54 -04:00
2009-07-27 03:22:56 -04:00
openGroupBookmarkBehavior : function ( )
2009-07-22 00:51:54 -04:00
{
2009-07-27 03:22:56 -04:00
var behavior = this . getTreePref ( 'openGroupBookmark.behavior' ) ;
if ( behavior & this . kGROUP _BOOKMARK _FIXED ) return behavior ;
2009-07-22 00:51:54 -04:00
2009-07-27 03:22:56 -04:00
var dummyTabFlag = behavior & this . kGROUP _BOOKMARK _USE _DUMMY ;
2009-07-22 00:51:54 -04:00
var checked = { value : false } ;
2009-07-27 03:22:56 -04:00
var button = this . PromptService . confirmEx ( window ,
2009-08-10 22:30:29 -04:00
this . treeBundle . getString ( 'openGroupBookmarkBehavior.title' ) ,
this . treeBundle . getString ( 'openGroupBookmarkBehavior.text' ) ,
2009-07-22 00:51:54 -04:00
( this . PromptService . BUTTON _TITLE _IS _STRING * this . PromptService . BUTTON _POS _0 ) +
( this . PromptService . BUTTON _TITLE _IS _STRING * this . PromptService . BUTTON _POS _1 ) +
( this . PromptService . BUTTON _TITLE _IS _STRING * this . PromptService . BUTTON _POS _2 ) ,
2009-08-10 22:30:29 -04:00
this . treeBundle . getString ( 'openGroupBookmarkBehavior.subTree' ) ,
this . treeBundle . getString ( 'openGroupBookmarkBehavior.separate' ) ,
this . treeBundle . getString ( 'openGroupBookmarkBehavior.replace' ) ,
this . treeBundle . getString ( 'openGroupBookmarkBehavior.never' ) ,
2009-07-22 00:51:54 -04:00
checked
) ;
2009-07-27 03:22:56 -04:00
if ( button < 0 ) button = 1 ;
2009-07-22 01:24:37 -04:00
var behaviors = [
this . kGROUP _BOOKMARK _SUBTREE | dummyTabFlag ,
2009-07-24 04:11:05 -04:00
this . kGROUP _BOOKMARK _SEPARATE ,
this . kGROUP _BOOKMARK _REPLACE
2009-07-22 01:24:37 -04:00
] ;
2009-07-27 03:22:56 -04:00
behavior = behaviors [ button ] ;
2009-07-22 00:51:54 -04:00
if ( checked . value ) {
2009-07-27 03:22:56 -04:00
this . setTreePref ( 'openGroupBookmark.behavior' , behavior ) ;
2009-07-22 00:51:54 -04:00
this . setPref ( 'browser.tabs.loadFolderAndReplace' , behavior & this . kGROUP _BOOKMARK _REPLACE ? true : false ) ;
}
return behavior ;
} ,
2009-07-27 03:22:56 -04:00
kGROUP _BOOKMARK _ASK : 0 ,
kGROUP _BOOKMARK _FIXED : 1 + 2 + 4 ,
2009-07-22 00:51:54 -04:00
kGROUP _BOOKMARK _SUBTREE : 1 ,
kGROUP _BOOKMARK _SEPARATE : 2 ,
kGROUP _BOOKMARK _REPLACE : 4 ,
kGROUP _BOOKMARK _USE _DUMMY : 256 ,
2009-08-09 20:10:40 -04:00
kGROUP _BOOKMARK _DONT _RESTORE _TREE _STRUCTURE : 512 ,
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
2008-02-25 20:14:12 -05:00
preInit : function ( )
{
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()' ,
'!TreeStyleTabService.tearOffSubTreeFromRemote() && $&'
) ) ;
}
else {
eval ( 'window.BrowserStartup = ' + source . replace (
'gBrowser.swapBrowsersAndCloseOther(gBrowser.selectedTab, uriToLoad);' ,
'if (!TreeStyleTabService.tearOffSubTreeFromRemote()) { $& }'
) ) ;
}
}
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 ,
defaultTabFocusAllowance : function ( aBrowser )
{
var tab = aBrowser . selectedTab ;
return (
! this . getPref ( 'browser.tabs.selectOwnerOnClose' ) ||
! tab . owner ||
(
aBrowser . _removingTabs &&
aBrowser . _removingTabs . indexOf ( tab . owner ) > - 1
)
) ;
} ,
kPREF _VERSION : 4 ,
migratePrefs : function ( )
{
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.hideNewTabButton' ,
'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-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
} ,
2008-03-08 03:57:17 -05:00
init : function ( )
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 ) ;
2007-10-22 05:59:43 -04:00
document . getElementById ( 'contentAreaContextMenu' ) . addEventListener ( 'popupshowing' , 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-07-03 05:58:34 -04:00
this . ObserverService . addObserver ( this , 'private-browsing-change-granted' , false ) ;
2007-10-16 13:22:28 -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.indent' ) ;
this . onPrefChange ( 'extensions.treestyletab.tabbar.autoHide.mode' ) ;
this . onPrefChange ( 'extensions.treestyletab.clickOnIndentSpaces.enabled' ) ;
this . onPrefChange ( 'browser.link.open_newwindow.restriction.override' ) ;
this . onPrefChange ( 'browser.tabs.loadFolderAndReplace.override' ) ;
this . onPrefChange ( 'extensions.treestyletab.tabbar.style' ) ;
this . onPrefChange ( 'extensions.treestyletab.tabbar.scroll.smooth' ) ;
this . onPrefChange ( 'extensions.treestyletab.tabbar.scroll.duration' ) ;
this . onPrefChange ( 'extensions.treestyletab.animation.enabled' ) ;
this . onPrefChange ( 'extensions.treestyletab.animation.indent.duration' ) ;
this . onPrefChange ( 'extensions.treestyletab.animation.collapse.duration' ) ;
this . onPrefChange ( 'extensions.treestyletab.twisty.expandSensitiveArea' ) ;
2009-08-14 02:12:08 -04:00
this . onPrefChange ( 'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect.whileFocusMovingByShortcut' ) ;
2009-08-26 05:33:54 -04:00
if (
this . getPref ( 'browser.sessionstore.enabled' ) === false ||
(
this . getPref ( 'browser.startup.page' ) != 3 &&
! this . getPref ( 'browser.sessionstore.resume_session_once' ) / * &&
! this . getPref ( 'browser.sessionstore.resume_from_crash' ) * /
)
)
this . completelyRestored = true ;
2007-10-16 13:22:28 -04:00
} ,
2008-10-14 00:57:35 -04:00
initialized : false ,
2009-08-26 05:33:54 -04:00
completelyRestored : false ,
2008-11-09 23:48:11 -05:00
2007-10-16 13:22:28 -04:00
initTabBrowser : function ( aTabBrowser )
{
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
2007-11-14 14:34:36 -05:00
updateTabDNDObserver : function ( 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-25 06:35:53 -04:00
if ( aEvent . shiftKey && this . getAttribute ( this . treeStyleTab . kFIXED ) != 'true' ) {
2009-08-25 03:20:56 -04:00
let dt = aEvent . dataTransfer ;
dt . mozSetDataAt ( this . treeStyleTab . kDRAG _TYPE _TABBAR , Date . now ( ) , 0 ) ;
dt . mozCursor = 'move' ;
let tabbar = this . mTabContainer ;
let box = tabbar . boxObject ;
dt . setDragImage (
this . mTabContainer ,
aEvent . screenX - box . screenX ,
aEvent . screenY - box . screenY
) ;
this . mPanelContainer . setAttribute ( this . treeStyleTab . kDROP _POSITION , 'unknown' ) ;
aEvent . stopPropagation ( ) ;
}
else $ & ] ] >
)
) ;
}
else { // Firefox 3.0.x
eval ( 'aObserver.onDragStart = ' +
2009-08-25 06:47:59 -04:00
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 [
(
( ! aEvent . shiftKey || this . getAttribute ( this . treeStyleTab . kFIXED ) == 'true' ) &&
$ &
)
] ] >
2009-08-25 06:47:59 -04:00
) . replace ( // Tab Mix Plus
'event.target.localName != "tab"' ,
< ! [ CDATA [
( event . shiftKey && gBrowser . getAttribute ( gBrowser . treeStyleTab . kFIXED ) != 'true' ) ||
$ &
] ] >
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
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 ( // Tab Mix Plus
2007-11-17 08:32:41 -05:00
/\.screenY/g , '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.invertedPositionProp]'
2007-11-14 07:31:14 -05:00
) . replace ( // Tab Mix Plus
2007-11-17 08:32:41 -05:00
/\.height/g , '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.invertedSizeProp]'
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 ) ;
if ( tab && tab . getAttribute ( TreeStyleTabService . kCOLLAPSED ) == 'true' )
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"'
)
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
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 ||
tab . getAttribute ( 'locked' ) == 'true' // Tab Mix Plus
) ;
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 ||
tab . getAttribute ( 'locked' ) == 'true' // Tab Mix Plus
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
)
) ;
} ,
2007-10-21 11:02:58 -04:00
overrideGlobalFunctions : function ( )
{
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' )
} ) ? true : ( TreeStyleTabService . readyToOpenChildTab ( ) , false )
] ] >
) . 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 [
if ( ! ( 'TMP_contentAreaClick' in window ) && // do nothing for Tab Mix Plus
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
else if ( ! ( 'TMP_contentAreaClick' in window ) && // do nothing for Tab Mix Plus
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-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 )
treeStyleTab . endAutoHideForFullScreen ( ) ;
else
treeStyleTab . startAutoHideForFullScreen ( ) ;
}
] ] >
)
) ;
2009-08-25 03:20:56 -04:00
2009-08-25 06:05:47 -04:00
if ( ! ( '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-04-27 21:32:01 -04:00
_splitFunctionNames : function ( aString )
{
return String ( aString )
. split ( /\s+/ )
. map ( function ( aString ) {
return aString
. replace ( /\/\*.*\*\//g , '' )
. replace ( /\/\/.+$/ , '' )
. replace ( /^\s+|\s+$/g , '' ) ;
} ) ;
} ,
_getFunctionSource : function ( aFunc )
{
var func ;
try {
eval ( 'func = ' + aFunc ) ;
}
catch ( e ) {
return null ;
}
return func ? func . toSource ( ) : null ;
} ,
2008-09-26 10:13:29 -04:00
initBar : function ( )
{
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
2007-10-16 13:22:28 -04:00
destroy : function ( )
{
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
2007-10-22 05:59:43 -04:00
document . getElementById ( 'contentAreaContextMenu' ) . removeEventListener ( 'popupshowing' , this , false ) ;
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-07-03 05:58:34 -04:00
this . ObserverService . removeObserver ( this , 'private-browsing-change-granted' ) ;
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
2007-10-16 13:22:28 -04:00
destroyTabBrowser : function ( aTabBrowser )
{
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
2007-10-16 13:22:28 -04:00
handleEvent : function ( aEvent )
{
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-12 14:47:36 -04:00
if ( aEvent . currentTarget . id == 'contentAreaContextMenu' &&
aEvent . target == aEvent . currentTarget ) {
this . initContextMenu ( ) ;
}
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 ,
startListenKeyEventsFor : function ( aReason )
{
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 ;
} ,
endListenKeyEventsFor : function ( aReason )
{
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 ;
}
} ,
2008-03-08 03:57:17 -05:00
onKeyDown : function ( aEvent )
{
var b = this . browser ;
if ( ! b || ! b . treeStyleTab ) return ;
var sv = b . treeStyleTab ;
2009-03-29 15:02:06 -04:00
if ( this . delayedAutoShowForShortcutDone )
this . cancelDelayedAutoShowForShortcut ( ) ;
2008-03-08 03:57:17 -05:00
2008-10-17 08:35:55 -04:00
this . accelKeyPressed = this . isAccelKeyPressed ( aEvent ) ;
2008-03-08 03:57:17 -05:00
if (
2009-01-24 00:39:22 -05:00
this . getTabs ( b ) . snapshotLength > 1 &&
2008-03-08 03:57:17 -05:00
! aEvent . altKey &&
2008-03-09 08:34:10 -04:00
this . accelKeyPressed
2008-03-08 03:57:17 -05:00
) {
2009-08-14 02:12:08 -04:00
if ( sv . autoHideEnabled &&
this . getTreePref ( 'tabbar.autoShow.accelKeyDown' ) &&
2008-09-26 10:13:29 -04:00
! sv . autoHideShown &&
2009-05-12 14:21:44 -04:00
! sv . delayedAutoShowTimer &&
! this . delayedAutoShowForShortcutTimer ) {
2009-03-29 15:02:06 -04:00
this . delayedAutoShowForShortcutTimer = window . setTimeout (
2008-03-09 01:36:52 -05:00
function ( aSelf ) {
2009-05-12 14:21:44 -04:00
this . delayedAutoShowForShortcutDone = true ;
2008-03-09 01:36:52 -05:00
sv . showTabbar ( sv . kSHOWN _BY _SHORTCUT ) ;
2009-05-13 02:09:17 -04:00
sv = null ;
b = null ;
2008-03-09 01:36:52 -05:00
} ,
2008-03-09 08:18:58 -04:00
this . getTreePref ( 'tabbar.autoShow.accelKeyDown.delay' ) ,
2008-03-09 01:36:52 -05:00
this
) ;
2009-03-29 15:02:06 -04:00
this . delayedAutoShowForShortcutDone = false ;
2008-03-08 03:57:17 -05:00
}
}
2008-03-09 08:18:58 -04:00
else {
2009-08-14 02:12:08 -04:00
if ( sv . autoHideEnabled )
sv . hideTabbar ( ) ;
2008-03-09 08:18:58 -04:00
}
2008-03-08 03:57:17 -05:00
} ,
2009-03-29 15:02:06 -04:00
cancelDelayedAutoShowForShortcut : function ( )
2008-03-08 03:57:17 -05:00
{
2009-03-29 15:02:06 -04:00
if ( this . delayedAutoShowForShortcutTimer ) {
window . clearTimeout ( this . delayedAutoShowForShortcutTimer ) ;
this . delayedAutoShowForShortcutTimer = null ;
2008-03-08 03:57:17 -05:00
}
} ,
2009-03-29 15:02:06 -04:00
delayedAutoShowForShortcutTimer : null ,
delayedAutoShowForShortcutDone : true ,
2008-03-09 08:18:58 -04:00
accelKeyPressed : false ,
2008-03-08 05:07:28 -05:00
2008-03-08 03:57:17 -05:00
onKeyRelease : function ( aEvent )
{
var b = this . browser ;
if ( ! b || ! b . treeStyleTab ) return ;
var sv = b . treeStyleTab ;
2009-03-29 15:02:06 -04:00
this . cancelDelayedAutoShowForShortcut ( ) ;
2008-03-08 03:57:17 -05:00
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 )
) ;
if (
scrollDown ||
scrollUp ||
( // when you release "shift" key
2008-06-18 10:04:50 -04:00
sv . autoHideShown &&
2008-03-08 03:57:17 -05:00
standBy && ! aEvent . shiftKey &&
aEvent . charCode == 0 && aEvent . keyCode == 16
)
) {
2009-08-14 02:12:08 -04:00
if ( sv . autoHideEnabled &&
this . getTreePref ( 'tabbar.autoShow.tabSwitch' ) )
2008-03-09 08:34:10 -04:00
sv . showTabbar ( sv . kSHOWN _BY _SHORTCUT ) ;
2008-03-08 03:57:17 -05:00
return ;
}
2009-08-14 02:12:08 -04:00
// when you just release accel key...
if ( sv . autoHideEnabled &&
sv . showHideTabbarReason == sv . kSHOWN _BY _SHORTCUT ) {
2008-03-09 01:36:52 -05:00
sv . hideTabbar ( ) ;
2009-08-14 02:12:08 -04:00
}
if ( this . _tabShouldBeExpandedAfterKeyReleased ) {
let tab = this . _tabShouldBeExpandedAfterKeyReleased ;
if ( this . hasChildTabs ( tab ) &&
( tab . getAttribute ( this . kSUBTREE _COLLAPSED ) == 'true' ) ) {
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-08-14 02:36:59 -04: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-08-14 02:12:08 -04:00
// autohide
2009-05-13 02:09:17 -04:00
updateAutoHideKeyListeners : function ( )
{
if (
this . getTreePref ( 'tabbar.autoHide.mode' ) &&
2009-08-14 02:12:08 -04:00
this . shouldListenKeyEventsForAutoHide
2009-05-13 02:09:17 -04:00
) {
2009-08-14 02:12:08 -04:00
this . startListenKeyEventsFor ( this . LISTEN _FOR _AUTOHIDE ) ;
2009-05-13 02:09:17 -04:00
}
else {
2009-08-14 02:12:08 -04:00
this . endListenKeyEventsFor ( this . LISTEN _FOR _AUTOHIDE ) ;
2009-05-13 02:09:17 -04:00
}
window . setTimeout ( function ( ) {
if ( window . windowState != Components . interfaces . nsIDOMChromeWindow . STATE _NORMAL ) return ;
window . resizeBy ( - 1 , - 1 ) ;
window . resizeBy ( 1 , 1 ) ;
} , 0 ) ;
} ,
2009-08-14 02:12:08 -04:00
get shouldListenKeyEventsForAutoHide ( )
2009-04-08 05:16:39 -04:00
{
2009-08-14 10:51:01 -04:00
return ! this . ctrlTabPreviewsEnabled &&
2009-08-14 02:36:59 -04:00
(
this . getTreePref ( 'tabbar.autoShow.accelKeyDown' ) ||
this . getTreePref ( 'tabbar.autoShow.tabSwitch' ) ||
this . getTreePref ( 'tabbar.autoShow.feedback' )
) ;
2009-04-08 05:16:39 -04:00
} ,
2009-08-14 02:12:08 -04:00
2007-11-14 14:34:36 -05:00
onTabbarResized : function ( aEvent )
2007-10-16 13:22:28 -04:00
{
2008-06-17 02:22:49 -04:00
var b = this . getTabBrowserFromChild ( aEvent . currentTarget ) ;
2009-07-07 04:30:30 -04:00
if ( ! b . treeStyleTab . isVertical ) {
this . setTreePref ( 'tabbar.height' , b . mStrip . boxObject . height ) ;
}
else {
if ( ! b . treeStyleTab . tabbarExpanded )
this . setTreePref ( 'tabbar.shrunkenWidth' , b . mStrip . boxObject . width ) ;
else
this . setTreePref ( 'tabbar.width' , b . mStrip . boxObject . width ) ;
}
2007-10-16 13:22:28 -04:00
} ,
2007-11-14 14:34:36 -05:00
initContextMenu : function ( )
2007-10-18 14:20:54 -04:00
{
2007-11-14 14:34:36 -05:00
var item = document . getElementById ( 'context-treestyletab-openSelectionLinks' ) ;
var sep = document . getElementById ( 'context-treestyletab-openSelectionLinks-separator' ) ;
if ( this . getTreePref ( 'show.openSelectionLinks' ) && this . getSelectionLinks ( ) . length ) {
item . removeAttribute ( 'hidden' ) ;
sep . removeAttribute ( 'hidden' ) ;
2007-10-18 14:20:54 -04:00
}
2007-11-14 14:34:36 -05:00
else {
item . setAttribute ( 'hidden' , true ) ;
sep . setAttribute ( 'hidden' , true ) ;
2007-10-20 12:47:08 -04:00
}
} ,
2008-10-14 13:48:19 -04:00
showHideSubTreeMenuItem : function ( 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
2007-11-14 14:34:36 -05:00
var hasSubTree = false ;
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 ;
2007-11-14 14:34:36 -05:00
hasSubTree = true ;
2007-10-20 12:47:08 -04:00
break ;
}
2007-11-14 14:34:36 -05:00
if ( hasSubTree )
aMenuItem . removeAttribute ( 'hidden' ) ;
else
aMenuItem . setAttribute ( 'hidden' , true ) ;
2007-10-20 12:47:08 -04:00
} ,
2009-05-13 02:09:17 -04:00
2009-05-14 08:51:01 -04:00
updateTabWidthPrefs : function ( aPrefName )
2009-05-13 02:09:17 -04:00
{
var expanded = this . getTreePref ( 'tabbar.width' ) ;
var shrunken = this . getTreePref ( 'tabbar.shrunkenWidth' ) ;
if ( expanded <= shrunken ) {
this . tabbarWidthResetting = true ;
if ( aPrefName == 'extensions.treestyletab.tabbar.width' )
this . setTreePref ( 'tabbar.shrunkenWidth' , parseInt ( expanded / 1.5 ) ) ;
else
this . setTreePref ( 'tabbar.width' , parseInt ( shrunken * 1.5 ) ) ;
this . tabbarWidthResetting = false ;
}
} ,
2009-07-31 03:02:13 -04:00
handleTooltip : function ( aEvent , aTab )
{
var label ;
var collapsed = aTab . getAttribute ( this . kSUBTREE _COLLAPSED ) == 'true' ;
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-08-09 23:15:15 -04:00
var tree = this . getTreePref ( 'tooltip.includeChildren' ) ?
[ 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 : [ ] ,
onTabRestored : function ( aEvent )
{
this . _restoringTabs . push ( aEvent . originalTarget ) ;
} ,
processRestoredTabs : function ( )
{
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
2007-11-26 09:51:59 -05:00
removeTabSubTree : function ( aTabOrTabs , aOnlyChildren )
2007-10-19 22:44:14 -04:00
{
2009-07-06 05:21:06 -04:00
var tabs = this . _normalizeToTabs ( 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-07-06 05:21:06 -04:00
var b = this . getTabBrowserFromChild ( tabs [ 0 ] ) ;
2007-10-19 22:44:14 -04:00
for ( var i = tabs . length - 1 ; i > - 1 ; i -- )
{
b . removeTab ( tabs [ i ] ) ;
}
} ,
2009-06-17 04:59:18 -04:00
warnAboutClosingTabs : function ( aTabsCount )
{
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 ;
} ,
2008-11-09 23:48:11 -05:00
2009-07-06 05:21:06 -04:00
_normalizeToTabs : function ( aTabOrTabs , aOnlyChildren )
{
var tabs = aTabOrTabs ;
if ( ! ( tabs instanceof Array ) ) {
tabs = [ aTabOrTabs ] ;
}
var b = this . getTabBrowserFromChild ( tabs [ 0 ] ) ;
var descendant = [ ] ;
for ( var i = 0 , maxi = tabs . length ; i < maxi ; i ++ )
{
descendant = descendant . concat ( b . treeStyleTab . getDescendantTabs ( tabs [ i ] ) ) ;
}
if ( aOnlyChildren )
tabs = this . cleanUpTabsArray ( descendant ) ;
else
tabs = this . cleanUpTabsArray ( tabs . concat ( descendant ) ) ;
return tabs ;
} ,
2007-11-14 14:34:36 -05:00
cleanUpTabsArray : function ( aTabs )
{
2009-03-16 10:04:29 -04:00
var newTabs = [ ] ;
aTabs . forEach ( function ( aTab ) {
2009-05-06 22:19:10 -04:00
if ( ! aTab . parentNode ) return ; // ignore removed tabs
2009-03-16 10:04:29 -04:00
if ( newTabs . indexOf ( aTab ) < 0 ) newTabs . push ( aTab ) ;
} ) ;
newTabs . sort ( function ( aA , aB ) {
return aA . _tPos - aB . _tPos ;
} ) ;
return newTabs ;
2007-11-14 14:34:36 -05:00
} ,
2009-07-06 05:21:06 -04:00
reloadTabSubTree : function ( aTabOrTabs , aOnlyChildren )
{
var tabs = this . _normalizeToTabs ( aTabOrTabs , aOnlyChildren ) ;
var b = this . getTabBrowserFromChild ( tabs [ 0 ] ) ;
for ( var i = tabs . length - 1 ; i > - 1 ; i -- )
{
b . reloadTab ( tabs [ i ] ) ;
}
} ,
2009-07-23 11:34:28 -04:00
createSubTree : function ( aTabs )
{
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-07-24 03:09:29 -04:00
var root = this . getTreePref ( 'createSubTree.underParent' ) ?
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 ) {
b . treeStyleTab . moveTabSubTreeTo ( root , next . _tPos ) ;
}
2009-07-23 12:14:45 -04:00
} , 0 , this ) ;
} ,
canCreateSubTree : function ( aTabs )
{
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
} ,
getRootTabs : function ( aTabs )
{
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-02-11 08:41:32 -05:00
openSelectionLinks : function ( aFrame )
2007-10-22 05:59:43 -04:00
{
2009-02-11 08:41:32 -05:00
aFrame = this . getCurrentFrame ( aFrame ) ;
2007-10-22 05:59:43 -04:00
var b = this . browser ;
2009-02-11 08:41:32 -05:00
var links = this . getSelectionLinks ( aFrame ) ;
if ( ! links . length ) return ;
2007-10-22 05:59:43 -04:00
2009-02-11 08:41:32 -05:00
var referrer = this . makeURIFromSpec ( aFrame . location . href ) ;
2007-10-22 05:59:43 -04:00
2009-02-11 08:41:32 -05:00
this . readyToOpenChildTab ( aFrame , true ) ;
links . forEach ( function ( aLink , aIndex ) {
var tab = b . addTab ( aLink . href , referrer ) ;
2008-10-17 08:35:55 -04:00
if ( aIndex == 0 && ! this . getPref ( 'browser.tabs.loadInBackground' ) )
2007-10-22 05:59:43 -04:00
b . selectedTab = tab ;
2008-10-17 08:35:55 -04:00
} , this ) ;
2009-02-11 08:41:32 -05:00
this . stopToOpenChildTab ( aFrame ) ;
2007-10-22 05:59:43 -04:00
} ,
2007-11-17 00:20:26 -05:00
2009-02-11 08:41:32 -05:00
getCurrentFrame : function ( aFrame )
2007-10-22 05:59:43 -04:00
{
2009-02-11 08:41:32 -05:00
if ( aFrame ) return aFrame ;
2007-10-22 05:59:43 -04:00
var targetWindow = document . commandDispatcher . focusedWindow ;
if ( ! targetWindow || targetWindow . top == window )
targetWindow = this . browser . contentWindow ;
2009-02-11 08:41:32 -05:00
return targetWindow ;
} ,
getSelectionLinks : function ( aFrame )
{
aFrame = this . getCurrentFrame ( aFrame ) ;
2007-10-22 05:59:43 -04:00
2009-02-11 08:41:32 -05:00
var links = [ ] ;
var selection = aFrame . getSelection ( ) ;
2007-10-22 05:59:43 -04:00
if ( ! selection || ! selection . rangeCount )
return links ;
2009-02-11 08:41:32 -05:00
for ( var i = 0 , maxi = selection . rangeCount ; i < maxi ; i ++ )
2007-10-22 05:59:43 -04:00
{
2009-02-11 08:41:32 -05:00
links = links . concat ( this . getLinksInRange ( selection . getRangeAt ( i ) ) ) ;
2007-10-22 05:59:43 -04:00
}
return links ;
} ,
2008-11-09 23:48:11 -05:00
2009-02-11 08:41:32 -05:00
getLinksInRange : function ( aRange )
2007-10-22 05:59:43 -04:00
{
2009-02-11 08:41:32 -05:00
// http://nanto.asablo.jp/blog/2008/10/18/3829312
var links = [ ] ;
if ( aRange . collapsed ) return links ;
var startCountExpression = 'count(preceding::*[@href])' ;
var startNode = aRange . startContainer ;
if ( startNode . nodeType == Node . ELEMENT _NODE ) {
if ( aRange . startOffset < startNode . childNodes . length ) {
startNode = startNode . childNodes [ aRange . startOffset ] ;
}
else {
startCountExpression += ' + count(descendant::*[@href])' ;
}
}
var startCount = this . evaluateXPath (
startCountExpression ,
startNode ,
XPathResult . NUMBER _TYPE
) . numberValue ;
2007-10-22 05:59:43 -04:00
2009-02-11 08:41:32 -05:00
var linksExpression = 'ancestor::*[@href] | preceding::*[@href]' ;
var endNode = aRange . endContainer ;
if ( endNode . nodeType == Node . ELEMENT _NODE ) {
if ( aRange . endOffset < endNode . childNodes . length ) {
endNode = endNode . childNodes [ aRange . endOffset ] ;
}
else {
linksExpression += ' | descendant-or-self::*[@href]' ;
}
}
var linksResult = this . evaluateXPath ( linksExpression , endNode ) ;
var allLinksCount = linksResult . snapshotLength ;
var contentRange = startNode . ownerDocument . createRange ( ) ;
if ( startCount < allLinksCount ) {
var lastNode = this . evaluateXPath (
'descendant-or-self::node()[not(child::node()) and not(following-sibling::node())]' ,
linksResult . snapshotItem ( startCount ) ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
contentRange . selectNodeContents ( lastNode ) ;
contentRange . setStart ( aRange . startContainer , aRange . startOffset ) ;
if ( contentRange . collapsed ) {
startCount ++ ;
}
}
if ( startCount < allLinksCount ) {
var firstNode = this . evaluateXPath (
'descendant-or-self::node()[not(child::node()) and not(preceding-sibling::node())]' ,
2009-02-11 11:52:47 -05:00
linksResult . snapshotItem ( allLinksCount - 1 ) ,
2009-02-11 08:41:32 -05:00
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
contentRange . selectNodeContents ( firstNode ) ;
contentRange . setEnd ( aRange . endContainer , aRange . endOffset ) ;
if ( contentRange . collapsed ) {
allLinksCount -- ;
}
}
contentRange . detach ( ) ;
for ( var i = startCount ; i < allLinksCount ; i ++ )
{
links . push ( linksResult . snapshotItem ( i ) ) ;
}
return links ;
2007-10-22 05:59:43 -04:00
} ,
2007-11-17 00:20:26 -05:00
collapseExpandAllSubtree : function ( aCollapse )
{
this . ObserverService . notifyObservers (
window ,
'TreeStyleTab:collapseExpandAllSubtree' ,
( aCollapse ? 'collapse' : 'open' )
) ;
} ,
2008-02-28 02:45:39 -05:00
2009-08-14 02:12:08 -04:00
expandTreeAfterKeyReleased : function ( aTab )
{
if ( this . getTreePref ( 'autoCollapseExpandSubTreeOnSelect.whileFocusMovingByShortcut' ) ) return ;
this . _tabShouldBeExpandedAfterKeyReleased = aTab || null ;
} ,
_tabShouldBeExpandedAfterKeyReleased : null ,
2009-05-15 11:51:12 -04:00
registerTabFocusAllowance : function ( aProcess ) /* PUBLIC API */
2008-03-02 13:16:57 -05:00
{
this . _tabFocusAllowance . push ( aProcess ) ;
} ,
_tabFocusAllowance : [ ] ,
2009-05-15 11:51:12 -04:00
registerExpandTwistyAreaAllowance : function ( aProcess ) /* PUBLIC API */
2009-05-08 02:04:22 -04:00
{
this . _expandTwistyAreaAllowance . push ( aProcess ) ;
} ,
_expandTwistyAreaAllowance : [ ] ,
2008-12-01 03:30:36 -05:00
tearOffSubTreeFromRemote : function ( )
{
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 ;
} ,
2008-03-08 03:57:17 -05:00
2009-07-03 05:58:34 -04:00
observe : function ( aSubject , aTopic , aData )
{
switch ( aTopic )
{
case 'nsPref:changed' :
this . onPrefChange ( aData ) ;
return ;
case 'private-browsing-change-granted' :
if ( aData == 'enter' )
this . ObserverService . notifyObservers ( window , 'TreeStyleTab:collapseExpandAllSubtree' , 'expand-now' ) ;
return ;
2009-08-26 05:33:54 -04:00
case 'sessionstore-windows-restored' :
this . completelyRestored = true ;
return ;
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' ,
'browser.link.open_newwindow.restriction.override' ,
2009-08-14 02:30:03 -04:00
'browser.tabs.loadFolderAndReplace.override' ,
'browser.ctrlTab.previews'
2008-03-03 03:26:51 -05:00
] ,
2007-10-16 13:22:28 -04:00
2009-07-03 05:58:34 -04:00
onPrefChange : function ( aPrefName )
2007-10-16 13:22:28 -04:00
{
var value = this . getPref ( aPrefName ) ;
switch ( aPrefName )
{
2009-04-07 13:14:09 -04:00
case 'extensions.treestyletab.indent' :
this . baseIndent = value ;
this . ObserverService . notifyObservers ( null , 'TreeStyleTab:indentModified' , value ) ;
2007-10-16 13:22:28 -04:00
break ;
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.
// this.autoHideMode = 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-05-13 02:09:17 -04:00
this . updateAutoHideKeyListeners ( ) ;
2008-03-08 03:57:17 -05:00
break ;
2008-06-17 06:29:16 -04:00
case 'extensions.treestyletab.tabbar.width' :
case 'extensions.treestyletab.tabbar.shrunkenWidth' :
2009-05-14 08:51:01 -04:00
this . updateTabWidthPrefs ( aPrefName ) ;
2008-06-17 06:29:16 -04:00
break ;
2008-03-03 03:26:51 -05:00
case 'browser.link.open_newwindow.restriction.override' :
case 'browser.tabs.loadFolderAndReplace.override' :
2009-05-13 02:09:17 -04:00
this . setPref ( aPrefName . replace ( '.override' , '' ) , this . getPref ( aPrefName ) ) ;
2008-03-03 03:26:51 -05:00
break ;
2008-12-03 08:17:40 -05:00
case 'extensions.treestyletab.clickOnIndentSpaces.enabled' :
this . shouldDetectClickOnIndentSpaces = this . getPref ( aPrefName ) ;
break ;
2009-04-08 12:00:51 -04:00
case 'extensions.treestyletab.tabbar.scroll.smooth' :
this . smoothScrollEnabled = value ;
break ;
2009-04-09 21:32:03 -04:00
case 'extensions.treestyletab.tabbar.scroll.duration' :
this . smoothScrollDuration = value ;
2009-04-08 12:00:51 -04:00
break ;
2009-04-07 12:09:17 -04:00
case 'extensions.treestyletab.animation.enabled' :
this . animationEnabled = value ;
break ;
2009-04-09 21:32:03 -04:00
case 'extensions.treestyletab.animation.indent.duration' :
this . indentDuration = value ;
2009-04-07 13:14:09 -04:00
break ;
2009-04-09 21:32:03 -04:00
case 'extensions.treestyletab.animation.collapse.duration' :
this . collapseDuration = value ;
2009-04-07 13:14:09 -04:00
break ;
2009-04-07 12:09:17 -04:00
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' ) ,
this . getPref ( 'extensions.treestyletab.tabbar.position' )
] . join ( '-' ) ) ;
break ;
2009-05-08 02:04:22 -04:00
case 'extensions.treestyletab.twisty.expandSensitiveArea' :
this . expandTwistyArea = value ;
break ;
2009-08-14 02:36:59 -04:00
case 'browser.ctrlTab.previews' :
this . updateAutoHideKeyListeners ( ) ;
2009-08-14 02:12:08 -04: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 ;
}
} ,
/* Save/Load Prefs */
2007-10-21 04:16:10 -04:00
2007-10-26 07:24:59 -04:00
getTreePref : function ( aPrefstring )
{
return this . getPref ( 'extensions.treestyletab.' + aPrefstring ) ;
} ,
2007-11-08 23:07:54 -05:00
setTreePref : function ( aPrefstring , aNewValue )
{
return this . setPref ( 'extensions.treestyletab.' + aPrefstring , aNewValue ) ;
2009-07-27 03:22:56 -04:00
} ,
clearTreePref : function ( aPrefstring )
{
return this . clearPref ( 'extensions.treestyletab.' + aPrefstring ) ;
2007-10-16 13:22:28 -04:00
}
} ;
2009-02-12 20:41:15 -05:00
TreeStyleTabService . _ _proto _ _ = window [ 'piro.sakura.ne.jp' ] . prefs ;
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