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/ElementIntersectionObserverData.h" | |
6 | |
7 #include "core/dom/Document.h" | |
8 #include "core/dom/Element.h" | |
9 #include "core/dom/IntersectionObservation.h" | |
10 #include "core/dom/IntersectionObserver.h" | |
11 #include "core/dom/IntersectionObserverController.h" | |
12 | |
13 namespace blink { | |
14 | |
15 ElementIntersectionObserverData::ElementIntersectionObserverData() { } | |
16 | |
17 ElementIntersectionObserverData::~ElementIntersectionObserverData() { } | |
18 | |
19 bool ElementIntersectionObserverData::hasIntersectionObserver() const | |
20 { | |
21 return !m_intersectionObservers.isEmpty(); | |
22 } | |
23 | |
24 bool ElementIntersectionObserverData::hasIntersectionObservation() const | |
25 { | |
26 return !m_intersectionObservations.isEmpty(); | |
27 } | |
28 | |
29 IntersectionObservation* ElementIntersectionObserverData::getObservationFor(Inte rsectionObserver& observer) | |
30 { | |
31 HeapHashMap<Member<IntersectionObserver>, Member<IntersectionObservation>>:: iterator i = m_intersectionObservations.find(&observer); | |
haraken
2016/01/07 00:48:17
Can we use auto& ?
szager1
2016/01/07 07:12:22
Done.
| |
32 if (i == m_intersectionObservations.end()) | |
33 return nullptr; | |
34 return i->value; | |
35 } | |
36 | |
37 void ElementIntersectionObserverData::addObservation(IntersectionObservation& ob servation) | |
38 { | |
39 m_intersectionObservations.add(&observation.observer(), &observation); | |
40 } | |
41 | |
42 void ElementIntersectionObserverData::removeObservation(IntersectionObserver& ob server) | |
43 { | |
44 m_intersectionObservations.remove(&observer); | |
45 } | |
46 | |
47 void ElementIntersectionObserverData::activateValidIntersectionObservers(Element & element) | |
48 { | |
49 IntersectionObserverController& controller = element.document().ensureInters ectionObserverController(); | |
50 for (auto& observer : m_intersectionObservers) { | |
51 controller.addTrackedObserver(*observer); | |
52 observer->setActive(true); | |
53 } | |
54 for (auto& observation : m_intersectionObservations) | |
55 observation.value->setActive(observation.key->isDescendantOfRoot(&elemen t)); | |
56 } | |
57 | |
58 void ElementIntersectionObserverData::deactivateAllIntersectionObservers(Element & element) | |
59 { | |
60 element.document().ensureIntersectionObserverController().removeTrackedObser versForRoot(element); | |
61 for (auto& observer : m_intersectionObservers) | |
62 observer->setActive(false); | |
63 for (auto& observation : m_intersectionObservations) | |
64 observation.value->setActive(false); | |
65 } | |
66 | |
67 #if !ENABLE(OILPAN) | |
68 void ElementIntersectionObserverData::dispose() | |
69 { | |
70 HeapVector<Member<IntersectionObservation>> observationsToDisconnect; | |
71 copyValuesToVector(m_intersectionObservations, observationsToDisconnect); | |
72 for (auto& observation : observationsToDisconnect) | |
73 observation->disconnect(); | |
74 ASSERT(m_intersectionObservations.isEmpty()); | |
75 | |
76 HeapVector<Member<IntersectionObserver>> observersToDisconnect; | |
77 copyToVector(m_intersectionObservers, observersToDisconnect); | |
78 for (auto& observer : observersToDisconnect) | |
79 observer->disconnect(); | |
haraken
2016/01/07 00:48:17
Why do you need to call disconnect() for Observers
szager1
2016/01/07 07:12:22
The first section disconnects observations for whi
haraken
2016/01/07 07:38:13
Thanks. I understand the second one is necessary (
| |
80 ASSERT(m_intersectionObservers.isEmpty()); | |
81 | |
82 m_weakPointerFactory.clear(); | |
83 } | |
84 #endif | |
85 | |
86 WeakPtrWillBeRawPtr<Element> ElementIntersectionObserverData::createWeakPtr(Elem ent* element) | |
87 { | |
88 #if ENABLE(OILPAN) | |
89 return element; | |
90 #else | |
91 if (!m_weakPointerFactory) | |
92 m_weakPointerFactory = adoptPtrWillBeNoop(new WeakPtrFactory<Element>(el ement)); | |
93 return m_weakPointerFactory->createWeakPtr(); | |
94 #endif | |
95 } | |
96 | |
97 DEFINE_TRACE(ElementIntersectionObserverData) | |
98 { | |
99 visitor->trace(m_intersectionObservers); | |
100 visitor->trace(m_intersectionObservations); | |
101 } | |
102 | |
103 } // namespace blink | |
OLD | NEW |