2007-10-16 17:22:28 +00:00
var TreeStyleTabService = {
2007-10-23 06:05:44 +00:00
kID : 'treestyletab-id' ,
kCHILDREN : 'treestyletab-children' ,
kPARENT : 'treestyletab-parent' ,
2007-11-26 21:17:46 +00:00
kANCESTOR : 'treestyletab-ancestors' ,
2007-10-23 06:05:44 +00:00
kINSERT _BEFORE : 'treestyletab-insert-before' ,
kSUBTREE _COLLAPSED : 'treestyletab-subtree-collapsed' ,
kCOLLAPSED : 'treestyletab-collapsed' ,
2007-11-30 19:22:34 +00:00
kTWISTY _HOVER : 'treestyletab-twisty-hover' ,
2007-10-23 06:05:44 +00:00
kNEST : 'treestyletab-nest' ,
kDROP _POSITION : 'treestyletab-drop-position' ,
kTABBAR _POSITION : 'treestyletab-tabbar-position' ,
2007-10-26 12:56:04 +00:00
kMODE : 'treestyletab-mode' ,
2007-10-23 06:05:44 +00:00
kUI _INVERTED : 'treestyletab-appearance-inverted' ,
kSCROLLBAR _INVERTED : 'treestyletab-scrollbar-inverted' ,
2007-10-25 22:59:34 +00:00
kALLOW _COLLAPSE : 'treestyletab-allow-subtree-collapse' ,
2008-12-02 03:50:34 +00:00
kHIDE _NEWTAB : 'treestyletab-hide-newtab-button' ,
2007-11-09 05:48:39 +00:00
kHIDE _ALLTABS : 'treestyletab-hide-alltabs-button' ,
2007-10-23 06:05:44 +00:00
kSTYLE : 'treestyletab-style' ,
2008-02-28 12:12:02 +00:00
kTWISTY _STYLE : 'treestyletab-twisty-style' ,
2007-10-23 06:05:44 +00:00
kFIRSTTAB _BORDER : 'treestyletab-firsttab-border' ,
2007-11-08 13:21:13 +00:00
kAUTOHIDE : 'treestyletab-tabbar-autohide' ,
2008-02-22 17:55:35 +00:00
kFIXED : 'treestyletab-tabbar-fixed' ,
2008-03-10 03:51:21 +00:00
kRESIZING : 'treestyletab-tabbar-resizing' ,
kTRANSPARENT : 'treestyletab-tabbar-transparent' ,
2007-10-18 17:11:03 +00:00
2007-10-20 06:12:22 +00: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' ,
2007-10-20 11:29:42 +00:00
kSPLITTER : 'treestyletab-splitter' ,
2007-11-30 19:22:34 +00:00
kSTRINGBUNDLE : 'treestyletab-stringbundle' ,
2007-10-16 17:22:28 +00:00
2007-10-20 02:44:14 +00:00
kMENUITEM _REMOVESUBTREE _SELECTION : 'multipletab-selection-item-removeTabSubTree' ,
2007-10-19 05:27:06 +00:00
2007-10-19 03:05:36 +00:00
kFOCUS _ALL : 0 ,
kFOCUS _VISIBLE : 1 ,
2007-10-20 02:44:14 +00:00
kDROP _BEFORE : - 1 ,
kDROP _ON : 0 ,
kDROP _AFTER : 1 ,
2008-10-17 17:16:16 +00:00
kACTION _MOVE : 1 ,
kACTION _STAY : 2 ,
kACTION _DUPLICATE : 4 ,
kACTION _IMPORT : 8 ,
2008-12-01 00:01:12 +00:00
kACTION _NEWTAB : 16 ,
2008-10-17 17:16:16 +00:00
kACTION _ATTACH : 1024 ,
kACTION _PART : 2048 ,
kACTIONS _FOR _SOURCE : 1 | 2 ,
kACTIONS _FOR _DESTINATION : 4 | 8 ,
2007-10-20 02:44:14 +00:00
2007-10-20 10:24:36 +00:00
kTABBAR _TOP : 1 ,
kTABBAR _BOTTOM : 2 ,
kTABBAR _LEFT : 4 ,
kTABBAR _RIGHT : 8 ,
kTABBAR _HORIZONTAL : 3 ,
kTABBAR _VERTICAL : 12 ,
2008-06-17 06:22:49 +00:00
kAUTOHIDE _MODE _DISABLED : 0 ,
kAUTOHIDE _MODE _HIDE : 1 ,
kAUTOHIDE _MODE _SHRINK : 2 ,
2008-06-17 10:16:57 +00: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 06:22:49 +00:00
2008-03-08 08:57:17 +00:00
kSHOWN _BY _UNKNOWN : 0 ,
kSHOWN _BY _SHORTCUT : 1 ,
kSHOWN _BY _MOUSEMOVE : 2 ,
2008-03-09 06:36:52 +00:00
kSHOWN _BY _FEEDBACK : 3 ,
2008-09-26 14:13:29 +00:00
kTRANSPARENT _NONE : 0 ,
kTRANSPARENT _PART : 1 ,
kTRANSPARENT _FULL : 2 ,
kTRANSPARENT _STYLE : [ 'none' , 'part' , 'full' ] ,
2008-03-08 08:57:17 +00:00
2007-10-31 00:38:37 +00:00
kINSERT _FISRT : 0 ,
kINSERT _LAST : 1 ,
2007-11-14 19:34:36 +00:00
baseLebelMargin : 12 ,
2008-12-03 13:17:40 +00:00
shouldDetectClickOnIndentSpaces : true ,
2007-11-09 03:10:10 +00:00
2007-10-16 17:22:28 +00: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 05:01:35 +00:00
this . _SessionStore = Components
. classes [ '@mozilla.org/browser/sessionstore;1' ]
. getService ( Components . interfaces . nsISessionStore ) ;
2007-10-16 17:22:28 +00:00
}
return this . _SessionStore ;
} ,
_SessionStore : null ,
2007-10-20 08:22:42 +00:00
get ObserverService ( ) {
if ( ! this . _ObserverService ) {
2008-02-22 05:01:35 +00:00
this . _ObserverService = Components
. classes [ '@mozilla.org/observer-service;1' ]
. getService ( Components . interfaces . nsIObserverService ) ;
2007-10-20 08:22:42 +00:00
}
return this . _ObserverService ;
} ,
_ObserverService : null ,
2007-10-22 09:59:43 +00:00
get IOService ( ) {
if ( ! this . _IOService ) {
2008-02-22 05:01:35 +00:00
this . _IOService = Components
. classes [ '@mozilla.org/network/io-service;1' ]
. getService ( Components . interfaces . nsIIOService ) ;
2007-10-22 09:59:43 +00:00
}
return this . _IOService ;
} ,
_IOService : null ,
2007-11-09 05:20:32 +00:00
2008-02-22 05:01:35 +00: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 ,
2007-11-09 05:20:32 +00:00
get isGecko18 ( ) {
var version = this . XULAppInfo . platformVersion . split ( '.' ) ;
return parseInt ( version [ 0 ] ) <= 1 && parseInt ( version [ 1 ] ) <= 8 ;
} ,
2008-05-23 03:30:49 +00:00
get isGecko19 ( ) {
var version = this . XULAppInfo . platformVersion . split ( '.' ) ;
return parseInt ( version [ 0 ] ) >= 2 || parseInt ( version [ 1 ] ) >= 9 ;
} ,
2007-11-09 05:20:32 +00:00
get XULAppInfo ( ) {
if ( ! this . _XULAppInfo ) {
this . _XULAppInfo = Components . classes [ '@mozilla.org/xre/app-info;1' ] . getService ( Components . interfaces . nsIXULAppInfo ) ;
}
return this . _XULAppInfo ;
} ,
_XULAppInfo : null ,
2007-11-30 19:22:34 +00:00
get stringbundle ( ) {
if ( ! this . _stringbundle ) {
this . _stringbundle = document . getElementById ( this . kSTRINGBUNDLE ) ;
}
return this . _stringbundle ;
} ,
_stringbundle : null ,
2008-11-10 04:48:11 +00:00
2007-10-21 08:16:10 +00:00
/* API */
2007-11-08 13:21:13 +00:00
2007-10-29 14:52:52 +00:00
readyToOpenChildTab : function ( aFrameOrTabBrowser , aMultiple , aInsertBefore )
2007-10-21 08:16:10 +00:00
{
2008-02-28 00:07:51 +00:00
if ( ! this . getTreePref ( 'autoAttachNewTabsAsChildren' ) ) return ;
2007-10-21 08:16:10 +00:00
var frame = this . getFrameFromTabBrowserElements ( aFrameOrTabBrowser ) ;
if ( ! frame ) return ;
2007-10-23 04:33:46 +00:00
var ownerBrowser = this . getTabBrowserFromFrame ( frame ) ;
2007-11-14 19:34:36 +00:00
ownerBrowser . treeStyleTab . readyToAttachNewTab = true ;
ownerBrowser . treeStyleTab . readyToAttachMultiple = aMultiple || false ;
ownerBrowser . treeStyleTab . multipleCount = 0 ;
ownerBrowser . treeStyleTab . parentTab = this . getTabFromFrame ( frame , ownerBrowser ) . getAttribute ( this . kID ) ;
ownerBrowser . treeStyleTab . insertBefore = aInsertBefore ? aInsertBefore . getAttribute ( this . kID ) : null ;
2007-10-21 08:16:10 +00:00
} ,
2007-10-22 00:40:04 +00:00
readyToOpenNewTabGroup : function ( aFrameOrTabBrowser )
{
2008-02-28 00:07:51 +00:00
if ( ! this . getTreePref ( 'autoAttachNewTabsAsChildren' ) ) return ;
2007-10-22 00:40:04 +00:00
var frame = this . getFrameFromTabBrowserElements ( aFrameOrTabBrowser ) ;
if ( ! frame ) return ;
this . stopToOpenChildTab ( frame ) ;
2007-10-23 04:33:46 +00:00
var ownerBrowser = this . getTabBrowserFromFrame ( frame ) ;
2007-11-14 19:34:36 +00:00
ownerBrowser . treeStyleTab . readyToAttachNewTabGroup = true ;
ownerBrowser . treeStyleTab . readyToAttachMultiple = true ;
ownerBrowser . treeStyleTab . multipleCount = 0 ;
2007-10-22 00:40:04 +00:00
} ,
2007-10-21 08:16:10 +00:00
stopToOpenChildTab : function ( aFrameOrTabBrowser )
{
var frame = this . getFrameFromTabBrowserElements ( aFrameOrTabBrowser ) ;
if ( ! frame ) return ;
2007-10-23 04:33:46 +00:00
var ownerBrowser = this . getTabBrowserFromFrame ( frame ) ;
2007-11-14 19:34:36 +00: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 ;
2007-10-21 08:16:10 +00:00
} ,
2007-10-21 08:17:59 +00:00
checkToOpenChildTab : function ( aFrameOrTabBrowser )
2007-10-21 08:16:10 +00:00
{
var frame = this . getFrameFromTabBrowserElements ( aFrameOrTabBrowser ) ;
if ( ! frame ) return false ;
2007-10-23 04:33:46 +00:00
var ownerBrowser = this . getTabBrowserFromFrame ( frame ) ;
2007-11-14 19:34:36 +00:00
return ownerBrowser . treeStyleTab . readyToAttachNewTab || ownerBrowser . treeStyleTab . readyToAttachNewTabGroup ? true : false ;
2007-10-21 08:16:10 +00:00
} ,
2007-10-28 16:07:10 +00:00
2007-10-29 15:49:00 +00:00
checkReadyToOpenNewTab : function ( aInfo )
2007-10-28 16:07:10 +00:00
{
2007-10-29 14:52:52 +00: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 18:03:24 +00:00
var info = aInfo || { uri : '' } ;
if ( /^javascript:/ . test ( info . uri ) ) return false ;
2007-10-29 15:22:50 +00:00
var frame = this . getFrameFromTabBrowserElements ( info . target ) ;
if ( ! frame ) return false ;
2007-10-28 17:16:48 +00:00
var external = info . external || { } ;
var internal = info . internal || { } ;
2007-11-14 19:34:36 +00:00
var b = this . getTabBrowserFromFrame ( frame ) ;
var nextTab = b . treeStyleTab . getNextSiblingTab ( currentTab ) ;
2007-10-28 17:16:48 +00:00
var targetHost = /^\w+:\/\/([^:\/]+)(\/|$)/ . test ( info . uri ) ? RegExp . $1 : null ;
2007-10-29 14:52:52 +00:00
var currentTab = this . getTabFromFrame ( frame ) ;
2007-10-28 16:07:10 +00:00
var currentURI = frame . location . href ;
var currentHost = currentURI . match ( /^\w+:\/\/([^:\/]+)(\/|$)/ ) ? RegExp . $1 : null ;
2007-11-14 19:34:36 +00:00
var parentTab = b . treeStyleTab . getParentTab ( currentTab ) ;
2007-10-28 16:07:10 +00:00
var parentURI = parentTab ? parentTab . linkedBrowser . currentURI : null ;
var parentHost = parentURI && parentURI . spec . match ( /^\w+:\/\/([^:\/]+)(\/|$)/ ) ? RegExp . $1 : null ;
2007-10-29 15:49:00 +00: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 ;
parent = parentHost == targetHost && ! internal . forceChild ? parentTab : frame ;
2007-10-31 00:38:37 +00:00
insertBefore = parentHost == targetHost && ! internal . forceChild &&
( this . getTreePref ( 'insertNewChildAt' ) == this . kINSERT _FIRST ?
nextTab :
(
2007-11-14 19:34:36 +00:00
b . treeStyleTab . getTabById ( currentTab . _ _treestyletab _ _next ) ||
2007-10-31 00:38:37 +00:00
( nextTab ? ( currentTab . _ _treestyletab _ _next = nextTab . getAttribute ( this . kID ) , nextTab ) : null )
)
) ;
2007-10-29 15:49:00 +00: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 16:07:10 +00:00
} ,
2008-09-26 14:13:29 +00:00
checkReadyToOpenNewTabOnLocationBar : function ( aURI , aModifier )
{
return this . checkReadyToOpenNewTab ( {
uri : aURI ,
external : {
newTab : this . getTreePref ( 'urlbar.loadDifferentDomainToNewTab' ) ,
forceChild : this . getTreePref ( 'urlbar.loadDifferentDomainToNewTab.asChild' )
} ,
internal : { newTab : this . getTreePref ( 'urlbar.loadSameDomainToNewChildTab' ) } ,
modifier : aModifier ,
invert : this . getTreePref ( 'urlbar.invertDefaultBehavior' )
} ) ;
} ,
2007-10-30 12:58:09 +00:00
2007-11-14 19:34:36 +00:00
/* backward compatibility */
getTempTreeStyleTab : function ( aTabBrowser )
{
return aTabBrowser . treeStyleTab || new TreeStyleTabBrowser ( aTabBrowser ) ;
} ,
initTabAttributes : function ( aTab , aTabBrowser )
{
2007-11-17 13:32:41 +00:00
var b = aTabBrowser || this . getTabBrowserFromChild ( aTab ) ;
2007-11-14 19:34:36 +00:00
this . getTempTreeStyleTab ( b ) . initTabAttributes ( aTab ) ;
} ,
initTabContents : function ( aTab , aTabBrowser )
{
2007-11-17 13:32:41 +00:00
var b = aTabBrowser || this . getTabBrowserFromChild ( aTab ) ;
2007-11-14 19:34:36 +00:00
this . getTempTreeStyleTab ( b ) . initTabContents ( aTab ) ;
} ,
initTabContentsOrder : function ( aTab , aTabBrowser )
{
2007-11-17 13:32:41 +00:00
var b = aTabBrowser || this . getTabBrowserFromChild ( aTab ) ;
2007-11-14 19:34:36 +00:00
this . getTempTreeStyleTab ( b ) . initTabContentsOrder ( aTab ) ;
} ,
2007-10-16 17:22:28 +00:00
/* Utilities */
2008-03-09 06:36:52 +00:00
2007-10-26 09:36:45 +00:00
isEventFiredOnTwisty : function ( aEvent )
2007-10-16 17:22:28 +00:00
{
var tab = this . getTabFromEvent ( aEvent ) ;
if ( ! tab ) return false ;
2008-04-29 18:17:44 +00:00
return this . hasChildTabs ( tab ) && this . evaluateXPath (
2007-11-14 12:34:36 +00:00
'ancestor-or-self::*[@class="' + this . kTWISTY + '" or (ancestor::xul:tabbrowser[@' + this . kMODE + '="vertical"] and @class="tab-icon")]' ,
2007-10-26 09:36:45 +00:00
aEvent . originalTarget || aEvent . target ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ? true : false ;
2007-10-18 17:11:03 +00:00
} ,
2007-10-18 18:20:54 +00:00
2008-12-15 02:59:51 +00:00
isEventFiredOnClickable : function ( aEvent )
{
return this . evaluateXPath (
2008-12-17 23:41:39 +00:00
'ancestor-or-self::*[contains(" button toolbarbutton scrollbar popup menupopup tooltip ", concat(" ", local-name(), " "))]' ,
2008-12-15 02:59:51 +00:00
aEvent . originalTarget ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ? true : false ;
} ,
2008-10-17 12:35:55 +00:00
isAccelKeyPressed : function ( aEvent )
{
return navigator . platform . toLowerCase ( ) . indexOf ( 'mac' ) > - 1 ?
( aEvent . metaKey || ( aEvent . keyCode == Components . interfaces . nsIDOMKeyEvent . DOM _VK _META ) ) :
( aEvent . ctrlKey || ( aEvent . keyCode == Components . interfaces . nsIDOMKeyEvent . DOM _VK _CONTROL ) ) ;
} ,
2008-02-22 05:01:35 +00:00
get browserWindow ( )
{
return this . WindowMediator . getMostRecentWindow ( 'navigator:browser' ) ;
} ,
2007-10-16 17:22:28 +00:00
get browser ( )
{
2008-02-22 05:01:35 +00:00
var w = this . browserWindow ;
return ! w ? null :
2008-02-22 05:04:35 +00:00
'SplitBrowser' in w ? w . SplitBrowser . activeBrowser :
2008-02-22 05:01:35 +00:00
w . gBrowser ;
2007-10-16 17:22:28 +00:00
} ,
2007-10-19 03:05:36 +00:00
evaluateXPath : function ( aExpression , aContext , aType )
{
if ( ! aType ) aType = XPathResult . ORDERED _NODE _SNAPSHOT _TYPE ;
try {
2008-10-17 12:35:55 +00:00
var xpathResult = ( aContext . ownerDocument || aContext || document ) . evaluate (
2007-10-19 03:05:36 +00:00
aExpression ,
2008-10-17 12:35:55 +00:00
( aContext || document ) ,
2007-10-19 03:05:36 +00:00
this . NSResolver ,
aType ,
null
) ;
}
catch ( e ) {
return {
singleNodeValue : null ,
snapshotLength : 0 ,
snapshotItem : function ( ) {
return null
}
} ;
}
return xpathResult ;
} ,
2007-10-16 17:22:28 +00: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 ;
} ,
getTabFromEvent : function ( aEvent )
{
2008-10-17 12:35:55 +00:00
return this . getTabFromChild ( aEvent . originalTarget || aEvent . target ) ;
2007-10-16 17:22:28 +00:00
} ,
2007-10-17 16:07:43 +00: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 05:39:22 +00:00
var tabs = this . getTabs ( b ) ;
var tab ;
for ( var i = 0 , maxi = tabs . snapshotLength ; i < maxi ; i ++ )
2007-10-17 16:07:43 +00:00
{
2009-01-24 05:39:22 +00:00
tab = tabs . snapshotItem ( i ) ;
if ( tab . linkedBrowser . docShell == docShell )
return tab ;
2007-10-17 16:07:43 +00:00
}
return null ;
} ,
2008-10-17 12:35:55 +00:00
getTabFromChild : function ( aTab )
{
return this . evaluateXPath (
'ancestor-or-self::xul:tab[ancestor::xul:tabbrowser]' ,
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
} ,
2007-11-17 13:32:41 +00:00
getTabBrowserFromChild : function ( aTab )
2007-10-16 17:22:28 +00:00
{
2007-10-17 16:07:43 +00:00
if ( ! aTab ) return null ;
2007-10-16 17:22:28 +00:00
if ( aTab . _ _treestyletab _ _linkedTabBrowser )
return aTab . _ _treestyletab _ _linkedTabBrowser ;
2007-10-26 10:25:59 +00:00
return this . evaluateXPath (
'ancestor-or-self::xul:tabbrowser' ,
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
2007-10-16 17:22:28 +00:00
} ,
2007-10-23 04:33:46 +00:00
getTabBrowserFromFrame : function ( aFrame )
{
2008-02-22 05:01:35 +00:00
var w = this . browserWindow ;
return ! w ? null :
( 'SplitBrowser' in w ) ? this . getTabBrowserFromChild ( w . SplitBrowser . getSubBrowserAndBrowserFromFrame ( aFrame . top ) . browser ) :
this . browser ;
2007-10-23 04:33:46 +00:00
} ,
2007-10-23 08:19:32 +00:00
2007-10-21 08:16:10 +00: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 13:32:41 +00:00
frame = this . getTabBrowserFromChild ( frame ) ;
2007-10-21 08:16:10 +00:00
if ( ! frame ) return null ;
frame = frame . contentWindow ;
}
}
if ( ! frame )
frame = this . browser . contentWindow ;
return frame ;
} ,
2007-10-21 15:02:58 +00:00
2007-11-17 12:50:36 +00:00
makeNewId : function ( )
{
return 'tab-<' + Date . now ( ) + '-' + parseInt ( Math . random ( ) * 65000 ) + '>' ;
} ,
2007-11-17 12:59:48 +00:00
2007-10-22 09:59:43 +00: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 16:31:00 +00:00
2007-11-14 19:34:36 +00:00
toggleAutoHide : function ( )
2007-11-12 16:31:00 +00:00
{
2008-06-17 06:22:49 +00:00
this . setTreePref ( 'tabbar.autoHide.mode' ,
this . getTreePref ( 'tabbar.autoHide.mode' ) == this . kAUTOHIDE _MODE _DISABLED ?
this . getTreePref ( 'tabbar.autoHide.mode.toggle' ) :
this . kAUTOHIDE _MODE _DISABLED
) ;
2007-11-12 16:31:00 +00:00
} ,
2007-11-17 12:59:48 +00:00
2008-02-22 17:55:35 +00:00
toggleFixed : function ( )
{
this . setTreePref ( 'tabbar.fixed' ,
! this . getTreePref ( 'tabbar.fixed' ) ) ;
} ,
2008-02-26 17:02:59 +00:00
changeTabbarPosition : function ( aNewPosition )
{
if ( ! aNewPosition || ! /^(top|bottom|left|right)$/i . test ( aNewPosition ) )
aNewPosition = 'top' ;
aNewPosition = aNewPosition . toLowerCase ( ) ;
this . setTreePref ( 'tabbar.position' , aNewPosition ) ;
if ( ! this . getTreePref ( 'tabbar.syncRelatedPrefsForDynamicPosition' ) ) return ;
var vertical = ( aNewPosition == 'left' || aNewPosition == 'right' ) ;
this . setTreePref ( 'enableSubtreeIndent' , vertical ) ;
this . setTreePref ( 'allowSubtreeCollapseExpand' , vertical ) ;
} ,
2008-02-28 07:45:39 +00:00
2007-11-17 12:59:48 +00:00
/* get tab(s) */
2008-02-22 17:55:35 +00:00
2007-11-17 12:59:48 +00:00
getTabById : function ( aId , aTabBrowserChildren )
{
if ( ! aId ) return null ;
2007-11-17 13:32:41 +00:00
var b = aTabBrowserChildren ? this . getTabBrowserFromChild ( aTabBrowserChildren ) : null ;
2007-11-17 12:59:48 +00: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 17:55:35 +00:00
2009-01-26 06:37:29 +00: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 06:39:51 +00:00
getFirstTab : function ( aTabBrowser )
{
return this . evaluateXPath (
'descendant::xul:tab[1]' ,
aTabBrowser . mTabContainer ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
} ,
2009-01-26 06:37:29 +00:00
getLastTab : function ( aTabBrowser )
{
return this . evaluateXPath (
'descendant::xul:tab[last()]' ,
aTabBrowser . mTabContainer ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
} ,
2009-01-24 05:39:22 +00:00
getNextTab : function ( aTab )
{
2009-01-26 06:13:37 +00:00
return this . evaluateXPath (
'following-sibling::xul:tab[1]' ,
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
2009-01-24 05:39:22 +00:00
} ,
getPreviousTab : function ( aTab )
{
2009-01-26 06:13:37 +00:00
return this . evaluateXPath (
'preceding-sibling::xul:tab[1]' ,
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
2009-01-24 05:39:22 +00:00
} ,
2007-11-17 12:59:48 +00:00
getNextVisibleTab : function ( aTab )
{
2009-01-26 06:13:37 +00:00
return this . evaluateXPath (
'following-sibling::xul:tab[not(@' + this . kCOLLAPSED + '="true")][1]' ,
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
2007-11-17 12:59:48 +00:00
} ,
getPreviousVisibleTab : function ( aTab )
{
2009-01-26 06:13:37 +00:00
return this . evaluateXPath (
'preceding-sibling::xul:tab[not(@' + this . kCOLLAPSED + '="true")][1]' ,
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
2007-11-17 12:59:48 +00:00
} ,
2007-11-26 22:43:50 +00:00
2008-02-22 06:58:50 +00:00
getLastVisibleTab : function ( aTab )
{
2009-01-26 06:13:37 +00:00
return this . evaluateXPath (
'child::xul:tab[not(@' + this . kCOLLAPSED + '="true")][last()]' ,
aTab . parentNode ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
2008-02-22 06:58:50 +00:00
} ,
getVisibleTabs : function ( aTab )
{
var xpathResult = this . evaluateXPath (
'child::xul:tab[not(@' + this . kCOLLAPSED + '="true")]' ,
aTab . parentNode
) ;
return xpathResult ;
} ,
2007-11-26 22:43:50 +00:00
getVisibleIndex : function ( aTab )
{
2009-02-11 07:11:21 +00:00
if ( aTab . getAttribute ( this . kCOLLAPSED ) == 'true' ) return - 1 ;
2007-11-26 22:43:50 +00:00
return this . evaluateXPath (
2009-01-26 06:13:37 +00:00
'count(preceding-sibling::xul:tab[not(@' + this . kCOLLAPSED + '="true")])' ,
aTab ,
XPathResult . NUMBER _TYPE
) . numberValue ;
2007-11-26 22:43:50 +00:00
} ,
2008-03-09 06:36:52 +00:00
2007-11-17 12:59:48 +00:00
/* tree manipulations */
2008-02-22 17:55:35 +00:00
2007-11-17 12:59:48 +00:00
get rootTabs ( )
{
return this . getArrayFromXPathResult (
this . evaluateXPath (
'child::xul:tab[not(@' + this . kNEST + ') or @' + this . kNEST + '="0" or @' + this . kNEST + '=""]' ,
this . browser . mTabContainer
)
) ;
} ,
getParentTab : function ( aTab )
{
if ( ! aTab ) return null ;
var id = aTab . getAttribute ( this . kID ) ;
if ( ! id ) return null ; // not initialized yet
return this . evaluateXPath (
2008-02-22 21:09:09 +00:00
'parent::*/child::xul:tab[contains(concat("|", @' + this . kCHILDREN + ', "|"), "|' + id + '|")]' ,
2007-11-17 12:59:48 +00:00
aTab ,
XPathResult . FIRST _ORDERED _NODE _TYPE
) . singleNodeValue ;
} ,
getRootTab : function ( aTab )
{
var parent = aTab ;
var root = aTab ;
while ( parent = this . getParentTab ( parent ) )
{
root = parent ;
}
return root ;
} ,
getNextSiblingTab : function ( aTab )
{
if ( ! aTab ) return null ;
var parentTab = this . getParentTab ( aTab ) ;
if ( ! parentTab ) {
var next = aTab ;
do {
next = next . nextSibling ;
}
2009-01-24 05:39:22 +00:00
while ( next &&
next . nodeType == Node . ELEMENT _NODE &&
this . getParentTab ( next ) ) ;
2007-11-17 12:59:48 +00: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 ;
} ,
getPreviousSiblingTab : function ( aTab )
{
if ( ! aTab ) return null ;
var parentTab = this . getParentTab ( aTab ) ;
if ( ! parentTab ) {
var prev = aTab ;
do {
prev = prev . previousSibling ;
}
2009-01-24 05:39:22 +00:00
while ( prev &&
prev . nodeType == Node . ELEMENT _NODE &&
this . getParentTab ( prev ) ) ;
2007-11-17 12:59:48 +00: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 ;
} ,
getChildTabs : function ( aTab , aAllTabsArray )
{
var tabs = [ ] ;
if ( ! aTab ) return null ;
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 ;
} ,
2008-04-29 18:17:44 +00:00
hasChildTabs : function ( aTab )
{
if ( ! aTab ) return false ;
return aTab . hasAttribute ( this . kCHILDREN ) ;
} ,
2007-11-17 12:59:48 +00:00
getDescendantTabs : function ( aTab )
{
var tabs = [ ] ;
this . getChildTabs ( aTab , tabs ) ;
return tabs ;
} ,
getFirstChildTab : function ( aTab )
{
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 ;
} ,
getLastChildTab : function ( aTab )
{
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 22:43:50 +00:00
getChildIndex : function ( aTab , aParent )
{
var parent = this . getParentTab ( aTab ) ;
2007-11-26 23:51:26 +00:00
if ( ! aParent || ! parent || aParent != parent ) {
2007-11-26 23:00:30 +00:00
parent = aTab ;
2007-11-26 22:43:50 +00: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 ;
}
}
} ,
2007-11-14 19:34:36 +00:00
2007-11-17 12:59:48 +00:00
/* Session Store API */
getTabValue : function ( aTab , aKey )
{
var value = null ;
try {
value = this . SessionStore . getTabValue ( aTab , aKey ) ;
}
catch ( e ) {
}
2008-06-20 05:57:38 +00:00
if ( this . useTMPSessionAPI ) {
var TMPValue = aTab . getAttribute ( this . kTMP _SESSION _DATA _PREFIX + aKey ) ;
if ( TMPValue ) value = TMPValue ;
}
2007-11-17 12:59:48 +00:00
return value ;
} ,
setTabValue : function ( aTab , aKey , aValue )
{
2008-06-20 05:57:38 +00:00
if ( ! aValue ) return this . deleteTabValue ( aTab , aKey ) ;
2007-11-17 12:59:48 +00:00
aTab . setAttribute ( aKey , aValue ) ;
try {
this . SessionStore . setTabValue ( aTab , aKey , aValue ) ;
}
catch ( e ) {
}
2008-06-20 05:57:38 +00:00
if ( this . useTMPSessionAPI )
aTab . setAttribute ( this . kTMP _SESSION _DATA _PREFIX + aKey , aValue ) ;
2007-11-17 12:59:48 +00:00
return aValue ;
} ,
deleteTabValue : function ( aTab , aKey )
{
aTab . removeAttribute ( aKey ) ;
try {
this . SessionStore . deleteTabValue ( aTab , aKey ) ;
}
catch ( e ) {
}
2008-06-20 05:57:38 +00:00
if ( this . useTMPSessionAPI )
aTab . removeAttribute ( this . kTMP _SESSION _DATA _PREFIX + aKey ) ;
2007-11-17 12:59:48 +00:00
} ,
2008-06-20 05:57:38 +00:00
2008-09-26 14:13:29 +00:00
useTMPSessionAPI : false ,
2008-06-20 05:57:38 +00:00
kTMP _SESSION _DATA _PREFIX : 'tmp-session-data-' ,
2007-11-17 12:59:48 +00:00
2007-10-16 17:22:28 +00:00
/* Initializing */
2008-11-10 04:48:11 +00:00
2008-02-26 01:14:12 +00:00
preInit : function ( )
{
2008-10-14 04:57:35 +00:00
if ( this . preInitialized ) return ;
this . preInitialized = true ;
2008-02-26 16:24:25 +00:00
window . removeEventListener ( 'DOMContentLoaded' , this , true ) ;
2008-02-26 01:14:12 +00:00
if ( ! document . getElementById ( 'content' ) ) return ;
2008-11-10 04:48:11 +00:00
window . addEventListener ( 'SSTabRestoring' , this , true ) ;
2008-12-01 08:30:36 +00: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-03 04:57:40 +00:00
eval ( 'nsBrowserAccess.prototype.openURI = ' +
nsBrowserAccess . prototype . openURI . toSource ( ) . replace (
/(switch\s*\(aWhere\))/ ,
< > < ! [ CDATA [
if ( aOpener &&
aWhere == Components . interfaces . nsIBrowserDOMWindow . OPEN _NEWTAB ) {
TreeStyleTabService . readyToOpenChildTab ( aOpener ) ;
}
$1 ] ] > < / >
)
) ;
2008-02-26 01:14:12 +00:00
this . overrideExtensionsPreInit ( ) ; // hacks.js
} ,
2008-10-14 04:57:35 +00:00
preInitialized : false ,
2008-03-08 08:57:17 +00:00
init : function ( )
2007-10-16 17:22:28 +00:00
{
if ( ! ( 'gBrowser' in window ) ) return ;
2008-10-14 04:57:35 +00:00
if ( this . initialized ) return ;
this . initialized = true ;
if ( ! this . preInitialized ) {
this . preInit ( ) ;
}
2008-11-10 04:48:11 +00:00
window . removeEventListener ( 'SSTabRestoring' , this , true ) ;
2008-10-14 04:57:35 +00:00
2007-10-16 17:22:28 +00:00
window . removeEventListener ( 'load' , this , false ) ;
2008-02-22 05:01:35 +00:00
window . addEventListener ( 'unload' , this , false ) ;
2007-10-22 09:59:43 +00:00
document . getElementById ( 'contentAreaContextMenu' ) . addEventListener ( 'popupshowing' , this , false ) ;
2007-11-14 15:09:47 +00:00
var appcontent = document . getElementById ( 'appcontent' ) ;
appcontent . addEventListener ( 'SubBrowserAdded' , this , false ) ;
appcontent . addEventListener ( 'SubBrowserRemoveRequest' , this , false ) ;
2007-10-17 13:25:50 +00:00
2007-10-16 17:22:28 +00:00
this . addPrefListener ( this ) ;
2008-02-26 01:14:12 +00:00
this . overrideExtensionsOnInitBefore ( ) ; // hacks.js
2007-10-21 15:02:58 +00:00
this . overrideGlobalFunctions ( ) ;
2007-10-16 17:22:28 +00:00
this . initTabBrowser ( gBrowser ) ;
2008-02-26 01:14:12 +00:00
this . overrideExtensionsOnInitAfter ( ) ; // hacks.js
2008-03-03 08:26:51 +00:00
2008-11-10 04:48:11 +00:00
this . processRestoredTabs ( ) ;
2007-11-14 19:34:36 +00:00
this . observe ( null , 'nsPref:changed' , 'extensions.treestyletab.levelMargin' ) ;
2008-06-17 06:22:49 +00:00
this . observe ( null , 'nsPref:changed' , 'extensions.treestyletab.tabbar.autoHide.mode' ) ;
2008-12-03 13:17:40 +00:00
this . observe ( null , 'nsPref:changed' , 'extensions.treestyletab.clickOnIndentSpaces.enabled' ) ;
2008-03-03 08:26:51 +00:00
this . observe ( null , 'nsPref:changed' , 'browser.link.open_newwindow.restriction.override' ) ;
this . observe ( null , 'nsPref:changed' , 'browser.tabs.loadFolderAndReplace.override' ) ;
2007-10-16 17:22:28 +00:00
} ,
2008-10-14 04:57:35 +00:00
initialized : false ,
2008-11-10 04:48:11 +00:00
2007-10-16 17:22:28 +00:00
initTabBrowser : function ( aTabBrowser )
{
2007-11-14 19:34:36 +00:00
if ( aTabBrowser . localName != 'tabbrowser' ) return ;
aTabBrowser . treeStyleTab = new TreeStyleTabBrowser ( aTabBrowser ) ;
aTabBrowser . treeStyleTab . init ( ) ;
2007-10-16 17:22:28 +00:00
} ,
2007-10-19 05:27:06 +00:00
2007-11-14 19:34:36 +00:00
updateTabDNDObserver : function ( aObserver )
2007-11-14 12:31:14 +00:00
{
2008-10-02 01:32:31 +00:00
var canDropFunctionName = '_setEffectAllowedForDataTransfer' in aObserver ?
'_setEffectAllowedForDataTransfer' : // Firefox 3.1 or later
'canDrop' ; // Firefox 3.0.x
eval ( 'aObserver.' + canDropFunctionName + ' = ' +
aObserver [ canDropFunctionName ] . toSource ( ) . replace (
2007-11-14 15:09:47 +00:00
'{' ,
'{ var TSTTabBrowser = this;'
) . replace (
2007-11-17 13:32:41 +00:00
/\.screenX/g , '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.positionProp]'
2007-11-14 12:31:14 +00:00
) . replace (
2007-11-17 13:32:41 +00:00
/\.width/g , '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.sizeProp]'
2007-11-14 12:31:14 +00:00
) . replace ( // Tab Mix Plus
2007-11-17 13:32:41 +00:00
/\.screenY/g , '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.invertedPositionProp]'
2007-11-14 12:31:14 +00:00
) . replace ( // Tab Mix Plus
2007-11-17 13:32:41 +00:00
/\.height/g , '[TreeStyleTabService.getTabBrowserFromChild(TSTTabBrowser).treeStyleTab.invertedSizeProp]'
2007-11-14 12:31:14 +00:00
) . replace (
2008-12-02 01:54:16 +00:00
/(return (?:true|dt.effectAllowed = "copyMove");)/ ,
2007-11-14 12:31:14 +00:00
< > < ! [ CDATA [
if ( ! ( function ( aSelf ) {
try {
2008-10-17 12:35:55 +00:00
var node = TST _DRAGSESSION . sourceNode ;
var tab = TSTTabBrowser . treeStyleTab . getTabFromChild ( node ) ;
if ( ! node ||
! tab ||
tab . parentNode != aSelf . mTabContainer )
2007-11-14 12:31:14 +00:00
return true ;
2008-11-07 04:58:37 +00:00
tab = TSTTabBrowser . treeStyleTab . getTabFromEvent ( aEvent ) ;
if ( tab && tab . getAttribute ( TreeStyleTabService . kCOLLAPSED ) == 'true' )
2007-11-14 12:31:14 +00:00
return false ;
2008-10-17 12:35:55 +00:00
var info = TSTTabBrowser . treeStyleTab . getDropAction ( aEvent , TST _DRAGSESSION ) ;
2007-11-14 12:31:14 +00:00
return info . canDrop ;
}
catch ( e ) {
dump ( 'TreeStyleTabService::canDrop\n' + e + '\n' ) ;
return false ;
}
2008-10-17 12:35:55 +00:00
} ) ( TSTTabBrowser ) ) {
2008-10-02 01:32:31 +00:00
return TST _DRAGDROP _DISALLOW _RETRUN _VALUE ;
2008-10-17 12:35:55 +00:00
}
2007-11-14 12:31:14 +00:00
$1
] ] > < / >
2008-10-17 12:35:55 +00:00
) . replace (
/TST_DRAGSESSION/g ,
( canDropFunctionName == 'canDrop' ?
'aDragSession' :
'TSTTabBrowser.treeStyleTab.getCurrentDragSession()'
)
2008-10-02 01:32:31 +00:00
) . replace (
/TST_DRAGDROP_DISALLOW_RETRUN_VALUE/g ,
( canDropFunctionName == 'canDrop' ?
'false' :
'dt.effectAllowed = "none"'
)
2007-11-14 12:31:14 +00:00
)
) ;
2008-10-02 01:32:31 +00:00
var dragOverFunctionName = '_onDragOver' in aObserver ?
'_onDragOver' : // Firefox 3.1 or later
'onDragOver' ; // Firefox 3.0.x
eval ( 'aObserver.' + dragOverFunctionName + ' = ' +
aObserver [ dragOverFunctionName ] . toSource ( ) . replace (
2007-11-14 12:31:14 +00:00
'{' ,
< > < ! [ CDATA [
{
var TSTTabBrowser = this ;
if ( ( function ( aSelf ) {
try {
2008-10-02 01:32:31 +00:00
var info = TSTTabBrowser . treeStyleTab . getDropAction ( aEvent , TST _DRAGSESSION ) ;
2007-11-14 12:31:14 +00: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 19:34:36 +00:00
TSTTabBrowser . treeStyleTab . clearDropPosition ( ) ;
2007-11-14 12:31:14 +00:00
2008-10-02 01:32:31 +00:00
if ( TST _DRAGDROP _DISALLOW _CHECK ) return true ;
2007-11-14 12:31:14 +00: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 ;
}
] ] > < / >
2008-10-02 01:32:31 +00:00
) . replace (
/TST_DRAGSESSION/g ,
( canDropFunctionName == 'canDrop' ?
'aDragSession' :
'null'
)
) . replace (
/TST_DRAGDROP_DISALLOW_CHECK/g ,
( canDropFunctionName == 'canDrop' ?
'!aSelf.canDrop(aEvent, aDragSession)' :
2008-12-02 01:54:16 +00:00
'aSelf._setEffectAllowedForDataTransfer(aEvent) == "none"'
2008-10-02 01:32:31 +00:00
)
2007-11-14 12:31:14 +00:00
)
) ;
2008-10-02 01:32:31 +00:00
var dragExitFunctionName = '_onDragLeave' in aObserver ?
'_onDragLeave' : // Firefox 3.1 or later
'onDragExit' ; // Firefox 3.0.x
eval ( 'aObserver.' + dragExitFunctionName + ' = ' +
aObserver [ dragExitFunctionName ] . toSource ( ) . replace (
2007-11-14 12:31:14 +00:00
/(this.mTabDropIndicatorBar\.[^;]+;)/ ,
2007-11-14 19:34:36 +00:00
'$1; this.treeStyleTab.clearDropPosition();'
2007-11-14 12:31:14 +00:00
)
) ;
2008-10-02 01:32:31 +00:00
var dropFunctionName = '_onDrop' in aObserver ?
'_onDrop' : // Firefox 3.1 or later
'onDrop' ; // Firefox 3.0.x
eval ( 'aObserver.' + dropFunctionName + ' = ' +
aObserver [ dropFunctionName ] . toSource ( ) . replace (
2007-11-14 12:31:14 +00:00
'{' ,
< > < ! [ CDATA [
{
var TSTTabBrowser = this ;
2007-11-14 19:34:36 +00:00
TSTTabBrowser . treeStyleTab . clearDropPosition ( ) ;
2008-10-02 01:32:31 +00:00
var dropActionInfo = TSTTabBrowser . treeStyleTab . getDropAction ( aEvent , TST _DRAGSESSION ) ;
2007-11-14 12:31:14 +00:00
] ] > < / >
2008-02-22 20:59:55 +00:00
) . replace ( // Firefox 2
2007-11-14 12:31:14 +00:00
/(if \(aDragSession[^\)]+\) \{)/ ,
2008-02-22 20:59:55 +00:00
< > < ! [ CDATA [ $1
2008-10-17 17:16:16 +00:00
if ( TSTTabBrowser . treeStyleTab . performDrop ( dropActionInfo , TST _DRAGSESSION . sourceNode ) )
2007-11-14 12:31:14 +00:00
return ;
] ] > < / >
2008-10-02 01:32:31 +00:00
) . replace ( // Firefox 3.0.x, 3.1 or later
/(if \((accelKeyPressed|isCopy|dropEffect == "copy")\) {)/ ,
2008-02-22 20:59:55 +00:00
< > < ! [ CDATA [
2008-10-17 17:16:16 +00:00
if ( TSTTabBrowser . treeStyleTab . performDrop ( dropActionInfo , draggedTab ) )
2008-02-22 20:59:55 +00:00
return ;
2008-09-26 14:26:17 +00:00
$1 ] ] > < / >
2008-02-22 20:59:55 +00:00
) . replace ( // Firefox 3, duplication of tab
2008-12-03 18:26:32 +00:00
/(this.selectedTab = newTab;)(\s*\})?/g ,
2008-02-22 20:59:55 +00:00
< > < ! [ CDATA [ $1 ;
if ( dropActionInfo . position == TreeStyleTabService . kDROP _ON )
TSTTabBrowser . treeStyleTab . attachTabTo ( newTab , dropActionInfo . target ) ;
2008-12-03 18:26:32 +00:00
$2 ] ] > < / >
2008-02-24 08:11:17 +00:00
) . replace ( // Firefox 3, dragging tab from another window
'else if (draggedTab) {' ,
< > < ! [ CDATA [ $ &
2008-10-17 17:16:16 +00:00
if ( TSTTabBrowser . treeStyleTab . performDrop ( dropActionInfo , draggedTab ) )
2008-02-24 08:11:17 +00:00
return ;
] ] > < / >
2007-11-14 12:31:14 +00:00
) . replace (
/(this.loadOneTab\([^;]+\));/ ,
< > < ! [ CDATA [
2008-10-17 17:16:16 +00:00
TSTTabBrowser . treeStyleTab . performDrop ( dropActionInfo , $1 ) ;
2007-11-14 12:31:14 +00:00
return ;
] ] > < / >
) . replace (
'document.getBindingParent(aEvent.originalTarget).localName != "tab"' ,
'!TreeStyleTabService.getTabFromEvent(aEvent)'
) . replace (
'var tab = aEvent.target;' ,
2009-01-24 05:39:22 +00:00
< > < ! [ CDATA [ $ &
2007-11-14 12:31:14 +00:00
if (
tab . getAttribute ( 'locked' ) == 'true' || // Tab Mix Plus
TreeStyleTabService . getTreePref ( 'loadDroppedLinkToNewChildTab' ) ||
dropActionInfo . position != TreeStyleTabService . kDROP _ON
) {
2008-10-17 17:16:16 +00:00
TSTTabBrowser . treeStyleTab . performDrop ( dropActionInfo , TSTTabBrowser . loadOneTab ( getShortcutOrURI ( url ) , null , null , null , bgLoad , false ) ) ;
2007-11-14 12:31:14 +00:00
return ;
}
] ] > < / >
2008-10-02 01:32:31 +00:00
) . replace (
/TST_DRAGSESSION/g ,
( canDropFunctionName == 'canDrop' ?
'aDragSession' :
'TSTTabBrowser.treeStyleTab.getCurrentDragSession()'
)
2007-11-14 12:31:14 +00:00
)
) ;
} ,
2007-10-21 15:02:58 +00:00
overrideGlobalFunctions : function ( )
{
2008-09-26 14:13:29 +00:00
// window.__treestyletab__BrowserCustomizeToolbar = window.BrowserCustomizeToolbar;
// window.BrowserCustomizeToolbar = function() {
// TreeStyleTabService.destroyBar();
// window.__treestyletab__BrowserCustomizeToolbar.call(window);
// };
var toolbox = document . getElementById ( 'browser-toolbox' ) || // Firefox 3
document . getElementById ( 'navigator-toolbox' ) ; // Firefox 2
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 ( ) ;
} ;
}
2008-10-14 16:40:05 +00:00
this . initBar ( ) ;
2008-09-26 14:13:29 +00:00
2007-10-21 15:50:11 +00:00
var funcs ;
2008-02-22 03:05:52 +00:00
var func ;
2008-02-26 13:21:07 +00:00
var overwriteProcess ;
overwriteProcess = function ( aName ) {
var overwroteFunc ;
eval ( 'overwroteFunc = ' + aName ) ;
2008-09-26 14:13:29 +00:00
if (
! overwroteFunc ||
overwroteFunc . toSource ( ) . indexOf ( 'function BrowserLoadURL' ) != 0
2008-02-26 13:21:07 +00:00
)
2008-09-26 14:13:29 +00:00
return ;
eval ( aName + ' = ' + overwroteFunc . toSource ( ) . replace (
'aTriggeringEvent && aTriggeringEvent.altKey' ,
'TreeStyleTabService.checkReadyToOpenNewTabOnLocationBar(url, $&)'
) ) ;
2008-02-26 13:21:07 +00:00
} ;
overwriteProcess ( 'window.BrowserLoadURL' ) ;
if ( 'permaTabs' in window &&
'window.BrowserLoadURL' in permaTabs . utils . wrappedFunctions )
overwriteProcess ( 'permaTabs.utils.wrappedFunctions["window.BrowserLoadURL"]' ) ;
2007-10-21 15:50:11 +00:00
2007-10-26 11:24:59 +00:00
2007-10-21 15:02:58 +00:00
eval ( 'nsContextMenu.prototype.openLinkInTab = ' +
nsContextMenu . prototype . openLinkInTab . toSource ( ) . replace (
'{' ,
2008-02-27 01:26:38 +00:00
< > < ! [ CDATA [ $ &
TreeStyleTabService . readyToOpenChildTab ( this . target . ownerDocument . defaultView ) ;
2007-10-21 15:02:58 +00:00
] ] > < / >
)
) ;
eval ( 'nsContextMenu.prototype.openFrameInTab = ' +
nsContextMenu . prototype . openFrameInTab . toSource ( ) . replace (
'{' ,
2008-02-27 01:26:38 +00:00
< > < ! [ CDATA [ $ &
TreeStyleTabService . readyToOpenChildTab ( this . target . ownerDocument . defaultView ) ;
2007-10-21 15:02:58 +00:00
] ] > < / >
)
) ;
2008-11-07 04:38:21 +00:00
var viewImageMethod = ( 'viewImage' in nsContextMenu . prototype ) ? 'viewImage' : 'viewMedia' ;
eval ( 'nsContextMenu.prototype.' + viewImageMethod + ' = ' +
nsContextMenu . prototype [ viewImageMethod ] . toSource ( ) . replace (
2007-10-22 22:45:35 +00:00
'openUILink(' ,
< > < ! [ CDATA [
if ( String ( whereToOpenLink ( e , false , true ) ) . indexOf ( 'tab' ) == 0 )
TreeStyleTabService . readyToOpenChildTab ( this . target . ownerDocument . defaultView ) ;
2008-02-27 01:26:38 +00:00
$ & ] ] > < / >
2007-10-22 22:45:35 +00:00
)
) ;
eval ( 'nsContextMenu.prototype.viewBGImage = ' +
nsContextMenu . prototype . viewBGImage . toSource ( ) . replace (
'openUILink(' ,
< > < ! [ CDATA [
if ( String ( whereToOpenLink ( e , false , true ) ) . indexOf ( 'tab' ) == 0 )
TreeStyleTabService . readyToOpenChildTab ( this . target . ownerDocument . defaultView ) ;
2008-02-27 01:26:38 +00:00
$ & ] ] > < / >
2007-10-22 22:45:35 +00:00
)
) ;
eval ( 'nsContextMenu.prototype.addDictionaries = ' +
nsContextMenu . prototype . addDictionaries . toSource ( ) . replace (
'openUILinkIn(' ,
< > < ! [ CDATA [
if ( where . indexOf ( 'tab' ) == 0 )
TreeStyleTabService . readyToOpenChildTab ( this . target . ownerDocument . defaultView ) ;
2008-02-27 01:26:38 +00:00
$ & ] ] > < / >
2007-10-22 22:45:35 +00:00
)
) ;
2007-10-21 15:02:58 +00:00
2008-02-26 01:14:12 +00:00
funcs = 'handleLinkClick __splitbrowser__handleLinkClick __ctxextensions__handleLinkClick __treestyletab__highlander__origHandleLinkClick' . split ( ' ' ) ;
2007-10-21 15:50:11 +00:00
for ( var i in funcs )
{
2008-11-14 08:10:33 +00:00
if ( ! ( funcs [ i ] in window ) ||
! /^function handleLinkClick/ . test ( window [ funcs [ i ] ] . toString ( ) ) )
continue ;
eval ( 'window.' + funcs [ i ] + ' = ' +
window [ funcs [ i ] ] . toSource ( ) . 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 (
2009-01-22 15:03:58 +00:00
/ * <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> * /
2008-11-14 08:10:33 +00:00
'return false;case 1:' ,
< > < ! [ CDATA [
if ( ! ( 'TMP_contentAreaClick' in window ) && // do nothing for Tab Mix Plus
TreeStyleTabService . checkToOpenChildTab ( ) ) {
TreeStyleTabService . stopToOpenChildTab ( ) ;
2009-01-22 15:03:58 +00:00
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 ) ;
}
2008-11-14 08:10:33 +00:00
}
return false ;
case 1 :
] ] > < / >
)
) ;
break ;
2007-10-21 15:50:11 +00:00
}
2007-10-21 15:02:58 +00:00
2007-11-15 12:24:12 +00:00
funcs = 'contentAreaClick __contentAreaClick __ctxextensions__contentAreaClick' . split ( ' ' ) ;
2008-02-26 13:21:07 +00:00
overwriteProcess = function ( aName ) {
var overwroteFunc ;
eval ( 'overwroteFunc = ' + aName ) ;
2008-02-27 01:16:01 +00:00
if ( overwroteFunc . toSource ( ) . indexOf ( 'function contentAreaClick' ) != 0 ) return ;
2008-02-26 13:21:07 +00:00
eval ( aName + ' = ' +
overwroteFunc . toSource ( ) . replace (
2008-09-27 15:26:20 +00:00
/((openWebPanel\([^\;]+\);|PlacesUIUtils.showMinimalAddBookmarkUI\([^;]+\);)event.preventDefault\(\);return false;\})/ ,
2008-02-26 13:21:07 +00:00
< > < ! [ CDATA [
$1
else if ( ! ( 'TMP_contentAreaClick' in window ) && // do nothing for Tab Mix Plus
TreeStyleTabService . checkReadyToOpenNewTab ( {
uri : wrapper . href ,
external : {
newTab : TreeStyleTabService . getTreePref ( 'openOuterLinkInNewTab' ) || TreeStyleTabService . getTreePref ( 'openAnyLinkInNewTab' ) ,
forceChild : true
} ,
internal : {
newTab : TreeStyleTabService . getTreePref ( 'openAnyLinkInNewTab' )
}
} ) ) {
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
handleLinkClick ( event , wrapper . href , linkNode ) ;
return true ;
}
] ] > < / >
)
) ;
} ;
2007-10-28 17:16:48 +00:00
for ( var i in funcs )
{
2008-02-26 13:21:07 +00:00
if ( funcs [ i ] in window && window [ funcs [ i ] ] )
overwriteProcess ( 'window.' + funcs [ i ] ) ;
2007-10-28 17:16:48 +00:00
}
2008-02-26 13:21:07 +00:00
if ( 'permaTabs' in window &&
'window.contentAreaClick' in permaTabs . utils . wrappedFunctions )
overwriteProcess ( 'permaTabs.utils.wrappedFunctions["window.contentAreaClick"]' ) ;
2007-10-28 17:16:48 +00:00
2007-10-21 15:50:11 +00:00
funcs = 'gotoHistoryIndex BrowserForward BrowserBack __rewindforward__BrowserForward __rewindforward__BrowserBack' . split ( ' ' ) ;
for ( var i in funcs )
{
2007-10-28 16:07:10 +00:00
if ( funcs [ i ] in window &&
2008-11-17 03:14:57 +00:00
window [ funcs [ i ] ] &&
2007-10-28 16:07:10 +00:00
/^function (gotoHistoryIndex|BrowserForward|BrowserBack)/ . test ( window [ funcs [ i ] ] . toString ( ) ) )
2007-10-21 15:50:11 +00:00
eval ( 'window.' + funcs [ i ] + ' = ' +
window [ funcs [ i ] ] . toSource ( ) . replace (
2008-02-27 01:26:38 +00:00
/(openUILinkIn\()/g ,
2007-10-21 15:50:11 +00:00
< > < ! [ CDATA [
if ( where == 'tab' || where == 'tabshifted' )
TreeStyleTabService . readyToOpenChildTab ( ) ;
2008-02-27 01:26:38 +00:00
$1 ] ] > < / >
2007-10-21 15:50:11 +00:00
)
) ;
}
2007-10-21 15:02:58 +00:00
2008-02-22 03:05:52 +00:00
func = 'BrowserGoHome' in window ? 'BrowserGoHome' : 'BrowserHomeClick' ;
2008-02-26 13:21:07 +00:00
overwriteProcess = function ( aName , aFunc ) {
var overwroteFunc ;
eval ( 'overwroteFunc = ' + aName ) ;
2008-02-27 01:16:01 +00:00
if ( overwroteFunc . toSource ( ) . indexOf ( 'function ' + func ) != 0 ) return ;
2008-02-26 13:21:07 +00:00
eval ( aName + ' = ' +
overwroteFunc . toSource ( ) . replace (
'gBrowser.loadTabs(' ,
< > < ! [ CDATA [
TreeStyleTabService . readyToOpenNewTabGroup ( gBrowser ) ;
2008-02-27 01:26:38 +00:00
$ & ] ] > < / >
2008-02-26 13:21:07 +00:00
)
) ;
} ;
overwriteProcess ( 'window.' + func ) ;
if ( 'permaTabs' in window &&
'window.BrowserHomeClick' in permaTabs . utils . wrappedFunctions )
overwriteProcess ( 'permaTabs.utils.wrappedFunctions["window.BrowserHomeClick"]' ) ;
2007-10-22 22:45:35 +00:00
eval ( 'FeedHandler.loadFeed = ' +
FeedHandler . loadFeed . toSource ( ) . replace (
'openUILink(' ,
< > < ! [ CDATA [
if ( String ( whereToOpenLink ( event , false , true ) ) . indexOf ( 'tab' ) == 0 )
TreeStyleTabService . readyToOpenChildTab ( gBrowser ) ;
2008-02-27 01:26:38 +00:00
$ & ] ] > < / >
2007-10-22 22:45:35 +00:00
)
) ;
2008-06-17 11:57:29 +00:00
// Firefox 3 full screen
if ( 'FullScreen' in window && '_animateUp' in FullScreen ) {
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' ) {
treeStyleTab . autoHideMode = treeStyleTab . getTreePref ( window . fullScreen ? 'tabbar.autoHide.mode' : 'tabbar.autoHide.mode.fullscreen' ) ;
treeStyleTab . endAutoHide ( ) ;
2008-09-18 02:57:25 +00:00
if ( window . fullScreen )
treeStyleTab . checkTabsIndentOverflow ( ) ;
2008-06-17 11:57:29 +00:00
if ( treeStyleTab . autoHideMode != treeStyleTab . kAUTOHIDE _MODE _DISABLED )
treeStyleTab . startAutoHide ( ) ;
}
] ] >
)
) ;
}
2007-10-21 15:02:58 +00:00
} ,
2008-09-26 14:13:29 +00: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, $&)'
) ) ;
}
} ,
2008-10-14 17:48:19 +00:00
2007-10-16 17:22:28 +00:00
destroy : function ( )
{
2007-11-14 19:34:36 +00:00
window . removeEventListener ( 'unload' , this , false ) ;
2007-11-08 14:24:54 +00:00
2007-10-16 17:22:28 +00:00
this . destroyTabBrowser ( gBrowser ) ;
2008-03-08 08:57:17 +00:00
this . endListenKeyEvents ( ) ;
2007-10-22 09:59:43 +00:00
document . getElementById ( 'contentAreaContextMenu' ) . removeEventListener ( 'popupshowing' , this , false ) ;
2007-11-14 15:09:47 +00:00
var appcontent = document . getElementById ( 'appcontent' ) ;
appcontent . removeEventListener ( 'SubBrowserAdded' , this , false ) ;
appcontent . removeEventListener ( 'SubBrowserRemoveRequest' , this , false ) ;
2007-10-16 17:22:28 +00:00
this . removePrefListener ( this ) ;
} ,
2008-11-10 04:48:11 +00:00
2007-10-16 17:22:28 +00:00
destroyTabBrowser : function ( aTabBrowser )
{
2007-11-14 19:34:36 +00:00
if ( aTabBrowser . localName != 'tabbrowser' ) return ;
aTabBrowser . treeStyleTab . destroy ( ) ;
delete aTabBrowser . treeStyleTab ;
2007-10-16 17:22:28 +00:00
} ,
/* Event Handling */
2008-09-26 14:13:29 +00:00
2007-10-16 17:22:28 +00:00
handleEvent : function ( aEvent )
{
switch ( aEvent . type )
{
2008-02-26 01:14:12 +00:00
case 'DOMContentLoaded' :
this . preInit ( ) ;
return ;
2007-10-16 17:22:28 +00:00
case 'load' :
2007-11-14 19:34:36 +00:00
this . init ( ) ;
2007-10-18 17:11:03 +00:00
return ;
2007-10-16 17:22:28 +00:00
case 'unload' :
this . destroy ( ) ;
2007-10-18 17:11:03 +00:00
return ;
2007-10-16 17:22:28 +00:00
2008-11-10 04:48:11 +00:00
case 'SSTabRestoring' :
this . onTabRestored ( aEvent ) ;
return ;
2007-10-16 17:22:28 +00:00
case 'popupshowing' :
2007-10-22 09:59:43 +00:00
if ( aEvent . target != aEvent . currentTarget ) return ;
2007-11-14 19:34:36 +00:00
this . initContextMenu ( ) ;
2007-10-18 17:11:03 +00:00
return ;
2007-10-17 13:25:50 +00:00
2008-03-08 08:57:17 +00:00
case 'keydown' :
this . onKeyDown ( aEvent ) ;
return ;
case 'keyup' :
case 'keypress' :
this . onKeyRelease ( aEvent ) ;
return ;
2007-10-17 13:25:50 +00:00
case 'SubBrowserAdded' :
this . initTabBrowser ( aEvent . originalTarget . browser ) ;
2007-10-18 17:11:03 +00:00
return ;
2007-10-17 13:25:50 +00:00
case 'SubBrowserRemoveRequest' :
this . destroyTabBrowser ( aEvent . originalTarget . browser ) ;
2007-10-18 17:11:03 +00:00
return ;
2007-10-16 17:22:28 +00:00
}
} ,
2008-11-10 04:48:11 +00:00
2008-03-08 08:57:17 +00:00
onKeyDown : function ( aEvent )
{
var b = this . browser ;
if ( ! b || ! b . treeStyleTab ) return ;
var sv = b . treeStyleTab ;
2008-03-09 06:36:52 +00:00
if ( this . delayedAutoShowDone )
this . cancelDelayedAutoShow ( ) ;
2008-03-08 08:57:17 +00:00
2008-10-17 12:35:55 +00:00
this . accelKeyPressed = this . isAccelKeyPressed ( aEvent ) ;
2008-03-08 08:57:17 +00:00
if (
2009-01-24 05:39:22 +00:00
this . getTabs ( b ) . snapshotLength > 1 &&
2008-03-08 08:57:17 +00:00
! aEvent . altKey &&
2008-03-09 12:34:10 +00:00
this . accelKeyPressed
2008-03-08 08:57:17 +00:00
) {
2008-09-26 14:13:29 +00:00
if ( this . getTreePref ( 'tabbar.autoShow.accelKeyDown' ) &&
! sv . autoHideShown &&
2008-03-11 04:16:55 +00:00
! this . delayedAutoShowTimer ) {
2008-03-09 06:36:52 +00:00
this . delayedAutoShowTimer = window . setTimeout (
function ( aSelf ) {
aSelf . delayedAutoShowDone = true ;
sv . showTabbar ( sv . kSHOWN _BY _SHORTCUT ) ;
} ,
2008-03-09 12:18:58 +00:00
this . getTreePref ( 'tabbar.autoShow.accelKeyDown.delay' ) ,
2008-03-09 06:36:52 +00:00
this
) ;
this . delayedAutoShowDone = false ;
2008-03-08 08:57:17 +00:00
}
}
2008-03-09 12:18:58 +00:00
else {
2008-03-09 06:36:52 +00:00
sv . hideTabbar ( ) ;
2008-03-09 12:18:58 +00:00
}
2008-03-08 08:57:17 +00:00
} ,
cancelDelayedAutoShow : function ( )
{
if ( this . delayedAutoShowTimer ) {
2008-03-11 04:16:55 +00:00
window . clearTimeout ( this . delayedAutoShowTimer ) ;
2008-03-08 08:57:17 +00:00
this . delayedAutoShowTimer = null ;
}
} ,
delayedAutoShowTimer : null ,
2008-03-09 06:36:52 +00:00
delayedAutoShowDone : true ,
2008-03-09 12:18:58 +00:00
accelKeyPressed : false ,
2008-03-08 10:07:28 +00:00
2008-03-08 08:57:17 +00:00
onKeyRelease : function ( aEvent )
{
var b = this . browser ;
if ( ! b || ! b . treeStyleTab ) return ;
var sv = b . treeStyleTab ;
this . cancelDelayedAutoShow ( ) ;
var scrollDown ,
scrollUp ;
2008-10-17 12:35:55 +00:00
this . accelKeyPressed = this . isAccelKeyPressed ( aEvent ) ;
2008-03-09 12:34:10 +00:00
2008-10-17 12:35:55 +00:00
var standBy = scrollDown = scrollUp = ( ! aEvent . altKey && this . isAccelKeyPressed ( aEvent ) ) ;
2008-03-08 08:57:17 +00: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 14:04:50 +00:00
sv . autoHideShown &&
2008-03-08 08:57:17 +00:00
standBy && ! aEvent . shiftKey &&
aEvent . charCode == 0 && aEvent . keyCode == 16
)
) {
2008-03-09 12:34:10 +00:00
if ( this . getTreePref ( 'tabbar.autoShow.tabSwitch' ) )
sv . showTabbar ( sv . kSHOWN _BY _SHORTCUT ) ;
2008-03-08 08:57:17 +00:00
return ;
}
2008-03-09 06:36:52 +00:00
if ( sv . showHideTabbarReason == sv . kSHOWN _BY _SHORTCUT )
sv . hideTabbar ( ) ;
2008-03-08 08:57:17 +00:00
} ,
2008-09-26 14:13:29 +00:00
2008-03-08 08:57:17 +00:00
keyEventListening : false ,
startListenKeyEvents : function ( )
{
if ( this . keyEventListening ) return ;
window . addEventListener ( 'keydown' , this , true ) ;
window . addEventListener ( 'keyup' , this , true ) ;
window . addEventListener ( 'keypress' , this , true ) ;
this . keyEventListening = true ;
} ,
2007-10-16 17:22:28 +00:00
2008-03-08 08:57:17 +00:00
endListenKeyEvents : function ( )
{
if ( ! this . keyEventListening ) return ;
window . removeEventListener ( 'keydown' , this , true ) ;
window . removeEventListener ( 'keyup' , this , true ) ;
window . removeEventListener ( 'keypress' , this , true ) ;
this . keyEventListening = false ;
} ,
2007-11-14 19:34:36 +00:00
onTabbarResized : function ( aEvent )
2007-10-16 17:22:28 +00:00
{
2008-06-17 06:22:49 +00:00
var b = this . getTabBrowserFromChild ( aEvent . currentTarget ) ;
2008-06-17 12:55:05 +00:00
if ( ! b . treeStyleTab . tabbarExpanded )
2008-06-17 06:22:49 +00:00
this . setTreePref ( 'tabbar.shrunkenWidth' , b . mStrip . boxObject . width ) ;
else
this . setTreePref ( 'tabbar.width' , b . mStrip . boxObject . width ) ;
2007-10-16 17:22:28 +00:00
} ,
2007-11-14 19:34:36 +00:00
initContextMenu : function ( )
2007-10-18 18:20:54 +00:00
{
2007-11-14 19:34:36 +00: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 18:20:54 +00:00
}
2007-11-14 19:34:36 +00:00
else {
item . setAttribute ( 'hidden' , true ) ;
sep . setAttribute ( 'hidden' , true ) ;
2007-10-20 16:47:08 +00:00
}
} ,
2008-10-14 17:48:19 +00:00
showHideSubTreeMenuItem : function ( aMenuItem , aTabs )
2007-10-20 16:47:08 +00:00
{
2007-11-14 19:34:36 +00:00
if ( ! aMenuItem ||
aMenuItem . getAttribute ( 'hidden' ) == 'true' ||
! aTabs ||
! aTabs . length )
2007-11-12 15:29:12 +00:00
return ;
2007-10-20 16:47:08 +00:00
2007-11-14 19:34:36 +00:00
var hasSubTree = false ;
for ( var i = 0 , maxi = aTabs . length ; i < maxi ; i ++ )
2007-10-20 16:47:08 +00:00
{
2008-04-29 18:17:44 +00:00
if ( ! this . hasChildTabs ( aTabs [ i ] ) ) continue ;
2007-11-14 19:34:36 +00:00
hasSubTree = true ;
2007-10-20 16:47:08 +00:00
break ;
}
2007-11-14 19:34:36 +00:00
if ( hasSubTree )
aMenuItem . removeAttribute ( 'hidden' ) ;
else
aMenuItem . setAttribute ( 'hidden' , true ) ;
2007-10-20 16:47:08 +00:00
} ,
2008-11-10 04:48:11 +00: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 ) ;
if ( b ) b . treeStyleTab . restoreStructure ( aTab ) ;
}
catch ( e ) {
}
} , this ) ;
this . _restoringTabs = [ ] ;
} ,
2007-11-14 19:34:36 +00:00
/* Commands */
2008-11-10 04:48:11 +00:00
2007-11-26 14:51:59 +00:00
removeTabSubTree : function ( aTabOrTabs , aOnlyChildren )
2007-10-20 02:44:14 +00:00
{
var tabs = aTabOrTabs ;
if ( ! ( tabs instanceof Array ) ) {
tabs = [ aTabOrTabs ] ;
}
2007-11-17 13:32:41 +00:00
var b = this . getTabBrowserFromChild ( tabs [ 0 ] ) ;
2007-10-20 02:44:14 +00:00
var descendant = [ ] ;
for ( var i = 0 , maxi = tabs . length ; i < maxi ; i ++ )
{
2007-11-14 19:34:36 +00:00
descendant = descendant . concat ( b . treeStyleTab . getDescendantTabs ( tabs [ i ] ) ) ;
2007-10-20 02:44:14 +00:00
}
2007-11-26 14:51:59 +00:00
if ( aOnlyChildren )
tabs = this . cleanUpTabsArray ( descendant ) ;
else
tabs = this . cleanUpTabsArray ( tabs . concat ( descendant ) ) ;
2007-10-20 02:44:14 +00:00
var max = tabs . length ;
if ( ! max ) return ;
2008-10-14 14:45:57 +00:00
b . _ _treestyletab _ _closedTabsNum = max ;
2007-10-20 02:44:14 +00:00
if (
max > 1 &&
2008-10-14 14:45:57 +00:00
! b . warnAboutClosingTabs ( true )
) {
b . _ _treestyletab _ _closedTabsNum = 0 ;
2007-10-20 02:44:14 +00:00
return ;
2008-10-14 14:45:57 +00:00
}
b . _ _treestyletab _ _closedTabsNum = 0 ;
2007-10-20 02:44:14 +00:00
for ( var i = tabs . length - 1 ; i > - 1 ; i -- )
{
b . removeTab ( tabs [ i ] ) ;
}
} ,
2008-11-10 04:48:11 +00:00
2007-11-14 19:34:36 +00:00
cleanUpTabsArray : function ( aTabs )
{
2007-11-17 13:32:41 +00:00
var b = this . getTabBrowserFromChild ( aTabs [ 0 ] ) ;
2007-11-14 19:34:36 +00:00
2008-10-17 12:35:55 +00:00
aTabs = aTabs . map ( function ( aTab ) {
return aTab . getAttribute ( this . kID ) ;
} , this ) ;
2007-11-14 19:34:36 +00:00
aTabs . sort ( ) ;
aTabs = aTabs . join ( '|' ) . replace ( /([^\|]+)(\|\1)+/g , '$1' ) . split ( '|' ) ;
for ( var i = 0 , maxi = aTabs . length ; i < maxi ; i ++ )
{
aTabs [ i ] = b . treeStyleTab . getTabById ( aTabs [ i ] ) ;
}
return aTabs ;
} ,
2008-10-14 17:48:19 +00:00
bookmarkTabSubTree : function ( aTabOrTabs )
{
var tabs = aTabOrTabs ;
if ( ! ( tabs instanceof Array ) ) {
tabs = [ aTabOrTabs ] ;
}
var b = this . getTabBrowserFromChild ( tabs [ 0 ] ) ;
var bookmarkedTabs = [ ] ;
for ( var i = 0 , maxi = tabs . length ; i < maxi ; i ++ )
{
bookmarkedTabs . push ( tabs [ i ] ) ;
bookmarkedTabs = bookmarkedTabs . concat ( b . treeStyleTab . getDescendantTabs ( tabs [ i ] ) ) ;
}
if ( 'MultipleTabService' in window &&
'addBookmarkFor' in MultipleTabService ) {
MultipleTabService . addBookmarkFor ( bookmarkedTabs ) ;
}
this . _addBookmarkFor ( bookmarkedTabs ) ;
} ,
2008-11-10 04:48:11 +00:00
2008-10-14 17:48:19 +00:00
_addBookmarkFor : function ( aTabs ) // from Multiple Tab Handler
{
if ( ! aTabs ) return ;
var b = this . getTabBrowserFromChild ( aTabs [ 0 ] ) ;
if ( 'PlacesUIUtils' in window || 'PlacesUtils' in window ) { // Firefox 3
var utils = 'PlacesUIUtils' in window ? PlacesUIUtils : PlacesUtils ;
2008-10-15 10:12:51 +00:00
utils . showMinimalAddMultiBookmarkUI ( Array . slice ( aTabs ) . map ( this . addBookmarkTabsFilter ) ) ;
2008-10-14 17:48:19 +00:00
return ;
}
var currentTabInfo ;
var tabsInfo = Array . slice ( aTabs ) . map ( function ( aTab ) {
var webNav = aTab . linkedBrowser . webNavigation ;
var url = webNav . currentURI . spec ;
var name = '' ;
var charSet , description ;
try {
var doc = webNav . document ;
name = doc . title || url ;
charSet = doc . characterSet ;
description = BookmarksUtils . getDescriptionFromDocument ( doc ) ;
}
catch ( e ) {
name = url ;
}
return {
name : name ,
url : url ,
charset : charSet ,
description : description
} ;
} ) ;
window . openDialog (
'chrome://browser/content/bookmarks/addBookmark2.xul' ,
'' ,
BROWSER _ADD _BM _FEATURES ,
( aTabs . length == 1 ?
tabsInfo [ 0 ] :
{
name : gNavigatorBundle . getString ( 'bookmarkAllTabsDefault' ) ,
bBookmarkAllTabs : true ,
objGroup : tabsInfo
}
)
) ;
} ,
2008-10-15 10:12:51 +00:00
addBookmarkTabsFilter : function ( aTab )
{
return aTab . linkedBrowser . currentURI ;
} ,
2008-11-10 04:48:11 +00:00
2009-02-11 13:41:32 +00:00
openSelectionLinks : function ( aFrame )
2007-10-22 09:59:43 +00:00
{
2009-02-11 13:41:32 +00:00
aFrame = this . getCurrentFrame ( aFrame ) ;
2007-10-22 09:59:43 +00:00
var b = this . browser ;
2009-02-11 13:41:32 +00:00
var links = this . getSelectionLinks ( aFrame ) ;
if ( ! links . length ) return ;
2007-10-22 09:59:43 +00:00
2009-02-11 13:41:32 +00:00
var referrer = this . makeURIFromSpec ( aFrame . location . href ) ;
2007-10-22 09:59:43 +00:00
2009-02-11 13:41:32 +00:00
this . readyToOpenChildTab ( aFrame , true ) ;
links . forEach ( function ( aLink , aIndex ) {
var tab = b . addTab ( aLink . href , referrer ) ;
2008-10-17 12:35:55 +00:00
if ( aIndex == 0 && ! this . getPref ( 'browser.tabs.loadInBackground' ) )
2007-10-22 09:59:43 +00:00
b . selectedTab = tab ;
2008-10-17 12:35:55 +00:00
} , this ) ;
2009-02-11 13:41:32 +00:00
this . stopToOpenChildTab ( aFrame ) ;
2007-10-22 09:59:43 +00:00
} ,
2007-11-17 05:20:26 +00:00
2009-02-11 13:41:32 +00:00
getCurrentFrame : function ( aFrame )
2007-10-22 09:59:43 +00:00
{
2009-02-11 13:41:32 +00:00
if ( aFrame ) return aFrame ;
2007-10-22 09:59:43 +00:00
var targetWindow = document . commandDispatcher . focusedWindow ;
if ( ! targetWindow || targetWindow . top == window )
targetWindow = this . browser . contentWindow ;
2009-02-11 13:41:32 +00:00
return targetWindow ;
} ,
getSelectionLinks : function ( aFrame )
{
aFrame = this . getCurrentFrame ( aFrame ) ;
2007-10-22 09:59:43 +00:00
2009-02-11 13:41:32 +00:00
var links = [ ] ;
var selection = aFrame . getSelection ( ) ;
2007-10-22 09:59:43 +00:00
if ( ! selection || ! selection . rangeCount )
return links ;
2009-02-11 13:41:32 +00:00
for ( var i = 0 , maxi = selection . rangeCount ; i < maxi ; i ++ )
2007-10-22 09:59:43 +00:00
{
2009-02-11 13:41:32 +00:00
links = links . concat ( this . getLinksInRange ( selection . getRangeAt ( i ) ) ) ;
2007-10-22 09:59:43 +00:00
}
return links ;
} ,
2008-11-10 04:48:11 +00:00
2009-02-11 13:41:32 +00:00
getLinksInRange : function ( aRange )
2007-10-22 09:59:43 +00:00
{
2009-02-11 13:41:32 +00: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 09:59:43 +00:00
2009-02-11 13:41:32 +00: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 16:52:47 +00:00
linksResult . snapshotItem ( allLinksCount - 1 ) ,
2009-02-11 13:41:32 +00: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 09:59:43 +00:00
} ,
2007-11-17 05:20:26 +00:00
collapseExpandAllSubtree : function ( aCollapse )
{
this . ObserverService . notifyObservers (
window ,
'TreeStyleTab:collapseExpandAllSubtree' ,
( aCollapse ? 'collapse' : 'open' )
) ;
} ,
2008-02-28 07:45:39 +00:00
registerAttachTabPostProcess : function ( aProcess )
{
this . _attachTabPostProcesses . push ( aProcess ) ;
} ,
_attachTabPostProcesses : [ ] ,
2008-03-02 18:16:57 +00:00
registerTabFocusAllowance : function ( aProcess )
{
this . _tabFocusAllowance . push ( aProcess ) ;
} ,
_tabFocusAllowance : [ ] ,
registerCollapseExpandPostProcess : function ( aProcess )
{
this . _collapseExpandPostProcess . push ( aProcess ) ;
} ,
_collapseExpandPostProcess : [ ] ,
2008-12-01 08:30:36 +00: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-02 01:54:16 +00:00
( remoteMultipleTabService && remoteMultipleTabService . isSelected ( remoteTab ) ) ) {
2008-12-01 08:30:36 +00:00
var remoteBrowser = remoteService . getTabBrowserFromChild ( remoteTab ) ;
2008-12-01 09:14:05 +00:00
if ( remoteBrowser . treeStyleTab . isDraggingAllTabs ( remoteTab ) ) {
2008-12-01 08:30:36 +00:00
window . close ( ) ;
}
else {
2008-12-01 09:14:05 +00:00
var actionInfo = {
action : this . kACTIONS _FOR _DESTINATION | this . kACTION _IMPORT
} ;
2008-12-01 08:30:36 +00:00
window . setTimeout ( function ( ) {
var blankTab = gBrowser . selectedTab ;
gBrowser . treeStyleTab . performDrop ( actionInfo , remoteTab ) ;
window . setTimeout ( function ( ) {
gBrowser . removeTab ( blankTab ) ;
} , 0 ) ;
} , 0 ) ;
}
return true ;
}
return false ;
} ,
2008-03-08 08:57:17 +00:00
2007-10-16 17:22:28 +00:00
/* Pref Listener */
2008-03-08 10:07:28 +00:00
2008-03-03 08:26:51 +00:00
domains : [
'extensions.treestyletab' ,
'browser.link.open_newwindow.restriction.override' ,
'browser.tabs.loadFolderAndReplace.override'
] ,
2007-10-16 17:22:28 +00:00
observe : function ( aSubject , aTopic , aPrefName )
{
if ( aTopic != 'nsPref:changed' ) return ;
var value = this . getPref ( aPrefName ) ;
switch ( aPrefName )
{
2007-10-20 08:22:42 +00:00
case 'extensions.treestyletab.levelMargin' :
2007-11-14 19:34:36 +00:00
this . baseLebelMargin = value ;
2007-10-20 08:22:42 +00:00
this . ObserverService . notifyObservers ( null , 'TreeStyleTab:levelMarginModified' , value ) ;
2007-10-16 17:22:28 +00:00
break ;
2008-06-17 06:22:49 +00:00
case 'extensions.treestyletab.tabbar.autoHide.mode' :
2008-06-17 12:55:05 +00: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 12:34:10 +00:00
case 'extensions.treestyletab.tabbar.autoShow.accelKeyDown' :
2008-03-08 08:57:17 +00:00
case 'extensions.treestyletab.tabbar.autoShow.tabSwitch' :
2008-03-09 12:34:10 +00:00
case 'extensions.treestyletab.tabbar.autoShow.feedback' :
if (
2008-06-17 12:55:05 +00:00
this . getTreePref ( 'tabbar.autoHide.mode' ) &&
2008-03-09 12:34:10 +00:00
(
this . getTreePref ( 'tabbar.autoShow.accelKeyDown' ) ||
this . getTreePref ( 'tabbar.autoShow.tabSwitch' ) ||
this . getTreePref ( 'tabbar.autoShow.feedback' )
)
2008-09-27 15:48:25 +00:00
) {
2008-03-08 08:57:17 +00:00
this . startListenKeyEvents ( ) ;
2008-09-27 15:48:25 +00:00
}
else {
2008-03-08 08:57:17 +00:00
this . endListenKeyEvents ( ) ;
2008-09-27 15:48:25 +00:00
}
window . setTimeout ( function ( ) {
2008-11-07 15:48:56 +00:00
if ( window . windowState != Components . interfaces . nsIDOMChromeWindow . STATE _NORMAL ) return ;
2008-09-27 15:48:25 +00:00
window . resizeBy ( - 1 , - 1 ) ;
window . resizeBy ( 1 , 1 ) ;
} , 0 ) ;
2008-03-08 08:57:17 +00:00
break ;
2008-06-17 10:29:16 +00:00
case 'extensions.treestyletab.tabbar.width' :
case 'extensions.treestyletab.tabbar.shrunkenWidth' :
var expanded = this . getTreePref ( 'tabbar.width' ) ;
var shrunken = this . getTreePref ( 'tabbar.shrunkenWidth' ) ;
if ( ! this . tabbarWidthResetting &&
( expanded - this . getTreePref ( 'autoHide.area' ) ) < shrunken ) {
this . tabbarWidthResetting = true ;
if ( aPrefName == 'extensions.treestyletab.tabbar.width' )
this . setTreePref ( 'tabbar.shrunkenWidth' , parseInt ( expanded / 1.2 ) ) ;
else
this . setTreePref ( 'tabbar.width' , parseInt ( shrunken * 1.2 ) ) ;
this . tabbarWidthResetting = false ;
}
break ;
2008-03-03 08:26:51 +00:00
case 'browser.link.open_newwindow.restriction.override' :
case 'browser.tabs.loadFolderAndReplace.override' :
var target = aPrefName . replace ( '.override' , '' ) ;
this . setPref ( target , this . getPref ( aPrefName ) ) ;
break ;
2008-12-03 13:17:40 +00:00
case 'extensions.treestyletab.clickOnIndentSpaces.enabled' :
this . shouldDetectClickOnIndentSpaces = this . getPref ( aPrefName ) ;
break ;
2007-10-16 17:22:28 +00:00
default :
break ;
}
} ,
/* Save/Load Prefs */
2007-10-21 08:16:10 +00:00
2007-10-16 17:22:28 +00:00
get Prefs ( )
{
if ( ! this . _Prefs ) {
this . _Prefs = Components . classes [ '@mozilla.org/preferences;1' ] . getService ( Components . interfaces . nsIPrefBranch ) ;
}
return this . _Prefs ;
} ,
_Prefs : null ,
getPref : function ( aPrefstring )
{
try {
switch ( this . Prefs . getPrefType ( aPrefstring ) )
{
case this . Prefs . PREF _STRING :
return decodeURIComponent ( escape ( this . Prefs . getCharPref ( aPrefstring ) ) ) ;
break ;
case this . Prefs . PREF _INT :
return this . Prefs . getIntPref ( aPrefstring ) ;
break ;
default :
return this . Prefs . getBoolPref ( aPrefstring ) ;
break ;
}
}
catch ( e ) {
}
return null ;
} ,
2007-10-26 11:24:59 +00:00
getTreePref : function ( aPrefstring )
{
return this . getPref ( 'extensions.treestyletab.' + aPrefstring ) ;
} ,
2007-10-16 17:22:28 +00:00
setPref : function ( aPrefstring , aNewValue )
{
var pref = this . Prefs ;
var type ;
try {
type = typeof aNewValue ;
}
catch ( e ) {
type = null ;
}
switch ( type )
{
case 'string' :
pref . setCharPref ( aPrefstring , unescape ( encodeURIComponent ( aNewValue ) ) ) ;
break ;
case 'number' :
pref . setIntPref ( aPrefstring , parseInt ( aNewValue ) ) ;
break ;
default :
pref . setBoolPref ( aPrefstring , aNewValue ) ;
break ;
}
return true ;
} ,
2007-11-09 04:07:54 +00:00
setTreePref : function ( aPrefstring , aNewValue )
{
return this . setPref ( 'extensions.treestyletab.' + aPrefstring , aNewValue ) ;
} ,
2007-10-16 17:22:28 +00:00
clearPref : function ( aPrefstring )
{
try {
this . Prefs . clearUserPref ( aPrefstring ) ;
}
catch ( e ) {
}
return ;
} ,
addPrefListener : function ( aObserver )
{
var domains = ( 'domains' in aObserver ) ? aObserver . domains : [ aObserver . domain ] ;
try {
var pbi = this . Prefs . QueryInterface ( Components . interfaces . nsIPrefBranchInternal ) ;
for ( var i = 0 ; i < domains . length ; i ++ )
pbi . addObserver ( domains [ i ] , aObserver , false ) ;
}
catch ( e ) {
}
} ,
removePrefListener : function ( aObserver )
{
var domains = ( 'domains' in aObserver ) ? aObserver . domains : [ aObserver . domain ] ;
try {
var pbi = this . Prefs . QueryInterface ( Components . interfaces . nsIPrefBranchInternal ) ;
for ( var i = 0 ; i < domains . length ; i ++ )
pbi . removeObserver ( domains [ i ] , aObserver , false ) ;
}
catch ( e ) {
}
}
} ;
2008-02-26 16:24:25 +00:00
window . addEventListener ( 'DOMContentLoaded' , TreeStyleTabService , true ) ;
2007-10-16 17:22:28 +00:00
window . addEventListener ( 'load' , TreeStyleTabService , false ) ;
2007-11-17 05:20:26 +00:00