Diff
Modified: trunk/LayoutTests/ChangeLog (200777 => 200778)
--- trunk/LayoutTests/ChangeLog 2016-05-12 17:01:41 UTC (rev 200777)
+++ trunk/LayoutTests/ChangeLog 2016-05-12 17:53:38 UTC (rev 200778)
@@ -1,3 +1,15 @@
+2016-05-12 Eric Carlson <[email protected]>
+
+ Adjust "main content" video heuristic
+ https://bugs.webkit.org/show_bug.cgi?id=157532
+
+ Reviewed by Darin Adler.
+
+ * media/video-main-content-allow.html:
+ * media/video-main-content-autoplay-expected.txt: Added.
+ * media/video-main-content-autoplay.html: Added.
+ * media/video-main-content-deny-too-small.html:
+
2016-05-12 Antoine Quint <[email protected]>
Correctly handle prefixed and unprefixed variants in CSSStyleDeclaration
Modified: trunk/LayoutTests/media/video-main-content-allow.html (200777 => 200778)
--- trunk/LayoutTests/media/video-main-content-allow.html 2016-05-12 17:01:41 UTC (rev 200777)
+++ trunk/LayoutTests/media/video-main-content-allow.html 2016-05-12 17:53:38 UTC (rev 200778)
@@ -22,8 +22,8 @@
</script>
<style>
video {
- width: 600px;
- height: 400px;
+ width: 270px;
+ height: 480px;
}
</style>
</head>
Added: trunk/LayoutTests/media/video-main-content-autoplay-expected.txt (0 => 200778)
--- trunk/LayoutTests/media/video-main-content-autoplay-expected.txt (rev 0)
+++ trunk/LayoutTests/media/video-main-content-autoplay-expected.txt 2016-05-12 17:53:38 UTC (rev 200778)
@@ -0,0 +1,13 @@
+RUN(smallVideo.setAttribute('controls','controls'))
+RUN(smallVideo.setAttribute('autoplay','autoplay'))
+RUN(smallVideo.setAttribute('id','small'))
+RUN(document.body.appendChild(smallVideo))
+
+RUN(largeVideo.setAttribute('controls','controls'))
+RUN(largeVideo.setAttribute('autoplay','autoplay'))
+RUN(largeVideo.setAttribute('id','large'))
+RUN(document.body.appendChild(largeVideo))
+
+Large video auto-played, small video did not. OK
+END OF TEST
+
Added: trunk/LayoutTests/media/video-main-content-autoplay.html (0 => 200778)
--- trunk/LayoutTests/media/video-main-content-autoplay.html (rev 0)
+++ trunk/LayoutTests/media/video-main-content-autoplay.html 2016-05-12 17:53:38 UTC (rev 200778)
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>video-main-content-size-check</title>
+ <script src=""
+ <script src=""
+ <script>
+ var smallVideo;
+ var largeVideo;
+ var counter = 0;
+
+ function maybeEndTest()
+ {
+ if (++counter < 2)
+ return;
+
+ logResult(true, 'Large video auto-played, small video did not.');
+ endTest();
+ }
+
+ function playing(event)
+ {
+ if (event.target == smallVideo)
+ failTest('Small video should not autoplay.');
+ else
+ maybeEndTest();
+ }
+
+ function canPlayThrough(event)
+ {
+ if (event.target == smallVideo)
+ setTimeout(maybeEndTest, 100);
+ }
+
+ function go()
+ {
+ smallVideo = document.createElement('video');
+ internals.setMediaElementRestrictions(smallVideo, "RequireUserGestureForVideoRateChange,OverrideUserGestureRequirementForMainContent");
+ run("smallVideo.setAttribute('controls','controls')");
+ run("smallVideo.setAttribute('autoplay','autoplay')");
+ run("smallVideo.setAttribute('id','small')");
+ smallVideo.addEventListener('canplaythrough', canPlayThrough, true);
+ smallVideo.addEventListener('playing', playing, true);
+ run("document.body.appendChild(smallVideo)");
+
+ consoleWrite("");
+ largeVideo = document.createElement('video');
+ internals.setMediaElementRestrictions(largeVideo, "RequireUserGestureForVideoRateChange,OverrideUserGestureRequirementForMainContent");
+ run("largeVideo.setAttribute('controls','controls')");
+ run("largeVideo.setAttribute('autoplay','autoplay')");
+ run("largeVideo.setAttribute('id','large')");
+ largeVideo.addEventListener('canplaythrough', canPlayThrough, true);
+ largeVideo.addEventListener('playing', playing, true);
+ run("document.body.appendChild(largeVideo)");
+
+ consoleWrite("");
+ smallVideo.src = "" 'content/test');
+ largeVideo.src = "" 'content/test');
+ }
+
+ </script>
+ <style>
+ #large {
+ width: 270px;
+ height: 480px;
+ }
+ #small {
+ width: 400;
+ height: 240;
+ }
+ </style>
+ </head>
+ <body _onload_="go()">
+ </body>
+</html>
\ No newline at end of file
Modified: trunk/LayoutTests/media/video-main-content-deny-too-small.html (200777 => 200778)
--- trunk/LayoutTests/media/video-main-content-deny-too-small.html 2016-05-12 17:01:41 UTC (rev 200777)
+++ trunk/LayoutTests/media/video-main-content-deny-too-small.html 2016-05-12 17:53:38 UTC (rev 200778)
@@ -7,6 +7,7 @@
<script>
function go() {
video = document.createElement('video');
+ video.controls = ""
run('internals.setMediaElementRestrictions(video, "RequireUserGestureForVideoRateChange,OverrideUserGestureRequirementForMainContent")');
document.body.appendChild(video);
@@ -27,8 +28,8 @@
</script>
<style>
video {
- width: 200px;
- height: 100px;
+ width: 400px;
+ height: 299px;
}
</style>
</head>
Modified: trunk/Source/WebCore/ChangeLog (200777 => 200778)
--- trunk/Source/WebCore/ChangeLog 2016-05-12 17:01:41 UTC (rev 200777)
+++ trunk/Source/WebCore/ChangeLog 2016-05-12 17:53:38 UTC (rev 200778)
@@ -1,3 +1,20 @@
+2016-05-12 Eric Carlson <[email protected]>
+
+ Adjust "main content" video heuristic
+ https://bugs.webkit.org/show_bug.cgi?id=157532
+ <rdar://problem/25840861>
+
+ Reviewed by Darin Adler.
+
+ Test: media/video-main-content-autoplay.html, plus existing tests updated.
+
+ * html/MediaElementSession.cpp:
+ (WebCore::MediaElementSession::canControlControlsManager): Use isElementLargeEnoughForMainContent.
+ (WebCore::isMainContent): Ditto.
+ (WebCore::isElementLargeEnoughForMainContent): Check video area and aspect ratio.
+ (WebCore::MediaElementSession::mainContentCheckTimerFired): Call result.setToNonUserAgentShadowAncestor
+ so it doesn't hit test the video controls in the shadow DOM.
+
2016-05-12 Fujii Hironori <[email protected]>
[curl] ASSERTION FAILED: isLocalFile() || url == m_string in fast/dom/34176.html
Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (200777 => 200778)
--- trunk/Source/WebCore/html/MediaElementSession.cpp 2016-05-12 17:01:41 UTC (rev 200777)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp 2016-05-12 17:53:38 UTC (rev 200778)
@@ -54,11 +54,10 @@
namespace WebCore {
-static const int elementMainContentMinimumWidth = 400;
-static const int elementMainContentMinimumHeight = 300;
static const double elementMainContentCheckInterval = .250;
static bool isMainContent(const HTMLMediaElement&);
+static bool isElementLargeEnoughForMainContent(const HTMLMediaElement&);
#if !LOG_DISABLED
static String restrictionName(MediaElementSession::BehaviorRestrictions restriction)
@@ -224,8 +223,8 @@
if (!renderer)
return false;
- if (element.hasVideo() && renderer->clientWidth() >= elementMainContentMinimumWidth && renderer->clientHeight() >= elementMainContentMinimumHeight)
- return true;
+ if (isElementLargeEnoughForMainContent(element))
+ return true;
if (ScriptController::processingUserGestureForMedia())
return true;
@@ -506,8 +505,7 @@
if (!renderer)
return false;
- if (renderer->clientWidth() < elementMainContentMinimumWidth
- || renderer->clientHeight() < elementMainContentMinimumHeight)
+ if (!isElementLargeEnoughForMainContent(element))
return false;
// Elements which are hidden by style, or have been scrolled out of view, cannot be main content.
@@ -539,6 +537,7 @@
// Elements which are obscured by other elements cannot be main content.
mainRenderView.hitTest(request, result);
+ result.setToNonUserAgentShadowAncestor();
Element* hitElement = result.innerElement();
if (hitElement != &element)
return false;
@@ -546,6 +545,24 @@
return true;
}
+static bool isElementLargeEnoughForMainContent(const HTMLMediaElement& element)
+{
+ static const double elementMainContentAreaMinimum = 400 * 300;
+ static const double maximumAspectRatio = 1.8; // Slightly larger than 16:9.
+ static const double minimumAspectRatio = .5; // Slightly smaller than 16:9.
+
+ // Elements which have not yet been laid out, or which are not yet in the DOM, cannot be main content.
+ RenderBox* renderer = downcast<RenderBox>(element.renderer());
+ if (!renderer)
+ return false;
+
+ double width = renderer->clientWidth();
+ double height = renderer->clientHeight();
+ double area = width * height;
+ double aspectRatio = width / height;
+ return area >= elementMainContentAreaMinimum && aspectRatio >= minimumAspectRatio && aspectRatio <= maximumAspectRatio;
+}
+
void MediaElementSession::mainContentCheckTimerFired()
{
if (!hasBehaviorRestriction(OverrideUserGestureRequirementForMainContent))