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

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

Issue 1548523002: Use Document, rather than document element, for implicit root. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@intersection-observer
Patch Set: Nits, comments, rebaseline 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 IntersectionObservation* ElementIntersectionObserverData::getObservationFor(Inte rsectionObserver& observer)
30 {
31 auto i = m_intersectionObservations.find(&observer);
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<IntersectionObserver>> observersToDisconnect;
71 copyToVector(m_intersectionObservers, observersToDisconnect);
72 for (auto& observer : observersToDisconnect)
73 observer->disconnect();
74 ASSERT(m_intersectionObservers.isEmpty());
75 }
76 #endif
77
78 WeakPtrWillBeRawPtr<Element> ElementIntersectionObserverData::createWeakPtr(Elem ent* element)
79 {
80 #if ENABLE(OILPAN)
81 return element;
82 #else
83 if (!m_weakPointerFactory)
84 m_weakPointerFactory = adoptPtrWillBeNoop(new WeakPtrFactory<Element>(el ement));
85 return m_weakPointerFactory->createWeakPtr();
86 #endif
87 }
88
89 DEFINE_TRACE(ElementIntersectionObserverData)
90 {
91 visitor->trace(m_intersectionObservers);
92 visitor->trace(m_intersectionObservations);
93 }
94
95 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698