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

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

Issue 2475643004: Monitor the intersection of video and viewport. (Closed)
Patch Set: Addressed comments. Observe intersection changing. 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..ca65df9030a03cd1acb9c89c3afb3c1122038748 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,43 @@ 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;
+
+ float newVisibleRatio = 0;
miu 2016/11/15 23:29:26 Please remove |newVisibleRatio| and move the ratio
xjz 2016/11/16 01:06:45 Done.
+ LayoutRect newIntersectRect;
+ if (!geometry.rootRect.isEmpty() && geometry.doesIntersect) {
+ float intersectionArea =
+ geometry.intersectionRect.size().width().toFloat() *
+ geometry.intersectionRect.size().height().toFloat();
+ float rootArea = geometry.rootRect.size().width().toFloat() *
+ geometry.rootRect.size().height().toFloat();
+ newVisibleRatio = intersectionArea / rootArea;
+ newIntersectRect = geometry.intersectionRect;
+ }
+ if (newIntersectRect != m_lastIntersectRect) {
+ IntRect snappedRootBounds = pixelSnappedIntRect(geometry.rootRect);
+ IntersectionObserverEntry* newEntry = new IntersectionObserverEntry(
+ timestamp, newVisibleRatio, 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