diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/Modules/modern-media-controls/controls/scheduler.js | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/Modules/modern-media-controls/controls/scheduler.js')
-rw-r--r-- | Source/WebCore/Modules/modern-media-controls/controls/scheduler.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/Source/WebCore/Modules/modern-media-controls/controls/scheduler.js b/Source/WebCore/Modules/modern-media-controls/controls/scheduler.js new file mode 100644 index 000000000..f85beb037 --- /dev/null +++ b/Source/WebCore/Modules/modern-media-controls/controls/scheduler.js @@ -0,0 +1,66 @@ + +const scheduler = new class +{ + + constructor() + { + this._frameID = -1; + this._layoutCallbacks = new Set; + } + + // Public + + get hasScheduledLayoutCallbacks() + { + return this._frameID !== -1 || this._layoutCallbacks.size > 0; + } + + scheduleLayout(callback) + { + if (typeof callback !== "function") + return; + + this._layoutCallbacks.add(callback); + this._requestFrameIfNeeded(); + } + + unscheduleLayout(callback) + { + if (typeof callback !== "function") + return; + + this._layoutCallbacks.delete(callback); + } + + // Private + + _requestFrameIfNeeded() + { + if (this._frameID === -1 && this._layoutCallbacks.size > 0) + this._frameID = window.requestAnimationFrame(this._frameDidFire.bind(this)); + } + + _frameDidFire() + { + if (typeof scheduler.frameWillFire === "function") + scheduler.frameWillFire(); + + this._layout(); + this._frameID = -1; + this._requestFrameIfNeeded(); + + if (typeof scheduler.frameDidFire === "function") + scheduler.frameDidFire(); + } + + _layout() + { + // Layouts are not re-entrant. + const layoutCallbacks = this._layoutCallbacks; + this._layoutCallbacks = new Set; + + for (let callback of layoutCallbacks) + callback(); + } + +}; |