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