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

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

Issue 1449623002: IntersectionObserver: second cut. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Implemented root margin Created 5 years 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/Source/core/dom/IntersectionObserverRegistry.cpp
diff --git a/third_party/WebKit/Source/core/dom/IntersectionObserverRegistry.cpp b/third_party/WebKit/Source/core/dom/IntersectionObserverRegistry.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e59932412852e87aaf1f2a674de9a5af9e17b39d
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/IntersectionObserverRegistry.cpp
@@ -0,0 +1,89 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/dom/IntersectionObserverRegistry.h"
+
+#include "core/dom/Document.h"
+
+namespace blink {
+
+typedef HeapVector<Member<IntersectionObserver>> IntersectionObserverVector;
esprehn 2015/12/12 00:14:16 remove
szager1 2015/12/16 19:15:37 Done.
+
+IntersectionObserverRegistry::IntersectionObserverRegistry(Timer<Document>& timer)
+ : m_timer(timer)
+ , m_trackedIntersectionObservers(new IntersectionObserver::WeakHashSet())
+ , m_activeIntersectionObservers(new IntersectionObserver::HashSet())
+ , m_suspendedIntersectionObservers(new IntersectionObserver::HashSet())
esprehn 2015/12/12 00:14:16 remove, just make them members
szager1 2015/12/16 19:15:37 Done.
+{
+}
+
+void IntersectionObserverRegistry::scheduleIntersectionObserverForDelivery(IntersectionObserver& observer)
+{
+ if (m_activeIntersectionObservers->isEmpty())
+ m_timer.startOneShot(0, BLINK_FROM_HERE);
ojan 2015/12/12 01:06:29 Add a TODO to do this at idle time?
szager1 2015/12/16 19:15:37 Done.
+ m_activeIntersectionObservers->add(&observer);
+}
+
+void IntersectionObserverRegistry::resumeSuspendedIntersectionObservers()
+{
+ ASSERT(isMainThread());
+ if (m_suspendedIntersectionObservers->isEmpty())
+ return;
+
+ IntersectionObserverVector suspended;
+ copyToVector(*m_suspendedIntersectionObservers, suspended);
+ for (size_t i = 0; i < suspended.size(); ++i) {
ojan 2015/12/12 01:06:29 use auto : ?
szager1 2015/12/16 19:15:37 Done.
+ if (!suspended[i]->shouldBeSuspended()) {
+ m_suspendedIntersectionObservers->remove(suspended[i]);
+ scheduleIntersectionObserverForDelivery(*suspended[i]);
+ }
+ }
+}
+
+void IntersectionObserverRegistry::deliverIntersectionObservations()
+{
+ IntersectionObserverVector observers;
+ copyToVector(*m_activeIntersectionObservers, observers);
+ m_activeIntersectionObservers->clear();
+ for (size_t i = 0; i < observers.size(); ++i) {
ojan 2015/12/12 01:06:29 use auto : ?
szager1 2015/12/16 19:15:37 Done.
+ if (observers[i]->shouldBeSuspended())
+ m_suspendedIntersectionObservers->add(observers[i]);
+ else
+ observers[i]->deliver();
+ }
+}
+
+void IntersectionObserverRegistry::computeTrackedIntersectionObservations()
+{
+ // TODO: Need to define timestamp.
+ double timestamp = currentTime();
+ for (auto& observer: *m_trackedIntersectionObservers)
esprehn 2015/12/12 00:14:16 space
szager1 2015/12/16 19:15:37 Done.
+ observer->computeIntersectionObservations(timestamp);
+}
+
+void IntersectionObserverRegistry::addTrackedObserver(IntersectionObserver& observer)
+{
+ m_trackedIntersectionObservers->add(&observer);
+}
+
+void IntersectionObserverRegistry::removeTrackedObserversForRoot(Element* root)
+{
+ HeapVector<Member<IntersectionObserver>> toRemove;
+ for (auto& observer: *m_trackedIntersectionObservers) {
esprehn 2015/12/12 00:14:16 space
szager1 2015/12/16 19:15:37 Done.
+ if (observer->root() == root)
+ toRemove.append(observer);
+ }
+ for (auto& observer: toRemove)
esprehn 2015/12/12 00:14:16 space, we really need to get the linter fixed for
szager1 2015/12/16 19:15:37 Done.
+ m_trackedIntersectionObservers->remove(observer);
+}
+
+DEFINE_TRACE(IntersectionObserverRegistry)
+{
+ visitor->trace(m_trackedIntersectionObservers);
+ visitor->trace(m_activeIntersectionObservers);
+ visitor->trace(m_suspendedIntersectionObservers);
+}
+
+} // namespace blink {

Powered by Google App Engine
This is Rietveld 408576698