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

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: Add RuntimeEnabled flags to all idl's, fix test expectations. Created 4 years, 11 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
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..efa81ffa5ab50bc138a574b2bba573c8e8c4d437
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/ElementIntersectionObserverData.cpp
@@ -0,0 +1,103 @@
+// Copyright 2016 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 "core/dom/ElementIntersectionObserverData.h"
+
+#include "core/dom/Document.h"
+#include "core/dom/Element.h"
+#include "core/dom/IntersectionObservation.h"
+#include "core/dom/IntersectionObserver.h"
+#include "core/dom/IntersectionObserverController.h"
+
+namespace blink {
+
+ElementIntersectionObserverData::ElementIntersectionObserverData() { }
+
+ElementIntersectionObserverData::~ElementIntersectionObserverData() { }
+
+bool ElementIntersectionObserverData::hasIntersectionObserver() const
+{
+ return !m_intersectionObservers.isEmpty();
+}
+
+bool ElementIntersectionObserverData::hasIntersectionObservation() const
+{
+ return !m_intersectionObservations.isEmpty();
+}
+
+IntersectionObservation* ElementIntersectionObserverData::getObservationFor(IntersectionObserver& observer)
+{
+ auto i = m_intersectionObservations.find(&observer);
+ if (i == m_intersectionObservations.end())
+ return nullptr;
+ return i->value;
+}
+
+void ElementIntersectionObserverData::addObservation(IntersectionObservation& observation)
+{
+ m_intersectionObservations.add(&observation.observer(), &observation);
+}
+
+void ElementIntersectionObserverData::removeObservation(IntersectionObserver& observer)
+{
+ m_intersectionObservations.remove(&observer);
+}
+
+void ElementIntersectionObserverData::activateValidIntersectionObservers(Element& element)
+{
+ IntersectionObserverController& controller = element.document().ensureIntersectionObserverController();
+ for (auto& observer : m_intersectionObservers) {
+ controller.addTrackedObserver(*observer);
+ observer->setActive(true);
+ }
+ for (auto& observation : m_intersectionObservations)
+ observation.value->setActive(observation.key->isDescendantOfRoot(&element));
+}
+
+void ElementIntersectionObserverData::deactivateAllIntersectionObservers(Element& element)
+{
+ element.document().ensureIntersectionObserverController().removeTrackedObserversForRoot(element);
+ for (auto& observer : m_intersectionObservers)
+ observer->setActive(false);
+ for (auto& observation : m_intersectionObservations)
+ observation.value->setActive(false);
+}
+
+#if !ENABLE(OILPAN)
+void ElementIntersectionObserverData::dispose()
+{
+ HeapVector<Member<IntersectionObservation>> observationsToDisconnect;
+ copyValuesToVector(m_intersectionObservations, observationsToDisconnect);
+ for (auto& observation : observationsToDisconnect)
+ observation->disconnect();
+ ASSERT(m_intersectionObservations.isEmpty());
+
+ HeapVector<Member<IntersectionObserver>> observersToDisconnect;
+ copyToVector(m_intersectionObservers, observersToDisconnect);
+ for (auto& observer : observersToDisconnect)
+ observer->disconnect();
+ ASSERT(m_intersectionObservers.isEmpty());
+
+ m_weakPointerFactory.clear();
+}
+#endif
+
+WeakPtrWillBeRawPtr<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