Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/ElementIntersectionObserverData.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/ElementIntersectionObserverData.cpp b/third_party/WebKit/Source/core/dom/ElementIntersectionObserverData.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7d0ed4d2da13107f26a6441114602bfe63df2b50 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/dom/ElementIntersectionObserverData.cpp |
| @@ -0,0 +1,102 @@ |
| +// 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 "core/dom/ElementIntersectionObserverData.h" |
| + |
| +#include "core/dom/Document.h" |
| +#include "core/dom/Element.h" |
| +#include "core/dom/IntersectionObservation.h" |
| +#include "core/dom/IntersectionObserver.h" |
| +#include "core/dom/IntersectionObserverController.h" |
| + |
| +namespace blink { |
| + |
| +ElementIntersectionObserverData::ElementIntersectionObserverData() { } |
| + |
| +ElementIntersectionObserverData::~ElementIntersectionObserverData() { } |
| + |
| +bool ElementIntersectionObserverData::hasIntersectionObserver() const |
| +{ |
| + return !m_intersectionObservers.isEmpty(); |
| +} |
| + |
| +bool ElementIntersectionObserverData::hasIntersectionObservation() const |
| +{ |
| + return !m_intersectionObservations.isEmpty(); |
| +} |
| + |
| +bool ElementIntersectionObserverData::hasObservationFor(IntersectionObserver& observer) const |
| +{ |
| + return m_intersectionObservations.contains(&observer); |
| +} |
| + |
| +void ElementIntersectionObserverData::addObservation(IntersectionObservation& observation) |
| +{ |
| + m_intersectionObservations.add(&observation.observer(), &observation); |
| +} |
| + |
| +void ElementIntersectionObserverData::removeObservation(IntersectionObserver& observer) |
| +{ |
| + const auto& it = m_intersectionObservations.find(&observer); |
| + if (it != m_intersectionObservations.end()) |
| + it->value->disconnect(); |
| +} |
| + |
| +void ElementIntersectionObserverData::activateValidIntersectionObservers(Element& element) |
| +{ |
| + IntersectionObserverController& controller = element.document().ensureIntersectionObserverController(); |
| + for (auto& observer : m_intersectionObservers) { |
| + controller.addTrackedObserver(*observer); |
| + observer->setActive(true); |
| + } |
| + for (auto& observation : m_intersectionObservations) |
| + observation.value->setActive(observation.key->isDescendantOfRoot(&element)); |
| +} |
| + |
| +void ElementIntersectionObserverData::deactivateAllIntersectionObservers(Element& element) |
| +{ |
| + element.document().ensureIntersectionObserverController().removeTrackedObserversForRoot(element); |
| + for (auto& observer : m_intersectionObservers) |
| + observer->setActive(false); |
| + for (auto& observation : m_intersectionObservations) |
| + observation.value->setActive(false); |
| +} |
| + |
| +#if !ENABLE(OILPAN) |
| +void ElementIntersectionObserverData::dispose() |
| +{ |
| + HeapVector<Member<IntersectionObservation>> toDisconnect; |
| + copyValuesToVector(m_intersectionObservations, toDisconnect); |
| + for (auto& observation : toDisconnect) |
| + observation->disconnect(); |
|
haraken
2016/01/02 13:47:40
Once we remove IntersectionObservation::disconnect
|
| + ASSERT(m_intersectionObservations.isEmpty()); |
| + |
| + HeapVector<Member<IntersectionObserver>> toDispose; |
| + copyToVector(m_intersectionObservers, toDispose); |
| + for (auto& observer : toDispose) |
| + observer->dispose(); |
|
haraken
2016/01/02 13:47:40
This wouldn't be necessary. See my comment on Inte
|
| + ASSERT(m_intersectionObservers.isEmpty()); |
| + |
| + m_weakPointerFactory.clear(); |
|
haraken
2016/01/02 13:47:40
This wouldn't be necessary.
In conclusion, we can
|
| +} |
| +#endif |
| + |
| +WeakPtrWillBeRawPtr<Element> ElementIntersectionObserverData::createWeakPtr(Element* element) |
| +{ |
| +#if ENABLE(OILPAN) |
| + return element; |
| +#else |
| + if (!m_weakPointerFactory) |
| + m_weakPointerFactory = adoptPtrWillBeNoop(new WeakPtrFactory<Element>(element)); |
| + return m_weakPointerFactory->createWeakPtr(); |
| +#endif |
| +} |
| + |
| +DEFINE_TRACE(ElementIntersectionObserverData) |
| +{ |
| + visitor->trace(m_intersectionObservers); |
| + visitor->trace(m_intersectionObservations); |
| +} |
| + |
| +} // namespace blink |