| Index: third_party/WebKit/Source/core/dom/IntersectionObservationRegistry.cpp
|
| diff --git a/third_party/WebKit/Source/core/dom/IntersectionObservationRegistry.cpp b/third_party/WebKit/Source/core/dom/IntersectionObservationRegistry.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fc52d6ce81368e37295223016f1cd0b3e8d4dbd9
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/dom/IntersectionObservationRegistry.cpp
|
| @@ -0,0 +1,82 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "config.h"
|
| +#include "core/dom/IntersectionObservationRegistry.h"
|
| +
|
| +#include "core/dom/Document.h"
|
| +
|
| +namespace blink {
|
| +
|
| +typedef HeapVector<Member<IntersectionObserver>> IntersectionObserverVector;
|
| +
|
| +IntersectionObservationRegistry::IntersectionObservationRegistry(Timer<Document>& timer)
|
| + : m_timer(timer)
|
| +{
|
| +}
|
| +
|
| +void IntersectionObservationRegistry::activateIntersectionObserver(IntersectionObserver& observer)
|
| +{
|
| + if (m_activeIntersectionObservers->isEmpty())
|
| + m_timer.startOneShot(0, BLINK_FROM_HERE);
|
| + m_activeIntersectionObservers->add(&observer);
|
| +}
|
| +
|
| +void IntersectionObservationRegistry::resumeSuspendedIntersectionObservers()
|
| +{
|
| + ASSERT(isMainThread());
|
| + if (m_suspendedIntersectionObservers->isEmpty())
|
| + return;
|
| +
|
| + IntersectionObserverVector suspended;
|
| + copyToVector(*m_suspendedIntersectionObservers, suspended);
|
| + for (size_t i = 0; i < suspended.size(); ++i) {
|
| + if (!suspended[i]->shouldBeSuspended()) {
|
| + m_suspendedIntersectionObservers->remove(suspended[i]);
|
| + activateIntersectionObserver(*suspended[i]);
|
| + }
|
| + }
|
| +}
|
| +
|
| +void IntersectionObservationRegistry::deliverIntersectionObservations()
|
| +{
|
| + IntersectionObserverVector observers;
|
| + copyToVector(*m_activeIntersectionObservers, observers);
|
| + m_activeIntersectionObservers.clear();
|
| + for (size_t i = 0; i < observers.size(); ++i) {
|
| + if (observers[i]->shouldBeSuspended())
|
| + m_suspendedIntersectionObservers->add(observers[i]);
|
| + else
|
| + observers[i]->deliver();
|
| + }
|
| +}
|
| +
|
| +void IntersectionObservationRegistry::computeIntersectionObservations()
|
| +{
|
| + // TODO: Need to define timestamp.
|
| + double timestamp = currentTime();
|
| + for (auto& observation: *m_intersectionObservations) {
|
| + ASSERT(observation->target()->isInTreeScope());
|
| + observation->computeIntersectionObservations(timestamp);
|
| + }
|
| +}
|
| +
|
| +void IntersectionObservationRegistry::addObservation(IntersectionObservation& observation)
|
| +{
|
| + m_intersectionObservations->add(&observation);
|
| +}
|
| +
|
| +void IntersectionObservationRegistry::removeObservation(IntersectionObservation& observation)
|
| +{
|
| + m_intersectionObservations->remove(&observation);
|
| +}
|
| +
|
| +DEFINE_TRACE(IntersectionObservationRegistry)
|
| +{
|
| + visitor->trace(m_activeIntersectionObservers);
|
| + visitor->trace(m_suspendedIntersectionObservers);
|
| + visitor->trace(m_intersectionObservations);
|
| +}
|
| +
|
| +} // namespace blink {
|
|
|