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

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

Issue 1449623002: IntersectionObserver: second cut. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Added dispose() methods for expicit cleanup Created 5 years 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
OLDNEW
(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 "config.h"
6 #include "core/dom/ElementIntersectionObserverData.h"
7
8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h"
10 #include "core/dom/IntersectionObserverController.h"
11
12 namespace blink {
13
14 bool ElementIntersectionObserverData::hasIntersectionObserver() const
15 {
16 return !m_intersectionObservers.isEmpty();
17 }
18
19 bool ElementIntersectionObserverData::hasIntersectionObservation() const
20 {
21 return !m_intersectionObservations.isEmpty();
22 }
23
24 bool ElementIntersectionObserverData::hasObservationFor(IntersectionObserver& ob server) const
25 {
26 return m_intersectionObservations.find(&observer) != m_intersectionObservati ons.end();
esprehn 2015/12/17 01:40:28 .contains(), no need to compare to end()
szager1 2015/12/17 20:27:25 Done.
27 }
28
29 void ElementIntersectionObserverData::addObservation(IntersectionObservation& ob servation)
30 {
31 m_intersectionObservations.set(observation.observer(), &observation);
32 }
33
34 void ElementIntersectionObserverData::removeObservation(IntersectionObserver& ob server)
35 {
36 RawPtr<IntersectionObserver> key(&observer);
esprehn 2015/12/17 01:40:28 do these not implicitly construct?
szager1 2015/12/17 20:27:25 Whoops, this was left over from a previous attempt
37 HeapHashMap<Member<IntersectionObserver>, Member<IntersectionObservation>>:: iterator observationIterator = m_intersectionObservations.find(&observer);
esprehn 2015/12/17 01:40:28 auto
szager1 2015/12/17 20:27:25 Done.
38 if (observationIterator != m_intersectionObservations.end())
esprehn 2015/12/17 01:40:28 you can just write "it" for the iterator if you wa
szager1 2015/12/17 20:27:25 Done.
39 observationIterator->value->disconnect();
40 }
41
42 void ElementIntersectionObserverData::activateValidIntersectionObservers(Element & element)
43 {
44 IntersectionObserverController* registry = element.document().intersectionOb serverController();
esprehn 2015/12/17 01:40:28 controller
szager1 2015/12/17 20:27:25 Done.
45 for (auto& observer : m_intersectionObservers) {
46 registry->addTrackedObserver(*observer);
47 observer->setActive(true);
48 }
49 for (auto& observation : m_intersectionObservations)
50 observation.value->setActive(observation.key->isDescendantOfRoot(&elemen t));
51 }
52
53 void ElementIntersectionObserverData::deactivateAllIntersectionObservers(Element & element)
54 {
55 Document& document = element.document();
56 for (auto& observer : m_intersectionObservers) {
57 document.intersectionObserverController()->removeTrackedObserversForRoot (element);
esprehn 2015/12/17 01:40:28 maybe do this out of the loop and save to a variab
szager1 2015/12/17 20:27:25 Oh, this is wrong, removeTrackedObserversForRoot s
58 observer->setActive(false);
59 }
60 for (auto& observation : m_intersectionObservations)
61 observation.value->setActive(false);
62 }
63
64 #if !ENABLE(OILPAN)
65 void ElementIntersectionObserverData::dispose()
66 {
67 HeapVector<Member<IntersectionObservation>> toDisconnect;
68 copyValuesToVector(m_intersectionObservations, toDisconnect);
69 for (auto& observation : toDisconnect)
70 observation->disconnect();
71 ASSERT(m_intersectionObservations.isEmpty());
72
73 HeapVector<Member<IntersectionObserver>> toDispose;
74 copyToVector(m_intersectionObservers, toDispose);
75 for (auto& observer : toDispose)
76 observer->dispose();
77 ASSERT(m_intersectionObservers.isEmpty());
78
79 m_weakPointerFactory.clear();
80 }
81 #endif
82
83 WeakPtr<Element> ElementIntersectionObserverData::createWeakPtr(Element* element )
84 {
85 #if ENABLE(OILPAN)
86 return element;
87 #else
88 if (!m_weakPointerFactory)
89 m_weakPointerFactory = adoptPtrWillBeNoop(new WeakPtrFactory<Element>(el ement));
90 return m_weakPointerFactory->createWeakPtr();
91 #endif
92 }
93
94 DEFINE_TRACE(ElementIntersectionObserverData)
95 {
96 visitor->trace(m_intersectionObservers);
97 visitor->trace(m_intersectionObservations);
98 }
99
100 } // namespace blink {
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698