summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/modern-media-controls/controls/scheduler.js
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/Modules/modern-media-controls/controls/scheduler.js
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/Modules/modern-media-controls/controls/scheduler.js')
-rw-r--r--Source/WebCore/Modules/modern-media-controls/controls/scheduler.js66
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();
+ }
+
+};