don't load needless stylesheets

This commit is contained in:
Piro / SHIMODA Hiroshi 2011-05-26 23:22:42 +09:00
parent 47f32679c1
commit c9aca50c1b
4 changed files with 106 additions and 31 deletions

View File

@ -37,16 +37,75 @@ const EXPORTED_SYMBOLS = ['TreeStyleTabThemeManager'];
Components.utils.import('resource://treestyletab-modules/utils.js'); Components.utils.import('resource://treestyletab-modules/utils.js');
var TreeStyleTabThemeManager = { function TreeStyleTabThemeManager(aWindow)
preLoadImagesForStyle : function(aStyle) {
this.window = aWindow;
this._preLoadImagesForStyleDone = [];
this._preLoadImagesForStyleDoneImages = [];
}
TreeStyleTabThemeManager.prototype = {
destroy : function()
{ {
delete this.window;
},
set : function(aStyle, aPosition)
{
if (this._lastStyles)
this._lastStyles.forEach(function(aStyle) {
aStyle.parentNode.removeChild(aStyle);
});
this._lastStyles = null;
var styles = [];
switch (aStyle)
{
case 'default':
default:
case 'flat':
case 'mixed':
styles.push('chrome://treestyletab/skin/square/square.css');
styles.push('chrome://treestyletab/skin/square/dropshadow.css');
break;
case 'vertigo':
styles.push('chrome://treestyletab/skin/square/square.css');
break;
case 'metal':
styles.push('chrome://treestyletab/skin/metal/metal.css');
break;
case 'sidebar':
styles.push('chrome://treestyletab/skin/sidebar/sidebar.css');
break;
}
if (styles.length) {
this._lastStyles = styles.map(function(aStyle) {
var d = this.window.document;
var pi = d.createProcessingInstruction(
'xml-stylesheet',
'type="text/css" href="'+aStyle+'"'
);
d.insertBefore(pi, d.documentElement);
return pi;
}, this);
this.preloadImages(aStyle, aPosition);
}
},
preloadImages : function(aStyle, aPosition)
{
var key = aStyle+'-'+aPosition;
if (!aStyle || if (!aStyle ||
this._preLoadImagesForStyleDone.indexOf(aStyle) > -1) this._preLoadImagesForStyleDone.indexOf(key) > -1)
return; return;
this._preLoadImagesForStyleDone.push(aStyle); this._preLoadImagesForStyleDone.push(key);
var images = aStyle in this._preLoadImages ? var images = aStyle in this._preLoadImages ?
this._preLoadImages[aStyle] : this._preLoadImages[key] :
null ; null ;
if (!images) return; if (!images) return;
@ -54,12 +113,11 @@ var TreeStyleTabThemeManager = {
if (this._preLoadImagesForStyleDoneImages.indexOf(aImage) > -1) if (this._preLoadImagesForStyleDoneImages.indexOf(aImage) > -1)
return; return;
(new Image()).src = aImage; (new this.window.Image()).src = aImage;
this._preLoadImagesForStyleDoneImages.push(aImage); this._preLoadImagesForStyleDoneImages.push(aImage);
}, this); }, this);
}, },
_preLoadImagesForStyleDone : [],
_preLoadImagesForStyleDoneImages : [],
_preLoadImages : { _preLoadImages : {
'metal-left' : [ 'metal-left' : [
'chrome://treestyletab/skin/metal/tab-active-l.png', 'chrome://treestyletab/skin/metal/tab-active-l.png',

View File

@ -46,11 +46,6 @@ XPCOMUtils.defineLazyGetter(this, 'TreeStyleTabBrowser', function() {
Components.utils.import('resource://treestyletab-modules/browser.js', ns); Components.utils.import('resource://treestyletab-modules/browser.js', ns);
return ns.TreeStyleTabBrowser; return ns.TreeStyleTabBrowser;
}); });
XPCOMUtils.defineLazyGetter(this, 'TreeStyleTabThemeManager', function() {
var ns = {};
Components.utils.import('resource://treestyletab-modules/themeManager.js', ns);
return ns.TreeStyleTabThemeManager;
});
function TreeStyleTabWindow(aWindow) function TreeStyleTabWindow(aWindow)
{ {
@ -262,6 +257,26 @@ TreeStyleTabWindow.prototype = {
) : ) :
this.getTreePref('tabbar.autoHide.mode'); this.getTreePref('tabbar.autoHide.mode');
}, },
get autoHideWindow()
{
if (!this._autoHideWindow) {
let ns = {};
Components.utils.import('resource://treestyletab-modules/autoHide.js', ns);
this._autoHideWindow = new ns.AutoHideWindow(this.window);
}
return this._autoHideWindow;
},
get themeManager()
{
if (!this._themeManager) {
let ns = {};
Components.utils.import('resource://treestyletab-modules/themeManager.js', ns);
this._themeManager = new ns.TreeStyleTabThemeManager(this.window);
}
return this._themeManager;
},
/* Initializing */ /* Initializing */
@ -280,6 +295,9 @@ TreeStyleTabWindow.prototype = {
w.TreeStyleTabWindowHelper.preInit(); w.TreeStyleTabWindowHelper.preInit();
this.migratePrefs(); this.migratePrefs();
// initialize theme
this.onPrefChange('extensions.treestyletab.tabbar.style');
}, },
preInitialized : false, preInitialized : false,
@ -393,7 +411,11 @@ TreeStyleTabWindow.prototype = {
w.removeEventListener('load', this, false); w.removeEventListener('load', this, false);
w.addEventListener('unload', this, false); w.addEventListener('unload', this, false);
if (!this.browser) return; if (
w.location.href.indexOf('chrome://browser/content/browser.xul') != 0 ||
!this.browser
)
return;
if (this.initialized) return; if (this.initialized) return;
this.initialized = true; this.initialized = true;
@ -432,7 +454,6 @@ TreeStyleTabWindow.prototype = {
// Init autohide service only if it have to be activated. // Init autohide service only if it have to be activated.
if (this.isAutoHide) if (this.isAutoHide)
this.onPrefChange('extensions.treestyletab.tabbar.autoHide.mode'); this.onPrefChange('extensions.treestyletab.tabbar.autoHide.mode');
this.onPrefChange('extensions.treestyletab.tabbar.style');
this.onPrefChange('extensions.treestyletab.autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut'); this.onPrefChange('extensions.treestyletab.autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut');
}, },
initialized : false, initialized : false,
@ -535,6 +556,12 @@ TreeStyleTabWindow.prototype = {
let w = this.window; let w = this.window;
w.removeEventListener('unload', this, false); w.removeEventListener('unload', this, false);
this.autoHideWindow.destroy();
delete this._autoHideWindow;
this.themeManager.destroy();
delete this._themeManager;
this.browser.treeStyleTab.saveCurrentState(); this.browser.treeStyleTab.saveCurrentState();
this.destroyTabBrowser(this.browser); this.destroyTabBrowser(this.browser);
@ -1171,16 +1198,6 @@ TreeStyleTabWindow.prototype = {
} }
}, },
get autoHideWindow()
{
if (!this._autoHideWindow) {
let ns = {};
Components.utils.import('resource://treestyletab-modules/autoHide.js', ns);
this._autoHideWindow = new ns.AutoHideWindow(this.window);
}
return this._autoHideWindow;
},
toggleAutoHide : function TSTWindow_toggleAutoHide(aTabBrowser) /* PUBLIC API, for backward compatibility */ toggleAutoHide : function TSTWindow_toggleAutoHide(aTabBrowser) /* PUBLIC API, for backward compatibility */
{ {
this.autoHideWindow.toggleMode(aTabBrowser || this.browser); this.autoHideWindow.toggleMode(aTabBrowser || this.browser);
@ -1570,10 +1587,7 @@ TreeStyleTabWindow.prototype = {
case 'extensions.treestyletab.tabbar.style': case 'extensions.treestyletab.tabbar.style':
case 'extensions.treestyletab.tabbar.position': case 'extensions.treestyletab.tabbar.position':
TreeStyleTabThemeManager.preLoadImagesForStyle([ this.themeManager.set(this.getPref('extensions.treestyletab.tabbar.style'), this.position);
this.getPref('extensions.treestyletab.tabbar.style'),
this.position
].join('-'));
break; break;
case 'browser.ctrlTab.previews': case 'browser.ctrlTab.previews':

View File

@ -1,3 +1,5 @@
@import url("base.css"); @import url("base.css");
@import url("tab-surface.css"); @import url("tab-surface.css");
/* dynamically applied by themeManager.js
@import url("dropshadow.css");
*/

View File

@ -1,8 +1,9 @@
@import url("base.css"); @import url("base.css");
/* dynamically applied by themeManager.js
@import url("square/square.css"); @import url("square/square.css");
@import url("square/dropshadow.css");
@import url("metal/metal.css"); @import url("metal/metal.css");
@import url("sidebar/sidebar.css"); @import url("sidebar/sidebar.css");
*/
@import url("ui.css"); @import url("ui.css");