Bug 587876 - 'Undetermined progress bars should use mozRequestAnimationFrame'. r=roc

This commit is contained in:
Ben Turner 2010-08-16 17:06:29 -07:00
Родитель bb7fa21fd6
Коммит 1dcfeefd69
1 изменённых файлов: 28 добавлений и 21 удалений

Просмотреть файл

@ -72,41 +72,48 @@
<field name="_alive">true</field>
<method name="_init">
<body><![CDATA[
var stack = document.getAnonymousElementByAttribute(this, "anonid", "stack");
var spacer = document.getAnonymousElementByAttribute(this, "anonid", "spacer");
var stack =
document.getAnonymousElementByAttribute(this, "anonid", "stack");
var spacer =
document.getAnonymousElementByAttribute(this, "anonid", "spacer");
var isLTR =
document.defaultView.getComputedStyle(this, null).direction == "ltr";
var startTime = window.mozAnimationStartTime;
var self = this;
var isLTR =
document.defaultView.getComputedStyle(this, null).direction == "ltr";
var position = isLTR ? 4 : -1;
var interval = setInterval(function nextStep() {
function nextStep(event) {
try {
var width = stack.boxObject.width;
if (!width) {
// Maybe we've been removed from the document.
if (!self._alive)
clearInterval(interval);
if (self._alive)
mozRequestAnimationFrame();
else
window.removeEventListener("MozBeforePaint", nextStep, false);
return;
}
var elapsedTime = event.timeStamp - startTime;
// Width of chunk is 1/5 (determined by the ratio 2000:400) of the
// total width of the progress bar. The left edge of the chunk
// starts at -1 and moves all the way to 4. It covers the distance
// in 2 seconds.
var position = isLTR ? ((elapsedTime % 2000) / 400) - 1 :
((elapsedTime % 2000) / -400) + 4;
width = width >> 2;
spacer.height = stack.boxObject.height;
spacer.width = width;
spacer.left = width * position;
if (isLTR) {
position += 15 / (width + 150);
if (position >= 4)
position = -1;
}
else {
position -= 15 / (width + 150);
if (position < 0)
position = 4;
}
mozRequestAnimationFrame();
} catch (e) {
clearInterval(interval);
window.removeEventListener("MozBeforePaint", nextStep, false);
}
}, 20);
}
window.addEventListener("MozBeforePaint", nextStep, false);
mozRequestAnimationFrame();
]]></body>
</method>