| 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 a1f0ce6a74d593703d34135af4a59c9ecdc1652e..a7ea8164553f1584856340c3c17d460b17e5bbf9 100644
|
| --- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
|
| +++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
|
| @@ -39,6 +39,7 @@
|
| #include "core/dom/ElementTraversal.h"
|
| #include "core/dom/ElementVisibilityObserver.h"
|
| #include "core/dom/Fullscreen.h"
|
| +#include "core/dom/IntersectionGeometry.h"
|
| #include "core/dom/TaskRunnerHelper.h"
|
| #include "core/dom/shadow/ShadowRoot.h"
|
| #include "core/events/Event.h"
|
| @@ -126,6 +127,9 @@ using DocumentElementSetMap =
|
|
|
| namespace {
|
|
|
| +constexpr float kMostlyFillViewportThreshold = 0.85f;
|
| +constexpr double kMostlyFillViewportBecomeStableSeconds = 5;
|
| +
|
| enum MediaControlsShow {
|
| MediaControlsShowAttribute = 0,
|
| MediaControlsShowFullscreen,
|
| @@ -410,6 +414,9 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName,
|
| m_playbackProgressTimer(this,
|
| &HTMLMediaElement::playbackProgressTimerFired),
|
| m_audioTracksTimer(this, &HTMLMediaElement::audioTracksTimerFired),
|
| + m_viewportFillDebouncerTimer(
|
| + this,
|
| + &HTMLMediaElement::viewportFillDebouncerTimerFired),
|
| m_playedTimeRanges(),
|
| m_asyncEventQueue(GenericEventQueue::create(this)),
|
| m_playbackRate(1.0f),
|
| @@ -449,6 +456,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName,
|
| m_processingPreferenceChange(false),
|
| m_playingRemotely(false),
|
| m_inOverlayFullscreenVideo(false),
|
| + m_mostlyFillingViewport(false),
|
| m_audioTracks(this, AudioTrackList::create(*this)),
|
| m_videoTracks(this, VideoTrackList::create(*this)),
|
| m_textTracks(this, nullptr),
|
| @@ -1192,6 +1200,8 @@ void HTMLMediaElement::startPlayerLoad(const KURL& playerProvidedUrl) {
|
|
|
| m_webMediaPlayer->load(loadType(), source, corsMode());
|
|
|
| + m_webMediaPlayer->stablyFilledViewport(m_mostlyFillingViewport);
|
| +
|
| if (isFullscreen()) {
|
| // This handles any transition to or from fullscreen overlay mode.
|
| frame->chromeClient().enterFullscreenForElement(this);
|
| @@ -2504,6 +2514,8 @@ void HTMLMediaElement::startPlaybackProgressTimer() {
|
| }
|
|
|
| void HTMLMediaElement::playbackProgressTimerFired(TimerBase*) {
|
| + checkViewportIntersectionChanged();
|
| +
|
| if (!std::isnan(m_fragmentEndTime) && currentTime() >= m_fragmentEndTime &&
|
| getDirectionOfPlayback() == Forward) {
|
| m_fragmentEndTime = std::numeric_limits<double>::quiet_NaN();
|
| @@ -4193,4 +4205,42 @@ IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect()
|
| return result;
|
| }
|
|
|
| +void HTMLMediaElement::checkViewportIntersectionChanged() {
|
| + // TODO(xjz): Early return if we not in tab mirroring.
|
| +
|
| + IntersectionGeometry geometry(
|
| + &document(), this, Vector<Length>(),
|
| + IntersectionGeometry::ReportRootBounds::kShouldReportRootBounds);
|
| + geometry.computeGeometry();
|
| + IntRect intersectRect = geometry.intersectionIntRect();
|
| + if (m_currentIntersectRect == intersectRect)
|
| + return;
|
| +
|
| + m_currentIntersectRect = intersectRect;
|
| + // 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());
|
| + if (m_mostlyFillingViewport == isMostlyFillingViewport)
|
| + return;
|
| +
|
| + if (!isMostlyFillingViewport) {
|
| + m_mostlyFillingViewport = isMostlyFillingViewport;
|
| + if (m_webMediaPlayer)
|
| + m_webMediaPlayer->stablyFilledViewport(m_mostlyFillingViewport);
|
| + return;
|
| + }
|
| +
|
| + m_viewportFillDebouncerTimer.startOneShot(
|
| + kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE);
|
| +}
|
| +
|
| +void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) {
|
| + m_mostlyFillingViewport = true;
|
| + if (m_webMediaPlayer)
|
| + m_webMediaPlayer->stablyFilledViewport(m_mostlyFillingViewport);
|
| +}
|
| +
|
| } // namespace blink
|
|
|