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

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: Rebase again. 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 namespace blink { 119 namespace blink {
119 120
120 using namespace HTMLNames; 121 using namespace HTMLNames;
121 122
122 using WeakMediaElementSet = HeapHashSet<WeakMember<HTMLMediaElement>>; 123 using WeakMediaElementSet = HeapHashSet<WeakMember<HTMLMediaElement>>;
123 using DocumentElementSetMap = 124 using DocumentElementSetMap =
124 HeapHashMap<WeakMember<Document>, Member<WeakMediaElementSet>>; 125 HeapHashMap<WeakMember<Document>, Member<WeakMediaElementSet>>;
125 126
126 namespace { 127 namespace {
127 128
129 constexpr float kMostlyFillViewportThreshold = 0.85f;
130 constexpr double kMostlyFillViewportBecomeStableSeconds = 5;
131
128 enum MediaControlsShow { 132 enum MediaControlsShow {
129 MediaControlsShowAttribute = 0, 133 MediaControlsShowAttribute = 0,
130 MediaControlsShowFullscreen, 134 MediaControlsShowFullscreen,
131 MediaControlsShowNoScript, 135 MediaControlsShowNoScript,
132 MediaControlsShowNotShown, 136 MediaControlsShowNotShown,
133 MediaControlsShowMax 137 MediaControlsShowMax
134 }; 138 };
135 139
136 String urlForLoggingMedia(const KURL& url) { 140 String urlForLoggingMedia(const KURL& url) {
137 static const unsigned maximumURLLengthForLogging = 128; 141 static const unsigned maximumURLLengthForLogging = 128;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, 341 HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName,
338 Document& document) 342 Document& document)
339 : HTMLElement(tagName, document), 343 : HTMLElement(tagName, document),
340 ActiveScriptWrappable(this), 344 ActiveScriptWrappable(this),
341 ActiveDOMObject(&document), 345 ActiveDOMObject(&document),
342 m_loadTimer(this, &HTMLMediaElement::loadTimerFired), 346 m_loadTimer(this, &HTMLMediaElement::loadTimerFired),
343 m_progressEventTimer(this, &HTMLMediaElement::progressEventTimerFired), 347 m_progressEventTimer(this, &HTMLMediaElement::progressEventTimerFired),
344 m_playbackProgressTimer(this, 348 m_playbackProgressTimer(this,
345 &HTMLMediaElement::playbackProgressTimerFired), 349 &HTMLMediaElement::playbackProgressTimerFired),
346 m_audioTracksTimer(this, &HTMLMediaElement::audioTracksTimerFired), 350 m_audioTracksTimer(this, &HTMLMediaElement::audioTracksTimerFired),
351 m_viewportFillDebouncerTimer(
352 this,
353 &HTMLMediaElement::viewportFillDebouncerTimerFired),
347 m_playedTimeRanges(), 354 m_playedTimeRanges(),
348 m_asyncEventQueue(GenericEventQueue::create(this)), 355 m_asyncEventQueue(GenericEventQueue::create(this)),
349 m_playbackRate(1.0f), 356 m_playbackRate(1.0f),
350 m_defaultPlaybackRate(1.0f), 357 m_defaultPlaybackRate(1.0f),
351 m_networkState(kNetworkEmpty), 358 m_networkState(kNetworkEmpty),
352 m_readyState(kHaveNothing), 359 m_readyState(kHaveNothing),
353 m_readyStateMaximum(kHaveNothing), 360 m_readyStateMaximum(kHaveNothing),
354 m_volume(1.0f), 361 m_volume(1.0f),
355 m_lastSeekTime(0), 362 m_lastSeekTime(0),
356 m_previousProgressTime(std::numeric_limits<double>::max()), 363 m_previousProgressTime(std::numeric_limits<double>::max()),
(...skipping 19 matching lines...) Expand all
376 m_paused(true), 383 m_paused(true),
377 m_seeking(false), 384 m_seeking(false),
378 m_sentStalledEvent(false), 385 m_sentStalledEvent(false),
379 m_ignorePreloadNone(false), 386 m_ignorePreloadNone(false),
380 m_textTracksVisible(false), 387 m_textTracksVisible(false),
381 m_shouldPerformAutomaticTrackSelection(true), 388 m_shouldPerformAutomaticTrackSelection(true),
382 m_tracksAreReady(true), 389 m_tracksAreReady(true),
383 m_processingPreferenceChange(false), 390 m_processingPreferenceChange(false),
384 m_playingRemotely(false), 391 m_playingRemotely(false),
385 m_inOverlayFullscreenVideo(false), 392 m_inOverlayFullscreenVideo(false),
393 m_mostlyFillingViewport(false),
386 m_audioTracks(this, AudioTrackList::create(*this)), 394 m_audioTracks(this, AudioTrackList::create(*this)),
387 m_videoTracks(this, VideoTrackList::create(*this)), 395 m_videoTracks(this, VideoTrackList::create(*this)),
388 m_textTracks(this, nullptr), 396 m_textTracks(this, nullptr),
389 m_audioSourceNode(nullptr), 397 m_audioSourceNode(nullptr),
390 m_autoplayUmaHelper(AutoplayUmaHelper::create(this)), 398 m_autoplayUmaHelper(AutoplayUmaHelper::create(this)),
391 m_remotePlaybackClient(nullptr), 399 m_remotePlaybackClient(nullptr),
392 m_autoplayVisibilityObserver(nullptr) { 400 m_autoplayVisibilityObserver(nullptr) {
393 ThreadState::current()->registerPreFinalizer(this); 401 ThreadState::current()->registerPreFinalizer(this);
394 402
395 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")"; 403 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")";
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 1127
1120 m_webMediaPlayer->setPreload(effectivePreloadType()); 1128 m_webMediaPlayer->setPreload(effectivePreloadType());
1121 1129
1122 m_webMediaPlayer->requestRemotePlaybackDisabled( 1130 m_webMediaPlayer->requestRemotePlaybackDisabled(
1123 fastHasAttribute(disableremoteplaybackAttr)); 1131 fastHasAttribute(disableremoteplaybackAttr));
1124 1132
1125 m_webMediaPlayer->load(loadType(), source, corsMode()); 1133 m_webMediaPlayer->load(loadType(), source, corsMode());
1126 1134
1127 if (isFullscreen()) 1135 if (isFullscreen())
1128 m_webMediaPlayer->enteredFullscreen(); 1136 m_webMediaPlayer->enteredFullscreen();
1137
1138 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport);
1129 } 1139 }
1130 1140
1131 void HTMLMediaElement::setPlayerPreload() { 1141 void HTMLMediaElement::setPlayerPreload() {
1132 if (m_webMediaPlayer) 1142 if (m_webMediaPlayer)
1133 m_webMediaPlayer->setPreload(effectivePreloadType()); 1143 m_webMediaPlayer->setPreload(effectivePreloadType());
1134 1144
1135 if (loadIsDeferred() && effectivePreloadType() != WebMediaPlayer::PreloadNone) 1145 if (loadIsDeferred() && effectivePreloadType() != WebMediaPlayer::PreloadNone)
1136 startDeferredLoad(); 1146 startDeferredLoad();
1137 } 1147 }
1138 1148
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 void HTMLMediaElement::startPlaybackProgressTimer() { 2411 void HTMLMediaElement::startPlaybackProgressTimer() {
2402 if (m_playbackProgressTimer.isActive()) 2412 if (m_playbackProgressTimer.isActive())
2403 return; 2413 return;
2404 2414
2405 m_previousProgressTime = WTF::currentTime(); 2415 m_previousProgressTime = WTF::currentTime();
2406 m_playbackProgressTimer.startRepeating(maxTimeupdateEventFrequency, 2416 m_playbackProgressTimer.startRepeating(maxTimeupdateEventFrequency,
2407 BLINK_FROM_HERE); 2417 BLINK_FROM_HERE);
2408 } 2418 }
2409 2419
2410 void HTMLMediaElement::playbackProgressTimerFired(TimerBase*) { 2420 void HTMLMediaElement::playbackProgressTimerFired(TimerBase*) {
2421 checkViewportIntersectionChanged();
2422
2411 if (!std::isnan(m_fragmentEndTime) && currentTime() >= m_fragmentEndTime && 2423 if (!std::isnan(m_fragmentEndTime) && currentTime() >= m_fragmentEndTime &&
2412 getDirectionOfPlayback() == Forward) { 2424 getDirectionOfPlayback() == Forward) {
2413 m_fragmentEndTime = std::numeric_limits<double>::quiet_NaN(); 2425 m_fragmentEndTime = std::numeric_limits<double>::quiet_NaN();
2414 if (!m_paused) { 2426 if (!m_paused) {
2415 UseCounter::count(document(), 2427 UseCounter::count(document(),
2416 UseCounter::HTMLMediaElementPauseAtFragmentEnd); 2428 UseCounter::HTMLMediaElementPauseAtFragmentEnd);
2417 // changes paused to true and fires a simple event named pause at the 2429 // changes paused to true and fires a simple event named pause at the
2418 // media element. 2430 // media element.
2419 pauseInternal(); 2431 pauseInternal();
2420 } 2432 }
(...skipping 1605 matching lines...) Expand 10 before | Expand all | Expand 10 after
4026 } 4038 }
4027 4039
4028 DEFINE_TRACE(HTMLMediaElement::AudioClientImpl) { 4040 DEFINE_TRACE(HTMLMediaElement::AudioClientImpl) {
4029 visitor->trace(m_client); 4041 visitor->trace(m_client);
4030 } 4042 }
4031 4043
4032 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) { 4044 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) {
4033 visitor->trace(m_client); 4045 visitor->trace(m_client);
4034 } 4046 }
4035 4047
4048 void HTMLMediaElement::checkViewportIntersectionChanged() {
4049 // TODO(xjz): Early return if we not in tab mirroring.
4050
4051 IntersectionGeometry geometry(
4052 &document(), this, Vector<Length>(),
4053 IntersectionGeometry::ReportRootBounds::kShouldReportRootBounds);
4054 geometry.computeGeometry();
4055 IntRect intersectRect = geometry.intersectionIntRect();
4056 if (m_currentIntersectRect == intersectRect)
4057 return;
4058
4059 m_currentIntersectRect = intersectRect;
4060 // Reset on any intersection change, since this indicates the user is
4061 // scrolling around in the document, the document is changing layout, etc.
4062 m_viewportFillDebouncerTimer.stop();
4063 bool isMostlyFillingViewport =
4064 (m_currentIntersectRect.size().area() >
4065 kMostlyFillViewportThreshold * geometry.rootIntRect().size().area());
4066 if (m_mostlyFillingViewport == isMostlyFillingViewport)
4067 return;
4068
4069 if (!isMostlyFillingViewport) {
4070 m_mostlyFillingViewport = isMostlyFillingViewport;
4071 if (m_webMediaPlayer)
4072 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport);
4073 return;
4074 }
4075
4076 m_viewportFillDebouncerTimer.startOneShot(
4077 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE);
4078 }
4079
4080 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) {
4081 m_mostlyFillingViewport = true;
4082 if (m_webMediaPlayer)
4083 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport);
4084 }
4085
4036 } // namespace blink 4086 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLMediaElement.h ('k') | third_party/WebKit/Source/web/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698