タイマーを一箇所にまとめて、アニメーションの負荷を軽くした

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@4077 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2009-04-08 09:16:39 +00:00
parent bbf11ff688
commit 7de0a547d3
2 changed files with 82 additions and 25 deletions

View File

@ -32,7 +32,7 @@ var TreeStyleTabService = {
kDROP_MARKER_CONTAINER : 'treestyletab-drop-marker-container',
kCOUNTER : 'treestyletab-counter',
kCOUNTER_CONTAINER : 'treestyletab-counter-container',
kSPLITTER : 'treestyletab-splitter',
kSPLITTER : 'treestyletab-splitter',
kTABBAR_TOGGLER : 'treestyletab-tabbar-toggler',
kSTRINGBUNDLE : 'treestyletab-stringbundle',
@ -84,7 +84,7 @@ var TreeStyleTabService = {
kSHOWN_BY_UNKNOWN : 0,
kSHOWN_BY_SHORTCUT : 1 << 0,
kSHOWN_BY_MOUSEMOVE : 1 << 1,
kSHOWN_BY_FEEDBACK : 1 << 2,
kSHOWN_BY_FEEDBACK : 1 << 2,
kKEEP_SHOWN_ON_MOUSEOVER : (1 << 0) | (1 << 1) | (1 << 2),
kTRANSPARENT_NONE : 0,
@ -963,6 +963,50 @@ var TreeStyleTabService = {
useTMPSessionAPI : false,
kTMP_SESSION_DATA_PREFIX : 'tmp-session-data-',
/* animation */
animationTasks : [],
animationInterval : 10,
animationTimer : null,
addAnimationTask : function(aTask)
{
if (!aTask) return;
this.animationTasks.push(aTask);
if (this.animationTasks.length > 1) return;
this.endAnimations();
this.animationTimer = window.setInterval(
this.animationCallback,
this.animationInterval,
this
);
},
removeAnimationTask : function(aTask)
{
if (!aTask) return;
var index = this.animationTasks.indexOf(aTask);
if (index > -1) this.animationTasks.splice(index, 1);
if (!this.animationTasks.length)
this.endAnimations();
},
endAnimations : function()
{
if (!this.animationTimer) return;
window.clearInterval(this.animationTimer);
this.animationTimer = null;
},
animationCallback : function(aSelf)
{
// task should return true if it finishes.
aSelf.animationTasks = aSelf.animationTasks.filter(function(aTask) {
return !aTask();
});
if (!aSelf.animationTasks.length)
aSelf.endAnimations();
},
/* Initializing */
@ -1506,12 +1550,12 @@ catch(e) {
var treeStyleTab = gBrowser.treeStyleTab;
if (gBrowser.getAttribute(treeStyleTab.kTABBAR_POSITION) != 'top') {
treeStyleTab.autoHideMode = treeStyleTab.getTreePref(window.fullScreen ? 'tabbar.autoHide.mode.fullscreen' : 'tabbar.autoHide.mode' );
treeStyleTab.endAutoHide();
treeStyleTab.endAutoHide();
treeStyleTab.autoHideMode = treeStyleTab.getTreePref(window.fullScreen ? 'tabbar.autoHide.mode' : 'tabbar.autoHide.mode.fullscreen' );
if (window.fullScreen)
treeStyleTab.checkTabsIndentOverflow();
if (treeStyleTab.autoHideMode != treeStyleTab.kAUTOHIDE_MODE_DISABLED)
treeStyleTab.startAutoHide();
treeStyleTab.startAutoHide();
}
]]>
)
@ -1541,6 +1585,7 @@ catch(e) {
{
window.removeEventListener('unload', this, false);
this.endAnimations();
this.destroyTabBrowser(gBrowser);
this.endListenKeyEvents();
@ -1713,12 +1758,12 @@ catch(e) {
this.keyEventListening = false;
},
keyEventListening : false,
get shouldListenKeyEvents()
{
get shouldListenKeyEvents()
{
return this.getTreePref('tabbar.autoShow.accelKeyDown') ||
this.getTreePref('tabbar.autoShow.tabSwitch') ||
this.getTreePref('tabbar.autoShow.feedback');
},
this.getTreePref('tabbar.autoShow.tabSwitch') ||
this.getTreePref('tabbar.autoShow.feedback');
},
onTabbarResized : function(aEvent)
{

View File

@ -2821,7 +2821,9 @@ TreeStyleTabBrowser.prototype = {
var delta = aIndent - startIndent;
var delay = this.indentDelay;
var startTime = Date.now();
aTab.__treestyletab__updateTabIndentTimer = window.setInterval(function(aSelf) {
var self = this;
aTab.__treestyletab__updateTabIndentTask = function() {
var power = Math.min(1, (Date.now() - startTime) / delay);
var powerForStyle = Math.sin(90 * power * Math.PI / 180);
var indent = (power == 1) ?
@ -2834,14 +2836,19 @@ TreeStyleTabBrowser.prototype = {
aProp+':'+indent+'px !important;'
);
if (power == 1) aSelf.stopTabIndentAnimation(aTab);
}, 10, this);
if (power == 1) {
delete aTab.__treestyletab__updateTabIndentTask;
return true;
}
else {
return false;
}
};
TreeStyleTabService.addAnimationTask(aTab.__treestyletab__updateTabIndentTask);
},
stopTabIndentAnimation : function(aTab)
{
if (!aTab.__treestyletab__updateTabIndentTimer) return;
window.clearInterval(aTab.__treestyletab__updateTabIndentTimer);
aTab.__treestyletab__updateTabIndentTimer = null;
TreeStyleTabService.removeAnimationTask(aTab.__treestyletab__updateTabIndentTask);
},
inheritTabIndent : function(aNewTab, aExistingTab)
@ -3089,7 +3096,8 @@ TreeStyleTabBrowser.prototype = {
);
if (!aCollapsed) aTab.removeAttribute(this.kCOLLAPSED_DONE);
aTab.__treestyletab__updateTabCollapsedTimer = window.setInterval(function(aSelf) {
var self = this;
aTab.__treestyletab__updateTabCollapsedTask = function() {
var power = Math.min(1, (Date.now() - startTime) / delay);
var powerForStyle = Math.sin(90 * power * Math.PI / 180);
var margin = (power == 1) ?
@ -3107,25 +3115,29 @@ TreeStyleTabBrowser.prototype = {
);
if (power == 1) {
aSelf.stopTabCollapseAnimation(aTab);
aTab.removeAttribute(aSelf.kCOLLAPSING);
aTab.removeAttribute(self.kCOLLAPSING);
aTab.setAttribute(
'style',
aTab.getAttribute('style')
.replace(regexp, '')
.replace(aSelf.kOPACITY_RULE_REGEXP, '')
.replace(self.kOPACITY_RULE_REGEXP, '')
);
if (aCollapsed)
aTab.setAttribute(aSelf.kCOLLAPSED_DONE, true);
if (aCollapsed) {
aTab.setAttribute(self.kCOLLAPSED_DONE, true);
}
delete aTab.__treestyletab__updateTabCollapsedTask;
return true;
}
}, 10, this);
else {
return false;
}
};
TreeStyleTabService.addAnimationTask(aTab.__treestyletab__updateTabCollapsedTask);
},
kOPACITY_RULE_REGEXP : /opacity\s*:[^;]+;?/,
stopTabCollapseAnimation : function(aTab)
{
if (!aTab.__treestyletab__updateTabCollapsedTimer) return;
window.clearInterval(aTab.__treestyletab__updateTabCollapsedTimer);
aTab.__treestyletab__updateTabCollapsedTimer = null;
TreeStyleTabService.removeAnimationTask(aTab.__treestyletab__updateTabCollapsedTask);
},
collapseExpandTreesIntelligentlyFor : function(aTab, aJustNow)