タイマーを一箇所にまとめて、アニメーションの負荷を軽くした
git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@4077 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
parent
bbf11ff688
commit
7de0a547d3
@ -964,6 +964,50 @@ var TreeStyleTabService = {
|
|||||||
useTMPSessionAPI : false,
|
useTMPSessionAPI : false,
|
||||||
kTMP_SESSION_DATA_PREFIX : 'tmp-session-data-',
|
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 */
|
/* Initializing */
|
||||||
|
|
||||||
preInit : function()
|
preInit : function()
|
||||||
@ -1541,6 +1585,7 @@ catch(e) {
|
|||||||
{
|
{
|
||||||
window.removeEventListener('unload', this, false);
|
window.removeEventListener('unload', this, false);
|
||||||
|
|
||||||
|
this.endAnimations();
|
||||||
this.destroyTabBrowser(gBrowser);
|
this.destroyTabBrowser(gBrowser);
|
||||||
|
|
||||||
this.endListenKeyEvents();
|
this.endListenKeyEvents();
|
||||||
|
@ -2821,7 +2821,9 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
var delta = aIndent - startIndent;
|
var delta = aIndent - startIndent;
|
||||||
var delay = this.indentDelay;
|
var delay = this.indentDelay;
|
||||||
var startTime = Date.now();
|
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 power = Math.min(1, (Date.now() - startTime) / delay);
|
||||||
var powerForStyle = Math.sin(90 * power * Math.PI / 180);
|
var powerForStyle = Math.sin(90 * power * Math.PI / 180);
|
||||||
var indent = (power == 1) ?
|
var indent = (power == 1) ?
|
||||||
@ -2834,14 +2836,19 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
aProp+':'+indent+'px !important;'
|
aProp+':'+indent+'px !important;'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (power == 1) aSelf.stopTabIndentAnimation(aTab);
|
if (power == 1) {
|
||||||
}, 10, this);
|
delete aTab.__treestyletab__updateTabIndentTask;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TreeStyleTabService.addAnimationTask(aTab.__treestyletab__updateTabIndentTask);
|
||||||
},
|
},
|
||||||
stopTabIndentAnimation : function(aTab)
|
stopTabIndentAnimation : function(aTab)
|
||||||
{
|
{
|
||||||
if (!aTab.__treestyletab__updateTabIndentTimer) return;
|
TreeStyleTabService.removeAnimationTask(aTab.__treestyletab__updateTabIndentTask);
|
||||||
window.clearInterval(aTab.__treestyletab__updateTabIndentTimer);
|
|
||||||
aTab.__treestyletab__updateTabIndentTimer = null;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
inheritTabIndent : function(aNewTab, aExistingTab)
|
inheritTabIndent : function(aNewTab, aExistingTab)
|
||||||
@ -3089,7 +3096,8 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
);
|
);
|
||||||
if (!aCollapsed) aTab.removeAttribute(this.kCOLLAPSED_DONE);
|
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 power = Math.min(1, (Date.now() - startTime) / delay);
|
||||||
var powerForStyle = Math.sin(90 * power * Math.PI / 180);
|
var powerForStyle = Math.sin(90 * power * Math.PI / 180);
|
||||||
var margin = (power == 1) ?
|
var margin = (power == 1) ?
|
||||||
@ -3107,25 +3115,29 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (power == 1) {
|
if (power == 1) {
|
||||||
aSelf.stopTabCollapseAnimation(aTab);
|
aTab.removeAttribute(self.kCOLLAPSING);
|
||||||
aTab.removeAttribute(aSelf.kCOLLAPSING);
|
|
||||||
aTab.setAttribute(
|
aTab.setAttribute(
|
||||||
'style',
|
'style',
|
||||||
aTab.getAttribute('style')
|
aTab.getAttribute('style')
|
||||||
.replace(regexp, '')
|
.replace(regexp, '')
|
||||||
.replace(aSelf.kOPACITY_RULE_REGEXP, '')
|
.replace(self.kOPACITY_RULE_REGEXP, '')
|
||||||
);
|
);
|
||||||
if (aCollapsed)
|
if (aCollapsed) {
|
||||||
aTab.setAttribute(aSelf.kCOLLAPSED_DONE, true);
|
aTab.setAttribute(self.kCOLLAPSED_DONE, true);
|
||||||
}
|
}
|
||||||
}, 10, this);
|
delete aTab.__treestyletab__updateTabCollapsedTask;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TreeStyleTabService.addAnimationTask(aTab.__treestyletab__updateTabCollapsedTask);
|
||||||
},
|
},
|
||||||
kOPACITY_RULE_REGEXP : /opacity\s*:[^;]+;?/,
|
kOPACITY_RULE_REGEXP : /opacity\s*:[^;]+;?/,
|
||||||
stopTabCollapseAnimation : function(aTab)
|
stopTabCollapseAnimation : function(aTab)
|
||||||
{
|
{
|
||||||
if (!aTab.__treestyletab__updateTabCollapsedTimer) return;
|
TreeStyleTabService.removeAnimationTask(aTab.__treestyletab__updateTabCollapsedTask);
|
||||||
window.clearInterval(aTab.__treestyletab__updateTabCollapsedTimer);
|
|
||||||
aTab.__treestyletab__updateTabCollapsedTimer = null;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
collapseExpandTreesIntelligentlyFor : function(aTab, aJustNow)
|
collapseExpandTreesIntelligentlyFor : function(aTab, aJustNow)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user