Move some utilities from TSTBase to TSTUtils

This commit is contained in:
Piro / YUKI Hiroshi 2016-02-13 01:01:44 +09:00
parent 7f1196e0ef
commit 573f1d179d
6 changed files with 105 additions and 99 deletions

View File

@ -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;

View File

@ -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')
});

View File

@ -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
});

View File

@ -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 <piro.outsider.reflex@gmail.com>
@ -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];
}
}

View File

@ -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 <piro.outsider.reflex@gmail.com>
@ -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.'

View File

@ -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() ;