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

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

Issue 1921073002: Add partial viewport visibility check to autoplay experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/core/html/AutoplayExperimentHelper.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/AutoplayExperimentHelper.cpp
diff --git a/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.cpp b/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.cpp
index 74e3636d0e6934230447950cf1f0a813e84e9d4d..bbfbbe36f2c0692d0d8d03247198e7fff8e36e28 100644
--- a/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.cpp
+++ b/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.cpp
@@ -148,7 +148,7 @@ void AutoplayExperimentHelper::registerForPositionUpdatesIfNeeded()
{
// If we don't require that the player is in the viewport, then we don't
// need the listener.
- if (!enabled(IfViewport)) {
+ if (!requiresViewportVisibility()) {
if (!enabled(IfPageVisible))
return;
}
@@ -239,7 +239,7 @@ bool AutoplayExperimentHelper::meetsVisibilityRequirements() const
&& client().pageVisibilityState() != PageVisibilityStateVisible)
return false;
- if (!enabled(IfViewport))
+ if (!requiresViewportVisibility())
return true;
if (m_lastVisibleRect.isEmpty())
@@ -249,6 +249,12 @@ bool AutoplayExperimentHelper::meetsVisibilityRequirements() const
if (currentLocation.isEmpty())
return false;
+ // In partial-viewport mode, we require only 1x1 area.
+ if (enabled(IfPartialViewport)) {
+ return m_lastVisibleRect.intersects(currentLocation);
+ }
+
+ // Element must be completely visible, or as much as fits.
// If element completely fills the screen, then truncate it to exactly
// match the screen. Any element that is wider just has to cover.
if (currentLocation.x() <= m_lastVisibleRect.x()
@@ -382,6 +388,8 @@ AutoplayExperimentHelper::Mode AutoplayExperimentHelper::fromString(const String
value |= IfPageVisible;
if (mode.contains("-ifviewport"))
value |= IfViewport;
+ if (mode.contains("-ifpartialviewport"))
+ value |= IfPartialViewport;
if (mode.contains("-ifmuted"))
value |= IfMuted;
if (mode.contains("-ifmobile"))
@@ -477,4 +485,9 @@ void AutoplayExperimentHelper::loadingStarted()
: AnyAudioElement);
}
+bool AutoplayExperimentHelper::requiresViewportVisibility() const
+{
+ return enabled(IfViewport) || enabled(IfPartialViewport);
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/html/AutoplayExperimentHelper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698