| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/dom/NodeIntersectionObserverData.h" | |
| 6 | |
| 7 #include "core/dom/Document.h" | |
| 8 #include "core/dom/IntersectionObservation.h" | |
| 9 #include "core/dom/IntersectionObserver.h" | |
| 10 #include "core/dom/IntersectionObserverController.h" | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 NodeIntersectionObserverData::NodeIntersectionObserverData() {} | |
| 15 | |
| 16 IntersectionObservation* NodeIntersectionObserverData::getObservationFor( | |
| 17 IntersectionObserver& observer) { | |
| 18 auto i = m_intersectionObservations.find(&observer); | |
| 19 if (i == m_intersectionObservations.end()) | |
| 20 return nullptr; | |
| 21 return i->value; | |
| 22 } | |
| 23 | |
| 24 void NodeIntersectionObserverData::addObservation( | |
| 25 IntersectionObservation& observation) { | |
| 26 m_intersectionObservations.add( | |
| 27 TraceWrapperMember<IntersectionObserver>(this, &observation.observer()), | |
| 28 &observation); | |
| 29 } | |
| 30 | |
| 31 void NodeIntersectionObserverData::removeObservation( | |
| 32 IntersectionObserver& observer) { | |
| 33 m_intersectionObservations.remove(&observer); | |
| 34 } | |
| 35 | |
| 36 void NodeIntersectionObserverData::activateValidIntersectionObservers( | |
| 37 Node& node) { | |
| 38 IntersectionObserverController& controller = | |
| 39 node.document().ensureIntersectionObserverController(); | |
| 40 for (auto& observer : m_intersectionObservers) | |
| 41 controller.addTrackedObserver(*observer); | |
| 42 } | |
| 43 | |
| 44 void NodeIntersectionObserverData::deactivateAllIntersectionObservers( | |
| 45 Node& node) { | |
| 46 node.document() | |
| 47 .ensureIntersectionObserverController() | |
| 48 .removeTrackedObserversForRoot(node); | |
| 49 } | |
| 50 | |
| 51 DEFINE_TRACE(NodeIntersectionObserverData) { | |
| 52 visitor->trace(m_intersectionObservers); | |
| 53 visitor->trace(m_intersectionObservations); | |
| 54 } | |
| 55 | |
| 56 DEFINE_TRACE_WRAPPERS(NodeIntersectionObserverData) { | |
| 57 for (auto& entry : m_intersectionObservations) { | |
| 58 visitor->traceWrappers(entry.key); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 } // namespace blink | |
| OLD | NEW |