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 "config.h" | |
6 #include "core/dom/IntersectionObserverRegistry.h" | |
7 | |
8 #include "core/dom/Document.h" | |
9 | |
10 namespace blink { | |
11 | |
12 typedef HeapVector<Member<IntersectionObserver>> IntersectionObserverVector; | |
esprehn
2015/12/12 00:14:16
remove
szager1
2015/12/16 19:15:37
Done.
| |
13 | |
14 IntersectionObserverRegistry::IntersectionObserverRegistry(Timer<Document>& time r) | |
15 : m_timer(timer) | |
16 , m_trackedIntersectionObservers(new IntersectionObserver::WeakHashSet()) | |
17 , m_activeIntersectionObservers(new IntersectionObserver::HashSet()) | |
18 , m_suspendedIntersectionObservers(new IntersectionObserver::HashSet()) | |
esprehn
2015/12/12 00:14:16
remove, just make them members
szager1
2015/12/16 19:15:37
Done.
| |
19 { | |
20 } | |
21 | |
22 void IntersectionObserverRegistry::scheduleIntersectionObserverForDelivery(Inter sectionObserver& observer) | |
23 { | |
24 if (m_activeIntersectionObservers->isEmpty()) | |
25 m_timer.startOneShot(0, BLINK_FROM_HERE); | |
ojan
2015/12/12 01:06:29
Add a TODO to do this at idle time?
szager1
2015/12/16 19:15:37
Done.
| |
26 m_activeIntersectionObservers->add(&observer); | |
27 } | |
28 | |
29 void IntersectionObserverRegistry::resumeSuspendedIntersectionObservers() | |
30 { | |
31 ASSERT(isMainThread()); | |
32 if (m_suspendedIntersectionObservers->isEmpty()) | |
33 return; | |
34 | |
35 IntersectionObserverVector suspended; | |
36 copyToVector(*m_suspendedIntersectionObservers, suspended); | |
37 for (size_t i = 0; i < suspended.size(); ++i) { | |
ojan
2015/12/12 01:06:29
use auto : ?
szager1
2015/12/16 19:15:37
Done.
| |
38 if (!suspended[i]->shouldBeSuspended()) { | |
39 m_suspendedIntersectionObservers->remove(suspended[i]); | |
40 scheduleIntersectionObserverForDelivery(*suspended[i]); | |
41 } | |
42 } | |
43 } | |
44 | |
45 void IntersectionObserverRegistry::deliverIntersectionObservations() | |
46 { | |
47 IntersectionObserverVector observers; | |
48 copyToVector(*m_activeIntersectionObservers, observers); | |
49 m_activeIntersectionObservers->clear(); | |
50 for (size_t i = 0; i < observers.size(); ++i) { | |
ojan
2015/12/12 01:06:29
use auto : ?
szager1
2015/12/16 19:15:37
Done.
| |
51 if (observers[i]->shouldBeSuspended()) | |
52 m_suspendedIntersectionObservers->add(observers[i]); | |
53 else | |
54 observers[i]->deliver(); | |
55 } | |
56 } | |
57 | |
58 void IntersectionObserverRegistry::computeTrackedIntersectionObservations() | |
59 { | |
60 // TODO: Need to define timestamp. | |
61 double timestamp = currentTime(); | |
62 for (auto& observer: *m_trackedIntersectionObservers) | |
esprehn
2015/12/12 00:14:16
space
szager1
2015/12/16 19:15:37
Done.
| |
63 observer->computeIntersectionObservations(timestamp); | |
64 } | |
65 | |
66 void IntersectionObserverRegistry::addTrackedObserver(IntersectionObserver& obse rver) | |
67 { | |
68 m_trackedIntersectionObservers->add(&observer); | |
69 } | |
70 | |
71 void IntersectionObserverRegistry::removeTrackedObserversForRoot(Element* root) | |
72 { | |
73 HeapVector<Member<IntersectionObserver>> toRemove; | |
74 for (auto& observer: *m_trackedIntersectionObservers) { | |
esprehn
2015/12/12 00:14:16
space
szager1
2015/12/16 19:15:37
Done.
| |
75 if (observer->root() == root) | |
76 toRemove.append(observer); | |
77 } | |
78 for (auto& observer: toRemove) | |
esprehn
2015/12/12 00:14:16
space, we really need to get the linter fixed for
szager1
2015/12/16 19:15:37
Done.
| |
79 m_trackedIntersectionObservers->remove(observer); | |
80 } | |
81 | |
82 DEFINE_TRACE(IntersectionObserverRegistry) | |
83 { | |
84 visitor->trace(m_trackedIntersectionObservers); | |
85 visitor->trace(m_activeIntersectionObservers); | |
86 visitor->trace(m_suspendedIntersectionObservers); | |
87 } | |
88 | |
89 } // namespace blink { | |
OLD | NEW |