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

Side by Side 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, 7 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/AutoplayExperimentHelper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/html/AutoplayExperimentHelper.h" 5 #include "core/html/AutoplayExperimentHelper.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/frame/Settings.h" 8 #include "core/frame/Settings.h"
9 #include "core/html/HTMLMediaElement.h" 9 #include "core/html/HTMLMediaElement.h"
10 #include "core/layout/LayoutBox.h" 10 #include "core/layout/LayoutBox.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Try to play. If we can't, then install a listener. 141 // Try to play. If we can't, then install a listener.
142 if (!maybeStartPlaying()) 142 if (!maybeStartPlaying())
143 registerForPositionUpdatesIfNeeded(); 143 registerForPositionUpdatesIfNeeded();
144 } 144 }
145 } 145 }
146 146
147 void AutoplayExperimentHelper::registerForPositionUpdatesIfNeeded() 147 void AutoplayExperimentHelper::registerForPositionUpdatesIfNeeded()
148 { 148 {
149 // If we don't require that the player is in the viewport, then we don't 149 // If we don't require that the player is in the viewport, then we don't
150 // need the listener. 150 // need the listener.
151 if (!enabled(IfViewport)) { 151 if (!requiresViewportVisibility()) {
152 if (!enabled(IfPageVisible)) 152 if (!enabled(IfPageVisible))
153 return; 153 return;
154 } 154 }
155 155
156 m_client->setRequestPositionUpdates(true); 156 m_client->setRequestPositionUpdates(true);
157 157
158 // Set this unconditionally, in case we have no layout object yet. 158 // Set this unconditionally, in case we have no layout object yet.
159 m_registeredWithLayoutObject = true; 159 m_registeredWithLayoutObject = true;
160 } 160 }
161 161
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // treat it as the end of scroll. Autoplay if we should. 232 // treat it as the end of scroll. Autoplay if we should.
233 maybeStartPlaying(); 233 maybeStartPlaying();
234 } 234 }
235 235
236 bool AutoplayExperimentHelper::meetsVisibilityRequirements() const 236 bool AutoplayExperimentHelper::meetsVisibilityRequirements() const
237 { 237 {
238 if (enabled(IfPageVisible) 238 if (enabled(IfPageVisible)
239 && client().pageVisibilityState() != PageVisibilityStateVisible) 239 && client().pageVisibilityState() != PageVisibilityStateVisible)
240 return false; 240 return false;
241 241
242 if (!enabled(IfViewport)) 242 if (!requiresViewportVisibility())
243 return true; 243 return true;
244 244
245 if (m_lastVisibleRect.isEmpty()) 245 if (m_lastVisibleRect.isEmpty())
246 return false; 246 return false;
247 247
248 IntRect currentLocation = client().absoluteBoundingBoxRect(); 248 IntRect currentLocation = client().absoluteBoundingBoxRect();
249 if (currentLocation.isEmpty()) 249 if (currentLocation.isEmpty())
250 return false; 250 return false;
251 251
252 // In partial-viewport mode, we require only 1x1 area.
253 if (enabled(IfPartialViewport)) {
254 return m_lastVisibleRect.intersects(currentLocation);
255 }
256
257 // Element must be completely visible, or as much as fits.
252 // If element completely fills the screen, then truncate it to exactly 258 // If element completely fills the screen, then truncate it to exactly
253 // match the screen. Any element that is wider just has to cover. 259 // match the screen. Any element that is wider just has to cover.
254 if (currentLocation.x() <= m_lastVisibleRect.x() 260 if (currentLocation.x() <= m_lastVisibleRect.x()
255 && currentLocation.x() + currentLocation.width() >= m_lastVisibleRect.x( ) + m_lastVisibleRect.width()) { 261 && currentLocation.x() + currentLocation.width() >= m_lastVisibleRect.x( ) + m_lastVisibleRect.width()) {
256 currentLocation.setX(m_lastVisibleRect.x()); 262 currentLocation.setX(m_lastVisibleRect.x());
257 currentLocation.setWidth(m_lastVisibleRect.width()); 263 currentLocation.setWidth(m_lastVisibleRect.width());
258 } 264 }
259 265
260 if (currentLocation.y() <= m_lastVisibleRect.y() 266 if (currentLocation.y() <= m_lastVisibleRect.y()
261 && currentLocation.y() + currentLocation.height() >= m_lastVisibleRect.y () + m_lastVisibleRect.height()) { 267 && currentLocation.y() + currentLocation.height() >= m_lastVisibleRect.y () + m_lastVisibleRect.height()) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 { 381 {
376 Mode value = ExperimentOff; 382 Mode value = ExperimentOff;
377 if (mode.contains("-forvideo")) 383 if (mode.contains("-forvideo"))
378 value |= ForVideo; 384 value |= ForVideo;
379 if (mode.contains("-foraudio")) 385 if (mode.contains("-foraudio"))
380 value |= ForAudio; 386 value |= ForAudio;
381 if (mode.contains("-ifpagevisible")) 387 if (mode.contains("-ifpagevisible"))
382 value |= IfPageVisible; 388 value |= IfPageVisible;
383 if (mode.contains("-ifviewport")) 389 if (mode.contains("-ifviewport"))
384 value |= IfViewport; 390 value |= IfViewport;
391 if (mode.contains("-ifpartialviewport"))
392 value |= IfPartialViewport;
385 if (mode.contains("-ifmuted")) 393 if (mode.contains("-ifmuted"))
386 value |= IfMuted; 394 value |= IfMuted;
387 if (mode.contains("-ifmobile")) 395 if (mode.contains("-ifmobile"))
388 value |= IfMobile; 396 value |= IfMobile;
389 if (mode.contains("-playmuted")) 397 if (mode.contains("-playmuted"))
390 value |= PlayMuted; 398 value |= PlayMuted;
391 399
392 return value; 400 return value;
393 } 401 }
394 402
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 { 478 {
471 if (m_recordedElement) 479 if (m_recordedElement)
472 return; 480 return;
473 481
474 m_recordedElement = true; 482 m_recordedElement = true;
475 recordAutoplayMetric(client().isHTMLVideoElement() 483 recordAutoplayMetric(client().isHTMLVideoElement()
476 ? AnyVideoElement 484 ? AnyVideoElement
477 : AnyAudioElement); 485 : AnyAudioElement);
478 } 486 }
479 487
488 bool AutoplayExperimentHelper::requiresViewportVisibility() const
489 {
490 return enabled(IfViewport) || enabled(IfPartialViewport);
491 }
492
480 } // namespace blink 493 } // namespace blink
OLDNEW
« 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