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

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

Issue 2475643004: Monitor the intersection of video and viewport. (Closed)
Patch Set: Fix trybots failure. 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/IntersectionObservation.cpp
diff --git a/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp b/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp
index c9c04457e5ea67c7f176de9f8542466870e0c392..04de0b1913767e8eeb2d146319f38c85d3fc3f34 100644
--- a/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp
+++ b/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp
@@ -22,6 +22,8 @@ IntersectionObservation::IntersectionObservation(IntersectionObserver& observer,
m_shouldReportRootBounds(shouldReportRootBounds),
m_lastThresholdIndex(0) {}
+IntersectionObservation::~IntersectionObservation() {}
+
void IntersectionObservation::applyRootMargin(LayoutRect& rect) const {
if (m_shouldReportRootBounds)
m_observer->applyRootMargin(rect);
@@ -255,4 +257,35 @@ DEFINE_TRACE(IntersectionObservation) {
visitor->trace(m_target);
}
+ViewportIntersectionObservation::ViewportIntersectionObservation(
+ IntersectionObserver& observer,
+ Element& element)
+ : IntersectionObservation(observer, element, true),
+ m_lastIntersectRect(std::numeric_limits<float>::min(),
+ std::numeric_limits<float>::min(),
+ std::numeric_limits<float>::min(),
+ std::numeric_limits<float>::min()) {}
+
+ViewportIntersectionObservation::~ViewportIntersectionObservation() {}
+
+void ViewportIntersectionObservation::computeIntersectionObservations(
+ DOMHighResTimeStamp timestamp) {
+ IntersectionGeometry geometry;
+ if (!computeGeometry(geometry))
+ return;
+
+ LayoutRect newIntersectRect;
+ if (!geometry.rootRect.isEmpty() && geometry.doesIntersect)
+ newIntersectRect = geometry.intersectionRect;
+ if (newIntersectRect != m_lastIntersectRect) {
+ IntRect snappedRootBounds = pixelSnappedIntRect(geometry.rootRect);
+ IntersectionObserverEntry* newEntry = new IntersectionObserverEntry(
+ timestamp, 0, pixelSnappedIntRect(geometry.targetRect),
+ &snappedRootBounds, pixelSnappedIntRect(geometry.intersectionRect),
+ target());
+ observer().enqueueIntersectionObserverEntry(*newEntry);
+ m_lastIntersectRect = newIntersectRect;
+ }
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698