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

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: haraken nits 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
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/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 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.add(&observation.observer(), &observation);
37 }
38
39 void ElementIntersectionObserverData::removeObservation(IntersectionObserver& ob server)
haraken 2016/01/03 16:34:20 Don't you need to remove the <Observer, Observatio
szager1 2016/01/04 03:53:04 Yes, good catch; I will work on simplifying the te
40 {
41 const auto& it = m_intersectionObservations.find(&observer);
42 if (it != m_intersectionObservations.end())
43 it->value->disconnect();
44 }
45
46 void ElementIntersectionObserverData::activateValidIntersectionObservers(Element & element)
47 {
48 IntersectionObserverController& controller = element.document().ensureInters ectionObserverController();
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)
58 {
59 element.document().ensureIntersectionObserverController().removeTrackedObser versForRoot(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 WeakPtrWillBeRawPtr<Element> ElementIntersectionObserverData::createWeakPtr(Elem ent* element)
86 {
87 #if ENABLE(OILPAN)
88 return element;
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698