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

Unified Diff: third_party/WebKit/Source/core/dom/IntersectionObserverController.cpp

Issue 1780163002: Revert of IntersectionObserver: use an idle callback to send notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « third_party/WebKit/Source/core/dom/IntersectionObserverController.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/IntersectionObserverController.cpp
diff --git a/third_party/WebKit/Source/core/dom/IntersectionObserverController.cpp b/third_party/WebKit/Source/core/dom/IntersectionObserverController.cpp
index 5b71c685889d2d4d00020ff01b8f133dbd7a66c0..055b3c64c4bf36f518927d131f177cd7b6840ed4 100644
--- a/third_party/WebKit/Source/core/dom/IntersectionObserverController.cpp
+++ b/third_party/WebKit/Source/core/dom/IntersectionObserverController.cpp
@@ -5,7 +5,6 @@
#include "core/dom/IntersectionObserverController.h"
#include "core/dom/Document.h"
-#include "core/dom/IdleRequestOptions.h"
namespace blink {
@@ -20,8 +19,8 @@
IntersectionObserverController::IntersectionObserverController(Document* document)
: ActiveDOMObject(document)
- , m_callbackIsScheduled(false)
- , m_callbackFiredWhileSuspended(false)
+ , m_timer(this, &IntersectionObserverController::deliverIntersectionObservations)
+ , m_timerFiredWhileSuspended(false)
{
}
@@ -29,39 +28,28 @@
void IntersectionObserverController::scheduleIntersectionObserverForDelivery(IntersectionObserver& observer)
{
+ // TODO(szager): use idle callback with a timeout. Until we do that, there is no
+ // reliable way to write a test for takeRecords, because it's impossible to guarantee
+ // that javascript will get a chance to run before the timer fires.
+ if (!m_timer.isActive())
+ m_timer.startOneShot(0, BLINK_FROM_HERE);
m_pendingIntersectionObservers.add(&observer);
- if (m_callbackIsScheduled)
- return;
- Document* document = toDocument(getExecutionContext());
- if (!document)
- return;
- m_callbackIsScheduled = true;
- IdleRequestOptions options;
- // The IntersectionObserver spec mandates that notifications be sent within 100ms.
- options.setTimeout(100);
- document->requestIdleCallback(this, options);
}
void IntersectionObserverController::resume()
{
- // If the callback fired while DOM objects were suspended, notifications might be late, so deliver
- // them right away (rather than waiting to fire again).
- if (m_callbackFiredWhileSuspended) {
- m_callbackFiredWhileSuspended = false;
- deliverIntersectionObservations();
+ // If the timer fired while DOM objects were suspended, notifications might be late, so deliver
+ // them right away (rather than waiting for m_timer to fire again).
+ if (m_timerFiredWhileSuspended) {
+ m_timerFiredWhileSuspended = false;
+ deliverIntersectionObservations(nullptr);
}
}
-void IntersectionObserverController::handleEvent(IdleDeadline*)
-{
- m_callbackIsScheduled = false;
- deliverIntersectionObservations();
-}
-
-void IntersectionObserverController::deliverIntersectionObservations()
+void IntersectionObserverController::deliverIntersectionObservations(Timer<IntersectionObserverController>*)
{
if (getExecutionContext()->activeDOMObjectsAreSuspended()) {
- m_callbackFiredWhileSuspended = true;
+ m_timerFiredWhileSuspended = true;
return;
}
IntersectionObserverVector observers;
@@ -100,7 +88,6 @@
visitor->trace(m_trackedIntersectionObservers);
visitor->trace(m_pendingIntersectionObservers);
ActiveDOMObject::trace(visitor);
- IdleRequestCallback::trace(visitor);
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/dom/IntersectionObserverController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698