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/NodeIntersectionObserverData.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" |
(...skipping 28 matching lines...) Expand all Loading... |
39 } | 39 } |
40 | 40 |
41 void NodeIntersectionObserverData::removeObservation(IntersectionObserver& obser
ver) | 41 void NodeIntersectionObserverData::removeObservation(IntersectionObserver& obser
ver) |
42 { | 42 { |
43 m_intersectionObservations.remove(&observer); | 43 m_intersectionObservations.remove(&observer); |
44 } | 44 } |
45 | 45 |
46 void NodeIntersectionObserverData::activateValidIntersectionObservers(Node& node
) | 46 void NodeIntersectionObserverData::activateValidIntersectionObservers(Node& node
) |
47 { | 47 { |
48 IntersectionObserverController& controller = node.document().ensureIntersect
ionObserverController(); | 48 IntersectionObserverController& controller = node.document().ensureIntersect
ionObserverController(); |
49 // Activate observers for which node is root. | 49 for (auto& observer : m_intersectionObservers) |
50 for (auto& observer : m_intersectionObservers) { | |
51 controller.addTrackedObserver(*observer); | 50 controller.addTrackedObserver(*observer); |
52 observer->setActive(true); | |
53 } | |
54 // A document can be root, but not target. | |
55 if (node.isDocumentNode()) | |
56 return; | |
57 // Active observers for which node is target. | |
58 for (auto& observation : m_intersectionObservations) | |
59 observation.value->setActive(observation.key->isDescendantOfRoot(&toElem
ent(node))); | |
60 } | 51 } |
61 | 52 |
62 void NodeIntersectionObserverData::deactivateAllIntersectionObservers(Node& node
) | 53 void NodeIntersectionObserverData::deactivateAllIntersectionObservers(Node& node
) |
63 { | 54 { |
64 node.document().ensureIntersectionObserverController().removeTrackedObserver
sForRoot(node); | 55 node.document().ensureIntersectionObserverController().removeTrackedObserver
sForRoot(node); |
65 for (auto& observer : m_intersectionObservers) | |
66 observer->setActive(false); | |
67 for (auto& observation : m_intersectionObservations) | |
68 observation.value->setActive(false); | |
69 } | 56 } |
70 | 57 |
71 #if !ENABLE(OILPAN) | 58 #if !ENABLE(OILPAN) |
72 void NodeIntersectionObserverData::dispose() | 59 void NodeIntersectionObserverData::dispose() |
73 { | 60 { |
74 HeapVector<Member<IntersectionObserver>> observersToDisconnect; | 61 HeapVector<Member<IntersectionObserver>> observersToDisconnect; |
75 copyToVector(m_intersectionObservers, observersToDisconnect); | 62 copyToVector(m_intersectionObservers, observersToDisconnect); |
76 for (auto& observer : observersToDisconnect) | 63 for (auto& observer : observersToDisconnect) |
77 observer->disconnect(); | 64 observer->disconnect(); |
78 ASSERT(m_intersectionObservers.isEmpty()); | 65 ASSERT(m_intersectionObservers.isEmpty()); |
(...skipping 13 matching lines...) Expand all Loading... |
92 #endif | 79 #endif |
93 } | 80 } |
94 | 81 |
95 DEFINE_TRACE(NodeIntersectionObserverData) | 82 DEFINE_TRACE(NodeIntersectionObserverData) |
96 { | 83 { |
97 visitor->trace(m_intersectionObservers); | 84 visitor->trace(m_intersectionObservers); |
98 visitor->trace(m_intersectionObservations); | 85 visitor->trace(m_intersectionObservations); |
99 } | 86 } |
100 | 87 |
101 } // namespace blink | 88 } // namespace blink |
OLD | NEW |