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

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 from PS#2. 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 int64_t kOneHundredPercent = 100;
131 constexpr int64_t kMostlyFillViewportThresholdPercent = 85;
132 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.
133
129 enum MediaControlsShow { 134 enum MediaControlsShow {
130 MediaControlsShowAttribute = 0, 135 MediaControlsShowAttribute = 0,
131 MediaControlsShowFullscreen, 136 MediaControlsShowFullscreen,
132 MediaControlsShowNoScript, 137 MediaControlsShowNoScript,
133 MediaControlsShowNotShown, 138 MediaControlsShowNotShown,
134 MediaControlsShowMax 139 MediaControlsShowMax
135 }; 140 };
136 141
137 String urlForLoggingMedia(const KURL& url) { 142 String urlForLoggingMedia(const KURL& url) {
138 static const unsigned maximumURLLengthForLogging = 128; 143 static const unsigned maximumURLLengthForLogging = 128;
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, 408 HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName,
404 Document& document) 409 Document& document)
405 : HTMLElement(tagName, document), 410 : HTMLElement(tagName, document),
406 ActiveScriptWrappable(this), 411 ActiveScriptWrappable(this),
407 ActiveDOMObject(&document), 412 ActiveDOMObject(&document),
408 m_loadTimer(this, &HTMLMediaElement::loadTimerFired), 413 m_loadTimer(this, &HTMLMediaElement::loadTimerFired),
409 m_progressEventTimer(this, &HTMLMediaElement::progressEventTimerFired), 414 m_progressEventTimer(this, &HTMLMediaElement::progressEventTimerFired),
410 m_playbackProgressTimer(this, 415 m_playbackProgressTimer(this,
411 &HTMLMediaElement::playbackProgressTimerFired), 416 &HTMLMediaElement::playbackProgressTimerFired),
412 m_audioTracksTimer(this, &HTMLMediaElement::audioTracksTimerFired), 417 m_audioTracksTimer(this, &HTMLMediaElement::audioTracksTimerFired),
418 m_viewportFillDebouncerTimer(
419 this,
420 &HTMLMediaElement::viewportFillDebouncerTimerFired),
413 m_playedTimeRanges(), 421 m_playedTimeRanges(),
414 m_asyncEventQueue(GenericEventQueue::create(this)), 422 m_asyncEventQueue(GenericEventQueue::create(this)),
415 m_playbackRate(1.0f), 423 m_playbackRate(1.0f),
416 m_defaultPlaybackRate(1.0f), 424 m_defaultPlaybackRate(1.0f),
417 m_networkState(kNetworkEmpty), 425 m_networkState(kNetworkEmpty),
418 m_readyState(kHaveNothing), 426 m_readyState(kHaveNothing),
419 m_readyStateMaximum(kHaveNothing), 427 m_readyStateMaximum(kHaveNothing),
420 m_volume(1.0f), 428 m_volume(1.0f),
421 m_lastSeekTime(0), 429 m_lastSeekTime(0),
422 m_previousProgressTime(std::numeric_limits<double>::max()), 430 m_previousProgressTime(std::numeric_limits<double>::max()),
(...skipping 762 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->stablyFilledMostViewport(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() {
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
4209 ExecutionContext* context = getExecutionContext();
4210 DCHECK(context->isDocument());
4211 Document& document = toDocument(*context);
4212 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.
4213 geometry.computeGeometry();
4214 IntRect intersectRect = geometry.intersectionIntRect();
4215 if (m_currentIntersectRect == intersectRect)
4216 return;
4217
4218 m_currentIntersectRect = intersectRect;
4219 // Reset on any intersection change, since this indicates the user is
4220 // scrolling around in the document, the document is changing layout, etc.
4221 m_viewportFillDebouncerTimer.stop();
4222 bool isMostlyFillingViewport =
4223 (kOneHundredPercent * m_currentIntersectRect.size().area() >
4224 kMostlyFillViewportThresholdPercent *
ojan 2016/11/24 00:48:33 Nit: If you make this kMostlyFillViewportThreshold
xjz 2016/11/24 02:16:16 Done.
4225 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->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.
4233 return;
4234 }
4235
4236 m_viewportFillDebouncerTimer.startOneShot(kMostlyFillViewportBecomeStableTime,
4237 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"
4238 }
4239
4240 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) {
4241 m_mostlyFillingViewport = true;
4242 if (m_webMediaPlayer)
4243 m_webMediaPlayer->stablyFilledMostViewport(true);
4244 }
4245
4196 } // namespace blink 4246 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698