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; | |
haraken
2015/12/22 01:13:30
Define this in the header file and use it in the h
esprehn
2015/12/22 07:50:33
I'd rather we just typed the type out and removed
szager1
2015/12/22 07:53:41
This is contrary to comments received from esprehn
| |
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); | |
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(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 for (auto& observer : toRemove) | |
78 m_trackedIntersectionObservers.remove(observer); | |
haraken
2015/12/22 01:13:30
You can use removeAll.
szager1
2015/12/22 07:53:41
Done.
| |
79 } | |
80 | |
81 void IntersectionObserverController::dispose() | |
82 { | |
83 m_timer.stop(); | |
84 m_trackedIntersectionObservers.clear(); | |
85 m_activeIntersectionObservers.clear(); | |
86 m_suspendedIntersectionObservers.clear(); | |
87 } | |
88 | |
89 DEFINE_TRACE(IntersectionObserverController) | |
90 { | |
91 visitor->trace(m_trackedIntersectionObservers); | |
92 visitor->trace(m_activeIntersectionObservers); | |
93 visitor->trace(m_suspendedIntersectionObservers); | |
94 } | |
95 | |
96 } // namespace blink { | |
OLD | NEW |