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

Side by Side Diff: third_party/WebKit/Source/core/dom/NodeIntersectionObserverData.cpp

Issue 1580783003: Revert of Use Document, rather than document element, for implicit root. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@intersection-observer
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/NodeIntersectionObserverData.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 NodeIntersectionObserverData::~NodeIntersectionObserverData() { }
17
18 bool NodeIntersectionObserverData::hasIntersectionObserver() const
19 {
20 return !m_intersectionObservers.isEmpty();
21 }
22
23 bool NodeIntersectionObserverData::hasIntersectionObservation() const
24 {
25 return !m_intersectionObservations.isEmpty();
26 }
27
28 IntersectionObservation* NodeIntersectionObserverData::getObservationFor(Interse ctionObserver& observer)
29 {
30 auto i = m_intersectionObservations.find(&observer);
31 if (i == m_intersectionObservations.end())
32 return nullptr;
33 return i->value;
34 }
35
36 void NodeIntersectionObserverData::addObservation(IntersectionObservation& obser vation)
37 {
38 m_intersectionObservations.add(&observation.observer(), &observation);
39 }
40
41 void NodeIntersectionObserverData::removeObservation(IntersectionObserver& obser ver)
42 {
43 m_intersectionObservations.remove(&observer);
44 }
45
46 void NodeIntersectionObserverData::activateValidIntersectionObservers(Node& node )
47 {
48 IntersectionObserverController& controller = node.document().ensureIntersect ionObserverController();
49 // Activate observers for which node is root.
50 for (auto& observer : m_intersectionObservers) {
51 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 }
61
62 void NodeIntersectionObserverData::deactivateAllIntersectionObservers(Node& node )
63 {
64 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 }
70
71 #if !ENABLE(OILPAN)
72 void NodeIntersectionObserverData::dispose()
73 {
74 HeapVector<Member<IntersectionObserver>> observersToDisconnect;
75 copyToVector(m_intersectionObservers, observersToDisconnect);
76 for (auto& observer : observersToDisconnect)
77 observer->disconnect();
78 ASSERT(m_intersectionObservers.isEmpty());
79 }
80 #endif
81
82 WeakPtrWillBeRawPtr<Node> NodeIntersectionObserverData::createWeakPtr(Node* node )
83 {
84 #if ENABLE(OILPAN)
85 return node;
86 #else
87 if (!m_weakPointerFactory)
88 m_weakPointerFactory = adoptPtrWillBeNoop(new WeakPtrFactory<Node>(node) );
89 WeakPtr<Node> result = m_weakPointerFactory->createWeakPtr();
90 ASSERT(result.get() == node);
91 return result;
92 #endif
93 }
94
95 DEFINE_TRACE(NodeIntersectionObserverData)
96 {
97 visitor->trace(m_intersectionObservers);
98 visitor->trace(m_intersectionObservations);
99 }
100
101 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/NodeIntersectionObserverData.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698