diff --git a/content/treestyletab/bookmarksOverlay.xul b/content/treestyletab/bookmarksOverlay.xul
index c5caae05..d7bfa90b 100644
--- a/content/treestyletab/bookmarksOverlay.xul
+++ b/content/treestyletab/bookmarksOverlay.xul
@@ -2,6 +2,7 @@
+
diff --git a/content/treestyletab/res/animationManager.js b/content/treestyletab/res/animationManager.js
new file mode 100644
index 00000000..0427fbde
--- /dev/null
+++ b/content/treestyletab/res/animationManager.js
@@ -0,0 +1,102 @@
+/*
+ Animation Task Manager
+
+ Usage:
+ window['piro.sakura.ne.jp'].animationManager.task(function() {
+ // some animation task runned by interval
+ return isFinish; // boolean
+ });
+ // stop all
+ window['piro.sakura.ne.jp'].animationManager.stop();
+
+ lisence: The MIT License, Copyright (c) 2009 SHIMODA "Piro" Hiroshi
+ http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
+ original:
+ http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/animationManager.js
+*/
+(function() {
+ const currentRevision = 1;
+
+ if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
+
+ var loadedRevision = 'animationManager' in window['piro.sakura.ne.jp'] ?
+ window['piro.sakura.ne.jp'].animationManager.revision :
+ 0 ;
+ var tasks = !loadedRevision ? [] : window['piro.sakura.ne.jp'].animationManager.tasks ;
+ if (loadedRevision && loadedRevision > currentRevision) {
+ return;
+ }
+
+ var Cc = Components.classes;
+ var Ci = Components.interfaces;
+
+ window['piro.sakura.ne.jp'].animationManager = {
+ revision : currentRevision,
+
+ addTask : function(aTask, aBeginningValue, aFinalValue, aDelay)
+ {
+ if (!aTask) return;
+ this.tasks.push({
+ task : aTask,
+ start : Date.now(),
+ beginning : aBeginningValue,
+ final : aFinalValue,
+ delay : aDelay
+ });
+ if (this.tasks.length > 1) return;
+ this.stop();
+ this.timer = window.setInterval(
+ this.onAnimation,
+ this.interval,
+ this
+ );
+ },
+
+ removeTask : function(aTask)
+ {
+ if (!aTask) return;
+ var task;
+ for (var i in this.tasks)
+ {
+ task = this.tasks[i];
+ if (task.task != aTask) continue;
+ delete task.task;
+ delete task.start;
+ delete task.beginning;
+ delete task.final;
+ delete task.delay;
+ this.tasks.splice(i, 1);
+ break;
+ }
+ if (!this.tasks.length)
+ this.stop();
+ },
+
+ stop : function()
+ {
+ if (!this.timer) return;
+ window.clearInterval(this.timer);
+ this.timer = null;
+ },
+
+ tasks : tasks,
+ interval : 10,
+ timer : null,
+
+ onAnimation : function(aSelf)
+ {
+ // task should return true if it finishes.
+ aSelf.tasks = aSelf.tasks.filter(function(aTask) {
+ return !aTask(
+ Date.now() - aTask.start,
+ aTask.beginning,
+ aTask.final,
+ aTask.delay
+ );
+ });
+ if (!aSelf.tasks.length)
+ aSelf.stop();
+ }
+
+ };
+})();
diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js
index 6d959af7..8af3b95f 100644
--- a/content/treestyletab/treestyletab.js
+++ b/content/treestyletab/treestyletab.js
@@ -963,50 +963,6 @@ 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 */
@@ -1585,7 +1541,7 @@ catch(e) {
{
window.removeEventListener('unload', this, false);
- this.endAnimations();
+ window['piro.sakura.ne.jp'].animationManager.stop();
this.destroyTabBrowser(gBrowser);
this.endListenKeyEvents();
diff --git a/content/treestyletab/treestyletab.xul b/content/treestyletab/treestyletab.xul
index 7c2a81d2..21da8d4d 100644
--- a/content/treestyletab/treestyletab.xul
+++ b/content/treestyletab/treestyletab.xul
@@ -11,6 +11,7 @@
+
diff --git a/content/treestyletab/treestyletabbrowser.js b/content/treestyletab/treestyletabbrowser.js
index dca584b3..c0fd5595 100644
--- a/content/treestyletab/treestyletabbrowser.js
+++ b/content/treestyletab/treestyletabbrowser.js
@@ -2819,12 +2819,9 @@ TreeStyleTabBrowser.prototype = {
var startIndent = this.getPropertyPixelValue(aTab, aProp);
var delta = aIndent - startIndent;
- var delay = this.indentDelay;
- var startTime = Date.now();
-
- var self = this;
- aTab.__treestyletab__updateTabIndentTask = function() {
- var power = Math.min(1, (Date.now() - startTime) / delay);
+ var self = this;
+ aTab.__treestyletab__updateTabIndentTask = function(aTime, aBeginning, aFinal, aDelay) {
+ var power = Math.min(1, aTime / aDelay);
var powerForStyle = Math.sin(90 * power * Math.PI / 180);
var indent = (power == 1) ?
aIndent :
@@ -2844,11 +2841,16 @@ TreeStyleTabBrowser.prototype = {
return false;
}
};
- TreeStyleTabService.addAnimationTask(aTab.__treestyletab__updateTabIndentTask);
+ window['piro.sakura.ne.jp'].animationManager.addTask(
+ aTab.__treestyletab__updateTabIndentTask,
+ 0, 0, this.indentDelay
+ );
},
stopTabIndentAnimation : function(aTab)
{
- TreeStyleTabService.removeAnimationTask(aTab.__treestyletab__updateTabIndentTask);
+ window['piro.sakura.ne.jp'].animationManager.removeTask(
+ aTab.__treestyletab__updateTabIndentTask
+ );
},
inheritTabIndent : function(aNewTab, aExistingTab)
@@ -3082,8 +3084,6 @@ TreeStyleTabBrowser.prototype = {
var startOpacity = aCollapsed ? 1 : 0 ;
var endOpacity = aCollapsed ? 0 : 1 ;
var deltaOpacity = endOpacity - startOpacity;
- var delay = this.collapseDelay;
- var startTime = Date.now();
var collapseProp = this.collapseProp;
aTab.setAttribute(this.kCOLLAPSING, true);
@@ -3097,8 +3097,8 @@ TreeStyleTabBrowser.prototype = {
if (!aCollapsed) aTab.removeAttribute(this.kCOLLAPSED_DONE);
var self = this;
- aTab.__treestyletab__updateTabCollapsedTask = function() {
- var power = Math.min(1, (Date.now() - startTime) / delay);
+ aTab.__treestyletab__updateTabCollapsedTask = function(aTime, aBeginning, aFinal, aDelay) {
+ var power = Math.min(1, aTime / aDelay);
var powerForStyle = Math.sin(90 * power * Math.PI / 180);
var margin = (power == 1) ?
endMargin :
@@ -3132,12 +3132,17 @@ TreeStyleTabBrowser.prototype = {
return false;
}
};
- TreeStyleTabService.addAnimationTask(aTab.__treestyletab__updateTabCollapsedTask);
+ window['piro.sakura.ne.jp'].animationManager.addTask(
+ aTab.__treestyletab__updateTabCollapsedTask,
+ 0, 0, this.collapseDelay
+ );
},
kOPACITY_RULE_REGEXP : /opacity\s*:[^;]+;?/,
stopTabCollapseAnimation : function(aTab)
{
- TreeStyleTabService.removeAnimationTask(aTab.__treestyletab__updateTabCollapsedTask);
+ window['piro.sakura.ne.jp'].animationManager.removeTask(
+ aTab.__treestyletab__updateTabCollapsedTask
+ );
},
collapseExpandTreesIntelligentlyFor : function(aTab, aJustNow)