| Index: third_party/WebKit/Source/core/dom/NodeIntersectionObserverData.cpp
|
| diff --git a/third_party/WebKit/Source/core/dom/ElementIntersectionObserverData.cpp b/third_party/WebKit/Source/core/dom/NodeIntersectionObserverData.cpp
|
| similarity index 54%
|
| rename from third_party/WebKit/Source/core/dom/ElementIntersectionObserverData.cpp
|
| rename to third_party/WebKit/Source/core/dom/NodeIntersectionObserverData.cpp
|
| index 32b8d5733df148dad9f0dc2371d4a87046c968f8..2eaa0776936f94c27f625d3c7ec230964d469447 100644
|
| --- a/third_party/WebKit/Source/core/dom/ElementIntersectionObserverData.cpp
|
| +++ b/third_party/WebKit/Source/core/dom/NodeIntersectionObserverData.cpp
|
| @@ -2,31 +2,30 @@
|
| // 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/NodeIntersectionObserverData.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() { }
|
| +NodeIntersectionObserverData::NodeIntersectionObserverData() { }
|
|
|
| -ElementIntersectionObserverData::~ElementIntersectionObserverData() { }
|
| +NodeIntersectionObserverData::~NodeIntersectionObserverData() { }
|
|
|
| -bool ElementIntersectionObserverData::hasIntersectionObserver() const
|
| +bool NodeIntersectionObserverData::hasIntersectionObserver() const
|
| {
|
| return !m_intersectionObservers.isEmpty();
|
| }
|
|
|
| -bool ElementIntersectionObserverData::hasIntersectionObservation() const
|
| +bool NodeIntersectionObserverData::hasIntersectionObservation() const
|
| {
|
| return !m_intersectionObservations.isEmpty();
|
| }
|
|
|
| -IntersectionObservation* ElementIntersectionObserverData::getObservationFor(IntersectionObserver& observer)
|
| +IntersectionObservation* NodeIntersectionObserverData::getObservationFor(IntersectionObserver& observer)
|
| {
|
| auto i = m_intersectionObservations.find(&observer);
|
| if (i == m_intersectionObservations.end())
|
| @@ -34,30 +33,35 @@ IntersectionObservation* ElementIntersectionObserverData::getObservationFor(Inte
|
| return i->value;
|
| }
|
|
|
| -void ElementIntersectionObserverData::addObservation(IntersectionObservation& observation)
|
| +void NodeIntersectionObserverData::addObservation(IntersectionObservation& observation)
|
| {
|
| m_intersectionObservations.add(&observation.observer(), &observation);
|
| }
|
|
|
| -void ElementIntersectionObserverData::removeObservation(IntersectionObserver& observer)
|
| +void NodeIntersectionObserverData::removeObservation(IntersectionObserver& observer)
|
| {
|
| m_intersectionObservations.remove(&observer);
|
| }
|
|
|
| -void ElementIntersectionObserverData::activateValidIntersectionObservers(Element& element)
|
| +void NodeIntersectionObserverData::activateValidIntersectionObservers(Node& node)
|
| {
|
| - IntersectionObserverController& controller = element.document().ensureIntersectionObserverController();
|
| + IntersectionObserverController& controller = node.document().ensureIntersectionObserverController();
|
| + // Activate observers for which node is root.
|
| for (auto& observer : m_intersectionObservers) {
|
| controller.addTrackedObserver(*observer);
|
| observer->setActive(true);
|
| }
|
| + // A document can be root, but not target.
|
| + if (node.isDocumentNode())
|
| + return;
|
| + // Active observers for which node is target.
|
| for (auto& observation : m_intersectionObservations)
|
| - observation.value->setActive(observation.key->isDescendantOfRoot(&element));
|
| + observation.value->setActive(observation.key->isDescendantOfRoot(&toElement(node)));
|
| }
|
|
|
| -void ElementIntersectionObserverData::deactivateAllIntersectionObservers(Element& element)
|
| +void NodeIntersectionObserverData::deactivateAllIntersectionObservers(Node& node)
|
| {
|
| - element.document().ensureIntersectionObserverController().removeTrackedObserversForRoot(element);
|
| + node.document().ensureIntersectionObserverController().removeTrackedObserversForRoot(node);
|
| for (auto& observer : m_intersectionObservers)
|
| observer->setActive(false);
|
| for (auto& observation : m_intersectionObservations)
|
| @@ -65,7 +69,7 @@ void ElementIntersectionObserverData::deactivateAllIntersectionObservers(Element
|
| }
|
|
|
| #if !ENABLE(OILPAN)
|
| -void ElementIntersectionObserverData::dispose()
|
| +void NodeIntersectionObserverData::dispose()
|
| {
|
| HeapVector<Member<IntersectionObserver>> observersToDisconnect;
|
| copyToVector(m_intersectionObservers, observersToDisconnect);
|
| @@ -77,18 +81,20 @@ void ElementIntersectionObserverData::dispose()
|
| }
|
| #endif
|
|
|
| -WeakPtrWillBeRawPtr<Element> ElementIntersectionObserverData::createWeakPtr(Element* element)
|
| +WeakPtrWillBeRawPtr<Node> NodeIntersectionObserverData::createWeakPtr(Node* node)
|
| {
|
| #if ENABLE(OILPAN)
|
| - return element;
|
| + return node;
|
| #else
|
| if (!m_weakPointerFactory)
|
| - m_weakPointerFactory = adoptPtrWillBeNoop(new WeakPtrFactory<Element>(element));
|
| - return m_weakPointerFactory->createWeakPtr();
|
| + m_weakPointerFactory = adoptPtrWillBeNoop(new WeakPtrFactory<Node>(node));
|
| + WeakPtr<Node> result = m_weakPointerFactory->createWeakPtr();
|
| + ASSERT(result.get() == node);
|
| + return result;
|
| #endif
|
| }
|
|
|
| -DEFINE_TRACE(ElementIntersectionObserverData)
|
| +DEFINE_TRACE(NodeIntersectionObserverData)
|
| {
|
| visitor->trace(m_intersectionObservers);
|
| visitor->trace(m_intersectionObservations);
|
|
|