OLD | NEW |
---|---|
(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 "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_activeIntersectionObservers.isEmpty()) | |
24 m_timer.startOneShot(0, BLINK_FROM_HERE); | |
haraken
2016/01/02 13:47:41
It's better to check m_timer.isActive() before sta
szager1
2016/01/02 19:18:34
Done.
| |
25 m_activeIntersectionObservers.add(&observer); | |
26 } | |
27 | |
28 void IntersectionObserverController::resumeSuspendedIntersectionObservers() | |
29 { | |
30 ASSERT(isMainThread()); | |
31 if (m_suspendedIntersectionObservers.isEmpty()) | |
32 return; | |
33 | |
34 IntersectionObserverVector suspended; | |
35 copyToVector(m_suspendedIntersectionObservers, suspended); | |
36 for (auto& observer : suspended) { | |
37 if (!observer->shouldBeSuspended()) { | |
38 m_suspendedIntersectionObservers.remove(observer); | |
39 scheduleIntersectionObserverForDelivery(*observer); | |
40 } | |
41 } | |
42 } | |
43 | |
44 void IntersectionObserverController::deliverIntersectionObservations(Timer<Inter sectionObserverController>*) | |
45 { | |
46 IntersectionObserverVector observers; | |
47 copyToVector(m_activeIntersectionObservers, observers); | |
48 m_activeIntersectionObservers.clear(); | |
49 for (auto& observer : observers) { | |
50 if (observer->shouldBeSuspended()) | |
51 m_suspendedIntersectionObservers.add(observer); | |
52 else | |
53 observer->deliver(); | |
54 } | |
55 } | |
56 | |
57 void IntersectionObserverController::computeTrackedIntersectionObservations() | |
58 { | |
59 // TODO(szager): Need to define timestamp. | |
60 double timestamp = currentTime(); | |
61 for (auto& observer : m_trackedIntersectionObservers) | |
62 observer->computeIntersectionObservations(timestamp); | |
63 } | |
64 | |
65 void IntersectionObserverController::addTrackedObserver(IntersectionObserver& ob server) | |
66 { | |
67 m_trackedIntersectionObservers.add(&observer); | |
68 } | |
69 | |
70 void IntersectionObserverController::removeTrackedObserversForRoot(const Element & root) | |
71 { | |
72 HeapVector<Member<IntersectionObserver>> toRemove; | |
73 for (auto& observer : m_trackedIntersectionObservers) { | |
74 if (observer->root() == &root) | |
75 toRemove.append(observer); | |
76 } | |
77 m_trackedIntersectionObservers.removeAll(toRemove); | |
78 } | |
79 | |
80 void IntersectionObserverController::dispose() | |
haraken
2016/01/02 13:47:41
This dispose() shouldn't be necessary even in non-
szager1
2016/01/02 19:18:34
Done.
| |
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 | |
OLD | NEW |