Chromium Code Reviews| 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 15cfa0c58d3abf30b990eb31af2990fcf99f6554..fdd73549151eca5b07b67cfd8cc160c94889c7cf 100644 |
| --- a/third_party/WebKit/Source/core/dom/IntersectionObserverController.cpp |
| +++ b/third_party/WebKit/Source/core/dom/IntersectionObserverController.cpp |
| @@ -5,6 +5,7 @@ |
| #include "core/dom/IntersectionObserverController.h" |
| #include "core/dom/Document.h" |
| +#include "core/dom/IdleRequestOptions.h" |
| namespace blink { |
| @@ -19,7 +20,7 @@ IntersectionObserverController* IntersectionObserverController::create(Document* |
| IntersectionObserverController::IntersectionObserverController(Document* document) |
| : ActiveDOMObject(document) |
| - , m_timer(this, &IntersectionObserverController::deliverIntersectionObservations) |
| + , m_timerIsScheduled(false) |
|
Sami
2016/03/08 17:32:42
nit: s/timer/callback/ (here and below)?
szager1
2016/03/08 18:51:32
Done.
|
| , m_timerFiredWhileSuspended(false) |
| { |
| } |
| @@ -31,22 +32,35 @@ void IntersectionObserverController::scheduleIntersectionObserverForDelivery(Int |
| // TODO(szager): use idle callback with a timeout. Until we do that, there is no |
|
Sami
2016/03/08 17:32:42
Did you mean to remove this TODO?
szager1
2016/03/08 18:51:32
Done.
|
| // 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_timerIsScheduled) |
| + return; |
| + Document* document = toDocument(executionContext()); |
| + if (!document) |
| + return; |
| + m_timerIsScheduled = true; |
| + IdleRequestOptions options; |
| + options.setTimeout(100); |
|
haraken
2016/03/08 03:44:03
We want to remove hard-coded timers in the future
szager1
2016/03/08 18:51:32
100ms is required by the IntersectionObserver spec
haraken
2016/03/08 23:05:58
Then maybe worth adding a comment and mention that
szager1
2016/03/08 23:12:02
Done.
|
| + document->requestIdleCallback(this, options); |
| } |
| void IntersectionObserverController::resume() |
| { |
| // 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). |
| + // them right away (rather than waiting to fire again). |
| if (m_timerFiredWhileSuspended) { |
| m_timerFiredWhileSuspended = false; |
| - deliverIntersectionObservations(nullptr); |
| + deliverIntersectionObservations(); |
| } |
| } |
| -void IntersectionObserverController::deliverIntersectionObservations(Timer<IntersectionObserverController>*) |
| +void IntersectionObserverController::handleEvent(IdleDeadline*) |
| +{ |
| + m_timerIsScheduled = false; |
| + deliverIntersectionObservations(); |
| +} |
| + |
| +void IntersectionObserverController::deliverIntersectionObservations() |
| { |
| if (executionContext()->activeDOMObjectsAreSuspended()) { |
| m_timerFiredWhileSuspended = true; |
| @@ -88,6 +102,7 @@ DEFINE_TRACE(IntersectionObserverController) |
| visitor->trace(m_trackedIntersectionObservers); |
| visitor->trace(m_pendingIntersectionObservers); |
| ActiveDOMObject::trace(visitor); |
| + IdleRequestCallback::trace(visitor); |
| } |
| } // namespace blink |