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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 2511143006: Detect change on the intersection of video and viewport. (Closed)
Patch Set: Addressed comments. Created 4 years 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 21 matching lines...) Expand all
32 #include "bindings/core/v8/ScriptController.h" 32 #include "bindings/core/v8/ScriptController.h"
33 #include "bindings/core/v8/ScriptEventListener.h" 33 #include "bindings/core/v8/ScriptEventListener.h"
34 #include "bindings/core/v8/ScriptPromiseResolver.h" 34 #include "bindings/core/v8/ScriptPromiseResolver.h"
35 #include "core/HTMLNames.h" 35 #include "core/HTMLNames.h"
36 #include "core/css/MediaList.h" 36 #include "core/css/MediaList.h"
37 #include "core/dom/Attribute.h" 37 #include "core/dom/Attribute.h"
38 #include "core/dom/DOMException.h" 38 #include "core/dom/DOMException.h"
39 #include "core/dom/ElementTraversal.h" 39 #include "core/dom/ElementTraversal.h"
40 #include "core/dom/ElementVisibilityObserver.h" 40 #include "core/dom/ElementVisibilityObserver.h"
41 #include "core/dom/Fullscreen.h" 41 #include "core/dom/Fullscreen.h"
42 #include "core/dom/IntersectionGeometry.h"
42 #include "core/dom/TaskRunnerHelper.h" 43 #include "core/dom/TaskRunnerHelper.h"
43 #include "core/dom/shadow/ShadowRoot.h" 44 #include "core/dom/shadow/ShadowRoot.h"
44 #include "core/events/Event.h" 45 #include "core/events/Event.h"
45 #include "core/frame/FrameView.h" 46 #include "core/frame/FrameView.h"
46 #include "core/frame/LocalFrame.h" 47 #include "core/frame/LocalFrame.h"
47 #include "core/frame/Settings.h" 48 #include "core/frame/Settings.h"
48 #include "core/frame/UseCounter.h" 49 #include "core/frame/UseCounter.h"
49 #include "core/frame/csp/ContentSecurityPolicy.h" 50 #include "core/frame/csp/ContentSecurityPolicy.h"
50 #include "core/html/AutoplayUmaHelper.h" 51 #include "core/html/AutoplayUmaHelper.h"
51 #include "core/html/HTMLMediaSource.h" 52 #include "core/html/HTMLMediaSource.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 namespace blink { 120 namespace blink {
120 121
121 using namespace HTMLNames; 122 using namespace HTMLNames;
122 123
123 using WeakMediaElementSet = HeapHashSet<WeakMember<HTMLMediaElement>>; 124 using WeakMediaElementSet = HeapHashSet<WeakMember<HTMLMediaElement>>;
124 using DocumentElementSetMap = 125 using DocumentElementSetMap =
125 HeapHashMap<WeakMember<Document>, Member<WeakMediaElementSet>>; 126 HeapHashMap<WeakMember<Document>, Member<WeakMediaElementSet>>;
126 127
127 namespace { 128 namespace {
128 129
130 constexpr float kMostlyFillViewportThreshold = 0.85f;
131 constexpr double kMostlyFillViewportBecomeStableSeconds = 5;
132
129 enum MediaControlsShow { 133 enum MediaControlsShow {
130 MediaControlsShowAttribute = 0, 134 MediaControlsShowAttribute = 0,
131 MediaControlsShowFullscreen, 135 MediaControlsShowFullscreen,
132 MediaControlsShowNoScript, 136 MediaControlsShowNoScript,
133 MediaControlsShowNotShown, 137 MediaControlsShowNotShown,
134 MediaControlsShowMax 138 MediaControlsShowMax
135 }; 139 };
136 140
137 String urlForLoggingMedia(const KURL& url) { 141 String urlForLoggingMedia(const KURL& url) {
138 static const unsigned maximumURLLengthForLogging = 128; 142 static const unsigned maximumURLLengthForLogging = 128;
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, 407 HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName,
404 Document& document) 408 Document& document)
405 : HTMLElement(tagName, document), 409 : HTMLElement(tagName, document),
406 ActiveScriptWrappable(this), 410 ActiveScriptWrappable(this),
407 ActiveDOMObject(&document), 411 ActiveDOMObject(&document),
408 m_loadTimer(this, &HTMLMediaElement::loadTimerFired), 412 m_loadTimer(this, &HTMLMediaElement::loadTimerFired),
409 m_progressEventTimer(this, &HTMLMediaElement::progressEventTimerFired), 413 m_progressEventTimer(this, &HTMLMediaElement::progressEventTimerFired),
410 m_playbackProgressTimer(this, 414 m_playbackProgressTimer(this,
411 &HTMLMediaElement::playbackProgressTimerFired), 415 &HTMLMediaElement::playbackProgressTimerFired),
412 m_audioTracksTimer(this, &HTMLMediaElement::audioTracksTimerFired), 416 m_audioTracksTimer(this, &HTMLMediaElement::audioTracksTimerFired),
417 m_viewportFillDebouncerTimer(
418 this,
419 &HTMLMediaElement::viewportFillDebouncerTimerFired),
413 m_playedTimeRanges(), 420 m_playedTimeRanges(),
414 m_asyncEventQueue(GenericEventQueue::create(this)), 421 m_asyncEventQueue(GenericEventQueue::create(this)),
415 m_playbackRate(1.0f), 422 m_playbackRate(1.0f),
416 m_defaultPlaybackRate(1.0f), 423 m_defaultPlaybackRate(1.0f),
417 m_networkState(kNetworkEmpty), 424 m_networkState(kNetworkEmpty),
418 m_readyState(kHaveNothing), 425 m_readyState(kHaveNothing),
419 m_readyStateMaximum(kHaveNothing), 426 m_readyStateMaximum(kHaveNothing),
420 m_volume(1.0f), 427 m_volume(1.0f),
421 m_lastSeekTime(0), 428 m_lastSeekTime(0),
422 m_previousProgressTime(std::numeric_limits<double>::max()), 429 m_previousProgressTime(std::numeric_limits<double>::max()),
(...skipping 19 matching lines...) Expand all
442 m_paused(true), 449 m_paused(true),
443 m_seeking(false), 450 m_seeking(false),
444 m_sentStalledEvent(false), 451 m_sentStalledEvent(false),
445 m_ignorePreloadNone(false), 452 m_ignorePreloadNone(false),
446 m_textTracksVisible(false), 453 m_textTracksVisible(false),
447 m_shouldPerformAutomaticTrackSelection(true), 454 m_shouldPerformAutomaticTrackSelection(true),
448 m_tracksAreReady(true), 455 m_tracksAreReady(true),
449 m_processingPreferenceChange(false), 456 m_processingPreferenceChange(false),
450 m_playingRemotely(false), 457 m_playingRemotely(false),
451 m_inOverlayFullscreenVideo(false), 458 m_inOverlayFullscreenVideo(false),
459 m_mostlyFillingViewport(false),
452 m_audioTracks(this, AudioTrackList::create(*this)), 460 m_audioTracks(this, AudioTrackList::create(*this)),
453 m_videoTracks(this, VideoTrackList::create(*this)), 461 m_videoTracks(this, VideoTrackList::create(*this)),
454 m_textTracks(this, nullptr), 462 m_textTracks(this, nullptr),
455 m_playPromiseResolveTask(CancellableTaskFactory::create( 463 m_playPromiseResolveTask(CancellableTaskFactory::create(
456 this, 464 this,
457 &HTMLMediaElement::resolveScheduledPlayPromises)), 465 &HTMLMediaElement::resolveScheduledPlayPromises)),
458 m_playPromiseRejectTask(CancellableTaskFactory::create( 466 m_playPromiseRejectTask(CancellableTaskFactory::create(
459 this, 467 this,
460 &HTMLMediaElement::rejectScheduledPlayPromises)), 468 &HTMLMediaElement::rejectScheduledPlayPromises)),
461 m_audioSourceNode(nullptr), 469 m_audioSourceNode(nullptr),
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 // wrapper. 1193 // wrapper.
1186 m_audioSourceProvider.wrap(m_webMediaPlayer->getAudioSourceProvider()); 1194 m_audioSourceProvider.wrap(m_webMediaPlayer->getAudioSourceProvider());
1187 m_webMediaPlayer->setVolume(effectiveMediaVolume()); 1195 m_webMediaPlayer->setVolume(effectiveMediaVolume());
1188 1196
1189 m_webMediaPlayer->setPoster(posterImageURL()); 1197 m_webMediaPlayer->setPoster(posterImageURL());
1190 1198
1191 m_webMediaPlayer->setPreload(effectivePreloadType()); 1199 m_webMediaPlayer->setPreload(effectivePreloadType());
1192 1200
1193 m_webMediaPlayer->load(loadType(), source, corsMode()); 1201 m_webMediaPlayer->load(loadType(), source, corsMode());
1194 1202
1203 m_webMediaPlayer->stablyFilledViewport(m_mostlyFillingViewport);
1204
1195 if (isFullscreen()) { 1205 if (isFullscreen()) {
1196 // This handles any transition to or from fullscreen overlay mode. 1206 // This handles any transition to or from fullscreen overlay mode.
1197 frame->chromeClient().enterFullscreenForElement(this); 1207 frame->chromeClient().enterFullscreenForElement(this);
1198 } 1208 }
1199 } 1209 }
1200 1210
1201 void HTMLMediaElement::setPlayerPreload() { 1211 void HTMLMediaElement::setPlayerPreload() {
1202 if (m_webMediaPlayer) 1212 if (m_webMediaPlayer)
1203 m_webMediaPlayer->setPreload(effectivePreloadType()); 1213 m_webMediaPlayer->setPreload(effectivePreloadType());
1204 1214
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
2497 void HTMLMediaElement::startPlaybackProgressTimer() { 2507 void HTMLMediaElement::startPlaybackProgressTimer() {
2498 if (m_playbackProgressTimer.isActive()) 2508 if (m_playbackProgressTimer.isActive())
2499 return; 2509 return;
2500 2510
2501 m_previousProgressTime = WTF::currentTime(); 2511 m_previousProgressTime = WTF::currentTime();
2502 m_playbackProgressTimer.startRepeating(maxTimeupdateEventFrequency, 2512 m_playbackProgressTimer.startRepeating(maxTimeupdateEventFrequency,
2503 BLINK_FROM_HERE); 2513 BLINK_FROM_HERE);
2504 } 2514 }
2505 2515
2506 void HTMLMediaElement::playbackProgressTimerFired(TimerBase*) { 2516 void HTMLMediaElement::playbackProgressTimerFired(TimerBase*) {
2517 checkViewportIntersectionChanged();
2518
2507 if (!std::isnan(m_fragmentEndTime) && currentTime() >= m_fragmentEndTime && 2519 if (!std::isnan(m_fragmentEndTime) && currentTime() >= m_fragmentEndTime &&
2508 getDirectionOfPlayback() == Forward) { 2520 getDirectionOfPlayback() == Forward) {
2509 m_fragmentEndTime = std::numeric_limits<double>::quiet_NaN(); 2521 m_fragmentEndTime = std::numeric_limits<double>::quiet_NaN();
2510 if (!m_paused) { 2522 if (!m_paused) {
2511 UseCounter::count(document(), 2523 UseCounter::count(document(),
2512 UseCounter::HTMLMediaElementPauseAtFragmentEnd); 2524 UseCounter::HTMLMediaElementPauseAtFragmentEnd);
2513 // changes paused to true and fires a simple event named pause at the 2525 // changes paused to true and fires a simple event named pause at the
2514 // media element. 2526 // media element.
2515 pauseInternal(); 2527 pauseInternal();
2516 } 2528 }
(...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after
4186 } 4198 }
4187 4199
4188 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() 4200 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect()
4189 const { 4201 const {
4190 IntRect result; 4202 IntRect result;
4191 if (LayoutObject* object = m_element->layoutObject()) 4203 if (LayoutObject* object = m_element->layoutObject())
4192 result = object->absoluteBoundingBoxRect(); 4204 result = object->absoluteBoundingBoxRect();
4193 return result; 4205 return result;
4194 } 4206 }
4195 4207
4208 void HTMLMediaElement::checkViewportIntersectionChanged() {
4209 // TODO(xjz): Early return if we not in tab mirroring.
4210
4211 IntersectionGeometry geometry(
4212 &document(), this, Vector<Length>(),
4213 IntersectionGeometry::ReportRootBounds::kShouldReportRootBounds);
4214 geometry.computeGeometry();
4215 IntRect intersectRect = geometry.intersectionIntRect();
4216 if (m_currentIntersectRect == intersectRect)
4217 return;
4218
4219 m_currentIntersectRect = intersectRect;
4220 // Reset on any intersection change, since this indicates the user is
4221 // scrolling around in the document, the document is changing layout, etc.
4222 m_viewportFillDebouncerTimer.stop();
4223 bool isMostlyFillingViewport =
4224 (m_currentIntersectRect.size().area() >
4225 kMostlyFillViewportThreshold * geometry.rootIntRect().size().area());
4226 if (m_mostlyFillingViewport == isMostlyFillingViewport)
4227 return;
4228
4229 if (!isMostlyFillingViewport) {
4230 m_mostlyFillingViewport = isMostlyFillingViewport;
4231 if (m_webMediaPlayer)
4232 m_webMediaPlayer->stablyFilledViewport(m_mostlyFillingViewport);
4233 return;
4234 }
4235
4236 m_viewportFillDebouncerTimer.startOneShot(
4237 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE);
4238 }
4239
4240 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) {
4241 m_mostlyFillingViewport = true;
4242 if (m_webMediaPlayer)
4243 m_webMediaPlayer->stablyFilledViewport(m_mostlyFillingViewport);
4244 }
4245
4196 } // namespace blink 4246 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698