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

Side by Side Diff: third_party/WebKit/Source/core/dom/IntersectionObserverController.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/IntersectionObserverController.h"
7
8 #include "core/dom/Document.h"
9
10 namespace blink {
11
12 typedef HeapVector<Member<IntersectionObserver>> IntersectionObserverVector;
13
14 IntersectionObserverController::IntersectionObserverController()
15 : m_timer(this, &IntersectionObserverController::deliverIntersectionObservat ions)
16 {
17 }
18
19 void IntersectionObserverController::scheduleIntersectionObserverForDelivery(Int ersectionObserver& observer)
20 {
21 // TODO: use idle callback with a timeout
esprehn 2015/12/17 01:40:29 ditto for adding your name
szager1 2015/12/17 20:27:26 Done, here and elsewhere.
22 if (m_activeIntersectionObservers.isEmpty())
23 m_timer.startOneShot(0, BLINK_FROM_HERE);
24 m_activeIntersectionObservers.add(&observer);
25 }
26
27 void IntersectionObserverController::resumeSuspendedIntersectionObservers()
28 {
29 ASSERT(isMainThread());
30 if (m_suspendedIntersectionObservers.isEmpty())
31 return;
32
33 IntersectionObserverVector suspended;
34 copyToVector(m_suspendedIntersectionObservers, suspended);
35 for (auto& observer : suspended) {
36 if (!observer->shouldBeSuspended()) {
37 m_suspendedIntersectionObservers.remove(observer);
38 scheduleIntersectionObserverForDelivery(*observer);
39 }
40 }
41 }
42
43 void IntersectionObserverController::deliverIntersectionObservations(Timer<Inter sectionObserverController>*)
44 {
45 IntersectionObserverVector observers;
46 copyToVector(m_activeIntersectionObservers, observers);
47 m_activeIntersectionObservers.clear();
48 for (auto& observer : observers) {
49 if (observer->shouldBeSuspended())
50 m_suspendedIntersectionObservers.add(observer);
51 else
52 observer->deliver();
53 }
54 }
55
56 void IntersectionObserverController::computeTrackedIntersectionObservations()
57 {
58 // TODO: Need to define timestamp.
esprehn 2015/12/17 01:40:29 ditto
59 double timestamp = currentTime();
60 for (auto& observer : m_trackedIntersectionObservers)
61 observer->computeIntersectionObservations(timestamp);
62 }
63
64 void IntersectionObserverController::addTrackedObserver(IntersectionObserver& ob server)
65 {
66 m_trackedIntersectionObservers.add(&observer);
67 }
68
69 void IntersectionObserverController::removeTrackedObserversForRoot(Element& root )
70 {
71 HeapVector<Member<IntersectionObserver>> toRemove;
72 for (auto& observer : m_trackedIntersectionObservers) {
73 if (observer->root() == &root)
74 toRemove.append(observer);
75 }
76 for (auto& observer : toRemove)
77 m_trackedIntersectionObservers.remove(observer);
78 }
79
80 void IntersectionObserverController::dispose()
81 {
82 m_timer.stop();
83 m_trackedIntersectionObservers.clear();
84 m_activeIntersectionObservers.clear();
85 m_suspendedIntersectionObservers.clear();
86 }
87
88 DEFINE_TRACE(IntersectionObserverController)
89 {
90 visitor->trace(m_trackedIntersectionObservers);
91 visitor->trace(m_activeIntersectionObservers);
92 visitor->trace(m_suspendedIntersectionObservers);
93 }
94
95 } // namespace blink {
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698