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/IntersectionObservationRegistry.h" | |
7 | |
8 #include "core/dom/Document.h" | |
9 | |
10 namespace blink { | |
11 | |
12 typedef WillBeHeapVector<RefPtrWillBeMember<IntersectionObserver>> IntersectionO bserverVector; | |
13 | |
14 IntersectionObservationRegistry::IntersectionObservationRegistry(Timer<Document> & timer) | |
15 : m_timer(timer) | |
16 { | |
17 } | |
18 | |
19 IntersectionObservationRegistry::~IntersectionObservationRegistry() | |
20 { | |
21 resumeSuspendedIntersectionObservers(); | |
22 deliverIntersectionObservations(); | |
23 ASSERT(!m_suspendedIntersectionObservers.size()); | |
24 } | |
25 | |
26 | |
27 void IntersectionObservationRegistry::activateIntersectionObserver(IntersectionO bserver& observer) | |
28 { | |
29 if (m_activeIntersectionObservers.isEmpty()) | |
30 m_timer.startOneShot(0, BLINK_FROM_HERE); | |
31 m_activeIntersectionObservers.add(&observer); | |
32 } | |
33 | |
34 void IntersectionObservationRegistry::resumeSuspendedIntersectionObservers() | |
35 { | |
36 ASSERT(isMainThread()); | |
37 if (m_suspendedIntersectionObservers.isEmpty()) | |
38 return; | |
39 | |
40 IntersectionObserverVector suspended; | |
41 copyToVector(m_suspendedIntersectionObservers, suspended); | |
42 for (size_t i = 0; i < suspended.size(); ++i) { | |
43 if (!suspended[i]->shouldBeSuspended()) { | |
44 m_suspendedIntersectionObservers.remove(suspended[i]); | |
45 activateIntersectionObserver(*suspended[i]); | |
46 } | |
47 } | |
48 } | |
49 | |
50 void IntersectionObservationRegistry::deliverIntersectionObservations() | |
51 { | |
52 IntersectionObserverVector observers; | |
53 copyToVector(m_activeIntersectionObservers, observers); | |
54 m_activeIntersectionObservers.clear(); | |
55 for (size_t i = 0; i < observers.size(); ++i) { | |
56 if (observers[i]->shouldBeSuspended()) | |
57 m_suspendedIntersectionObservers.add(observers[i]); | |
58 else | |
59 observers[i]->deliver(); | |
60 } | |
61 } | |
62 | |
63 void IntersectionObservationRegistry::computeIntersectionObservations() | |
64 { | |
65 // TODO: Need to define timestamp. | |
66 double timestamp = currentTime(); | |
67 for (auto& observation: m_intersectionObservations) { | |
68 ASSERT(observation->target()->isInTreeScope()); | |
69 observation->computeIntersectionObservations(timestamp); | |
70 } | |
71 } | |
72 | |
73 void IntersectionObservationRegistry::addObservation(IntersectionObservation& ob servation) | |
74 { | |
75 m_intersectionObservations.add(adoptRef(&observation)); | |
haraken
2015/11/16 00:41:34
adoptRefWillBeNoop ? Otherwise, it won't compile w
szager1
2015/11/19 19:15:38
Fixed in next patch (either with adoptRefWillBeNoo
| |
76 } | |
77 | |
78 void IntersectionObservationRegistry::removeObservation(IntersectionObservation& observation) | |
79 { | |
80 m_intersectionObservations.remove(adoptRef(&observation)); | |
81 } | |
82 | |
83 } // namespace blink { | |
OLD | NEW |