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..6602688036bf32fdb795e33eb975e2c2c39e2041 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( |
|
miu
2016/11/09 22:02:08
Get rid of the special-case boolean (see comments
xjz
2016/11/11 01:07:29
Keeps the boolean to indicate observing element/vi
|
| + 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 isObservingRatio) |
| : 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_observeElementViewportRatio(isObservingRatio) { |
| 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_observeElementViewportRatio) { |
|
miu
2016/11/09 22:02:08
Please get rid of this extra boolean. Instead, the
xjz
2016/11/11 01:07:29
As discussed offline, the |target| is the video el
|
| + shouldReportRootBounds = true; |
| + } else if (target->document() == rootNode()->document()) { |
| shouldReportRootBounds = true; |
| isDOMDescendant = rootNode()->isShadowIncludingInclusiveAncestorOf(target); |
| } else if (targetFrame && rootFrame) { |