diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/client/inspector/animation/current-time-timer.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/inspector/animation/current-time-timer.js')
-rw-r--r-- | devtools/client/inspector/animation/current-time-timer.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/devtools/client/inspector/animation/current-time-timer.js b/devtools/client/inspector/animation/current-time-timer.js new file mode 100644 index 0000000000..4c08eb09ad --- /dev/null +++ b/devtools/client/inspector/animation/current-time-timer.js @@ -0,0 +1,75 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * In animation inspector, the scrubber and the progress bar moves along the current time + * of animation. However, the processing which sync with actual animations is heavy since + * we have to communication by the actor. The role of this class is to make the pseudo + * current time in animation inspector to proceed. + */ +class CurrentTimeTimer { + /** + * Constructor. + * + * @param {Object} timeScale + * @param {Bool} shouldStopAfterEndTime + * If need to stop the timer after animation end time, set true. + * @param {window} win + * Be used for requestAnimationFrame and performance. + * @param {Function} onUpdated + * Listener function to get updating. + * This function is called with 2 parameters. + * 1st: current time + * 2nd: if shouldStopAfterEndTime is true and + * the current time is over the end time, true is given. + */ + constructor(timeScale, shouldStopAfterEndTime, win, onUpdated) { + this.baseCurrentTime = timeScale.getCurrentTime(); + this.endTime = timeScale.getDuration(); + this.timerStartTime = win.performance.now(); + + this.shouldStopAfterEndTime = shouldStopAfterEndTime; + this.onUpdated = onUpdated; + this.win = win; + this.next = this.next.bind(this); + } + + destroy() { + this.stop(); + this.onUpdated = null; + this.win = null; + } + + /** + * Proceed the pseudo current time. + */ + next() { + if (this.doStop) { + return; + } + + const currentTime = + this.baseCurrentTime + this.win.performance.now() - this.timerStartTime; + + if (this.endTime < currentTime && this.shouldStopAfterEndTime) { + this.onUpdated(this.endTime, true); + return; + } + + this.onUpdated(currentTime); + this.win.requestAnimationFrame(this.next); + } + + start() { + this.next(); + } + + stop() { + this.doStop = true; + } +} + +module.exports = CurrentTimeTimer; |