| Index: third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
|
| diff --git a/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp b/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
|
| index 60be0837ef1f6001b6cdf4493d28ebe1097ff8b6..2bfda308d700a92cd534e3f25ac579e0f6fc8631 100644
|
| --- a/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
|
| +++ b/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
|
| @@ -188,8 +188,13 @@ IntersectionObserver* IntersectionObserver::create(
|
|
|
| IntersectionObserverCallbackImpl* intersectionObserverCallback =
|
| new IntersectionObserverCallbackImpl(document, std::move(callback));
|
| - return new IntersectionObserver(*intersectionObserverCallback, *root,
|
| - rootMargin, thresholds);
|
| + if (thresholds.isEmpty()) {
|
| + return new ViewportIntersectionObserver(*intersectionObserverCallback,
|
| + *root, rootMargin);
|
| + } else {
|
| + return new IntersectionObserver(*intersectionObserverCallback, *root,
|
| + rootMargin, thresholds);
|
| + }
|
| }
|
|
|
| IntersectionObserver::IntersectionObserver(
|
| @@ -235,6 +240,8 @@ IntersectionObserver::IntersectionObserver(
|
| *this);
|
| }
|
|
|
| +IntersectionObserver::~IntersectionObserver() {}
|
| +
|
| void IntersectionObserver::clearWeakMembers(Visitor* visitor) {
|
| if (ThreadHeap::isHeapObjectAlive(m_root))
|
| return;
|
| @@ -280,7 +287,7 @@ void IntersectionObserver::observe(Element* target,
|
| }
|
|
|
| IntersectionObservation* observation =
|
| - new IntersectionObservation(*this, *target, shouldReportRootBounds);
|
| + createObservation(*target, shouldReportRootBounds);
|
| target->ensureIntersectionObserverData().addObservation(*observation);
|
| m_observations.add(observation);
|
|
|
| @@ -445,6 +452,12 @@ void IntersectionObserver::deliver() {
|
| m_callback->handleEvent(entries, *this);
|
| }
|
|
|
| +IntersectionObservation* IntersectionObserver::createObservation(
|
| + Element& target,
|
| + bool shouldReportRootBounds) {
|
| + return new IntersectionObservation(*this, target, shouldReportRootBounds);
|
| +}
|
| +
|
| DEFINE_TRACE(IntersectionObserver) {
|
| visitor->template registerWeakMembers<
|
| IntersectionObserver, &IntersectionObserver::clearWeakMembers>(this);
|
| @@ -453,4 +466,18 @@ DEFINE_TRACE(IntersectionObserver) {
|
| visitor->trace(m_entries);
|
| }
|
|
|
| +ViewportIntersectionObserver::ViewportIntersectionObserver(
|
| + IntersectionObserverCallback& callback,
|
| + Node& node,
|
| + const Vector<Length>& rootMargin)
|
| + : IntersectionObserver(callback, node, rootMargin, Vector<float>()) {}
|
| +
|
| +ViewportIntersectionObserver::~ViewportIntersectionObserver() {}
|
| +
|
| +IntersectionObservation* ViewportIntersectionObserver::createObservation(
|
| + Element& target,
|
| + bool) {
|
| + return new ViewportIntersectionObservation(*this, target);
|
| +}
|
| +
|
| } // namespace blink
|
|
|