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

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

Issue 1449623002: IntersectionObserver: second cut. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Added dispose() methods for expicit cleanup 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/ElementIntersectionObserverData.cpp
diff --git a/third_party/WebKit/Source/core/dom/ElementIntersectionObserverData.cpp b/third_party/WebKit/Source/core/dom/ElementIntersectionObserverData.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c95fce1f49a61d639efd6d06c0960d078d3bee58
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/ElementIntersectionObserverData.cpp
@@ -0,0 +1,100 @@
+// 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/ElementIntersectionObserverData.h"
+
+#include "core/dom/Document.h"
+#include "core/dom/Element.h"
+#include "core/dom/IntersectionObserverController.h"
+
+namespace blink {
+
+bool ElementIntersectionObserverData::hasIntersectionObserver() const
+{
+ return !m_intersectionObservers.isEmpty();
+}
+
+bool ElementIntersectionObserverData::hasIntersectionObservation() const
+{
+ return !m_intersectionObservations.isEmpty();
+}
+
+bool ElementIntersectionObserverData::hasObservationFor(IntersectionObserver& observer) const
+{
+ return m_intersectionObservations.find(&observer) != m_intersectionObservations.end();
esprehn 2015/12/17 01:40:28 .contains(), no need to compare to end()
szager1 2015/12/17 20:27:25 Done.
+}
+
+void ElementIntersectionObserverData::addObservation(IntersectionObservation& observation)
+{
+ m_intersectionObservations.set(observation.observer(), &observation);
+}
+
+void ElementIntersectionObserverData::removeObservation(IntersectionObserver& observer)
+{
+ RawPtr<IntersectionObserver> key(&observer);
esprehn 2015/12/17 01:40:28 do these not implicitly construct?
szager1 2015/12/17 20:27:25 Whoops, this was left over from a previous attempt
+ HeapHashMap<Member<IntersectionObserver>, Member<IntersectionObservation>>::iterator observationIterator = m_intersectionObservations.find(&observer);
esprehn 2015/12/17 01:40:28 auto
szager1 2015/12/17 20:27:25 Done.
+ if (observationIterator != m_intersectionObservations.end())
esprehn 2015/12/17 01:40:28 you can just write "it" for the iterator if you wa
szager1 2015/12/17 20:27:25 Done.
+ observationIterator->value->disconnect();
+}
+
+void ElementIntersectionObserverData::activateValidIntersectionObservers(Element& element)
+{
+ IntersectionObserverController* registry = element.document().intersectionObserverController();
esprehn 2015/12/17 01:40:28 controller
szager1 2015/12/17 20:27:25 Done.
+ for (auto& observer : m_intersectionObservers) {
+ registry->addTrackedObserver(*observer);
+ observer->setActive(true);
+ }
+ for (auto& observation : m_intersectionObservations)
+ observation.value->setActive(observation.key->isDescendantOfRoot(&element));
+}
+
+void ElementIntersectionObserverData::deactivateAllIntersectionObservers(Element& element)
+{
+ Document& document = element.document();
+ for (auto& observer : m_intersectionObservers) {
+ document.intersectionObserverController()->removeTrackedObserversForRoot(element);
esprehn 2015/12/17 01:40:28 maybe do this out of the loop and save to a variab
szager1 2015/12/17 20:27:25 Oh, this is wrong, removeTrackedObserversForRoot s
+ observer->setActive(false);
+ }
+ for (auto& observation : m_intersectionObservations)
+ observation.value->setActive(false);
+}
+
+#if !ENABLE(OILPAN)
+void ElementIntersectionObserverData::dispose()
+{
+ HeapVector<Member<IntersectionObservation>> toDisconnect;
+ copyValuesToVector(m_intersectionObservations, toDisconnect);
+ for (auto& observation : toDisconnect)
+ observation->disconnect();
+ ASSERT(m_intersectionObservations.isEmpty());
+
+ HeapVector<Member<IntersectionObserver>> toDispose;
+ copyToVector(m_intersectionObservers, toDispose);
+ for (auto& observer : toDispose)
+ observer->dispose();
+ ASSERT(m_intersectionObservers.isEmpty());
+
+ m_weakPointerFactory.clear();
+}
+#endif
+
+WeakPtr<Element> ElementIntersectionObserverData::createWeakPtr(Element* element)
+{
+#if ENABLE(OILPAN)
+ return element;
+#else
+ if (!m_weakPointerFactory)
+ m_weakPointerFactory = adoptPtrWillBeNoop(new WeakPtrFactory<Element>(element));
+ return m_weakPointerFactory->createWeakPtr();
+#endif
+}
+
+DEFINE_TRACE(ElementIntersectionObserverData)
+{
+ visitor->trace(m_intersectionObservers);
+ visitor->trace(m_intersectionObservations);
+}
+
+} // namespace blink {

Powered by Google App Engine
This is Rietveld 408576698