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

Unified Diff: third_party/WebKit/Source/core/dom/IntersectionObservation.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/IntersectionObservation.cpp
diff --git a/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp b/third_party/WebKit/Source/core/dom/IntersectionObservation.cpp
index c9c04457e5ea67c7f176de9f8542466870e0c392..8d6a7b07776c07c08b564db4881aedca8833163a 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,37 @@ DEFINE_TRACE(IntersectionObservation) {
visitor->trace(m_target);
}
+IntersectViewportRatioObservation::IntersectViewportRatioObservation(
+ IntersectionObserver& observer,
+ Element& element)
+ : IntersectionObservation(observer, element, true) {}
+
+IntersectViewportRatioObservation::~IntersectViewportRatioObservation() {}
+
+void IntersectViewportRatioObservation::computeIntersectionObservations(
+ DOMHighResTimeStamp timestamp) {
+ IntersectionGeometry geometry;
+ if (!computeGeometry(geometry))
+ return;
+
+ float newVisibleRatio = 0;
+ if (!geometry.targetRect.isEmpty() && geometry.doesIntersect) {
miu 2016/11/14 21:03:33 This should check that |rootRect| is not empty ins
xjz 2016/11/15 23:03:39 Done.
+ 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;
+ }
+ if (newVisibleRatio != m_lastVisibleRatio) {
miu 2016/11/14 21:03:33 A second thought on this: Maybe we should send the
xjz 2016/11/15 23:03:39 Since we don't know the more intelligent logic for
+ IntRect snappedRootBounds = pixelSnappedIntRect(geometry.rootRect);
+ IntersectionObserverEntry* newEntry = new IntersectionObserverEntry(
+ timestamp, newVisibleRatio, pixelSnappedIntRect(geometry.targetRect),
+ &snappedRootBounds, pixelSnappedIntRect(geometry.intersectionRect),
+ target());
+ observer().enqueueIntersectionObserverEntry(*newEntry);
+ m_lastVisibleRatio = newVisibleRatio;
+ }
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698