ライブラリ使用

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@4079 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2009-04-08 09:44:44 +00:00
parent 7de0a547d3
commit 0c467f248c
5 changed files with 124 additions and 59 deletions

View File

@ -2,6 +2,7 @@
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="res/prefs.js" type="application/x-javascript"/> <script src="res/prefs.js" type="application/x-javascript"/>
<script src="res/boxObject.js" type="application/x-javascript"/> <script src="res/boxObject.js" type="application/x-javascript"/>
<script src="res/animationManager.js" type="application/x-javascript"/>
<script src="treestyletab.js" type="application/x-javascript"/> <script src="treestyletab.js" type="application/x-javascript"/>
<script src="bookmarksOverlay.js" type="application/x-javascript"/> <script src="bookmarksOverlay.js" type="application/x-javascript"/>
</overlay> </overlay>

View File

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

View File

@ -963,50 +963,6 @@ 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 */
@ -1585,7 +1541,7 @@ catch(e) {
{ {
window.removeEventListener('unload', this, false); window.removeEventListener('unload', this, false);
this.endAnimations(); window['piro.sakura.ne.jp'].animationManager.stop();
this.destroyTabBrowser(gBrowser); this.destroyTabBrowser(gBrowser);
this.endListenKeyEvents(); this.endListenKeyEvents();

View File

@ -11,6 +11,7 @@
<script src="res/prefs.js" type="application/x-javascript"/> <script src="res/prefs.js" type="application/x-javascript"/>
<script src="res/boxObject.js" type="application/x-javascript"/> <script src="res/boxObject.js" type="application/x-javascript"/>
<script src="res/autoScroll.js" type="application/x-javascript"/> <script src="res/autoScroll.js" type="application/x-javascript"/>
<script src="res/animationManager.js" type="application/x-javascript"/>
<script src="treestyletab.js" type="application/x-javascript; version=1.7"/> <script src="treestyletab.js" type="application/x-javascript; version=1.7"/>
<script src="treestyletabbrowser.js" type="application/x-javascript; version=1.7"/> <script src="treestyletabbrowser.js" type="application/x-javascript; version=1.7"/>
<script src="preloadImages.js" type="application/x-javascript; version=1.7"/> <script src="preloadImages.js" type="application/x-javascript; version=1.7"/>

View File

@ -2819,12 +2819,9 @@ TreeStyleTabBrowser.prototype = {
var startIndent = this.getPropertyPixelValue(aTab, aProp); var startIndent = this.getPropertyPixelValue(aTab, aProp);
var delta = aIndent - startIndent; var delta = aIndent - startIndent;
var delay = this.indentDelay; var self = this;
var startTime = Date.now(); aTab.__treestyletab__updateTabIndentTask = function(aTime, aBeginning, aFinal, aDelay) {
var power = Math.min(1, aTime / aDelay);
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 powerForStyle = Math.sin(90 * power * Math.PI / 180);
var indent = (power == 1) ? var indent = (power == 1) ?
aIndent : aIndent :
@ -2844,11 +2841,16 @@ TreeStyleTabBrowser.prototype = {
return false; return false;
} }
}; };
TreeStyleTabService.addAnimationTask(aTab.__treestyletab__updateTabIndentTask); window['piro.sakura.ne.jp'].animationManager.addTask(
aTab.__treestyletab__updateTabIndentTask,
0, 0, this.indentDelay
);
}, },
stopTabIndentAnimation : function(aTab) stopTabIndentAnimation : function(aTab)
{ {
TreeStyleTabService.removeAnimationTask(aTab.__treestyletab__updateTabIndentTask); window['piro.sakura.ne.jp'].animationManager.removeTask(
aTab.__treestyletab__updateTabIndentTask
);
}, },
inheritTabIndent : function(aNewTab, aExistingTab) inheritTabIndent : function(aNewTab, aExistingTab)
@ -3082,8 +3084,6 @@ TreeStyleTabBrowser.prototype = {
var startOpacity = aCollapsed ? 1 : 0 ; var startOpacity = aCollapsed ? 1 : 0 ;
var endOpacity = aCollapsed ? 0 : 1 ; var endOpacity = aCollapsed ? 0 : 1 ;
var deltaOpacity = endOpacity - startOpacity; var deltaOpacity = endOpacity - startOpacity;
var delay = this.collapseDelay;
var startTime = Date.now();
var collapseProp = this.collapseProp; var collapseProp = this.collapseProp;
aTab.setAttribute(this.kCOLLAPSING, true); aTab.setAttribute(this.kCOLLAPSING, true);
@ -3097,8 +3097,8 @@ TreeStyleTabBrowser.prototype = {
if (!aCollapsed) aTab.removeAttribute(this.kCOLLAPSED_DONE); if (!aCollapsed) aTab.removeAttribute(this.kCOLLAPSED_DONE);
var self = this; var self = this;
aTab.__treestyletab__updateTabCollapsedTask = function() { aTab.__treestyletab__updateTabCollapsedTask = function(aTime, aBeginning, aFinal, aDelay) {
var power = Math.min(1, (Date.now() - startTime) / delay); var power = Math.min(1, aTime / aDelay);
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) ?
endMargin : endMargin :
@ -3132,12 +3132,17 @@ TreeStyleTabBrowser.prototype = {
return false; 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*:[^;]+;?/, kOPACITY_RULE_REGEXP : /opacity\s*:[^;]+;?/,
stopTabCollapseAnimation : function(aTab) stopTabCollapseAnimation : function(aTab)
{ {
TreeStyleTabService.removeAnimationTask(aTab.__treestyletab__updateTabCollapsedTask); window['piro.sakura.ne.jp'].animationManager.removeTask(
aTab.__treestyletab__updateTabCollapsedTask
);
}, },
collapseExpandTreesIntelligentlyFor : function(aTab, aJustNow) collapseExpandTreesIntelligentlyFor : function(aTab, aJustNow)