Chromium Code Reviews| 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 32ef04c78978b5f0856a4812c1ff8499585d1e5d..f7653c7b843cf4e6bcab817fae277aa8a5a5e020 100644 |
| --- a/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp |
| +++ b/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp |
| @@ -169,7 +169,8 @@ IntersectionObserver* IntersectionObserver::create( |
| if (exceptionState.hadException()) |
| return nullptr; |
| - return new IntersectionObserver(callback, *root, rootMargin, thresholds); |
| + return new IntersectionObserver(callback, *root, rootMargin, thresholds, |
| + false); |
| } |
| IntersectionObserver* IntersectionObserver::create( |
| @@ -189,14 +190,34 @@ IntersectionObserver* IntersectionObserver::create( |
| IntersectionObserverCallbackImpl* intersectionObserverCallback = |
| new IntersectionObserverCallbackImpl(document, std::move(callback)); |
| return new IntersectionObserver(*intersectionObserverCallback, *root, |
| - rootMargin, thresholds); |
| + rootMargin, thresholds, false); |
| +} |
| + |
| +IntersectionObserver* IntersectionObserver::create( |
| + const Vector<Length>& rootMargin, |
| + Document* document, |
| + std::unique_ptr<EventCallback> callback, |
| + ExceptionState& exceptionState) { |
| + Node* root = getRootNode(document); |
| + if (!root) { |
| + exceptionState.throwDOMException( |
| + HierarchyRequestError, |
| + "Unable to get root node in main frame to track."); |
| + return nullptr; |
| + } |
| + |
| + IntersectionObserverCallbackImpl* intersectionObserverCallback = |
| + new IntersectionObserverCallbackImpl(document, std::move(callback)); |
| + return new IntersectionObserver(*intersectionObserverCallback, *root, |
| + rootMargin, Vector<float>(), true); |
| } |
| IntersectionObserver::IntersectionObserver( |
| IntersectionObserverCallback& callback, |
| Node& root, |
| const Vector<Length>& rootMargin, |
| - const Vector<float>& thresholds) |
| + const Vector<float>& thresholds, |
| + bool observeViewportIntersection) |
| : m_callback(&callback), |
| m_root(&root), |
| m_thresholds(thresholds), |
| @@ -204,7 +225,8 @@ IntersectionObserver::IntersectionObserver( |
| m_rightMargin(Fixed), |
| m_bottomMargin(Fixed), |
| m_leftMargin(Fixed), |
| - m_initialState(InitialState::kHidden) { |
| + m_initialState(InitialState::kHidden), |
| + m_observeViewportIntersection(observeViewportIntersection) { |
| switch (rootMargin.size()) { |
| case 0: |
| break; |
| @@ -269,7 +291,9 @@ void IntersectionObserver::observe(Element* target, |
| LocalFrame* targetFrame = target->document().frame(); |
| LocalFrame* rootFrame = m_root->document().frame(); |
| - if (target->document() == rootNode()->document()) { |
| + if (m_observeViewportIntersection) { |
| + shouldReportRootBounds = true; |
| + } else if (target->document() == rootNode()->document()) { |
|
szager1
2016/11/16 17:53:54
Please push the logic for determining shouldReport
xjz
2016/11/16 20:38:59
Sorry, I didn't quite get your comment "It's very
|
| shouldReportRootBounds = true; |
| isDOMDescendant = rootNode()->isShadowIncludingInclusiveAncestorOf(target); |
| } else if (targetFrame && rootFrame) { |
| @@ -279,8 +303,13 @@ void IntersectionObserver::observe(Element* target, |
| isDOMDescendant = (targetFrame->tree().top() == rootFrame); |
| } |
| - IntersectionObservation* observation = |
| - new IntersectionObservation(*this, *target, shouldReportRootBounds); |
| + IntersectionObservation* observation; |
| + if (m_observeViewportIntersection) { |
|
szager1
2016/11/16 17:53:54
Why is this 'if' clause necessary? The value of s
xjz
2016/11/16 20:38:59
This 'if' clause here is to create the ViewportInt
|
| + observation = new ViewportIntersectionObservation(*this, *target); |
| + } else { |
| + observation = |
| + new IntersectionObservation(*this, *target, shouldReportRootBounds); |
| + } |
| target->ensureIntersectionObserverData().addObservation(*observation); |
| m_observations.add(observation); |