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

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: clean up teardown logic 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/IntersectionObserverController.h"
6
7 #include "core/dom/Document.h"
8
9 namespace blink {
10
11 typedef HeapVector<Member<IntersectionObserver>> IntersectionObserverVector;
12
13 IntersectionObserverController::IntersectionObserverController()
14 : m_timer(this, &IntersectionObserverController::deliverIntersectionObservat ions)
15 {
16 }
17
18 IntersectionObserverController::~IntersectionObserverController() { }
19
20 void IntersectionObserverController::scheduleIntersectionObserverForDelivery(Int ersectionObserver& observer)
21 {
22 // TODO(szager): use idle callback with a timeout
23 if (!m_timer.isActive())
24 m_timer.startOneShot(0, BLINK_FROM_HERE);
25 m_pendingIntersectionObservers.add(&observer);
26 }
27
28 void IntersectionObserverController::deliverIntersectionObservations(Timer<Inter sectionObserverController>*)
29 {
30 IntersectionObserverVector observers;
31 copyToVector(m_pendingIntersectionObservers, observers);
32 m_pendingIntersectionObservers.clear();
33 for (auto& observer : observers)
34 observer->deliver();
35 }
36
37 void IntersectionObserverController::computeTrackedIntersectionObservations()
38 {
39 // TODO(szager): Need to define timestamp.
40 double timestamp = currentTime();
41 for (auto& observer : m_trackedIntersectionObservers)
haraken 2016/01/07 00:48:17 Just to confirm: It is not possible that m_tracked
szager1 2016/01/07 07:12:22 That's correct. Javascript cannot run during the
42 observer->computeIntersectionObservations(timestamp);
43 }
44
45 void IntersectionObserverController::addTrackedObserver(IntersectionObserver& ob server)
46 {
47 m_trackedIntersectionObservers.add(&observer);
48 }
49
50 void IntersectionObserverController::removeTrackedObserversForRoot(const Element & root)
51 {
52 HeapVector<Member<IntersectionObserver>> toRemove;
53 for (auto& observer : m_trackedIntersectionObservers) {
54 if (observer->root() == &root)
55 toRemove.append(observer);
56 }
57 m_trackedIntersectionObservers.removeAll(toRemove);
58 }
59
60 DEFINE_TRACE(IntersectionObserverController)
61 {
62 visitor->trace(m_trackedIntersectionObservers);
63 visitor->trace(m_pendingIntersectionObservers);
64 }
65
66 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698