Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Unified Diff: third_party/WebKit/ManualTests/compositor-worker/sticky/js/viewport-observer.js

Issue 1547893003: WIP - compositor worker mega patch. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/ManualTests/compositor-worker/sticky/js/viewport-observer.js
diff --git a/third_party/WebKit/ManualTests/compositor-worker/sticky/js/viewport-observer.js b/third_party/WebKit/ManualTests/compositor-worker/sticky/js/viewport-observer.js
new file mode 100644
index 0000000000000000000000000000000000000000..70df1c14d3865d343e7a6f0085a256b29682b2c7
--- /dev/null
+++ b/third_party/WebKit/ManualTests/compositor-worker/sticky/js/viewport-observer.js
@@ -0,0 +1,43 @@
+// Incomplete / Naive implementation of ViewportObserver based on spec at:
+// https://docs.google.com/document/d/14y3ReQo_TU8N81V1okwmfT5LtRxj-20UiNJ3ddU9vsI/edit?pli=1#heading=h.epew5hgbndxp
+window.ViewportObserver = function() {
+
+ function ViewportObserver(callback) {
+ this.callback_ = callback;
+ this.targets_ = [];
+ this.changedRecords_ = [];
+ this.notifyNow_ = this.notify_.bind(this);
+ }
+
+ ViewportObserver.prototype.observe = function(target) {
+ if (this.targets_.indexOf(target) != -1)
+ return;
+ var listenOn = target == document.scrollingElement ? document : target;
+ listenOn.addEventListener('scroll', this.onScroll_.bind(this, target));
+ this.targets_.push(target);
+ this.onScroll_(target);
+ };
+
+ ViewportObserver.prototype.onScroll_ = function(target) {
+ this.changedRecords_.push({
+ time: performance.now(),
+ viewport: getViewportRect(target),
+ element: target
+ });
+ this.notify_();
+ };
+
+ ViewportObserver.prototype.scheduleNotify_ = function() {
+ if (!this.timeoutId_)
+ this.timeoutId_ = setTimeout(this.notifyNow_, 0);
+ };
+
+ ViewportObserver.prototype.notify_ = function() {
+ clearTimeout(this.timeoutId_);
+ this.timeoutId_ = undefined;
+ this.callback_(this.changedRecords_);
+ this.changedRecords_.length = 0;
+ };
+
+ return ViewportObserver;
+}();

Powered by Google App Engine
This is Rietveld 408576698