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 HeapVector<Member<IntersectionObserver>> IntersectionObserverVector; |
| 13 |
| 14 IntersectionObservationRegistry::IntersectionObservationRegistry(Timer<Document>
& timer) |
| 15 : m_timer(timer) |
| 16 { |
| 17 } |
| 18 |
| 19 void IntersectionObservationRegistry::activateIntersectionObserver(IntersectionO
bserver& observer) |
| 20 { |
| 21 if (m_activeIntersectionObservers->isEmpty()) |
| 22 m_timer.startOneShot(0, BLINK_FROM_HERE); |
| 23 m_activeIntersectionObservers->add(&observer); |
| 24 } |
| 25 |
| 26 void IntersectionObservationRegistry::resumeSuspendedIntersectionObservers() |
| 27 { |
| 28 ASSERT(isMainThread()); |
| 29 if (m_suspendedIntersectionObservers->isEmpty()) |
| 30 return; |
| 31 |
| 32 IntersectionObserverVector suspended; |
| 33 copyToVector(*m_suspendedIntersectionObservers, suspended); |
| 34 for (size_t i = 0; i < suspended.size(); ++i) { |
| 35 if (!suspended[i]->shouldBeSuspended()) { |
| 36 m_suspendedIntersectionObservers->remove(suspended[i]); |
| 37 activateIntersectionObserver(*suspended[i]); |
| 38 } |
| 39 } |
| 40 } |
| 41 |
| 42 void IntersectionObservationRegistry::deliverIntersectionObservations() |
| 43 { |
| 44 IntersectionObserverVector observers; |
| 45 copyToVector(*m_activeIntersectionObservers, observers); |
| 46 m_activeIntersectionObservers.clear(); |
| 47 for (size_t i = 0; i < observers.size(); ++i) { |
| 48 if (observers[i]->shouldBeSuspended()) |
| 49 m_suspendedIntersectionObservers->add(observers[i]); |
| 50 else |
| 51 observers[i]->deliver(); |
| 52 } |
| 53 } |
| 54 |
| 55 void IntersectionObservationRegistry::computeIntersectionObservations() |
| 56 { |
| 57 // TODO: Need to define timestamp. |
| 58 double timestamp = currentTime(); |
| 59 for (auto& observation: *m_intersectionObservations) { |
| 60 ASSERT(observation->target()->isInTreeScope()); |
| 61 observation->computeIntersectionObservations(timestamp); |
| 62 } |
| 63 } |
| 64 |
| 65 void IntersectionObservationRegistry::addObservation(IntersectionObservation& ob
servation) |
| 66 { |
| 67 m_intersectionObservations->add(&observation); |
| 68 } |
| 69 |
| 70 void IntersectionObservationRegistry::removeObservation(IntersectionObservation&
observation) |
| 71 { |
| 72 m_intersectionObservations->remove(&observation); |
| 73 } |
| 74 |
| 75 DEFINE_TRACE(IntersectionObservationRegistry) |
| 76 { |
| 77 visitor->trace(m_activeIntersectionObservers); |
| 78 visitor->trace(m_suspendedIntersectionObservers); |
| 79 visitor->trace(m_intersectionObservations); |
| 80 } |
| 81 |
| 82 } // namespace blink { |
OLD | NEW |