2009-12-25 11:51:24 -05:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2009-12-25 11:38:14 -05:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Tree Style Tab.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is SHIMODA Hiroshi.
|
2011-01-10 02:02:15 -05:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010-2011
|
2009-12-25 11:38:14 -05:00
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): SHIMODA Hiroshi <piro@p.club.ne.jp>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ******/
|
2009-12-25 11:51:24 -05:00
|
|
|
|
2010-07-06 23:13:33 -04:00
|
|
|
const EXPORTED_SYMBOLS = ['TreeStyleTabUtils'];
|
2009-12-25 12:55:55 -05:00
|
|
|
|
2010-07-06 23:13:33 -04:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
2009-12-25 11:51:24 -05:00
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
Components.utils.import('resource://treestyletab-modules/lib/prefs.js');
|
|
|
|
Components.utils.import('resource://treestyletab-modules/lib/boxObject.js');
|
|
|
|
Components.utils.import('resource://treestyletab-modules/lib/stringBundle.js');
|
|
|
|
Components.utils.import('resource://treestyletab-modules/lib/extensions.js');
|
|
|
|
Components.utils.import('resource://treestyletab-modules/lib/animationManager.js');
|
|
|
|
Components.utils.import('resource://treestyletab-modules/lib/autoScroll.js');
|
|
|
|
Components.utils.import('resource://treestyletab-modules/lib/confirmWithTab.js');
|
2009-12-25 13:23:18 -05:00
|
|
|
|
2010-12-06 07:04:52 -05:00
|
|
|
Components.utils.import('resource://treestyletab-modules/lib/namespace.jsm');
|
2010-06-22 05:38:42 -04:00
|
|
|
var window = getNamespaceFor('piro.sakura.ne.jp');
|
2009-12-25 13:23:18 -05:00
|
|
|
|
2009-12-25 11:51:24 -05:00
|
|
|
var TreeStyleTabUtils = {
|
2010-03-24 11:38:08 -04:00
|
|
|
tabsHash : null,
|
2010-05-08 04:30:39 -04:00
|
|
|
inWindowDestoructionProcess : false,
|
2009-12-25 11:51:24 -05:00
|
|
|
|
2009-12-25 13:13:33 -05:00
|
|
|
/* attributes */
|
2009-12-25 12:55:55 -05:00
|
|
|
kID : 'treestyletab-id',
|
|
|
|
kCHILDREN : 'treestyletab-children',
|
|
|
|
kPARENT : 'treestyletab-parent',
|
|
|
|
kANCESTOR : 'treestyletab-ancestors',
|
|
|
|
kNEST : 'treestyletab-nest',
|
|
|
|
kINSERT_BEFORE : 'treestyletab-insert-before',
|
|
|
|
kINSERT_AFTER : 'treestyletab-insert-after',
|
2009-12-25 15:07:00 -05:00
|
|
|
kCLOSED_SET_ID : 'treestyletab-closed-set-id',
|
2009-12-25 12:55:55 -05:00
|
|
|
|
|
|
|
kID_RESTORING : 'treestyletab-id-restoring',
|
|
|
|
kCHILDREN_RESTORING : 'treestyletab-children-restoring',
|
|
|
|
|
|
|
|
kSUBTREE_COLLAPSED : 'treestyletab-subtree-collapsed',
|
|
|
|
kCOLLAPSED : 'treestyletab-collapsed',
|
|
|
|
kCOLLAPSED_DONE : 'treestyletab-collapsed-done',
|
2010-05-02 00:30:51 -04:00
|
|
|
kCOLLAPSING_PHASE : 'treestyletab-collapsing-phase',
|
|
|
|
kCOLLAPSING_PHASE_TO_BE_COLLAPSED : 'collapse',
|
|
|
|
kCOLLAPSING_PHASE_TO_BE_EXPANDED : 'expand',
|
2009-12-25 12:55:55 -05:00
|
|
|
kALLOW_COLLAPSE : 'treestyletab-allow-subtree-collapse',
|
2010-11-24 11:14:36 -05:00
|
|
|
kALLOW_STACK : 'treestyletab-stack-collapsed-tabs',
|
2010-08-07 11:46:16 -04:00
|
|
|
kREMOVED : 'treestyletab-removed',
|
2009-12-25 12:55:55 -05:00
|
|
|
|
|
|
|
kX_OFFSET : 'treestyletab-x-offset',
|
|
|
|
kY_OFFSET : 'treestyletab-y-offset',
|
|
|
|
|
|
|
|
kTABBAR_POSITION : 'treestyletab-tabbar-position',
|
|
|
|
kMODE : 'treestyletab-mode',
|
|
|
|
|
2010-03-31 06:37:41 -04:00
|
|
|
kHIDE_NEWTAB : 'treestyletab-hide-newtab-button',
|
2009-12-25 12:55:55 -05:00
|
|
|
kHIDE_ALLTABS : 'treestyletab-hide-alltabs-button',
|
|
|
|
kSTYLE : 'treestyletab-style',
|
|
|
|
kFIRSTTAB_BORDER : 'treestyletab-firsttab-border',
|
|
|
|
kFIXED : 'treestyletab-tabbar-fixed',
|
|
|
|
kRESIZING : 'treestyletab-tabbar-resizing',
|
|
|
|
kINDENTED : 'treestyletab-tabs-indented',
|
2010-11-29 05:35:47 -05:00
|
|
|
kMAX_LEVEL : 'treestyletab-max-tree-level',
|
2010-03-28 14:22:15 -04:00
|
|
|
kPRINT_PREVIEW : 'treestyletab-print-preview',
|
2010-05-02 00:30:51 -04:00
|
|
|
kANIMATION_ENABLED : 'treestyletab-animation-enabled',
|
2009-12-25 12:55:55 -05:00
|
|
|
|
|
|
|
kTAB_INVERTED : 'treestyletab-tab-inverted',
|
|
|
|
kTAB_CONTENTS_INVERTED : 'treestyletab-tab-contents-inverted',
|
|
|
|
kCLOSEBOX_INVERTED : 'treestyletab-closebox-inverted',
|
|
|
|
|
|
|
|
kTWISTY_HOVER : 'treestyletab-twisty-hover',
|
|
|
|
kTWISTY_STYLE : 'treestyletab-twisty-style',
|
|
|
|
|
|
|
|
kDROP_POSITION : 'treestyletab-drop-position',
|
|
|
|
kDRAG_TYPE_TABBAR : 'application/x-moz-treestyletab-tabbrowser-tabbar',
|
|
|
|
kDROP_POSITION_UNKNOWN : 'unknown',
|
|
|
|
kTABBAR_MOVE_FORCE : 'force',
|
|
|
|
kTABBAR_MOVE_NORMAL : 'normal',
|
2010-11-30 19:40:27 -05:00
|
|
|
|
|
|
|
/* classes */
|
|
|
|
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',
|
|
|
|
kCOUNTER_PAREN : 'treestyletab-counter-paren',
|
|
|
|
kSPLITTER : 'treestyletab-splitter',
|
|
|
|
kTABBAR_TOGGLER : 'treestyletab-tabbar-toggler',
|
|
|
|
kTABBAR_PLACEHOLDER : 'treestyletab-tabbar-placeholder',
|
|
|
|
|
2010-12-01 19:02:27 -05:00
|
|
|
/* event types, topics */
|
2010-12-20 06:54:42 -05:00
|
|
|
kEVENT_TYPE_TAB_FOCUS_SWITCHING_KEY_DOWN : 'nsDOMTreeStyleTabFocusSwitchingKeyDown',
|
|
|
|
kEVENT_TYPE_TAB_FOCUS_SWITCHING_START : 'nsDOMTreeStyleTabFocusSwitchingStart',
|
|
|
|
kEVENT_TYPE_TAB_FOCUS_SWITCHING_END : 'nsDOMTreeStyleTabFocusSwitchingEnd',
|
2011-01-09 11:40:24 -05:00
|
|
|
kTAB_FOCUS_SWITCHING_SCROLL_DOWN : (1 << 0),
|
|
|
|
kTAB_FOCUS_SWITCHING_SCROLL_UP : (1 << 1),
|
|
|
|
kTAB_FOCUS_SWITCHING_STAND_BY : (1 << 2),
|
|
|
|
kTAB_FOCUS_SWITCHING_ONLY_SHIFT_KEY : (1 << 3),
|
2010-12-20 06:54:42 -05:00
|
|
|
kEVENT_TYPE_SUBTREE_CLOSING : 'nsDOMTreeStyleTabSubtreeClosing',
|
|
|
|
kEVENT_TYPE_SUBTREE_CLOSED : 'nsDOMTreeStyleTabSubtreeClosed',
|
|
|
|
kEVENT_TYPE_TAB_COLLAPSED_STATE_CHANGED : 'nsDOMTreeStyleTabCollapsedStateChange',
|
|
|
|
kEVENT_TYPE_TABBAR_POSITION_CHANGING : 'nsDOMTreeStyleTabTabbarPositionChanging',
|
|
|
|
kEVENT_TYPE_TABBAR_POSITION_CHANGED : 'nsDOMTreeStyleTabTabbarPositionChanged',
|
|
|
|
kEVENT_TYPE_TABBAR_STATE_CHANGING : 'nsDOMTreeStyleTabTabbarStateChanging',
|
|
|
|
kEVENT_TYPE_TABBAR_STATE_CHANGED : 'nsDOMTreeStyleTabTabbarStateChanged',
|
|
|
|
kEVENT_TYPE_FOCUS_NEXT_TAB : 'nsDOMTreeStyleTabFocusNextTab',
|
|
|
|
kEVENT_TYPE_ATTACHED : 'nsDOMTreeStyleTabAttached',
|
|
|
|
kEVENT_TYPE_DETACHED : 'nsDOMTreeStyleTabParted',
|
2010-11-30 19:40:27 -05:00
|
|
|
|
2010-12-20 06:54:42 -05:00
|
|
|
kEVENT_TYPE_PRINT_PREVIEW_ENTERED : 'nsDOMTreeStyleTabPrintPreviewEntered',
|
|
|
|
kEVENT_TYPE_PRINT_PREVIEW_EXITED : 'nsDOMTreeStyleTabPrintPreviewExited',
|
|
|
|
kEVENT_TYPE_AUTO_HIDE_STATE_CHANGING : 'nsDOMTreeStyleTabAutoHideStateChanging',
|
|
|
|
kEVENT_TYPE_AUTO_HIDE_STATE_CHANGE : 'nsDOMTreeStyleTabAutoHideStateChange',
|
2010-11-30 19:33:07 -05:00
|
|
|
|
|
|
|
kTOPIC_INDENT_MODIFIED : 'TreeStyleTab:indentModified',
|
|
|
|
kTOPIC_COLLAPSE_EXPAND_ALL : 'TreeStyleTab:collapseExpandAllSubtree',
|
|
|
|
kTOPIC_CHANGE_TREEVIEW_AVAILABILITY : 'TreeStyleTab:changeTreeViewAvailability',
|
2009-12-25 12:55:55 -05:00
|
|
|
|
2009-12-25 13:13:33 -05:00
|
|
|
/* other constant values */
|
|
|
|
kFOCUS_ALL : 0,
|
|
|
|
kFOCUS_VISIBLE : 1,
|
|
|
|
|
|
|
|
kDROP_BEFORE : -1,
|
|
|
|
kDROP_ON : 0,
|
|
|
|
kDROP_AFTER : 1,
|
|
|
|
|
|
|
|
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),
|
2010-02-03 08:43:39 -05:00
|
|
|
kTABBAR_REGULAR : (1 << 0) | (1 << 2),
|
|
|
|
kTABBAR_INVERTED : (1 << 3) | (1 << 4),
|
2009-12-25 13:13:33 -05:00
|
|
|
|
|
|
|
kINSERT_FISRT : 0,
|
|
|
|
kINSERT_LAST : 1,
|
2010-04-22 05:24:21 -04:00
|
|
|
|
2010-12-03 09:50:42 -05:00
|
|
|
kTABBAR_UPDATE_BY_UNKNOWN_REASON : (1 << 0),
|
|
|
|
kTABBAR_UPDATE_BY_RESET : (1 << 1),
|
|
|
|
kTABBAR_UPDATE_BY_PREF_CHANGE : (1 << 2),
|
|
|
|
kTABBAR_UPDATE_BY_APPEARANCE_CHANGE : (1 << 3),
|
|
|
|
kTABBAR_UPDATE_BY_SHOWHIDE_TABBAR : (1 << 4),
|
|
|
|
kTABBAR_UPDATE_BY_TABBAR_RESIZE : (1 << 5),
|
|
|
|
kTABBAR_UPDATE_BY_WINDOW_RESIZE : (1 << 6),
|
|
|
|
kTABBAR_UPDATE_BY_FULLSCREEN : (1 << 7),
|
|
|
|
kTABBAR_UPDATE_BY_PRIVATE_BROWSING : (1 << 8),
|
|
|
|
kTABBAR_UPDATE_BY_AUTOHIDE : (1 << 9),
|
2011-01-07 08:08:22 -05:00
|
|
|
kTABBAR_UPDATE_BY_INITIALIZE : (1 << 10),
|
2011-01-09 22:27:02 -05:00
|
|
|
kTABBAR_UPDATE_NOW : (1 << 5) | (1 << 6) | (1 << 9) | (1 << 10),
|
2010-12-03 09:50:42 -05:00
|
|
|
kTABBAR_UPDATE_SYNC_TO_TABBAR : (1 << 0) | (1 << 1) | (1 << 2) | (1 << 5) | (1 << 8) | (1 << 9),
|
2011-01-07 08:08:22 -05:00
|
|
|
kTABBAR_UPDATE_SYNC_TO_PLACEHOLDER : (1 << 3) | (1 << 4) | (1 << 6) | (1 << 7) | (1 << 10),
|
2010-12-03 09:50:42 -05:00
|
|
|
|
2010-04-22 05:24:21 -04:00
|
|
|
MAX_TABBAR_SIZE_RATIO : 0.8,
|
|
|
|
DEFAULT_SHRUNKEN_WIDTH_RATIO : 0.67,
|
2009-12-25 13:13:33 -05:00
|
|
|
|
|
|
|
/* base variables */
|
|
|
|
baseIndent : 12,
|
|
|
|
shouldDetectClickOnIndentSpaces : true,
|
|
|
|
|
|
|
|
smoothScrollEnabled : true,
|
|
|
|
smoothScrollDuration : 150,
|
|
|
|
|
|
|
|
animationEnabled : true,
|
|
|
|
indentDuration : 200,
|
|
|
|
collapseDuration : 150,
|
|
|
|
|
2009-12-25 13:45:52 -05:00
|
|
|
shouldExpandTwistyArea : true,
|
2010-07-25 12:13:19 -04:00
|
|
|
|
|
|
|
scrollToNewTabMode : false,
|
2009-12-25 13:13:33 -05:00
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
get SessionStore() {
|
|
|
|
if (!this._SessionStore) {
|
|
|
|
this._SessionStore = Cc['@mozilla.org/browser/sessionstore;1'].getService(Ci.nsISessionStore);
|
|
|
|
}
|
|
|
|
return this._SessionStore;
|
|
|
|
},
|
|
|
|
_SessionStore : null,
|
|
|
|
|
|
|
|
get ObserverService() {
|
|
|
|
if (!this._ObserverService) {
|
|
|
|
this._ObserverService = Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
|
|
|
|
}
|
|
|
|
return this._ObserverService;
|
|
|
|
},
|
|
|
|
_ObserverService : null,
|
|
|
|
|
|
|
|
get IOService() {
|
|
|
|
if (!this._IOService) {
|
|
|
|
this._IOService = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);
|
|
|
|
}
|
|
|
|
return this._IOService;
|
|
|
|
},
|
|
|
|
_IOService : null,
|
|
|
|
|
|
|
|
get WindowMediator() {
|
|
|
|
if (!this._WindowMediator) {
|
|
|
|
this._WindowMediator = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);
|
|
|
|
}
|
|
|
|
return this._WindowMediator;
|
|
|
|
},
|
|
|
|
_WindowMediator : null,
|
|
|
|
|
|
|
|
get PromptService()
|
|
|
|
{
|
|
|
|
if (!this._PromptService) {
|
|
|
|
this._PromptService = Cc['@mozilla.org/embedcomp/prompt-service;1'].getService(Ci.nsIPromptService);
|
|
|
|
}
|
|
|
|
return this._PromptService;
|
|
|
|
},
|
|
|
|
_PromptService : null,
|
|
|
|
|
|
|
|
get XULAppInfo() {
|
|
|
|
if (!this._XULAppInfo) {
|
2010-07-29 03:14:52 -04:00
|
|
|
this._XULAppInfo = Cc['@mozilla.org/xre/app-info;1'].getService(Ci.nsIXULAppInfo).QueryInterface(Ci.nsIXULRuntime);
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
|
|
|
return this._XULAppInfo;
|
|
|
|
},
|
|
|
|
_XULAppInfo : null,
|
|
|
|
get Comparator() {
|
|
|
|
if (!this._Comparator) {
|
|
|
|
this._Comparator = Cc['@mozilla.org/xpcom/version-comparator;1'].getService(Ci.nsIVersionComparator);
|
|
|
|
}
|
|
|
|
return this._Comparator;
|
|
|
|
},
|
|
|
|
_Comparator : null,
|
|
|
|
|
2009-12-25 13:45:52 -05:00
|
|
|
get treeBundle() {
|
2010-06-22 14:00:16 -04:00
|
|
|
return window['piro.sakura.ne.jp'].stringBundle
|
2009-12-25 13:45:52 -05:00
|
|
|
.get('chrome://treestyletab/locale/treestyletab.properties');
|
|
|
|
},
|
|
|
|
get tabbrowserBundle() {
|
2010-06-22 14:00:16 -04:00
|
|
|
return window['piro.sakura.ne.jp'].stringBundle
|
2009-12-25 13:45:52 -05:00
|
|
|
.get('chrome://browser/locale/tabbrowser.properties');
|
|
|
|
},
|
|
|
|
|
2010-11-17 12:50:54 -05:00
|
|
|
get extensions() { return window['piro.sakura.ne.jp'].extensions; },
|
2010-06-22 14:00:16 -04:00
|
|
|
get animationManager() { return window['piro.sakura.ne.jp'].animationManager; },
|
|
|
|
get autoScroll() { return window['piro.sakura.ne.jp'].autoScroll; },
|
|
|
|
|
2009-12-25 11:51:24 -05:00
|
|
|
init : function TSTUtils_init()
|
2009-12-25 11:38:14 -05:00
|
|
|
{
|
|
|
|
if (this._initialized) return;
|
|
|
|
|
2010-10-24 23:06:02 -04:00
|
|
|
this.isMac = this.XULAppInfo.OS == 'Darwin';
|
|
|
|
|
|
|
|
this.applyPlatformDefaultPrefs();
|
2009-12-25 12:55:55 -05:00
|
|
|
|
2009-12-25 11:38:14 -05:00
|
|
|
this.addPrefListener(this);
|
2009-12-25 13:13:33 -05:00
|
|
|
|
|
|
|
this.onPrefChange('extensions.treestyletab.indent');
|
|
|
|
this.onPrefChange('extensions.treestyletab.clickOnIndentSpaces.enabled');
|
|
|
|
this.onPrefChange('browser.tabs.loadFolderAndReplace.override');
|
|
|
|
this.onPrefChange('browser.tabs.insertRelatedAfterCurrent.override');
|
2010-03-31 06:34:30 -04:00
|
|
|
this.onPrefChange('extensions.stm.tabBarMultiRows.override'); // Super Tab Mode
|
2009-12-25 13:13:33 -05:00
|
|
|
this.onPrefChange('extensions.treestyletab.tabbar.scroll.smooth');
|
|
|
|
this.onPrefChange('extensions.treestyletab.tabbar.scroll.duration');
|
2010-07-25 12:13:19 -04:00
|
|
|
this.onPrefChange('extensions.treestyletab.tabbar.scrollToNewTab.mode');
|
2009-12-25 13:13:33 -05:00
|
|
|
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');
|
2010-04-06 09:38:05 -04:00
|
|
|
|
|
|
|
try {
|
2010-10-24 23:06:02 -04:00
|
|
|
if (this.XULAppInfo.OS == 'WINNT')
|
2010-08-26 11:51:06 -04:00
|
|
|
this.updateAeroPeek();
|
2010-04-06 09:38:05 -04:00
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
dump(e+'\n');
|
|
|
|
}
|
2009-12-25 11:38:14 -05:00
|
|
|
},
|
|
|
|
_initialized : false,
|
2010-10-24 23:06:02 -04:00
|
|
|
applyPlatformDefaultPrefs : function TSTUtils_applyPlatformDefaultPrefs()
|
|
|
|
{
|
|
|
|
var OS = this.XULAppInfo.OS;
|
2010-11-18 02:04:31 -05:00
|
|
|
var processed = {};
|
2010-10-24 23:06:02 -04:00
|
|
|
this.getDescendant('extensions.treestyletab.platform.'+OS).forEach(function(aKey) {
|
2010-11-18 02:04:31 -05:00
|
|
|
var key = aKey.replace('platform.'+OS+'.', '');
|
|
|
|
this.setDefaultPref(key, this.getPref(aKey));
|
|
|
|
processed[key] = true;
|
|
|
|
}, this);
|
|
|
|
this.getDescendant('extensions.treestyletab.platform.default').forEach(function(aKey) {
|
|
|
|
var key = aKey.replace('platform.default.', '');
|
|
|
|
if (!(key in processed))
|
|
|
|
this.setDefaultPref(key, this.getPref(aKey));
|
2010-10-24 23:06:02 -04:00
|
|
|
}, this);
|
|
|
|
},
|
2010-04-06 09:38:05 -04:00
|
|
|
|
|
|
|
updateAeroPeek : function TSTUtils_updateAeroPeek()
|
|
|
|
{
|
|
|
|
var ns = {};
|
|
|
|
Components.utils.import('resource://gre/modules/WindowsPreviewPerTab.jsm', ns);
|
|
|
|
this.AeroPeek = ns.AeroPeek;
|
|
|
|
},
|
|
|
|
|
2009-12-25 13:13:33 -05:00
|
|
|
observe : function TSTUtils_observe(aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
switch (aTopic)
|
|
|
|
{
|
|
|
|
case 'nsPref:changed':
|
|
|
|
this.onPrefChange(aData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/* utilities */
|
2009-12-25 12:55:55 -05:00
|
|
|
|
2009-12-25 13:23:18 -05:00
|
|
|
getBoxObjectFor : function TSTUtils_getBoxObjectFor(aNode)
|
|
|
|
{
|
2010-06-22 14:00:16 -04:00
|
|
|
return window['piro.sakura.ne.jp'].boxObject.getBoxObjectFor(aNode);
|
2009-12-25 13:23:18 -05:00
|
|
|
},
|
|
|
|
|
2009-12-26 03:03:35 -05:00
|
|
|
evalInSandbox : function TSTUtils_evalInSandbox(aCode, aOwner)
|
2009-12-25 15:48:14 -05:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
var sandbox = new Components.utils.Sandbox(aOwner || 'about:blank');
|
|
|
|
return Components.utils.evalInSandbox(aCode, sandbox);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
}
|
|
|
|
return void(0);
|
|
|
|
},
|
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
get browserWindow()
|
2010-05-08 01:37:41 -04:00
|
|
|
{
|
|
|
|
return this.topBrowserWindow;
|
|
|
|
},
|
|
|
|
get topBrowserWindow()
|
2009-12-25 12:55:55 -05:00
|
|
|
{
|
|
|
|
return this.WindowMediator.getMostRecentWindow('navigator:browser');
|
|
|
|
},
|
|
|
|
|
2010-05-08 01:37:41 -04:00
|
|
|
get browserWindows()
|
|
|
|
{
|
|
|
|
var windows = [];
|
|
|
|
|
|
|
|
var targets = this.WindowMediator.getZOrderDOMWindowEnumerator('navigator:browser', true);
|
|
|
|
// By the bug 156333, we cannot find windows by their Z order on Linux.
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=156333
|
|
|
|
if (!targets.hasMoreElements())
|
|
|
|
targets = this.WindowMediator.getEnumerator('navigator:browser');
|
|
|
|
|
|
|
|
while (targets.hasMoreElements())
|
|
|
|
{
|
|
|
|
let target = targets.getNext()
|
|
|
|
.QueryInterface(Ci.nsIDOMWindowInternal);
|
|
|
|
windows.push(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
return windows;
|
|
|
|
},
|
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
get browser()
|
|
|
|
{
|
|
|
|
var w = this.browserWindow;
|
|
|
|
return !w ? null :
|
|
|
|
'SplitBrowser' in w ? w.SplitBrowser.activeBrowser :
|
|
|
|
w.gBrowser ;
|
|
|
|
},
|
|
|
|
|
2010-12-01 19:02:27 -05:00
|
|
|
get currentDragSession()
|
|
|
|
{
|
|
|
|
return Cc['@mozilla.org/widget/dragservice;1']
|
|
|
|
.getService(Ci.nsIDragService)
|
|
|
|
.getCurrentSession();
|
|
|
|
},
|
|
|
|
|
2009-12-25 13:45:52 -05:00
|
|
|
dropLinksOnTabBehavior : function TSTUtils_dropLinksOnTabBehavior()
|
|
|
|
{
|
|
|
|
var behavior = this.getTreePref('dropLinksOnTab.behavior');
|
|
|
|
if (behavior & this.kDROPLINK_FIXED) return behavior;
|
|
|
|
|
|
|
|
var checked = { value : false };
|
|
|
|
var newChildTab = this.PromptService.confirmEx(this.browserWindow,
|
|
|
|
this.treeBundle.getString('dropLinkOnTab.title'),
|
|
|
|
this.treeBundle.getString('dropLinkOnTab.text'),
|
|
|
|
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_0) +
|
|
|
|
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_1),
|
|
|
|
this.treeBundle.getString('dropLinkOnTab.openNewChildTab'),
|
|
|
|
this.treeBundle.getString('dropLinkOnTab.loadInTheTab'),
|
|
|
|
null,
|
|
|
|
this.treeBundle.getString('dropLinkOnTab.never'),
|
|
|
|
checked
|
|
|
|
) == 0;
|
|
|
|
|
|
|
|
behavior = newChildTab ? this.kDROPLINK_NEWTAB : this.kDROPLINK_LOAD ;
|
|
|
|
if (checked.value)
|
|
|
|
this.setTreePref('dropLinksOnTab.behavior', behavior);
|
|
|
|
|
|
|
|
return behavior
|
|
|
|
},
|
|
|
|
kDROPLINK_ASK : 0,
|
|
|
|
kDROPLINK_FIXED : 1 + 2,
|
|
|
|
kDROPLINK_LOAD : 1,
|
|
|
|
kDROPLINK_NEWTAB : 2,
|
|
|
|
|
|
|
|
openGroupBookmarkBehavior : function TSTUtils_openGroupBookmarkBehavior()
|
|
|
|
{
|
|
|
|
var behavior = this.getTreePref('openGroupBookmark.behavior');
|
|
|
|
if (behavior & this.kGROUP_BOOKMARK_FIXED) return behavior;
|
|
|
|
|
|
|
|
var dummyTabFlag = behavior & this.kGROUP_BOOKMARK_USE_DUMMY;
|
|
|
|
|
|
|
|
var checked = { value : false };
|
|
|
|
var button = this.PromptService.confirmEx(this.browserWindow,
|
|
|
|
this.treeBundle.getString('openGroupBookmarkBehavior.title'),
|
|
|
|
this.treeBundle.getString('openGroupBookmarkBehavior.text'),
|
|
|
|
(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),
|
|
|
|
this.treeBundle.getString('openGroupBookmarkBehavior.subTree'),
|
|
|
|
this.treeBundle.getString('openGroupBookmarkBehavior.separate'),
|
|
|
|
this.treeBundle.getString('openGroupBookmarkBehavior.replace'),
|
|
|
|
this.treeBundle.getString('openGroupBookmarkBehavior.never'),
|
|
|
|
checked
|
|
|
|
);
|
|
|
|
|
|
|
|
if (button < 0) button = 1;
|
|
|
|
var behaviors = [
|
|
|
|
this.kGROUP_BOOKMARK_SUBTREE | dummyTabFlag,
|
|
|
|
this.kGROUP_BOOKMARK_SEPARATE,
|
|
|
|
this.kGROUP_BOOKMARK_REPLACE
|
|
|
|
];
|
|
|
|
behavior = behaviors[button];
|
|
|
|
|
|
|
|
if (checked.value) {
|
|
|
|
this.setTreePref('openGroupBookmark.behavior', behavior);
|
|
|
|
this.setPref('browser.tabs.loadFolderAndReplace', behavior & this.kGROUP_BOOKMARK_REPLACE ? true : false );
|
|
|
|
}
|
|
|
|
return behavior;
|
|
|
|
},
|
|
|
|
kGROUP_BOOKMARK_ASK : 0,
|
|
|
|
kGROUP_BOOKMARK_FIXED : 1 + 2 + 4,
|
|
|
|
kGROUP_BOOKMARK_SUBTREE : 1,
|
|
|
|
kGROUP_BOOKMARK_SEPARATE : 2,
|
|
|
|
kGROUP_BOOKMARK_REPLACE : 4,
|
2010-07-29 22:39:51 -04:00
|
|
|
kGROUP_BOOKMARK_USE_DUMMY : 256,
|
|
|
|
kGROUP_BOOKMARK_USE_DUMMY_FORCE : 1024,
|
2009-12-25 13:45:52 -05:00
|
|
|
kGROUP_BOOKMARK_DONT_RESTORE_TREE_STRUCTURE : 512,
|
2010-07-29 22:39:51 -04:00
|
|
|
kGROUP_BOOKMARK_EXPAND_ALL_TREE : 2048,
|
2009-12-25 13:45:52 -05:00
|
|
|
|
2010-12-20 06:41:22 -05:00
|
|
|
bookmarkDroppedTabsBehavior : function TSTUtils_bookmarkDroppedTabsBehavior()
|
|
|
|
{
|
2011-01-05 20:25:17 -05:00
|
|
|
var behavior = this.getTreePref('bookmarkDroppedTabs.behavior');
|
2010-12-20 06:41:22 -05:00
|
|
|
if (behavior & this.kBOOKMARK_DROPPED_TABS_FIXED) return behavior;
|
|
|
|
|
|
|
|
var checked = { value : false };
|
|
|
|
var button = this.PromptService.confirmEx(this.browserWindow,
|
|
|
|
this.treeBundle.getString('bookmarkDroppedTabs.title'),
|
|
|
|
this.treeBundle.getString('bookmarkDroppedTabs.text'),
|
|
|
|
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_0) +
|
|
|
|
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_1),
|
|
|
|
this.treeBundle.getString('bookmarkDroppedTabs.bookmarkAll'),
|
|
|
|
this.treeBundle.getString('bookmarkDroppedTabs.bookmarkOnlyParent'),
|
|
|
|
null,
|
|
|
|
this.treeBundle.getString('bookmarkDroppedTabs.never'),
|
|
|
|
checked
|
|
|
|
);
|
|
|
|
|
|
|
|
if (button < 0) button = 1;
|
|
|
|
var behaviors = [
|
|
|
|
this.kBOOKMARK_DROPPED_TABS_ALL,
|
|
|
|
this.kBOOKMARK_DROPPED_TABS_ONLY_PARENT
|
|
|
|
];
|
|
|
|
behavior = behaviors[button];
|
|
|
|
|
|
|
|
if (checked.value)
|
2011-01-05 20:25:17 -05:00
|
|
|
this.setTreePref('bookmarkDroppedTabs.behavior', behavior);
|
2010-12-20 06:41:22 -05:00
|
|
|
|
|
|
|
return behavior;
|
|
|
|
},
|
|
|
|
kBOOKMARK_DROPPED_TABS_ASK : 0,
|
|
|
|
kBOOKMARK_DROPPED_TABS_FIXED : 1 + 2,
|
|
|
|
kBOOKMARK_DROPPED_TABS_ALL : 1,
|
|
|
|
kBOOKMARK_DROPPED_TABS_ONLY_PARENT : 2,
|
|
|
|
|
2010-11-10 11:14:04 -05:00
|
|
|
askUndoCloseTabSetBehavior : function TSTUtils_askUndoCloseTabSetBehavior(aRestoredTab, aCount)
|
2009-12-26 23:56:16 -05:00
|
|
|
{
|
2010-11-10 11:14:04 -05:00
|
|
|
var behavior = this.undoCloseTabSetBehavior;
|
|
|
|
if (behavior & this.kUNDO_CLOSE_SET) behavior ^= this.kUNDO_CLOSE_SET;
|
|
|
|
|
|
|
|
var self = this;
|
2010-11-11 21:09:05 -05:00
|
|
|
var neverAskState = (behavior & this.kUNDO_ASK) ? false : true ;
|
2010-11-10 11:14:04 -05:00
|
|
|
var checkbox = {
|
|
|
|
label : this.treeBundle.getString('undoCloseTabSetBehavior.never'),
|
2010-11-11 21:09:05 -05:00
|
|
|
checked : neverAskState
|
2010-11-10 11:14:04 -05:00
|
|
|
};
|
2010-11-10 12:13:18 -05:00
|
|
|
return confirmWithTab({
|
|
|
|
tab : aRestoredTab,
|
|
|
|
label : this.treeBundle.getFormattedString('undoCloseTabSetBehavior.label', [aCount]),
|
|
|
|
value : 'treestyletab-undo-close-tree',
|
|
|
|
buttons : [
|
|
|
|
this.treeBundle.getString('undoCloseTabSetBehavior.set'),
|
|
|
|
this.treeBundle.getString('undoCloseTabSetBehavior.separate')
|
|
|
|
],
|
|
|
|
checkbox : checkbox,
|
|
|
|
cancelEvents : ['TabClose', 'SSTabRestoring']
|
2010-11-10 11:14:04 -05:00
|
|
|
})
|
|
|
|
.next(function(aButtonIndex) {
|
2010-11-10 12:05:02 -05:00
|
|
|
if (aButtonIndex == 0) {
|
2010-11-10 11:14:04 -05:00
|
|
|
behavior |= self.kUNDO_CLOSE_SET;
|
2010-11-10 12:05:02 -05:00
|
|
|
}
|
2010-11-11 21:09:05 -05:00
|
|
|
if (checkbox.checked != neverAskState) {
|
2010-11-10 12:05:02 -05:00
|
|
|
behavior ^= self.kUNDO_ASK;
|
2010-11-10 11:14:04 -05:00
|
|
|
self.setTreePref('undoCloseTabSet.behavior', behavior);
|
2010-11-10 12:05:02 -05:00
|
|
|
}
|
2010-11-10 11:14:04 -05:00
|
|
|
return behavior;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
get undoCloseTabSetBehavior()
|
|
|
|
{
|
|
|
|
return this.getTreePref('undoCloseTabSet.behavior');
|
2009-12-26 23:56:16 -05:00
|
|
|
},
|
|
|
|
kUNDO_ASK : 1,
|
|
|
|
kUNDO_CLOSE_SET : 2,
|
|
|
|
kUNDO_CLOSE_FULL_SET : 256,
|
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
// event
|
|
|
|
|
|
|
|
isNewTabAction : function TSTUtils_isNewTabAction(aEvent)
|
|
|
|
{
|
|
|
|
return aEvent.button == 1 || (aEvent.button == 0 && this.isAccelKeyPressed(aEvent));
|
|
|
|
},
|
|
|
|
|
|
|
|
isAccelKeyPressed : function TSTUtils_isAccelKeyPressed(aEvent)
|
|
|
|
{
|
|
|
|
if ( // this is releasing of the accel key!
|
|
|
|
(aEvent.type == 'keyup') &&
|
|
|
|
(aEvent.keyCode == (this.isMac ? Ci.nsIDOMKeyEvent.DOM_VK_META : Ci.nsIDOMKeyEvent.DOM_VK_CONTROL ))
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this.isMac ?
|
|
|
|
(aEvent.metaKey || (aEvent.keyCode == Ci.nsIDOMKeyEvent.DOM_VK_META)) :
|
|
|
|
(aEvent.ctrlKey || (aEvent.keyCode == Ci.nsIDOMKeyEvent.DOM_VK_CONTROL)) ;
|
|
|
|
},
|
|
|
|
|
2010-04-06 22:13:58 -04:00
|
|
|
isCopyAction : function TSTUtils_isCopyAction(aEvent)
|
|
|
|
{
|
|
|
|
return this.isAccelKeyPressed(aEvent) ||
|
|
|
|
(aEvent.dataTransfer && aEvent.dataTransfer.dropEffect == 'copy');
|
|
|
|
},
|
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
isEventFiredOnClosebox : function TSTUtils_isEventFiredOnClosebox(aEvent)
|
|
|
|
{
|
|
|
|
return this.evaluateXPath(
|
|
|
|
'ancestor-or-self::*[contains(concat(" ", normalize-space(@class), " "), " tab-close-button ")]',
|
|
|
|
aEvent.originalTarget || aEvent.target,
|
|
|
|
Ci.nsIDOMXPathResult.BOOLEAN_TYPE
|
|
|
|
).booleanValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
isEventFiredOnClickable : function TSTUtils_isEventFiredOnClickable(aEvent)
|
|
|
|
{
|
|
|
|
return this.evaluateXPath(
|
2010-09-16 00:07:58 -04:00
|
|
|
'ancestor-or-self::*[contains(" button toolbarbutton scrollbar popup menupopup panel tooltip splitter ", concat(" ", local-name(), " "))]',
|
2009-12-25 12:55:55 -05:00
|
|
|
aEvent.originalTarget,
|
|
|
|
Ci.nsIDOMXPathResult.BOOLEAN_TYPE
|
|
|
|
).booleanValue;
|
|
|
|
},
|
2009-12-25 13:45:52 -05:00
|
|
|
|
|
|
|
isEventFiredOnTwisty : function TSTUtils_isEventFiredOnTwisty(aEvent)
|
|
|
|
{
|
|
|
|
var tab = this.getTabFromEvent(aEvent);
|
2010-02-04 03:56:21 -05:00
|
|
|
if (!tab ||
|
|
|
|
!this.hasChildTabs(tab) ||
|
|
|
|
!this.canCollapseSubtree(tab))
|
|
|
|
return false;
|
2009-12-25 13:45:52 -05:00
|
|
|
|
2010-12-27 04:58:02 -05:00
|
|
|
var twisty = tab.ownerDocument.getAnonymousElementByAttribute(tab, 'class', this.kTWISTY);
|
|
|
|
if (!twisty)
|
|
|
|
return false;
|
2009-12-25 13:45:52 -05:00
|
|
|
|
2010-12-27 04:58:02 -05:00
|
|
|
var box = twisty.boxObject;
|
|
|
|
var minX = box.screenX;
|
|
|
|
var minY = box.screenY;
|
|
|
|
var maxX = minX + box.width;
|
|
|
|
var maxY = minY + box.height;
|
2011-01-15 23:46:18 -05:00
|
|
|
if (!box.width || !box.height) {
|
|
|
|
minX = maxX = tab.boxObject.screenX + tab.boxObject.width;
|
|
|
|
minY = maxY = tab.boxObject.screenY + tab.boxObject.height;
|
|
|
|
}
|
2011-01-15 22:01:59 -05:00
|
|
|
if (
|
|
|
|
(this.shouldExpandTwistyArea || !box.width || !box.height) &&
|
|
|
|
!this._expandTwistyAreaBlockers.length
|
|
|
|
) {
|
2010-12-27 04:58:02 -05:00
|
|
|
let icon = tab.ownerDocument.getAnonymousElementByAttribute(tab, 'class', 'tab-icon');
|
|
|
|
let box = icon.boxObject;
|
|
|
|
minX = Math.min(minX, box.screenX);
|
|
|
|
minY = Math.min(minY, box.screenY);
|
|
|
|
maxX = Math.max(maxX, box.screenX + box.width);
|
|
|
|
maxY = Math.max(maxY, box.screenY + box.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
var x = aEvent.screenX;
|
|
|
|
var y = aEvent.screenY;
|
|
|
|
return (x >= minX && x <= maxX && y >= minY && y <= maxY);
|
2009-12-25 13:45:52 -05:00
|
|
|
},
|
|
|
|
|
2011-01-11 05:29:14 -05:00
|
|
|
// called with target(nsIDOMEventTarget), document(nsIDOMDocument), type(string) and data(object)
|
|
|
|
fireDataContainerEvent : function()
|
|
|
|
{
|
|
|
|
var target, document, type, data, canBubble, cancellable;
|
|
|
|
Array.slice(arguments).forEach(function(aArg) {
|
|
|
|
if (typeof aArg == 'boolean') {
|
|
|
|
if (canBubble === void(0))
|
|
|
|
canBubble = aArg;
|
|
|
|
else
|
|
|
|
cancellable = aArg;
|
|
|
|
}
|
|
|
|
else if (typeof aArg == 'string')
|
|
|
|
type = aArg;
|
|
|
|
else if (aArg instanceof Ci.nsIDOMDocument)
|
|
|
|
document = aArg;
|
|
|
|
else if (aArg instanceof Ci.nsIDOMEventTarget)
|
|
|
|
target = aArg;
|
|
|
|
else
|
|
|
|
data = aArg;
|
|
|
|
});
|
|
|
|
if (!target)
|
|
|
|
target = document;
|
|
|
|
if (!document)
|
|
|
|
document = target.ownerDocument || target;
|
|
|
|
|
|
|
|
var event = document.createEvent('DataContainerEvent');
|
|
|
|
event.initEvent(type, canBubble, cancellable);
|
|
|
|
for (var i in data)
|
|
|
|
{
|
|
|
|
if (!data.hasOwnProperty(i))
|
|
|
|
continue;
|
|
|
|
event.setData(i, data[i]);
|
|
|
|
event[i] = data[i]; // for backward compatibility
|
|
|
|
}
|
|
|
|
|
|
|
|
return target.dispatchEvent(event);
|
|
|
|
},
|
|
|
|
|
2009-12-25 13:45:52 -05:00
|
|
|
registerExpandTwistyAreaBlocker : function TSTUtils_registerExpandTwistyAreaBlocker(aBlocker) /* PUBLIC API */
|
|
|
|
{
|
2009-12-25 13:48:07 -05:00
|
|
|
if (this._expandTwistyAreaBlockers.indexOf(aBlocker) < 0)
|
|
|
|
this._expandTwistyAreaBlockers.push(aBlocker);
|
2009-12-25 13:45:52 -05:00
|
|
|
},
|
2009-12-25 13:48:07 -05:00
|
|
|
_expandTwistyAreaBlockers : [],
|
2009-12-25 13:45:52 -05:00
|
|
|
|
|
|
|
registerExpandTwistyAreaAllowance : function TSTUtils_registerExpandTwistyAreaAllowance(aAllowance) /* PUBLIC API, obsolete, for backward compatibility */
|
|
|
|
{
|
|
|
|
this.registerExpandTwistyAreaBlocker(aAllowance.toSource());
|
|
|
|
},
|
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
// string
|
|
|
|
|
|
|
|
makeNewId : function TSTUtils_makeNewId()
|
|
|
|
{
|
|
|
|
return 'tab-<'+Date.now()+'-'+parseInt(Math.random() * 65000)+'>';
|
|
|
|
},
|
|
|
|
|
2009-12-25 15:07:00 -05:00
|
|
|
makeNewClosedSetId : function TSTUtils_makeNewId()
|
|
|
|
{
|
|
|
|
return 'tabs-closed-set-<'+Date.now()+'-'+parseInt(Math.random() * 65000)+'>';
|
|
|
|
},
|
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
makeURIFromSpec : function TSTUtils_makeURIFromSpec(aURI)
|
|
|
|
{
|
|
|
|
var newURI;
|
|
|
|
aURI = aURI || '';
|
|
|
|
if (aURI && String(aURI).indexOf('file:') == 0) {
|
|
|
|
var fileHandler = this.IOService.getProtocolHandler('file').QueryInterface(Ci.nsIFileProtocolHandler);
|
|
|
|
var tempLocalFile = fileHandler.getFileFromURLSpec(aURI);
|
|
|
|
newURI = this.IOService.newFileURI(tempLocalFile);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!/^\w+\:/.test(aURI)) aURI = 'http://'+aURI;
|
|
|
|
newURI = this.IOService.newURI(aURI, null, null);
|
|
|
|
}
|
|
|
|
return newURI;
|
|
|
|
},
|
|
|
|
|
|
|
|
getGroupTabURI : function TSTUtils_getGroupTabURI(aTitle)
|
|
|
|
{
|
|
|
|
return 'about:treestyletab-group'+(aTitle === void(0) ? '' : '?'+encodeURIComponent(aTitle) );
|
|
|
|
},
|
|
|
|
|
|
|
|
// xpath
|
|
|
|
|
|
|
|
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 '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
evaluateXPath : function TSTUtils_evaluateXPath(aExpression, aContext, aType)
|
|
|
|
{
|
|
|
|
if (!aType) aType = Ci.nsIDOMXPathResult.ORDERED_NODE_SNAPSHOT_TYPE;
|
|
|
|
try {
|
|
|
|
var XPathResult = (aContext.ownerDocument || aContext).evaluate(
|
|
|
|
aExpression,
|
|
|
|
(aContext || document),
|
|
|
|
this.NSResolver,
|
|
|
|
aType,
|
|
|
|
null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
return {
|
|
|
|
singleNodeValue : null,
|
|
|
|
snapshotLength : 0,
|
|
|
|
snapshotItem : function() {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return XPathResult;
|
|
|
|
},
|
|
|
|
|
|
|
|
getArrayFromXPathResult : function TSTUtils_getArrayFromXPathResult(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-12-25 13:13:33 -05:00
|
|
|
/* Session Store API */
|
|
|
|
|
|
|
|
getTabValue : function TSTUtils_getTabValue(aTab, aKey)
|
|
|
|
{
|
|
|
|
var value = '';
|
|
|
|
try {
|
|
|
|
value = this.SessionStore.getTabValue(aTab, aKey);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.useTMPSessionAPI) {
|
|
|
|
let TMPValue = aTab.getAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey);
|
|
|
|
if (TMPValue) value = TMPValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
|
|
|
|
setTabValue : function TSTUtils_setTabValue(aTab, aKey, aValue)
|
|
|
|
{
|
|
|
|
if (!aValue) return this.deleteTabValue(aTab, aKey);
|
|
|
|
|
|
|
|
aTab.setAttribute(aKey, aValue);
|
|
|
|
try {
|
|
|
|
this.checkCachedSessionDataExpiration(aTab);
|
|
|
|
this.SessionStore.setTabValue(aTab, aKey, aValue);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.useTMPSessionAPI)
|
|
|
|
aTab.setAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey, aValue);
|
|
|
|
|
|
|
|
return aValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteTabValue : function TSTUtils_deleteTabValue(aTab, aKey)
|
|
|
|
{
|
|
|
|
aTab.removeAttribute(aKey);
|
|
|
|
try {
|
|
|
|
this.checkCachedSessionDataExpiration(aTab);
|
|
|
|
this.SessionStore.setTabValue(aTab, aKey, '');
|
|
|
|
this.SessionStore.deleteTabValue(aTab, aKey);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.useTMPSessionAPI)
|
|
|
|
aTab.removeAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey);
|
|
|
|
},
|
|
|
|
|
|
|
|
// workaround for http://piro.sakura.ne.jp/latest/blosxom/mozilla/extension/treestyletab/2009-09-29_debug.htm
|
|
|
|
checkCachedSessionDataExpiration : function TSTUtils_checkCachedSessionDataExpiration(aTab)
|
|
|
|
{
|
2010-01-28 11:33:00 -05:00
|
|
|
var data = aTab.linkedBrowser.__SS_data || // Firefox 3.6-
|
|
|
|
aTab.linkedBrowser.parentNode.__SS_data; // -Frefox 3.5
|
|
|
|
if (data &&
|
|
|
|
data._tabStillLoading &&
|
2010-09-26 11:32:44 -04:00
|
|
|
aTab.getAttribute('busy') != 'true' &&
|
2010-10-24 14:29:49 -04:00
|
|
|
aTab.linkedBrowser.__SS_restoreState != 1)
|
2010-01-28 11:33:00 -05:00
|
|
|
data._tabStillLoading = false;
|
2009-12-25 13:13:33 -05:00
|
|
|
},
|
|
|
|
|
2009-12-25 22:25:29 -05:00
|
|
|
markAsClosedSet : function TSTUtils_markAsClosedSet(aTabs) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
if (!aTabs || aTabs.length <= 1) return;
|
|
|
|
var id = this.makeNewClosedSetId() + '::' + aTabs.length;
|
|
|
|
aTabs.forEach(function(aTab) {
|
|
|
|
this.setTabValue(aTab, this.kCLOSED_SET_ID, id);
|
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
|
|
|
|
unmarkAsClosedSet : function TSTUtils_unmarkAsClosedSet(aTabs) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
if (!aTabs || !aTabs.length) return;
|
|
|
|
aTabs.forEach(function(aTab) {
|
|
|
|
this.deleteTabValue(aTab, this.kCLOSED_SET_ID);
|
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
|
2009-12-25 13:13:33 -05:00
|
|
|
useTMPSessionAPI : false,
|
|
|
|
|
|
|
|
kTMP_SESSION_DATA_PREFIX : 'tmp-session-data-',
|
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
// tab
|
|
|
|
|
2010-03-23 09:33:00 -04:00
|
|
|
getTabStrip : function TSTUtils_getTabStrip(aTabBrowser)
|
2010-04-06 09:38:05 -04:00
|
|
|
{
|
|
|
|
if (!(aTabBrowser instanceof Ci.nsIDOMElement))
|
2010-03-27 10:52:25 -04:00
|
|
|
return null;
|
2010-04-06 09:38:05 -04:00
|
|
|
|
2010-03-25 20:20:51 -04:00
|
|
|
var strip = aTabBrowser.mStrip;
|
2010-04-08 19:50:08 -04:00
|
|
|
return (strip && strip instanceof Ci.nsIDOMElement) ?
|
2010-03-25 20:20:51 -04:00
|
|
|
strip :
|
|
|
|
aTabBrowser.tabContainer.parentNode;
|
2010-03-23 09:33:00 -04:00
|
|
|
},
|
2010-04-06 09:38:05 -04:00
|
|
|
get tabStrip()
|
2010-03-23 09:33:00 -04:00
|
|
|
{
|
|
|
|
return this.getTabStrip(this.browser);
|
|
|
|
},
|
|
|
|
|
2010-04-29 23:20:18 -04:00
|
|
|
getTabContainerBox : function TSTUtils_getTabContainerBox(aTabBrowser)
|
|
|
|
{
|
|
|
|
if (!(aTabBrowser instanceof Ci.nsIDOMElement))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
var strip = this.getTabStrip(aTabBrowser);
|
|
|
|
return strip.tabsToolbarInnerBox || aTabBrowser.tabContainer;
|
|
|
|
},
|
|
|
|
get tabContainerBox()
|
|
|
|
{
|
|
|
|
return this.getTabContainerBox(this.browser);
|
|
|
|
},
|
|
|
|
|
2010-03-25 03:58:47 -04:00
|
|
|
setTabbrowserAttribute : function TSTUtils_setTabbrowserAttribute(aName, aValue, aTabBrowser)
|
2010-03-23 12:12:49 -04:00
|
|
|
{
|
2010-03-28 14:22:15 -04:00
|
|
|
aTabBrowser = aTabBrowser || this.mTabBrowser || this.browser;
|
2010-03-23 12:12:49 -04:00
|
|
|
if (aValue) {
|
|
|
|
aTabBrowser.setAttribute(aName, aValue);
|
|
|
|
aTabBrowser.mTabContainer.setAttribute(aName, aValue);
|
2010-03-25 23:17:16 -04:00
|
|
|
aTabBrowser.treeStyleTab.setTabStripAttribute(aName, aValue);
|
2010-03-23 12:12:49 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aTabBrowser.removeAttribute(aName);
|
|
|
|
aTabBrowser.mTabContainer.removeAttribute(aName);
|
2010-03-25 23:17:16 -04:00
|
|
|
aTabBrowser.treeStyleTab.removeTabStripAttribute(aName);
|
2010-03-23 12:12:49 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-03-28 14:22:15 -04:00
|
|
|
removeTabbrowserAttribute : function TSTUtils_removeTabbrowserAttribute(aName, aTabBrowser)
|
|
|
|
{
|
|
|
|
this.setTabbrowserAttribute(aName, null, aTabBrowser);
|
|
|
|
},
|
|
|
|
|
2010-04-29 23:20:18 -04:00
|
|
|
setTabStripAttribute : function TSTUtils_setTabStripAttribute(aAttr, aValue)
|
|
|
|
{
|
|
|
|
var strip = this.tabStrip;
|
|
|
|
if (!strip) return;
|
2010-09-13 21:04:00 -04:00
|
|
|
var isFeatureAttribute = aAttr.indexOf('treestyletab-') == 0;
|
2010-04-29 23:20:18 -04:00
|
|
|
if (aValue) {
|
|
|
|
strip.setAttribute(aAttr, aValue);
|
2010-09-13 21:04:00 -04:00
|
|
|
if (isFeatureAttribute) {
|
|
|
|
// Only attributes for TST's feature are applied to the root element.
|
|
|
|
// (width, height, and other general attributes have to be ignored!)
|
|
|
|
strip.ownerDocument.defaultView.setTimeout(function(aSelf) {
|
|
|
|
strip.ownerDocument.documentElement.setAttribute(aAttr, aValue);
|
|
|
|
}, 10, this);
|
|
|
|
}
|
2010-04-29 23:20:18 -04:00
|
|
|
if (this._tabStripPlaceHolder)
|
|
|
|
this._tabStripPlaceHolder.setAttribute(aAttr, aValue);
|
|
|
|
if (strip.tabsToolbarInnerBox)
|
|
|
|
strip.tabsToolbarInnerBox.setAttribute(aAttr, aValue);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strip.removeAttribute(aAttr);
|
2010-09-13 21:04:00 -04:00
|
|
|
if (isFeatureAttribute) {
|
|
|
|
strip.ownerDocument.defaultView.setTimeout(function(aSelf) {
|
|
|
|
strip.ownerDocument.documentElement.removeAttribute(aAttr);
|
|
|
|
}, 10, this);
|
|
|
|
}
|
2010-04-29 23:20:18 -04:00
|
|
|
if (this._tabStripPlaceHolder)
|
|
|
|
this._tabStripPlaceHolder.removeAttribute(aAttr);
|
|
|
|
if (strip.tabsToolbarInnerBox)
|
|
|
|
strip.tabsToolbarInnerBox.removeAttribute(aAttr);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
removeTabStripAttribute : function TSTUtils_removeTabStripAttribute(aAttr)
|
|
|
|
{
|
|
|
|
this.setTabStripAttribute(aAttr, null);
|
|
|
|
},
|
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
getTabFromChild : function TSTUtils_getTabFromChild(aTab)
|
|
|
|
{
|
|
|
|
return this.evaluateXPath(
|
2010-03-23 11:12:43 -04:00
|
|
|
'ancestor-or-self::xul:tab',
|
2009-12-25 12:55:55 -05:00
|
|
|
aTab,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
getTabFromEvent : function TSTUtils_getTabFromEvent(aEvent)
|
|
|
|
{
|
|
|
|
return this.getTabFromChild(aEvent.originalTarget || aEvent.target);
|
|
|
|
},
|
|
|
|
|
2010-03-02 09:40:12 -05:00
|
|
|
getSplitterFromEvent : function TSTUtils_getSplitterFromEvent(aEvent)
|
|
|
|
{
|
|
|
|
return this.evaluateXPath(
|
|
|
|
'ancestor-or-self::xul:splitter[contains(concat(" ", normalize-space(@class), " "), " '+this.kSPLITTER+' ")]',
|
|
|
|
aEvent.originalTarget,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
|
|
|
},
|
|
|
|
|
2010-09-13 13:52:07 -04:00
|
|
|
isEventFiredOnGrippy : function TSTUtils_isEventFiredOnGrippy(aEvent)
|
|
|
|
{
|
|
|
|
return this.evaluateXPath(
|
|
|
|
'ancestor-or-self::xul:grippy',
|
|
|
|
aEvent.originalTarget,
|
|
|
|
Ci.nsIDOMXPathResult.BOOLEAN_TYPE
|
|
|
|
).booleanValue;
|
|
|
|
},
|
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
getTabFromFrame : function TSTUtils_getTabFromFrame(aFrame, aTabBrowser)
|
|
|
|
{
|
|
|
|
var b = aTabBrowser || this.browser;
|
2010-11-11 20:42:06 -05:00
|
|
|
var top = aFrame.top;
|
2010-09-14 03:39:17 -04:00
|
|
|
var tabs = this.getAllTabsArray(b);
|
2010-03-03 10:38:35 -05:00
|
|
|
for each (var tab in tabs)
|
2009-12-25 12:55:55 -05:00
|
|
|
{
|
2010-11-11 20:42:06 -05:00
|
|
|
if (tab.linkedBrowser.contentWindow == top)
|
2009-12-25 12:55:55 -05:00
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2010-03-24 13:20:30 -04:00
|
|
|
getTabbarFromChild : function TSTUtils_getTabbarFromChild(aNode)
|
2009-12-25 12:55:55 -05:00
|
|
|
{
|
|
|
|
return this.evaluateXPath(
|
2010-04-30 00:00:09 -04:00
|
|
|
'ancestor-or-self::*[contains(concat(" ", normalize-space(@class), " "), " tabbrowser-strip ")] | '+
|
|
|
|
'ancestor-or-self::xul:tabs[@tabbrowser] | ' +
|
|
|
|
'ancestor-or-self::xul:toolbar[@id="TabsToolbar"]/child::xul:tabs[@tabbrowser]',
|
2010-03-24 13:20:30 -04:00
|
|
|
aNode,
|
2009-12-25 12:55:55 -05:00
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
|
|
|
},
|
|
|
|
|
2010-03-24 13:20:30 -04:00
|
|
|
getTabbarFromEvent : function TSTUtils_getTabbarFromEvent(aEvent)
|
|
|
|
{
|
|
|
|
return this.getTabbarFromChild(aEvent.originalTarget || aEvent.target);
|
|
|
|
},
|
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
cleanUpTabsArray : function TSTUtils_cleanUpTabsArray(aTabs)
|
|
|
|
{
|
|
|
|
var newTabs = [];
|
|
|
|
aTabs.forEach(function(aTab) {
|
|
|
|
if (!aTab.parentNode) return; // ignore removed tabs
|
|
|
|
if (newTabs.indexOf(aTab) < 0) newTabs.push(aTab);
|
|
|
|
});
|
|
|
|
newTabs.sort(this.sortTabsByOrder);
|
|
|
|
return newTabs;
|
|
|
|
},
|
|
|
|
|
|
|
|
sortTabsByOrder : function TSTUtils_sortTabsByOrder(aA, aB)
|
|
|
|
{
|
|
|
|
return aA._tPos - aB._tPos;
|
|
|
|
},
|
|
|
|
|
2010-09-18 11:12:14 -04:00
|
|
|
gatherSubtreeMemberTabs : function TSTUtils_gatherSubtreeMemberTabs(aTabOrTabs, aOnlyChildren)
|
2009-12-25 12:55:55 -05:00
|
|
|
{
|
|
|
|
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]));
|
|
|
|
}
|
|
|
|
|
2010-09-18 11:12:14 -04:00
|
|
|
return this.cleanUpTabsArray(aOnlyChildren ? descendant : tabs.concat(descendant));
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
2009-12-27 06:22:44 -05:00
|
|
|
|
|
|
|
splitTabsToSubtrees : function TSTUtils_splitTabsToSubtrees(aTabs) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
var groups = [];
|
|
|
|
var group = [];
|
|
|
|
this.cleanUpTabsArray(aTabs)
|
|
|
|
.forEach(function(aTab) {
|
|
|
|
var parent = this.getParentTab(aTab);
|
|
|
|
if (!parent || group.indexOf(parent) < 0) {
|
|
|
|
if (group.length) groups.push(group);
|
|
|
|
group = [aTab];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
group.push(aTab);
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
if (group.length) groups.push(group);
|
|
|
|
return groups;
|
|
|
|
},
|
2009-12-25 12:55:55 -05:00
|
|
|
|
|
|
|
// tabbrowser
|
|
|
|
|
|
|
|
getTabBrowserFromChild : function TSTUtils_getTabBrowserFromChild(aTabBrowserChild)
|
|
|
|
{
|
2010-03-23 13:58:23 -04:00
|
|
|
if (!aTabBrowserChild)
|
|
|
|
return null;
|
2009-12-25 12:55:55 -05:00
|
|
|
|
2010-03-23 13:58:23 -04:00
|
|
|
if (aTabBrowserChild.__treestyletab__linkedTabBrowser) // tab
|
2009-12-25 12:55:55 -05:00
|
|
|
return aTabBrowserChild.__treestyletab__linkedTabBrowser;
|
|
|
|
|
2010-03-23 13:58:23 -04:00
|
|
|
if (aTabBrowserChild.localName == 'tabbrowser') // itself
|
2009-12-25 12:55:55 -05:00
|
|
|
return aTabBrowserChild;
|
|
|
|
|
2010-08-07 12:15:07 -04:00
|
|
|
if (aTabBrowserChild.tabbrowser) // tabs, Firefox 4.0 or later
|
2010-03-23 13:58:23 -04:00
|
|
|
return aTabBrowserChild.tabbrowser;
|
|
|
|
|
2010-08-07 12:15:07 -04:00
|
|
|
if (aTabBrowserChild.id == 'TabsToolbar') // tabs toolbar, Firefox 4.0 or later
|
2010-03-27 10:52:25 -04:00
|
|
|
return aTabBrowserChild.getElementsByTagName('tabs')[0].tabbrowser;
|
|
|
|
|
2010-08-07 12:15:07 -04:00
|
|
|
// tab context menu on Firefox 4.0
|
2010-04-01 13:37:30 -04:00
|
|
|
var popup = this.evaluateXPath(
|
|
|
|
'ancestor-or-self::xul:menupopup[@id="tabContextMenu"]',
|
|
|
|
aTabBrowserChild,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
2010-04-22 04:24:36 -04:00
|
|
|
if (popup && 'TabContextMenu' in aTabBrowserChild.ownerDocument.defaultView)
|
2010-04-22 04:29:18 -04:00
|
|
|
return this.getTabBrowserFromChild(aTabBrowserChild.ownerDocument.defaultView.TabContextMenu.contextTab);
|
2010-04-01 13:37:30 -04:00
|
|
|
|
2010-03-23 10:21:13 -04:00
|
|
|
var b = this.evaluateXPath(
|
|
|
|
'ancestor::xul:tabbrowser | '+
|
2010-04-29 23:51:31 -04:00
|
|
|
'ancestor::xul:tabs[@tabbrowser] |'+
|
2010-06-23 08:00:33 -04:00
|
|
|
'ancestor::xul:toolbar[@id="TabsToolbar"]/descendant::xul:tabs',
|
2009-12-25 12:55:55 -05:00
|
|
|
aTabBrowserChild,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
2010-03-23 10:21:13 -04:00
|
|
|
return (b && b.tabbrowser) || b;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getTabBrowserFromFrame : function TSTUtils_getTabBrowserFromFrame(aFrame)
|
|
|
|
{
|
|
|
|
var w = this.browserWindow;
|
|
|
|
return !w ? null :
|
|
|
|
('SplitBrowser' in w) ? this.getTabBrowserFromChild(w.SplitBrowser.getSubBrowserAndBrowserFromFrame(aFrame.top).browser) :
|
|
|
|
this.browser ;
|
|
|
|
},
|
|
|
|
|
|
|
|
getFrameFromTabBrowserElements : function TSTUtils_getFrameFromTabBrowserElements(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 {
|
|
|
|
frame = this.getTabBrowserFromChild(frame);
|
|
|
|
if (!frame) return null;
|
|
|
|
frame = frame.contentWindow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!frame)
|
|
|
|
frame = this.browser.contentWindow;
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* get tab(s) */
|
|
|
|
|
|
|
|
getTabById : function TSTUtils_getTabById(aId, aTabBrowserChildren)
|
|
|
|
{
|
|
|
|
if (!aId) return null;
|
2010-03-24 11:38:08 -04:00
|
|
|
|
|
|
|
if (aTabBrowserChildren && !(aTabBrowserChildren instanceof Ci.nsIDOMNode))
|
|
|
|
aTabBrowserChildren = null;
|
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
var b = this.getTabBrowserFromChild(aTabBrowserChildren) || this.browser;
|
2010-03-24 11:38:08 -04:00
|
|
|
|
|
|
|
if (this.tabsHash) // XPath-less implementation
|
|
|
|
return this.tabsHash[aId] || null;
|
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
return this.evaluateXPath(
|
2010-03-24 11:38:08 -04:00
|
|
|
'descendant::xul:tab[@'+this.kID+' = "'+aId+'"]',
|
|
|
|
b.mTabContainer,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
isTabDuplicated : function TSTUtils_isTabDuplicated(aTab)
|
|
|
|
{
|
|
|
|
if (!aTab) return false;
|
|
|
|
var id = this.getTabValue(aTab, this.kID);
|
|
|
|
var b = this.getTabBrowserFromChild(aTab) || this.browser;
|
|
|
|
return this.evaluateXPath(
|
2010-03-24 11:38:08 -04:00
|
|
|
'count(descendant::xul:tab[@'+this.kID+' = "'+id+'" or @'+this.kID_RESTORING+' = "'+id+'"]) > 1',
|
|
|
|
b.mTabContainer,
|
|
|
|
Ci.nsIDOMXPathResult.BOOLEAN_TYPE
|
|
|
|
).booleanValue;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns all tabs in the current group as a XPathResult.
|
|
|
|
* It includes tabs hidden by Tab Panorama.
|
|
|
|
*/
|
|
|
|
getAllTabs : function TSTUtils_getTabs(aTabBrowserChild) /* OBSOLETE */
|
|
|
|
{
|
|
|
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
|
|
|
return this.evaluateXPath(
|
|
|
|
'descendant::xul:tab',
|
|
|
|
b.mTabContainer
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all tabs in the current group as a XPathResult.
|
|
|
|
* It excludes tabs hidden by Tab Panorama.
|
|
|
|
*/
|
2010-03-03 10:38:35 -05:00
|
|
|
getTabs : function TSTUtils_getTabs(aTabBrowserChild) /* OBSOLETE */
|
2009-12-25 12:55:55 -05:00
|
|
|
{
|
|
|
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
|
|
|
return this.evaluateXPath(
|
2010-09-14 03:05:27 -04:00
|
|
|
'descendant::xul:tab[not(@hidden="true")]',
|
2010-03-24 11:38:08 -04:00
|
|
|
b.mTabContainer
|
|
|
|
);
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns all tabs in the current group as an array.
|
|
|
|
* It includes tabs hidden by Tab Panorama.
|
|
|
|
*/
|
|
|
|
getAllTabsArray : function TSTUtils_getAllTabsArray(aTabBrowserChild)
|
|
|
|
{
|
|
|
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
|
|
|
return Array.slice(b.mTabContainer.childNodes) ;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all tabs in the current group as an array.
|
|
|
|
* It excludes tabs hidden by Tab Panorama.
|
|
|
|
*/
|
2009-12-25 12:55:55 -05:00
|
|
|
getTabsArray : function TSTUtils_getTabsArray(aTabBrowserChild)
|
|
|
|
{
|
2010-03-03 10:38:35 -05:00
|
|
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
2010-09-14 03:05:27 -04:00
|
|
|
return b.visibleTabs || Array.slice(b.mTabContainer.childNodes) ;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns the first tab in the current group.
|
|
|
|
*/
|
2009-12-25 12:55:55 -05:00
|
|
|
getFirstTab : function TSTUtils_getFirstTab(aTabBrowserChild)
|
|
|
|
{
|
|
|
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
2010-09-14 03:05:27 -04:00
|
|
|
var tabs = b.visibleTabs;
|
|
|
|
return tabs ? tabs[0] : b.mTabContainer.firstChild;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns the first visible, not collapsed, and not pinned tab.
|
|
|
|
*/
|
2010-06-25 11:59:59 -04:00
|
|
|
getFirstNormalTab : function TSTUtils_getFirstNormalTab(aTabBrowserChild)
|
|
|
|
{
|
|
|
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
2010-08-13 13:14:46 -04:00
|
|
|
return this.evaluateXPath(
|
|
|
|
'descendant::xul:tab[not(@pinned="true") and not(@hidden="true")]',
|
|
|
|
b.mTabContainer,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
2010-06-25 11:59:59 -04:00
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns the last tab in the current group.
|
|
|
|
*/
|
2009-12-25 12:55:55 -05:00
|
|
|
getLastTab : function TSTUtils_getLastTab(aTabBrowserChild)
|
|
|
|
{
|
|
|
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
2010-09-14 03:05:27 -04:00
|
|
|
var tabs = b.visibleTabs;
|
|
|
|
return tabs ? tabs[tabs.length-1] : b.mTabContainer.lastChild ;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns the next tab in the current group.
|
|
|
|
*/
|
2009-12-25 12:55:55 -05:00
|
|
|
getNextTab : function TSTUtils_getNextTab(aTab)
|
|
|
|
{
|
|
|
|
if (!aTab) return null;
|
2010-09-14 03:05:27 -04:00
|
|
|
var b = this.getTabBrowserFromChild(aTab);
|
|
|
|
var tabs = b.visibleTabs;
|
|
|
|
if (tabs) {
|
|
|
|
let index = tabs.indexOf(aTab);
|
|
|
|
if (index > -1)
|
2010-11-17 12:50:54 -05:00
|
|
|
return tabs.length > index ? tabs[index+1] : null
|
2010-09-14 03:05:27 -04:00
|
|
|
}
|
2010-03-03 10:38:35 -05:00
|
|
|
var tab = aTab.nextSibling;
|
|
|
|
return (tab && tab.localName == 'tab') ? tab : null ;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns the previous tab in the current group.
|
|
|
|
*/
|
2009-12-25 12:55:55 -05:00
|
|
|
getPreviousTab : function TSTUtils_getPreviousTab(aTab)
|
|
|
|
{
|
|
|
|
if (!aTab) return null;
|
2010-09-14 03:05:27 -04:00
|
|
|
var b = this.getTabBrowserFromChild(aTab);
|
|
|
|
var tabs = b.visibleTabs;
|
|
|
|
if (tabs) {
|
|
|
|
let index = tabs.indexOf(aTab);
|
|
|
|
if (index > -1)
|
2010-11-17 12:50:54 -05:00
|
|
|
return 0 < index ? tabs[index-1] : null
|
2010-09-14 03:05:27 -04:00
|
|
|
}
|
2010-03-03 10:38:35 -05:00
|
|
|
var tab = aTab.previousSibling;
|
|
|
|
return (tab && tab.localName == 'tab') ? tab : null ;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns the index of the specified tab, in the current group.
|
|
|
|
*/
|
2009-12-25 12:55:55 -05:00
|
|
|
getTabIndex : function TSTUtils_getTabIndex(aTab)
|
|
|
|
{
|
|
|
|
if (!aTab) return -1;
|
2010-03-03 10:38:35 -05:00
|
|
|
var b = this.getTabBrowserFromChild(aTab);
|
|
|
|
return this.getTabsArray(b).indexOf(aTab);
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns the next not collapsed tab in the current group.
|
|
|
|
*/
|
2009-12-25 12:55:55 -05:00
|
|
|
getNextVisibleTab : function TSTUtils_getNextVisibleTab(aTab)
|
|
|
|
{
|
|
|
|
if (!aTab) return null;
|
|
|
|
|
2010-03-03 10:38:35 -05:00
|
|
|
var b = this.getTabBrowserFromChild(aTab);
|
|
|
|
if (!this.canCollapseSubtree(b))
|
2009-12-25 12:55:55 -05:00
|
|
|
return this.getNextTab(aTab);
|
|
|
|
|
2010-03-03 10:38:35 -05:00
|
|
|
var tabs = this.getVisibleTabsArray(b);
|
|
|
|
if (tabs.indexOf(aTab) < 0) tabs.push(aTab);
|
|
|
|
tabs.sort(this.sortTabsByOrder);
|
|
|
|
|
|
|
|
var index = tabs.indexOf(aTab);
|
|
|
|
return (index < tabs.length-1) ? tabs[index+1] : null ;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns the previous not collapsed tab in the current group.
|
|
|
|
*/
|
2009-12-25 12:55:55 -05:00
|
|
|
getPreviousVisibleTab : function TSTUtils_getPreviousVisibleTab(aTab)
|
|
|
|
{
|
|
|
|
if (!aTab) return null;
|
|
|
|
|
2010-03-03 10:38:35 -05:00
|
|
|
var b = this.getTabBrowserFromChild(aTab);
|
|
|
|
if (!this.canCollapseSubtree(b))
|
2009-12-25 12:55:55 -05:00
|
|
|
return this.getPreviousTab(aTab);
|
|
|
|
|
2010-03-03 10:38:35 -05:00
|
|
|
var tabs = this.getVisibleTabsArray(b);
|
|
|
|
if (tabs.indexOf(aTab) < 0) tabs.push(aTab);
|
|
|
|
tabs.sort(this.sortTabsByOrder);
|
|
|
|
|
|
|
|
var index = tabs.indexOf(aTab);
|
|
|
|
return (index > 0) ? tabs[index-1] : null ;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns the last not collapsed tab in the current group.
|
|
|
|
*/
|
2009-12-25 12:55:55 -05:00
|
|
|
getLastVisibleTab : function TSTUtils_getLastVisibleTab(aTabBrowserChild)
|
|
|
|
{
|
|
|
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
|
|
|
if (!b) return null;
|
2010-03-03 10:38:35 -05:00
|
|
|
var tabs = this.getVisibleTabsArray(b);
|
|
|
|
return tabs.length ? tabs[tabs.length-1] : null ;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns a XPathResult of not collapsed tabs in the current group.
|
|
|
|
*/
|
2010-03-03 10:38:35 -05:00
|
|
|
getVisibleTabs : function TSTUtils_getVisibleTabs(aTabBrowserChild) /* OBSOLETE */
|
2009-12-25 12:55:55 -05:00
|
|
|
{
|
|
|
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
|
|
|
if (!this.canCollapseSubtree(b))
|
|
|
|
return this.getTabs(b);
|
|
|
|
|
|
|
|
var XPathResult = this.evaluateXPath(
|
2010-08-13 13:14:46 -04:00
|
|
|
'child::xul:tab[not(@'+this.kCOLLAPSED+'="true") and not(@hidden="true")]',
|
2009-12-25 12:55:55 -05:00
|
|
|
b.mTabContainer
|
|
|
|
);
|
|
|
|
return XPathResult;
|
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns an array of not collapsed tabs in the current group.
|
|
|
|
*/
|
2010-03-03 10:38:35 -05:00
|
|
|
getVisibleTabsArray : function TSTUtils_getVisibleTabsArray(aTabBrowserChild)
|
|
|
|
{
|
|
|
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
|
|
|
var tabs = this.getTabsArray(b);
|
|
|
|
return this.canCollapseSubtree(b) ?
|
|
|
|
tabs.filter(function(aTab) {
|
|
|
|
return aTab.getAttribute(this.kCOLLAPSED) != 'true';
|
|
|
|
}, this) :
|
|
|
|
tabs ;
|
|
|
|
},
|
|
|
|
|
2010-09-14 03:39:17 -04:00
|
|
|
/**
|
|
|
|
* Returns the index of the specified tab, in the array of not collapsed
|
|
|
|
* tabs in the current group.
|
|
|
|
*/
|
2009-12-25 12:55:55 -05:00
|
|
|
getVisibleIndex : function TSTUtils_getVisibleIndex(aTab)
|
|
|
|
{
|
|
|
|
if (!aTab) return -1;
|
2010-03-03 10:38:35 -05:00
|
|
|
var b = this.getTabBrowserFromChild(aTab);
|
|
|
|
return this.getVisibleTabsArray(b).indexOf(aTab);
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/* notify "ready to open child tab(s)" */
|
|
|
|
|
|
|
|
readyToOpenChildTab : function TSTUtils_readyToOpenChildTab(aFrameOrTabBrowser, aMultiple, aInsertBefore) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
if (!this.getTreePref('autoAttachNewTabsAsChildren')) return;
|
|
|
|
|
|
|
|
var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser);
|
2010-09-13 09:58:30 -04:00
|
|
|
if (!frame)
|
|
|
|
return;
|
2009-12-25 12:55:55 -05:00
|
|
|
|
|
|
|
var ownerBrowser = this.getTabBrowserFromFrame(frame);
|
|
|
|
|
|
|
|
var parentTab = this.getTabFromFrame(frame, ownerBrowser);
|
2010-09-13 09:58:30 -04:00
|
|
|
if (!parentTab || parentTab.getAttribute('pinned') == 'true')
|
2010-09-09 05:00:11 -04:00
|
|
|
return;
|
2010-06-26 13:41:20 -04:00
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
ownerBrowser.treeStyleTab.ensureTabInitialized(parentTab);
|
|
|
|
var parentId = parentTab.getAttribute(this.kID);
|
|
|
|
|
|
|
|
var refId = null;
|
|
|
|
if (aInsertBefore) {
|
|
|
|
ownerBrowser.treeStyleTab.ensureTabInitialized(parentTab);
|
|
|
|
refId = aInsertBefore.getAttribute(this.kID);
|
|
|
|
}
|
|
|
|
|
|
|
|
ownerBrowser.treeStyleTab.readiedToAttachNewTab = true;
|
|
|
|
ownerBrowser.treeStyleTab.readiedToAttachMultiple = aMultiple || false ;
|
2010-12-07 11:28:23 -05:00
|
|
|
ownerBrowser.treeStyleTab.multipleCount = aMultiple ? 0 : -1 ;
|
2009-12-25 12:55:55 -05:00
|
|
|
ownerBrowser.treeStyleTab.parentTab = parentId;
|
|
|
|
ownerBrowser.treeStyleTab.insertBefore = refId;
|
|
|
|
},
|
|
|
|
|
2010-07-29 22:39:51 -04:00
|
|
|
readyToOpenNewTabGroup : function TSTUtils_readyToOpenNewTabGroup(aFrameOrTabBrowser, aTreeStructure, aExpandAllTree) /* PUBLIC API */
|
2009-12-25 12:55:55 -05:00
|
|
|
{
|
|
|
|
if (!this.getTreePref('autoAttachNewTabsAsChildren')) return;
|
|
|
|
|
|
|
|
var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser);
|
|
|
|
if (!frame) return;
|
|
|
|
|
|
|
|
this.stopToOpenChildTab(frame);
|
|
|
|
|
|
|
|
var ownerBrowser = this.getTabBrowserFromFrame(frame);
|
|
|
|
ownerBrowser.treeStyleTab.readiedToAttachNewTabGroup = true;
|
|
|
|
ownerBrowser.treeStyleTab.readiedToAttachMultiple = true;
|
|
|
|
ownerBrowser.treeStyleTab.multipleCount = 0;
|
|
|
|
ownerBrowser.treeStyleTab.treeStructure = aTreeStructure;
|
2010-07-29 22:39:51 -04:00
|
|
|
ownerBrowser.treeStyleTab.shouldExpandAllTree = aExpandAllTree ? true : false ;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
stopToOpenChildTab : function TSTUtils_stopToOpenChildTab(aFrameOrTabBrowser) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser);
|
|
|
|
if (!frame) return;
|
|
|
|
|
|
|
|
var ownerBrowser = this.getTabBrowserFromFrame(frame);
|
|
|
|
ownerBrowser.treeStyleTab.readiedToAttachNewTab = false;
|
|
|
|
ownerBrowser.treeStyleTab.readiedToAttachNewTabGroup = false;
|
|
|
|
ownerBrowser.treeStyleTab.readiedToAttachMultiple = false;
|
2010-12-07 11:28:23 -05:00
|
|
|
ownerBrowser.treeStyleTab.multipleCount = -1;
|
2009-12-25 12:55:55 -05:00
|
|
|
ownerBrowser.treeStyleTab.parentTab = null;
|
|
|
|
ownerBrowser.treeStyleTab.insertBefore = null;
|
|
|
|
ownerBrowser.treeStyleTab.treeStructure = null;
|
2010-07-29 22:39:51 -04:00
|
|
|
ownerBrowser.treeStyleTab.shouldExpandAllTree = false;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
checkToOpenChildTab : function TSTUtils_checkToOpenChildTab(aFrameOrTabBrowser) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser);
|
|
|
|
if (!frame) return false;
|
|
|
|
|
|
|
|
var ownerBrowser = this.getTabBrowserFromFrame(frame);
|
|
|
|
return ownerBrowser.treeStyleTab.readiedToAttachNewTab || ownerBrowser.treeStyleTab.readiedToAttachNewTabGroup ? true : false ;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* tree manipulations */
|
|
|
|
|
|
|
|
get treeViewEnabled() /* PUBLIC API */
|
|
|
|
{
|
|
|
|
return this._treeViewEnabled;
|
|
|
|
},
|
|
|
|
set treeViewEnabled(aValue)
|
|
|
|
{
|
|
|
|
this._treeViewEnabled = aValue ? true : false ;
|
|
|
|
this.ObserverService.notifyObservers(
|
|
|
|
window,
|
2010-11-30 19:33:07 -05:00
|
|
|
this.kTOPIC_CHANGE_TREEVIEW_AVAILABILITY,
|
2009-12-25 12:55:55 -05:00
|
|
|
this._treeViewEnabled
|
|
|
|
);
|
|
|
|
return aValue;
|
|
|
|
},
|
|
|
|
_treeViewEnabled : true,
|
|
|
|
|
|
|
|
get rootTabs() /* PUBLIC API */
|
|
|
|
{
|
|
|
|
return this.getArrayFromXPathResult(
|
|
|
|
this.evaluateXPath(
|
|
|
|
'child::xul:tab[not(@'+this.kNEST+') or @'+this.kNEST+'="0" or @'+this.kNEST+'=""]',
|
|
|
|
this.browser.mTabContainer
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2010-12-08 06:34:42 -05:00
|
|
|
get allRootTabs() /* PUBLIC API */
|
|
|
|
{
|
|
|
|
return this.rootTabs;
|
|
|
|
},
|
|
|
|
|
|
|
|
get visibleRootTabs() /* PUBLIC API */
|
|
|
|
{
|
|
|
|
return this.rootTabs.filter(function(aTab) {
|
|
|
|
return !aTab.hidden;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2010-11-29 03:24:45 -05:00
|
|
|
canCollapseSubtree : function TSTUtils_canCollapseSubtree(aTabOrTabBrowser) /* PUBLIC API */
|
2009-12-25 12:55:55 -05:00
|
|
|
{
|
2010-11-29 03:24:45 -05:00
|
|
|
if (aTabOrTabBrowser &&
|
|
|
|
aTabOrTabBrowser.localName == 'tab' &&
|
|
|
|
aTabOrTabBrowser.getAttribute(this.kALLOW_COLLAPSE) != 'true')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var b = this.getTabBrowserFromChild(aTabOrTabBrowser) || this.browser;
|
2009-12-25 12:55:55 -05:00
|
|
|
return b.getAttribute(this.kALLOW_COLLAPSE) == 'true';
|
|
|
|
},
|
|
|
|
|
|
|
|
isCollapsed : function TSTUtils_isCollapsed(aTab) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
if (!aTab || !this.canCollapseSubtree(aTab))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return aTab.getAttribute(this.kCOLLAPSED) == 'true';
|
|
|
|
},
|
|
|
|
|
|
|
|
isSubtreeCollapsed : function TSTUtils_isSubtreeCollapsed(aTab) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
if (!aTab || !this.canCollapseSubtree(aTab) || !this.hasChildTabs(aTab))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return aTab.getAttribute(this.kSUBTREE_COLLAPSED) == 'true';
|
|
|
|
},
|
|
|
|
|
|
|
|
shouldCloseTabSubtreeOf : function TSTUtils_shouldCloseTabSubtreeOf(aTab)
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
this.hasChildTabs(aTab) &&
|
|
|
|
(
|
|
|
|
this.getTreePref('closeParentBehavior') == this.CLOSE_PARENT_BEHAVIOR_CLOSE ||
|
|
|
|
this.isSubtreeCollapsed(aTab)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
shouldCloseTabSubTreeOf : function() { return this.shouldCloseTabSubtreeOf.apply(this, arguments); }, // obsolete, for backward compatibility
|
|
|
|
|
|
|
|
shouldCloseLastTabSubtreeOf : function TSTUtils_shouldCloseLastTabSubtreeOf(aTab)
|
|
|
|
{
|
|
|
|
var b = this.getTabBrowserFromChild(aTab);
|
|
|
|
return (
|
|
|
|
this.shouldCloseTabSubtreeOf(aTab) &&
|
2010-09-14 03:39:17 -04:00
|
|
|
this.getDescendantTabs(aTab).length + 1 == this.getAllTabsArray(b).length
|
2009-12-25 12:55:55 -05:00
|
|
|
);
|
|
|
|
},
|
|
|
|
shouldCloseLastTabSubTreeOf : function() { return this.shouldCloseLastTabSubtreeOf.apply(this, arguments); }, // obsolete, for backward compatibility
|
|
|
|
|
|
|
|
getParentTab : function TSTUtils_getParentTab(aTab) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
if (!aTab) return null;
|
2010-03-24 11:38:08 -04:00
|
|
|
|
|
|
|
if (this.tabsHash) { // XPath-less implementation
|
|
|
|
let parent = this.getTabById(aTab.getAttribute(this.kPARENT));
|
2010-03-25 10:49:22 -04:00
|
|
|
return (parent && parent != aTab) ? parent : null ;
|
2010-03-24 11:38:08 -04:00
|
|
|
}
|
|
|
|
|
2010-03-24 08:52:29 -04:00
|
|
|
return this.evaluateXPath(
|
2010-03-24 11:45:19 -04:00
|
|
|
'preceding-sibling::xul:tab[@'+this.kID+'="'+aTab.getAttribute(this.kPARENT)+'"][1]',
|
2010-03-24 11:38:08 -04:00
|
|
|
aTab,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
2010-12-01 03:40:18 -05:00
|
|
|
getAncestorTabs : function TSTUtils_getAncestorTabs(aTab) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
var tabs = [];
|
|
|
|
var parentTab = aTab;
|
|
|
|
while (parentTab = this.getParentTab(parentTab))
|
|
|
|
{
|
|
|
|
tabs.push(parentTab);
|
|
|
|
}
|
|
|
|
return tabs;
|
|
|
|
},
|
|
|
|
|
2009-12-25 12:55:55 -05:00
|
|
|
getRootTab : function TSTUtils_getRootTab(aTab) /* PUBLIC API */
|
|
|
|
{
|
2010-03-24 11:38:08 -04:00
|
|
|
if (!aTab) return null;
|
|
|
|
|
|
|
|
if (this.tabsHash) { // XPath-less implementation
|
|
|
|
let parent = aTab;
|
|
|
|
let root = aTab;
|
|
|
|
while (parent = this.getParentTab(parent))
|
|
|
|
{
|
|
|
|
root = parent;
|
|
|
|
}
|
|
|
|
return root;
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
2010-03-24 11:38:08 -04:00
|
|
|
|
|
|
|
return this.evaluateXPath(
|
|
|
|
'(self::*[not(@'+this.kPARENT+')] | preceding-sibling::xul:tab[not(@'+this.kPARENT+')])[last()]',
|
|
|
|
aTab,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getNextSiblingTab : function TSTUtils_getNextSiblingTab(aTab) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
if (!aTab) return null;
|
|
|
|
|
2010-03-24 11:38:08 -04:00
|
|
|
if (this.tabsHash) { // XPath-less implementation
|
|
|
|
let parentTab = this.getParentTab(aTab);
|
2009-12-25 12:55:55 -05:00
|
|
|
|
2010-03-24 11:38:08 -04:00
|
|
|
if (!parentTab) {
|
|
|
|
let next = aTab;
|
|
|
|
do {
|
|
|
|
next = next.nextSibling;
|
|
|
|
}
|
|
|
|
while (next &&
|
|
|
|
next.nodeType == Ci.nsIDOMNode.ELEMENT_NODE &&
|
|
|
|
this.getParentTab(next));
|
|
|
|
return next;
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
|
|
|
|
2010-03-24 11:38:08 -04:00
|
|
|
let children = parentTab.getAttribute(this.kCHILDREN);
|
|
|
|
if (children) {
|
|
|
|
let list = ('|'+children).split('|'+aTab.getAttribute(this.kID))[1].split('|');
|
|
|
|
for (let i = 0, maxi = list.length; i < maxi; i++)
|
|
|
|
{
|
|
|
|
let firstChild = this.getTabById(list[i], aTab);
|
|
|
|
if (firstChild) return firstChild;
|
|
|
|
}
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
2010-03-24 11:38:08 -04:00
|
|
|
return null;
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
2010-03-24 11:38:08 -04:00
|
|
|
|
|
|
|
var parent = aTab.getAttribute(this.kPARENT);
|
|
|
|
return this.evaluateXPath(
|
|
|
|
'following-sibling::xul:tab['+
|
|
|
|
(parent ? '@'+this.kPARENT+'="'+parent+'"' : 'not(@'+this.kPARENT+')' )+
|
|
|
|
'][1]',
|
|
|
|
aTab,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getPreviousSiblingTab : function TSTUtils_getPreviousSiblingTab(aTab) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
if (!aTab) return null;
|
|
|
|
|
2010-03-24 11:38:08 -04:00
|
|
|
if (this.tabsHash) { // XPath-less implementation
|
|
|
|
let parentTab = this.getParentTab(aTab);
|
2009-12-25 12:55:55 -05:00
|
|
|
|
2010-03-24 11:38:08 -04:00
|
|
|
if (!parentTab) {
|
|
|
|
let prev = aTab;
|
|
|
|
do {
|
|
|
|
prev = prev.previousSibling;
|
|
|
|
}
|
|
|
|
while (prev &&
|
|
|
|
prev.nodeType == Ci.nsIDOMNode.ELEMENT_NODE &&
|
|
|
|
this.getParentTab(prev));
|
|
|
|
return prev;
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
|
|
|
|
2010-03-24 11:38:08 -04:00
|
|
|
let children = parentTab.getAttribute(this.kCHILDREN);
|
|
|
|
if (children) {
|
|
|
|
let list = ('|'+children).split('|'+aTab.getAttribute(this.kID))[0].split('|');
|
|
|
|
for (let i = list.length-1; i > -1; i--)
|
|
|
|
{
|
|
|
|
let lastChild = this.getTabById(list[i], aTab);
|
|
|
|
if (lastChild) return lastChild;
|
|
|
|
}
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
2010-03-24 11:38:08 -04:00
|
|
|
return null;
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
2010-03-24 11:38:08 -04:00
|
|
|
|
|
|
|
var parent = aTab.getAttribute(this.kPARENT);
|
|
|
|
return this.evaluateXPath(
|
|
|
|
'preceding-sibling::xul:tab['+
|
|
|
|
(parent ? '@'+this.kPARENT+'="'+parent+'"' : 'not(@'+this.kPARENT+')' )+
|
|
|
|
'][1]',
|
|
|
|
aTab,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getChildTabs : function TSTUtils_getChildTabs(aTab, aAllTabsArray) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
var tabs = [];
|
|
|
|
if (!aTab) return tabs;
|
|
|
|
|
|
|
|
var children = aTab.getAttribute(this.kCHILDREN);
|
|
|
|
if (!children) return tabs;
|
|
|
|
|
|
|
|
if (aAllTabsArray) tabs = aAllTabsArray;
|
|
|
|
|
|
|
|
var list = children.split('|');
|
|
|
|
for (let i = 0, maxi = list.length; i < maxi; i++)
|
|
|
|
{
|
|
|
|
let tab = this.getTabById(list[i], aTab);
|
2010-03-25 10:49:22 -04:00
|
|
|
if (!tab || tab == aTab) continue;
|
2009-12-25 12:55:55 -05:00
|
|
|
tabs.push(tab);
|
|
|
|
if (aAllTabsArray)
|
|
|
|
this.getChildTabs(tab, tabs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tabs;
|
|
|
|
},
|
|
|
|
|
|
|
|
hasChildTabs : function TSTUtils_hasChildTabs(aTab) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
if (!aTab) return false;
|
|
|
|
return aTab.hasAttribute(this.kCHILDREN);
|
|
|
|
},
|
|
|
|
|
|
|
|
getDescendantTabs : function TSTUtils_getDescendantTabs(aTab) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
var tabs = [];
|
|
|
|
this.getChildTabs(aTab, tabs);
|
|
|
|
return tabs;
|
|
|
|
},
|
|
|
|
|
|
|
|
getFirstChildTab : function TSTUtils_getFirstChildTab(aTab) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
if (!aTab) return null;
|
|
|
|
|
2010-03-24 11:38:08 -04:00
|
|
|
if (this.tabsHash) { // XPath-less implementation
|
|
|
|
let children = aTab.getAttribute(this.kCHILDREN);
|
|
|
|
let firstChild = null;
|
|
|
|
if (children) {
|
|
|
|
let list = children.split('|');
|
|
|
|
for (let i = 0, maxi = list.length; i < maxi; i++)
|
|
|
|
{
|
|
|
|
firstChild = this.getTabById(list[i], aTab);
|
2010-03-25 10:49:22 -04:00
|
|
|
if (firstChild && firstChild != aTab) break;
|
2010-03-24 11:38:08 -04:00
|
|
|
}
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
2010-03-24 11:38:08 -04:00
|
|
|
return firstChild;
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
2010-03-24 11:38:08 -04:00
|
|
|
|
|
|
|
return this.evaluateXPath(
|
|
|
|
'following-sibling::xul:tab[@'+this.kPARENT+'="'+aTab.getAttribute(this.kID)+'"][1]',
|
|
|
|
aTab,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getLastChildTab : function TSTUtils_getLastChildTab(aTab) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
if (!aTab) return null;
|
|
|
|
|
2010-03-24 11:38:08 -04:00
|
|
|
if (this.tabsHash) { // XPath-less implementation
|
|
|
|
let children = aTab.getAttribute(this.kCHILDREN);
|
|
|
|
let lastChild = null;
|
|
|
|
if (children) {
|
|
|
|
let list = children.split('|');
|
|
|
|
for (let i = list.length-1; i > -1; i--)
|
|
|
|
{
|
|
|
|
lastChild = this.getTabById(list[i], aTab);
|
2010-03-25 11:52:11 -04:00
|
|
|
if (lastChild && lastChild != aTab) break;
|
2010-03-24 11:38:08 -04:00
|
|
|
}
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
2010-03-24 11:38:08 -04:00
|
|
|
return lastChild;
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
2010-03-24 11:38:08 -04:00
|
|
|
|
|
|
|
return this.evaluateXPath(
|
|
|
|
'following-sibling::xul:tab[@'+this.kPARENT+'="'+aTab.getAttribute(this.kID)+'"][last()]',
|
|
|
|
aTab,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getLastDescendantTab : function TSTUtils_getLastDescendantTab(aTab) /* PUBLIC API */
|
|
|
|
{
|
|
|
|
if (!aTab) return null;
|
|
|
|
|
2010-03-24 11:38:08 -04:00
|
|
|
if (this.tabsHash) { // XPath-less implementation
|
|
|
|
let tabs = this.getDescendantTabs(aTab);
|
|
|
|
return tabs.length ? tabs[tabs.length-1] : null ;
|
|
|
|
}
|
|
|
|
|
|
|
|
var parent = aTab.getAttribute(this.kPARENT);
|
|
|
|
return this.evaluateXPath(
|
|
|
|
'following-sibling::xul:tab['+
|
|
|
|
(parent ? '@'+this.kPARENT+'="'+parent+'"' : 'not(@'+this.kPARENT+')' )+
|
|
|
|
'][1]/preceding-sibling::xul:tab[1][not(@'+this.kID+'="'+aTab.getAttribute(this.kID)+'")]',
|
|
|
|
aTab,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
|
|
).singleNodeValue;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
2010-03-24 11:38:08 -04:00
|
|
|
getChildIndex : function TSTUtils_getChildIndex(aTab, aParent) /* PUBLIC API */
|
2009-12-25 12:55:55 -05:00
|
|
|
{
|
2010-03-24 11:38:08 -04:00
|
|
|
if (this.tabsHash) { // XPath-less implementation
|
|
|
|
let parent = this.getParentTab(aTab);
|
|
|
|
if (!aParent || !parent || aParent != parent) {
|
|
|
|
parent = aTab;
|
|
|
|
while (parent && parent != aParent)
|
|
|
|
{
|
|
|
|
aTab = parent;
|
|
|
|
parent = this.getParentTab(parent);
|
|
|
|
}
|
|
|
|
if (parent != aParent)
|
|
|
|
return -1;
|
|
|
|
aParent = parent;
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
|
|
|
|
2010-03-24 11:38:08 -04:00
|
|
|
if (aParent) {
|
|
|
|
let children = aParent.getAttribute(this.kCHILDREN);
|
|
|
|
let list = children.split('|');
|
|
|
|
let id = aTab.getAttribute(this.kID);
|
|
|
|
for (let i = 0, maxi = list.length; i < maxi; i++)
|
|
|
|
{
|
|
|
|
if (list[i] == id) return i;
|
|
|
|
}
|
|
|
|
return -1;
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
2010-03-24 11:38:08 -04:00
|
|
|
else {
|
|
|
|
let tabs = this.rootTabs;
|
|
|
|
for (let i = 0, maxi = tabs.length; i < maxi; i++)
|
|
|
|
{
|
|
|
|
if (tabs[i] == aTab) return i;
|
|
|
|
}
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
2010-03-24 11:38:08 -04:00
|
|
|
return -1;
|
2009-12-25 12:55:55 -05:00
|
|
|
}
|
2010-03-24 11:38:08 -04:00
|
|
|
|
|
|
|
var parent = aTab.getAttribute(this.kPARENT);
|
|
|
|
if (!parent) return -1;
|
|
|
|
return this.evaluateXPath(
|
|
|
|
'count(preceding-sibling::xul:tab[@'+this.kPARENT+' and @'+this.kPARENT+'="'+parent+'"])',
|
|
|
|
aTab,
|
|
|
|
Ci.nsIDOMXPathResult.NUMBER_TYPE
|
|
|
|
).numberValue;
|
2009-12-25 12:55:55 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getXOffsetOfTab : function TSTUtils_getXOffsetOfTab(aTab)
|
|
|
|
{
|
|
|
|
var extraCondition = this.canCollapseSubtree(aTab) ?
|
|
|
|
'[not(@'+this.kCOLLAPSED+'="true")]' :
|
|
|
|
'' ;
|
|
|
|
|
|
|
|
return this.evaluateXPath(
|
2010-08-13 13:14:46 -04:00
|
|
|
'sum((self::* | preceding-sibling::xul:tab[not(@hidden="true")]'+extraCondition+')'+
|
|
|
|
'/attribute::'+this.kX_OFFSET+')',
|
2009-12-25 12:55:55 -05:00
|
|
|
aTab,
|
|
|
|
Ci.nsIDOMXPathResult.NUMBER_TYPE
|
|
|
|
).numberValue;
|
|
|
|
},
|
|
|
|
getYOffsetOfTab : function TSTUtils_getYOffsetOfTab(aTab)
|
|
|
|
{
|
|
|
|
var extraCondition = this.canCollapseSubtree(aTab) ?
|
|
|
|
'[not(@'+this.kCOLLAPSED+'="true")]' :
|
|
|
|
'';
|
|
|
|
|
|
|
|
return this.evaluateXPath(
|
2010-08-13 13:14:46 -04:00
|
|
|
'sum((self::* | preceding-sibling::xul:tab[not(@hidden="true")]'+extraCondition+')'+
|
|
|
|
'/attribute::'+this.kY_OFFSET+')',
|
2009-12-25 12:55:55 -05:00
|
|
|
aTab,
|
|
|
|
Ci.nsIDOMXPathResult.NUMBER_TYPE
|
|
|
|
).numberValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
isGroupTab : function TSTUtils_isGroupTab(aTab, aLazyCheck)
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
(aLazyCheck || aTab.linkedBrowser.sessionHistory.count == 1) &&
|
|
|
|
aTab.linkedBrowser.currentURI.spec.indexOf('about:treestyletab-group') > -1
|
|
|
|
);
|
|
|
|
},
|
2010-09-09 06:03:03 -04:00
|
|
|
|
|
|
|
get pinnedTabsCount()
|
|
|
|
{
|
|
|
|
return this.evaluateXPath(
|
|
|
|
'count(child::xul:tab[@pinned="true"])',
|
|
|
|
this.browser.mTabContainer,
|
|
|
|
Ci.nsIDOMXPathResult.NUMBER_TYPE
|
|
|
|
).numberValue;
|
|
|
|
},
|
2009-12-25 12:55:55 -05:00
|
|
|
|
2009-12-25 13:13:33 -05:00
|
|
|
/* tabbar position */
|
2009-12-25 11:51:24 -05:00
|
|
|
|
|
|
|
get currentTabbarPosition() /* PUBLIC API */
|
2009-12-25 11:38:14 -05:00
|
|
|
{
|
2009-12-25 11:56:45 -05:00
|
|
|
return this.getTreePref('tabbar.position') || 'top';
|
2009-12-25 11:38:14 -05:00
|
|
|
},
|
|
|
|
set currentTabbarPosition(aValue)
|
|
|
|
{
|
2010-05-08 04:30:39 -04:00
|
|
|
var position = String(aValue).toLowerCase();
|
|
|
|
if (!position || !/^(top|bottom|left|right)$/.test(position))
|
2009-12-25 11:38:14 -05:00
|
|
|
position = 'top';
|
|
|
|
|
2010-05-08 04:30:39 -04:00
|
|
|
if (position != this.getTreePref('tabbar.position'))
|
|
|
|
this.setTreePref('tabbar.position', position);
|
2009-12-25 11:38:14 -05:00
|
|
|
|
|
|
|
return aValue;
|
|
|
|
},
|
2010-02-03 08:43:39 -05:00
|
|
|
|
|
|
|
getPositionFlag : function TSTUtils_getPositionFlag(aPosition)
|
|
|
|
{
|
|
|
|
aPosition = String(aPosition).toLowerCase();
|
|
|
|
return (aPosition == 'left') ? this.kTABBAR_LEFT :
|
|
|
|
(aPosition == 'right') ? this.kTABBAR_RIGHT :
|
|
|
|
(aPosition == 'bottom') ? this.kTABBAR_BOTTOM :
|
|
|
|
this.kTABBAR_TOP;
|
|
|
|
},
|
2009-12-25 11:51:24 -05:00
|
|
|
|
2009-12-25 13:13:33 -05:00
|
|
|
/* Pref Listener */
|
2009-12-25 11:56:45 -05:00
|
|
|
|
|
|
|
domains : [
|
2009-12-25 13:13:33 -05:00
|
|
|
'extensions.treestyletab.',
|
|
|
|
'browser.tabs.loadFolderAndReplace',
|
2010-03-31 06:34:30 -04:00
|
|
|
'browser.tabs.insertRelatedAfterCurrent',
|
|
|
|
'extensions.stm.tabBarMultiRows' // Super Tab Mode
|
2009-12-25 11:56:45 -05:00
|
|
|
],
|
|
|
|
|
|
|
|
onPrefChange : function TSTUtils_onPrefChange(aPrefName)
|
|
|
|
{
|
|
|
|
var value = this.getPref(aPrefName);
|
|
|
|
switch (aPrefName)
|
|
|
|
{
|
2009-12-25 13:13:33 -05:00
|
|
|
case 'extensions.treestyletab.indent':
|
|
|
|
this.baseIndent = value;
|
2010-11-30 19:33:07 -05:00
|
|
|
this.ObserverService.notifyObservers(null, this.kTOPIC_INDENT_MODIFIED, value);
|
2009-12-25 13:13:33 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'extensions.treestyletab.tabbar.width':
|
|
|
|
case 'extensions.treestyletab.tabbar.shrunkenWidth':
|
|
|
|
this.updateTabWidthPrefs(aPrefName);
|
|
|
|
break;
|
|
|
|
|
2010-05-02 00:32:08 -04:00
|
|
|
case 'browser.tabs.insertRelatedAfterCurrent':
|
2009-12-25 13:13:33 -05:00
|
|
|
case 'browser.tabs.loadFolderAndReplace':
|
2010-03-31 06:34:30 -04:00
|
|
|
case 'extensions.stm.tabBarMultiRows': // Super Tab Mode
|
2009-12-25 13:13:33 -05:00
|
|
|
if (this.prefOverriding) return;
|
|
|
|
aPrefName += '.override';
|
|
|
|
this.setPref(aPrefName, value);
|
2010-05-02 00:32:08 -04:00
|
|
|
case 'browser.tabs.insertRelatedAfterCurrent.override':
|
2009-12-25 13:13:33 -05:00
|
|
|
case 'browser.tabs.loadFolderAndReplace.override':
|
2010-03-31 06:34:30 -04:00
|
|
|
case 'extensions.stm.tabBarMultiRows.override': // Super Tab Mode
|
2010-05-02 00:51:19 -04:00
|
|
|
if (this.getPref(aPrefName+'.force')) {
|
|
|
|
let defaultValue = this.getDefaultPref(aPrefName);
|
|
|
|
if (value != defaultValue) {
|
|
|
|
this.setPref(aPrefName, defaultValue);
|
|
|
|
return;
|
|
|
|
}
|
2010-05-02 00:32:08 -04:00
|
|
|
}
|
2009-12-25 13:13:33 -05:00
|
|
|
this.prefOverriding = true;
|
2010-05-02 00:51:19 -04:00
|
|
|
let (target = aPrefName.replace('.override', '')) {
|
|
|
|
let originalValue = this.getPref(target);
|
|
|
|
if (originalValue !== null && originalValue != value)
|
|
|
|
this.setPref(target+'.backup', originalValue);
|
|
|
|
this.setPref(target, this.getPref(aPrefName));
|
|
|
|
}
|
2009-12-25 13:13:33 -05:00
|
|
|
this.prefOverriding = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'extensions.treestyletab.clickOnIndentSpaces.enabled':
|
|
|
|
this.shouldDetectClickOnIndentSpaces = this.getPref(aPrefName);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'extensions.treestyletab.tabbar.scroll.smooth':
|
|
|
|
this.smoothScrollEnabled = value;
|
|
|
|
break;
|
|
|
|
case 'extensions.treestyletab.tabbar.scroll.duration':
|
|
|
|
this.smoothScrollDuration = value;
|
|
|
|
break;
|
|
|
|
|
2010-07-25 12:13:19 -04:00
|
|
|
case 'extensions.treestyletab.tabbar.scrollToNewTab.mode':
|
|
|
|
this.scrollToNewTabMode = value;
|
|
|
|
break;
|
|
|
|
|
2009-12-25 13:13:33 -05:00
|
|
|
case 'extensions.treestyletab.animation.enabled':
|
|
|
|
this.animationEnabled = value;
|
|
|
|
break;
|
|
|
|
case 'extensions.treestyletab.animation.indent.duration':
|
|
|
|
this.indentDuration = value;
|
|
|
|
break;
|
|
|
|
case 'extensions.treestyletab.animation.collapse.duration':
|
|
|
|
this.collapseDuration = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'extensions.treestyletab.twisty.expandSensitiveArea':
|
2009-12-25 13:45:52 -05:00
|
|
|
this.shouldExpandTwistyArea = value;
|
2009-12-25 13:13:33 -05:00
|
|
|
break;
|
|
|
|
|
2009-12-25 11:56:45 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
2009-12-25 13:13:33 -05:00
|
|
|
|
|
|
|
updateTabWidthPrefs : function TSTUtils_updateTabWidthPrefs(aPrefName)
|
|
|
|
{
|
|
|
|
var expanded = this.getTreePref('tabbar.width');
|
|
|
|
var shrunken = this.getTreePref('tabbar.shrunkenWidth');
|
2010-04-22 05:24:21 -04:00
|
|
|
var originalExpanded = expanded;
|
|
|
|
var originalShrunken = shrunken;
|
|
|
|
if (aPrefName == 'extensions.treestyletab.tabbar.shrunkenWidth') {
|
|
|
|
if (expanded <= shrunken)
|
|
|
|
expanded = parseInt(shrunken / this.DEFAULT_SHRUNKEN_WIDTH_RATIO)
|
|
|
|
let w = this.browserWindow;
|
|
|
|
if (w && expanded > w.gBrowser.boxObject.width) {
|
|
|
|
expanded = w.gBrowser.boxObject.width * this.MAX_TABBAR_SIZE_RATIO;
|
|
|
|
if (expanded <= shrunken)
|
|
|
|
shrunken = parseInt(expanded * this.DEFAULT_SHRUNKEN_WIDTH_RATIO)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (expanded <= shrunken)
|
|
|
|
shrunken = parseInt(expanded * this.DEFAULT_SHRUNKEN_WIDTH_RATIO);
|
|
|
|
}
|
|
|
|
if (expanded != originalExpanded ||
|
|
|
|
shrunken != originalShrunken) {
|
2009-12-25 13:13:33 -05:00
|
|
|
this.tabbarWidthResetting = true;
|
2010-09-10 06:21:26 -04:00
|
|
|
this.setTreePref('tabbar.width', Math.max(0, expanded));
|
|
|
|
this.setTreePref('tabbar.shrunkenWidth', Math.max(0, shrunken));
|
2009-12-25 13:13:33 -05:00
|
|
|
this.tabbarWidthResetting = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-12-25 11:51:24 -05:00
|
|
|
/* Save/Load Prefs */
|
|
|
|
|
|
|
|
getTreePref : function TSTUtils_getTreePref(aPrefstring)
|
|
|
|
{
|
|
|
|
return this.getPref('extensions.treestyletab.'+aPrefstring);
|
|
|
|
},
|
|
|
|
|
|
|
|
setTreePref : function TSTUtils_setTreePref(aPrefstring, aNewValue)
|
|
|
|
{
|
|
|
|
return this.setPref('extensions.treestyletab.'+aPrefstring, aNewValue);
|
|
|
|
},
|
|
|
|
|
|
|
|
clearTreePref : function TSTUtils_clearTreePref(aPrefstring)
|
|
|
|
{
|
|
|
|
return this.clearPref('extensions.treestyletab.'+aPrefstring);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2010-06-22 14:00:16 -04:00
|
|
|
TreeStyleTabUtils.__proto__ = window['piro.sakura.ne.jp'].prefs;
|
2009-12-25 11:51:24 -05:00
|
|
|
|