Chromium Code Reviews| 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..6ff870222d36a03427e6b1f491a99a49914337f8 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,10 @@ using DocumentElementSetMap = |
| namespace { |
| +constexpr int64_t kOneHundredPercent = 100; |
| +constexpr int64_t kMostlyFillViewportThresholdPercent = 85; |
| +constexpr double kMostlyFillViewportBecomeStableTime = 5; |
|
ojan
2016/11/24 00:48:33
Nit: I generally prefer time values to say the uni
xjz
2016/11/24 02:16:16
Done.
|
| + |
| enum MediaControlsShow { |
| MediaControlsShowAttribute = 0, |
| MediaControlsShowFullscreen, |
| @@ -410,6 +415,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), |
| @@ -1192,6 +1200,8 @@ void HTMLMediaElement::startPlayerLoad(const KURL& playerProvidedUrl) { |
| m_webMediaPlayer->load(loadType(), source, corsMode()); |
| + m_webMediaPlayer->stablyFilledMostViewport(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() { |
|
ojan
2016/11/24 00:48:33
Can we early return if we're not tab casting so we
xjz
2016/11/24 02:16:16
Add TODO comment for now. Will see if this can be
|
| + ExecutionContext* context = getExecutionContext(); |
| + DCHECK(context->isDocument()); |
| + Document& document = toDocument(*context); |
| + IntersectionGeometry geometry(&document, this, Vector<Length>(), true); |
|
ojan
2016/11/24 00:48:33
Now that you're in the HTMLElement world, you can
xjz
2016/11/24 02:16:16
Done. Name the enum as ReportRootBounds.
|
| + 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 = |
| + (kOneHundredPercent * m_currentIntersectRect.size().area() > |
| + kMostlyFillViewportThresholdPercent * |
|
ojan
2016/11/24 00:48:33
Nit: If you make this kMostlyFillViewportThreshold
xjz
2016/11/24 02:16:16
Done.
|
| + geometry.rootIntRect().size().area()); |
| + if (m_mostlyFillingViewport == isMostlyFillingViewport) |
| + return; |
| + |
| + if (!isMostlyFillingViewport) { |
| + m_mostlyFillingViewport = isMostlyFillingViewport; |
| + if (m_webMediaPlayer) |
| + m_webMediaPlayer->stablyFilledMostViewport(false); |
|
ojan
2016/11/24 00:48:33
Nit: It took me a bit to understand these few line
xjz
2016/11/24 02:16:16
Done.
|
| + return; |
| + } |
| + |
| + m_viewportFillDebouncerTimer.startOneShot(kMostlyFillViewportBecomeStableTime, |
| + BLINK_FROM_HERE); |
|
ojan
2016/11/24 00:48:33
Indentation is off here. FWIW, I haven't used it m
xjz
2016/11/24 02:16:16
I always do "git cl format". Is the "indentation"
|
| +} |
| + |
| +void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) { |
| + m_mostlyFillingViewport = true; |
| + if (m_webMediaPlayer) |
| + m_webMediaPlayer->stablyFilledMostViewport(true); |
| +} |
| + |
| } // namespace blink |