From 573f1d179d6088ef1e14012c1cc492b003249560 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Sat, 13 Feb 2016 01:01:44 +0900 Subject: [PATCH] Move some utilities from TSTBase to TSTUtils --- modules/base.js | 91 +-------------------------------- modules/bookmark.js | 2 +- modules/browser.js | 2 +- modules/tabbarDNDObserver.js | 10 ++-- modules/utils.js | 97 +++++++++++++++++++++++++++++++++++- modules/window.js | 2 +- 6 files changed, 105 insertions(+), 99 deletions(-) diff --git a/modules/base.js b/modules/base.js index 9dcb7c95..3d20cd5e 100644 --- a/modules/base.js +++ b/modules/base.js @@ -234,69 +234,6 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, { } }, - updateNarrowScrollbarStyle : function TSTBase_updateNarrowScrollbarStyle() - { - const SSS = Cc['@mozilla.org/content/style-sheet-service;1'] - .getService(Ci.nsIStyleSheetService); - - if (this.lastAgentSheet && - SSS.sheetRegistered(this.lastAgentSheet, SSS.AGENT_SHEET)) - SSS.unregisterSheet(this.lastAgentSheet, SSS.AGENT_SHEET); - - const style = 'data:text/css,'+encodeURIComponent( - ('@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");' + - - 'tabs.tabbrowser-tabs[%MODE%="vertical"][%NARROW%="true"]' + - ' .tabbrowser-arrowscrollbox' + - ' > scrollbox' + - ' > scrollbar[orient="vertical"],' + - 'tabs.tabbrowser-tabs[%MODE%="vertical"][%NARROW%="true"]' + - ' .tabbrowser-arrowscrollbox' + - ' > scrollbox' + - ' > scrollbar[orient="vertical"] * {' + - ' max-width: %SIZE%;' + - ' min-width: %SIZE%;' + - '}' + - - 'tabs.tabbrowser-tabs[%MODE%="vertical"][%NARROW%="true"]' + - ' .tabbrowser-arrowscrollbox' + - ' > scrollbox' + - ' > scrollbar[orient="vertical"] {' + - ' font-size: %SIZE%;' + - '}' + - - 'tabs.tabbrowser-tabs[%MODE%="vertical"][%NARROW%="true"]' + - ' .tabbrowser-arrowscrollbox' + - ' > scrollbox' + - ' > scrollbar[orient="vertical"] * {' + - ' padding-left: 0;' + - ' padding-right: 0;' + - ' margin-left: 0;' + - ' margin-right: 0;' + - '}' + - - '%FORCE_NARROW_SCROLLBAR%') - .replace(/%FORCE_NARROW_SCROLLBAR%/g, - utils.getTreePref('tabbar.narrowScrollbar.overrideSystemAppearance') ? - this.kOVERRIDE_SYSTEM_SCROLLBAR_APPEARANCE : '' ) - .replace(/%MODE%/g, this.kMODE) - .replace(/%NARROW%/g, this.kNARROW_SCROLLBAR) - .replace(/%SIZE%/g, utils.getTreePref('tabbar.narrowScrollbar.size')) - ); - this.lastAgentSheet = this.makeURIFromSpec(style); - SSS.loadAndRegisterSheet(this.lastAgentSheet, SSS.AGENT_SHEET); - }, - kOVERRIDE_SYSTEM_SCROLLBAR_APPEARANCE : - 'tabs.tabbrowser-tabs[%MODE%="vertical"][%NARROW%="true"]' + - ' .tabbrowser-arrowscrollbox' + - ' > scrollbox' + - ' > scrollbar[orient="vertical"] {' + - ' appearance: none;' + - ' -moz-appearance: none;' + - ' background: ThreeDFace;' + - ' border: 1px solid ThreeDShadow;' + - '}', - lastAgentSheet : null, /* references to the owner */ @@ -706,32 +643,6 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, { { return 'tabs-closed-set-<'+Date.now()+'-'+parseInt(Math.random() * 65000)+'>'; }, - - makeURIFromSpec : function TSTBase_makeURIFromSpec(aURI) - { - var newURI; - aURI = aURI || ''; - if (aURI && String(aURI).indexOf('file:') == 0) { - var fileHandler = Services.io.getProtocolHandler('file').QueryInterface(Ci.nsIFileProtocolHandler); - var tempLocalFile = fileHandler.getFileFromURLSpec(aURI); - newURI = Services.io.newFileURI(tempLocalFile); - } - else { - if (!/^\w+\:/.test(aURI)) - aURI = 'http://'+aURI; - newURI = Services.io.newURI(aURI, null, null); - } - return newURI; - }, - - getGroupTabURI : function TSTBase_getGroupTabURI(aOptions) - { - aOptions = aOptions || {}; - var parameters = []; - parameters.push('title=' + encodeURIComponent(aOptions.title || '')); - parameters.push('temporary=' + !!aOptions.temporary); - return 'about:treestyletab-group?' + parameters.join('&'); - }, /* Session Store API */ @@ -2366,7 +2277,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, { return this.scrollToNewTabMode = value; case 'extensions.treestyletab.tabbar.narrowScrollbar.size': - return this.updateNarrowScrollbarStyle(); + return utils.updateNarrowScrollbarStyle(); case 'browser.tabs.animate': return this.animationEnabled = value; diff --git a/modules/bookmark.js b/modules/bookmark.js index 8d7a92d6..e35793a4 100644 --- a/modules/bookmark.js +++ b/modules/bookmark.js @@ -330,7 +330,7 @@ var TreeStyleTabBookmarksService = inherit(TreeStyleTabConstants, { ) { aIDs.unshift(-1); treeStructure = this.getTreeStructureFromItems(aIDs, 0); - let uri = TST.getGroupTabURI({ + let uri = utils.getGroupTabURI({ title: aFolderTitle, temporary: utils.getTreePref('openGroupBookmark.temporaryGroup') }); diff --git a/modules/browser.js b/modules/browser.js index 998f838b..f0431c95 100644 --- a/modules/browser.js +++ b/modules/browser.js @@ -5770,7 +5770,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, { } if (aInfo.behavior == this.kCLOSE_PARENT_BEHAVIOR_REPLACE_WITH_GROUP_TAB) { - let uri = this.getGroupTabURI({ + let uri = utils.getGroupTabURI({ title: aTab.label, temporary: true }); diff --git a/modules/tabbarDNDObserver.js b/modules/tabbarDNDObserver.js index 10ea59af..da0b61de 100644 --- a/modules/tabbarDNDObserver.js +++ b/modules/tabbarDNDObserver.js @@ -14,7 +14,7 @@ * The Original Code is the Tree Style Tab. * * The Initial Developer of the Original Code is YUKI "Piro" Hiroshi. - * Portions created by the Initial Developer are Copyright (C) 2010-2015 + * Portions created by the Initial Developer are Copyright (C) 2010-2016 * the Initial Developer. All Rights Reserved. * * Contributor(s): YUKI "Piro" Hiroshi @@ -79,14 +79,14 @@ TabbarDNDObserver.prototype = { readyToStartTabbarDrag : function TabbarDND_readyToStartTabbarDrag() { - var sheet = this.treeStyleTab.makeURIFromSpec('chrome://treestyletab/content/hide-embed.css'); + var sheet = utils.makeURIFromSpec('chrome://treestyletab/content/hide-embed.css'); if (!SSS.sheetRegistered(sheet, SSS.AGENT_SHEET)) SSS.loadAndRegisterSheet(sheet, SSS.AGENT_SHEET); }, readyToEndTabbarDrag : function TabbarDND_readyToEndTabbarDrag() { - var sheet = this.treeStyleTab.makeURIFromSpec('chrome://treestyletab/content/hide-embed.css'); + var sheet = utils.makeURIFromSpec('chrome://treestyletab/content/hide-embed.css'); if (SSS.sheetRegistered(sheet, SSS.AGENT_SHEET)) SSS.unregisterSheet(sheet, SSS.AGENT_SHEET); }, @@ -1219,7 +1219,7 @@ catch(e) { } let normalizedURI; try { - normalizedURI = this.treeStyleTab.makeURIFromSpec(aURI); + normalizedURI = utils.makeURIFromSpec(aURI); } catch(e) { } @@ -1291,7 +1291,7 @@ catch(e) { } // When a blank folder is dropped, just open a dummy tab with the folder name. if (children && children.length == 0) { - let uri = this.treeStyleTab.getGroupTabURI({ title: item.title }); + let uri = utils.getGroupTabURI({ title: item.title }); return [uri]; } } diff --git a/modules/utils.js b/modules/utils.js index ba4fde4e..ff2f92f5 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -14,7 +14,7 @@ * The Original Code is the Tree Style Tab. * * The Initial Developer of the Original Code is YUKI "Piro" Hiroshi. - * Portions created by the Initial Developer are Copyright (C) 2010-2015 + * Portions created by the Initial Developer are Copyright (C) 2010-2016 * the Initial Developer. All Rights Reserved. * * Contributor(s): YUKI "Piro" Hiroshi @@ -498,6 +498,101 @@ var TreeStyleTabUtils = { return aTreeStructure; }, + + updateNarrowScrollbarStyle : function utils_updateNarrowScrollbarStyle() + { + const SSS = Cc['@mozilla.org/content/style-sheet-service;1'] + .getService(Ci.nsIStyleSheetService); + + if (this.lastAgentSheetForNarrowScrollbar && + SSS.sheetRegistered(this.lastAgentSheetForNarrowScrollbar, SSS.AGENT_SHEET)) + SSS.unregisterSheet(this.lastAgentSheetForNarrowScrollbar, SSS.AGENT_SHEET); + + const style = 'data:text/css,'+encodeURIComponent( + ('@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");' + + + 'tabs.tabbrowser-tabs[%MODE%="vertical"][%NARROW%="true"]' + + ' .tabbrowser-arrowscrollbox' + + ' > scrollbox' + + ' > scrollbar[orient="vertical"],' + + 'tabs.tabbrowser-tabs[%MODE%="vertical"][%NARROW%="true"]' + + ' .tabbrowser-arrowscrollbox' + + ' > scrollbox' + + ' > scrollbar[orient="vertical"] * {' + + ' max-width: %SIZE%;' + + ' min-width: %SIZE%;' + + '}' + + + 'tabs.tabbrowser-tabs[%MODE%="vertical"][%NARROW%="true"]' + + ' .tabbrowser-arrowscrollbox' + + ' > scrollbox' + + ' > scrollbar[orient="vertical"] {' + + ' font-size: %SIZE%;' + + '}' + + + 'tabs.tabbrowser-tabs[%MODE%="vertical"][%NARROW%="true"]' + + ' .tabbrowser-arrowscrollbox' + + ' > scrollbox' + + ' > scrollbar[orient="vertical"] * {' + + ' padding-left: 0;' + + ' padding-right: 0;' + + ' margin-left: 0;' + + ' margin-right: 0;' + + '}' + + + '%FORCE_NARROW_SCROLLBAR%') + .replace(/%FORCE_NARROW_SCROLLBAR%/g, + utils.getTreePref('tabbar.narrowScrollbar.overrideSystemAppearance') ? + this.kOVERRIDE_SYSTEM_SCROLLBAR_APPEARANCE : '' ) + .replace(/%MODE%/g, this.kMODE) + .replace(/%NARROW%/g, this.kNARROW_SCROLLBAR) + .replace(/%SIZE%/g, utils.getTreePref('tabbar.narrowScrollbar.size')) + ); + this.lastAgentSheetForNarrowScrollbar = this.makeURIFromSpec(style); + SSS.loadAndRegisterSheet(this.lastAgentSheetForNarrowScrollbar, SSS.AGENT_SHEET); + }, + kOVERRIDE_SYSTEM_SCROLLBAR_APPEARANCE : + 'tabs.tabbrowser-tabs[%MODE%="vertical"][%NARROW%="true"]' + + ' .tabbrowser-arrowscrollbox' + + ' > scrollbox' + + ' > scrollbar[orient="vertical"] {' + + ' appearance: none;' + + ' -moz-appearance: none;' + + ' background: ThreeDFace;' + + ' border: 1px solid ThreeDShadow;' + + '}', + lastAgentSheetForNarrowScrollbar : null, + + + + + makeURIFromSpec : function utils_makeURIFromSpec(aURI) + { + var newURI; + aURI = aURI || ''; + if (aURI && String(aURI).indexOf('file:') == 0) { + var fileHandler = Services.io.getProtocolHandler('file').QueryInterface(Ci.nsIFileProtocolHandler); + var tempLocalFile = fileHandler.getFileFromURLSpec(aURI); + newURI = Services.io.newFileURI(tempLocalFile); + } + else { + if (!/^\w+\:/.test(aURI)) + aURI = 'http://'+aURI; + newURI = Services.io.newURI(aURI, null, null); + } + return newURI; + }, + + getGroupTabURI : function utils_getGroupTabURI(aOptions) + { + aOptions = aOptions || {}; + var parameters = []; + parameters.push('title=' + encodeURIComponent(aOptions.title || '')); + parameters.push('temporary=' + !!aOptions.temporary); + return 'about:treestyletab-group?' + parameters.join('&'); + }, + + /* Pref Listener */ domains : [ 'extensions.treestyletab.' diff --git a/modules/window.js b/modules/window.js index 764bd7c3..a417cce0 100644 --- a/modules/window.js +++ b/modules/window.js @@ -1689,7 +1689,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, { var shouldCreateGroup = aTabs.length > 1 && utils.getTreePref('createSubtree.underParent'); var root = shouldCreateGroup ? - b.addTab(this.getGroupTabURI({ + b.addTab(utils.getGroupTabURI({ temporary: utils.getTreePref('createSubtree.underParent.temporaryGroup') })) : aTabs.shift() ;