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 dbdb3f937f598f7f37bb4aad6f082e6f24f0c087..3a090e25ef8d830e61d27903431df88367b59068 100644 |
--- a/third_party/WebKit/Source/core/dom/IntersectionObserverController.cpp |
+++ b/third_party/WebKit/Source/core/dom/IntersectionObserverController.cpp |
@@ -6,7 +6,9 @@ |
#include "core/dom/Document.h" |
#include "core/dom/IdleRequestOptions.h" |
+#include "core/dom/TaskRunnerHelper.h" |
#include "platform/TraceEvent.h" |
+#include "platform/scheduler/CancellableTaskFactory.h" |
namespace blink { |
@@ -19,8 +21,10 @@ IntersectionObserverController* IntersectionObserverController::create(Document* |
IntersectionObserverController::IntersectionObserverController(Document* document) |
: ActiveDOMObject(document) |
+ , m_lowLatencyNotificationTask(CancellableTaskFactory::create(this, &IntersectionObserverController::deliverLowLatencyNotifications)) |
, m_callbackID(0) |
, m_callbackFiredWhileSuspended(false) |
+ , m_lowLatencyCallbackFiredWhileSuspended(false) |
szager1
2016/08/30 23:57:11
I don't think you need m_lowLatencyCallbacksFiredW
Sami
2016/08/31 11:08:55
Done.
|
{ |
} |
@@ -28,6 +32,12 @@ IntersectionObserverController::~IntersectionObserverController() { } |
void IntersectionObserverController::scheduleIntersectionObserverForDelivery(IntersectionObserver& observer) |
{ |
+ if (observer.lowLatency()) { |
szager1
2016/08/30 23:57:11
I think this would read better if you refactor it
Sami
2016/08/31 11:08:55
Good idea, done.
|
+ m_pendingLowLatencyIntersectionObservers.add(&observer); |
+ if (!m_lowLatencyNotificationTask->isPending()) |
+ TaskRunnerHelper::get(TaskType::Unthrottled, getExecutionContext())->postTask(BLINK_FROM_HERE, m_lowLatencyNotificationTask->cancelAndCreate()); |
+ return; |
+ } |
m_pendingIntersectionObservers.add(&observer); |
if (m_callbackID) |
return; |
@@ -44,6 +54,10 @@ 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_lowLatencyCallbackFiredWhileSuspended) { |
+ m_lowLatencyCallbackFiredWhileSuspended = false; |
+ deliverLowLatencyNotifications(); |
+ } |
if (m_callbackFiredWhileSuspended) { |
m_callbackFiredWhileSuspended = false; |
deliverIntersectionObservations(); |
@@ -74,6 +88,23 @@ void IntersectionObserverController::deliverIntersectionObservations() |
observer->deliver(); |
} |
+void IntersectionObserverController::deliverLowLatencyNotifications() |
+{ |
+ ExecutionContext* context = getExecutionContext(); |
+ if (!context) { |
+ m_pendingLowLatencyIntersectionObservers.clear(); |
+ return; |
+ } |
+ if (context->activeDOMObjectsAreSuspended()) { |
+ m_lowLatencyCallbackFiredWhileSuspended = true; |
+ return; |
+ } |
+ HeapHashSet<Member<IntersectionObserver>> observers; |
+ m_pendingLowLatencyIntersectionObservers.swap(observers); |
+ for (auto& observer : observers) |
+ observer->deliver(); |
+} |
+ |
void IntersectionObserverController::computeTrackedIntersectionObservations() |
{ |
TRACE_EVENT0("blink", "IntersectionObserverController::computeTrackedIntersectionObservations"); |
@@ -103,6 +134,7 @@ DEFINE_TRACE(IntersectionObserverController) |
{ |
visitor->trace(m_trackedIntersectionObservers); |
visitor->trace(m_pendingIntersectionObservers); |
+ visitor->trace(m_pendingLowLatencyIntersectionObservers); |
ActiveDOMObject::trace(visitor); |
IdleRequestCallback::trace(visitor); |
} |