Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Unified Diff: third_party/WebKit/Source/core/dom/IntersectionObserver.cpp

Issue 2475643004: Monitor the intersection of video and viewport. (Closed)
Patch Set: Addressed miu's comments from PS#5. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5154c7e535ac863d6c8e65bc425d7c5ec01eba71 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 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) {
+ shouldReportRootBounds = true;
+ } else if (target->document() == rootNode()->document()) {
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_observeElementViewportRatio) {
+ observation = new IntersectViewportRatioObservation(*this, *target);
+ } else {
+ observation =
+ new IntersectionObservation(*this, *target, shouldReportRootBounds);
+ }
target->ensureIntersectionObserverData().addObservation(*observation);
m_observations.add(observation);

Powered by Google App Engine
This is Rietveld 408576698