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

Unified Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 2696893002: [Blink>Media] Add heuristic for dominant video detection for Android (Closed)
Patch Set: Created 3 years, 10 months 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/html/HTMLMediaElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
index 9156bba583b6c602b3a8cc84b4db479d0b50a85d..332b08a3148a7f30206a0d445ab1f4748f40953c 100644
--- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
@@ -125,7 +125,8 @@ using DocumentElementSetMap =
namespace {
-constexpr float kMostlyFillViewportThreshold = 0.85f;
+constexpr float kMostlyFillViewportThresholdInDominantDimension = 0.85f;
+constexpr float kMostlyFillViewportThresholdForTargetVisibleRatio = 0.75f;
constexpr double kMostlyFillViewportBecomeStableSeconds = 5;
constexpr double kCheckViewportIntersectionIntervalSeconds = 1;
@@ -4109,9 +4110,10 @@ void HTMLMediaElement::checkViewportIntersectionTimerFired(TimerBase*) {
// Reset on any intersection change, since this indicates the user is
// scrolling around in the document, the document is changing layout, etc.
m_viewportFillDebouncerTimer.stop();
- bool isMostlyFillingViewport =
- (m_currentIntersectRect.size().area() >
- kMostlyFillViewportThreshold * geometry.rootIntRect().size().area());
+
+ bool isMostlyFillingViewport = computeIsMostlyFillingViewport(
+ geometry.targetIntRect(), geometry.rootIntRect(),
+ geometry.intersectionIntRect());
if (m_mostlyFillingViewport == isMostlyFillingViewport)
return;
@@ -4132,4 +4134,22 @@ void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) {
m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport);
}
+bool HTMLMediaElement::computeIsMostlyFillingViewport(
+ const IntRect& targetRect,
+ const IntRect& rootRect,
+ const IntRect& intersectionRect) {
+ if (targetRect.size().area() == 0 ||
+ intersectionRect.size().area() <=
+ kMostlyFillViewportThresholdForTargetVisibleRatio *
+ targetRect.size().area()) {
+ return false;
+ }
+
+ float xOccupationRatio = 1.0f * intersectionRect.width() / rootRect.width();
+ float yOccupationRatio = 1.0f * intersectionRect.height() / rootRect.height();
mlamouri (slow - plz ping) 2017/02/15 11:08:04 nit: I guess those can be `const float`
Zhiqiang Zhang (Slow) 2017/02/15 11:52:09 Done.
+
+ return std::max(xOccupationRatio, yOccupationRatio) >=
+ kMostlyFillViewportThresholdInDominantDimension;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698