OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 | |
esprehn
2015/12/22 07:50:32
I might rename these .hasObservation() and hasObse
| |
25 { | |
26 return !m_intersectionObservations.isEmpty(); | |
27 } | |
28 | |
29 bool ElementIntersectionObserverData::hasObservationFor(IntersectionObserver& ob server) const | |
30 { | |
31 return m_intersectionObservations.contains(&observer); | |
32 } | |
33 | |
34 void ElementIntersectionObserverData::addObservation(IntersectionObservation& ob servation) | |
35 { | |
36 m_intersectionObservations.set(observation.observer(), &observation); | |
haraken
2015/12/22 01:13:29
Add ASSERT(!m_intersectionObservations.contains(..
esprehn
2015/12/22 07:50:32
Since this is a HashMap this should be .add() not
szager1
2015/12/22 07:53:41
Done.
szager1
2015/12/22 08:49:49
Done.
| |
37 } | |
38 | |
39 void ElementIntersectionObserverData::removeObservation(IntersectionObserver& ob server) | |
40 { | |
41 const auto& it = m_intersectionObservations.find(&observer); | |
42 if (it != m_intersectionObservations.end()) | |
haraken
2015/12/22 01:13:29
Can we change this to:
ASSERT(it != m_intersect
szager1
2015/12/22 07:53:41
This comes from an API call:
observer.unobserve(t
| |
43 it->value->disconnect(); | |
44 } | |
45 | |
46 void ElementIntersectionObserverData::activateValidIntersectionObservers(Element & element) | |
47 { | |
48 IntersectionObserverController& controller = element.document().intersection ObserverController(); | |
49 for (auto& observer : m_intersectionObservers) { | |
50 controller.addTrackedObserver(*observer); | |
51 observer->setActive(true); | |
52 } | |
53 for (auto& observation : m_intersectionObservations) | |
54 observation.value->setActive(observation.key->isDescendantOfRoot(&elemen t)); | |
55 } | |
56 | |
57 void ElementIntersectionObserverData::deactivateAllIntersectionObservers(Element & element) | |
haraken
2015/12/22 01:13:29
Just to confirm: If the Element and the Document d
esprehn
2015/12/22 07:50:32
That's only true when Oilpan is enabled I think, o
szager1
2015/12/22 07:53:41
That should be fine, regular garbage collection sh
| |
58 { | |
59 element.document().intersectionObserverController().removeTrackedObserversFo rRoot(element); | |
60 for (auto& observer : m_intersectionObservers) | |
61 observer->setActive(false); | |
62 for (auto& observation : m_intersectionObservations) | |
63 observation.value->setActive(false); | |
64 } | |
65 | |
66 #if !ENABLE(OILPAN) | |
67 void ElementIntersectionObserverData::dispose() | |
68 { | |
69 HeapVector<Member<IntersectionObservation>> toDisconnect; | |
70 copyValuesToVector(m_intersectionObservations, toDisconnect); | |
71 for (auto& observation : toDisconnect) | |
72 observation->disconnect(); | |
73 ASSERT(m_intersectionObservations.isEmpty()); | |
74 | |
75 HeapVector<Member<IntersectionObserver>> toDispose; | |
76 copyToVector(m_intersectionObservers, toDispose); | |
77 for (auto& observer : toDispose) | |
78 observer->dispose(); | |
79 ASSERT(m_intersectionObservers.isEmpty()); | |
80 | |
81 m_weakPointerFactory.clear(); | |
82 } | |
83 #endif | |
84 | |
85 WeakPtr<Element> ElementIntersectionObserverData::createWeakPtr(Element* element ) | |
86 { | |
87 #if ENABLE(OILPAN) | |
88 return element; | |
esprehn
2015/12/22 07:50:32
does this actually work? The return type doesn't n
szager1
2015/12/22 08:49:49
Good catch!
| |
89 #else | |
90 if (!m_weakPointerFactory) | |
91 m_weakPointerFactory = adoptPtrWillBeNoop(new WeakPtrFactory<Element>(el ement)); | |
92 return m_weakPointerFactory->createWeakPtr(); | |
93 #endif | |
94 } | |
95 | |
96 DEFINE_TRACE(ElementIntersectionObserverData) | |
97 { | |
98 visitor->trace(m_intersectionObservers); | |
99 visitor->trace(m_intersectionObservations); | |
100 } | |
101 | |
102 } // namespace blink { | |
OLD | NEW |