Title: [203928] trunk
Revision
203928
Author
wenson_hs...@apple.com
Date
2016-07-29 17:11:27 -0700 (Fri, 29 Jul 2016)

Log Message

Media controls are not displayed for some autoplaying videos at certain browser dimensions
https://bugs.webkit.org/show_bug.cgi?id=160360
<rdar://problem/27179484>

Reviewed by Myles C. Maxfield.

Source/WebCore:

Previously, if a video's aspect ratio fell outside of the range [0.5, 1.8], we would
not consider it main content and would subsequently not show media controls for it.
This meant that on many websites that scale video dimensions to match the mainframe,
if the mainframe is too wide (e.g. full bounds on a widescreen display) we would not
consider the video to be main content. To fix this, we only consider aspect ratio to
be a requirement if the video does not already take up most of the space in the
mainframe.

Covered by two new TestWebKitAPI unit tests.

* html/MediaElementSession.cpp:
(WebCore::isElementLargeRelativeToMainFrame):
(WebCore::isElementLargeEnoughForMainContent):

Tools:

Adds two tests verifying that videos may be considered main content as long as they
are large enough and cover a majority of the mainframe's viewport.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2Cocoa/full-size-autoplaying-video-with-audio.html: Added.
* TestWebKitAPI/Tests/WebKit2Cocoa/skinny-autoplaying-video-with-audio.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (203927 => 203928)


--- trunk/Source/WebCore/ChangeLog	2016-07-30 00:07:37 UTC (rev 203927)
+++ trunk/Source/WebCore/ChangeLog	2016-07-30 00:11:27 UTC (rev 203928)
@@ -1,3 +1,25 @@
+2016-07-29  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Media controls are not displayed for some autoplaying videos at certain browser dimensions
+        https://bugs.webkit.org/show_bug.cgi?id=160360
+        <rdar://problem/27179484>
+
+        Reviewed by Myles C. Maxfield.
+
+        Previously, if a video's aspect ratio fell outside of the range [0.5, 1.8], we would
+        not consider it main content and would subsequently not show media controls for it.
+        This meant that on many websites that scale video dimensions to match the mainframe,
+        if the mainframe is too wide (e.g. full bounds on a widescreen display) we would not
+        consider the video to be main content. To fix this, we only consider aspect ratio to
+        be a requirement if the video does not already take up most of the space in the
+        mainframe.
+
+        Covered by two new TestWebKitAPI unit tests.
+
+        * html/MediaElementSession.cpp:
+        (WebCore::isElementLargeRelativeToMainFrame):
+        (WebCore::isElementLargeEnoughForMainContent):
+
 2016-07-29  Zalan Bujtas  <za...@apple.com>
 
         Do not set negative rate on AVSampleBufferRenderSynchronizer.

Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (203927 => 203928)


--- trunk/Source/WebCore/html/MediaElementSession.cpp	2016-07-30 00:07:37 UTC (rev 203927)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp	2016-07-30 00:11:27 UTC (rev 203928)
@@ -599,11 +599,32 @@
     return true;
 }
 
+static bool isElementLargeRelativeToMainFrame(const HTMLMediaElement& element)
+{
+    static const double minimumPercentageOfMainFrameAreaForMainContent = 0.9;
+    auto* renderer = element.renderer();
+    if (!renderer)
+        return false;
+
+    auto* documentFrame = element.document().frame();
+    if (!documentFrame)
+        return false;
+
+    if (!documentFrame->mainFrame().view())
+        return false;
+
+    auto& mainFrameView = *documentFrame->mainFrame().view();
+    auto maxVisibleClientWidth = std::min(renderer->clientWidth().toInt(), mainFrameView.visibleWidth());
+    auto maxVisibleClientHeight = std::min(renderer->clientHeight().toInt(), mainFrameView.visibleHeight());
+
+    return maxVisibleClientWidth * maxVisibleClientHeight > minimumPercentageOfMainFrameAreaForMainContent * mainFrameView.visibleWidth() * mainFrameView.visibleHeight();
+}
+
 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.
+    static const double minimumAspectRatio = .5; // Slightly smaller than 9:16.
 
     // Elements which have not yet been laid out, or which are not yet in the DOM, cannot be main content.
     auto* renderer = element.renderer();
@@ -614,7 +635,14 @@
     double height = renderer->clientHeight();
     double area = width * height;
     double aspectRatio = width / height;
-    return area >= elementMainContentAreaMinimum && aspectRatio >= minimumAspectRatio && aspectRatio <= maximumAspectRatio;
+
+    if (area < elementMainContentAreaMinimum)
+        return false;
+
+    if (aspectRatio >= minimumAspectRatio && aspectRatio <= maximumAspectRatio)
+        return true;
+
+    return isElementLargeRelativeToMainFrame(element);
 }
 
 void MediaElementSession::mainContentCheckTimerFired()

Modified: trunk/Tools/ChangeLog (203927 => 203928)


--- trunk/Tools/ChangeLog	2016-07-30 00:07:37 UTC (rev 203927)
+++ trunk/Tools/ChangeLog	2016-07-30 00:11:27 UTC (rev 203928)
@@ -1,3 +1,20 @@
+2016-07-29  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Media controls are not displayed for some autoplaying videos at certain browser dimensions
+        https://bugs.webkit.org/show_bug.cgi?id=160360
+        <rdar://problem/27179484>
+
+        Reviewed by Myles C. Maxfield.
+
+        Adds two tests verifying that videos may be considered main content as long as they
+        are large enough and cover a majority of the mainframe's viewport.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKit2Cocoa/full-size-autoplaying-video-with-audio.html: Added.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/skinny-autoplaying-video-with-audio.html: Added.
+
 2016-07-29  Mark Lam  <mark....@apple.com>
 
         Gardening: removed unused variable.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (203927 => 203928)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-07-30 00:07:37 UTC (rev 203927)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-07-30 00:11:27 UTC (rev 203928)
@@ -435,6 +435,8 @@
 		CEBABD491B71687C0051210A /* should-open-external-schemes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEBABD481B71687C0051210A /* should-open-external-schemes.html */; };
 		E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */; };
 		E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */; };
+		F4F405BC1D4C0D1C007A9707 /* full-size-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */; };
+		F4F405BD1D4C0D1C007A9707 /* skinny-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */; };
 		F660AA1115A5F631003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */; };
 		F660AA1515A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA1415A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp */; };
 		F6B7BE9517469212008A3445 /* DidAssociateFormControls_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6B7BE92174691EF008A3445 /* DidAssociateFormControls_Bundle.cpp */; };
@@ -504,6 +506,8 @@
 			dstPath = TestWebKitAPI.resources;
 			dstSubfolderSpec = 7;
 			files = (
+				F4F405BC1D4C0D1C007A9707 /* full-size-autoplaying-video-with-audio.html in Copy Resources */,
+				F4F405BD1D4C0D1C007A9707 /* skinny-autoplaying-video-with-audio.html in Copy Resources */,
 				515BE16F1D428BB100DD7C68 /* StoreBlobToBeDeleted.html in Copy Resources */,
 				2E1DFDF11D42E1E400714A00 /* large-video-seek-to-beginning-and-play-after-ending.html in Copy Resources */,
 				2E1B7B021D41B1B9007558B4 /* large-video-hides-controls-after-seek-to-end.html in Copy Resources */,
@@ -1083,6 +1087,8 @@
 		E4A757D3178AEA5B00B5D7A4 /* Deque.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Deque.cpp; sourceTree = "<group>"; };
 		E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoop.cpp; sourceTree = "<group>"; };
 		F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
+		F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "full-size-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
+		F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "skinny-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
 		F660AA0C15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback.cpp; sourceTree = "<group>"; };
 		F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback_Bundle.cpp; sourceTree = "<group>"; };
 		F660AA1215A619C8003A1243 /* InjectedBundleInitializationUserDataCallbackWins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleInitializationUserDataCallbackWins.cpp; sourceTree = "<group>"; };
@@ -1356,6 +1362,8 @@
 		A16F66B81C40E9E100BD4D24 /* Resources */ = {
 			isa = PBXGroup;
 			children = (
+				F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */,
+				F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */,
 				2E1DFDF01D42E14400714A00 /* large-video-seek-to-beginning-and-play-after-ending.html */,
 				2E1B7B011D41B1B3007558B4 /* large-video-hides-controls-after-seek-to-end.html */,
 				2E1DFDEE1D42A6EB00714A00 /* large-videos-with-audio-autoplay.html */,

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm (203927 => 203928)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm	2016-07-30 00:07:37 UTC (rev 203927)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm	2016-07-30 00:11:27 UTC (rev 203928)
@@ -415,6 +415,44 @@
     EXPECT_TRUE([webView _hasActiveVideoForControlsManager]);
 }
 
+TEST(VideoControlsManager, VideoControlsManagerLongSkinnyVideoInWideMainFrame)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 1600, 800) configuration:configuration.get()]);
+    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
+    [[window contentView] addSubview:webView.get()];
+
+    RetainPtr<MediaPlaybackMessageHandler> handler = adoptNS([[MediaPlaybackMessageHandler alloc] initWithWKWebView:webView.get() finalMessageString:@"playing"]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"playingHandler"];
+    [handler setExpectedToHaveControlsManager:NO];
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"skinny-autoplaying-video-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&testedControlsManagerAfterPlaying);
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
+}
+
+TEST(VideoControlsManager, VideoControlsManagerFullSizeVideoInWideMainFrame)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 1600, 800) configuration:configuration.get()]);
+    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
+    [[window contentView] addSubview:webView.get()];
+
+    RetainPtr<MediaPlaybackMessageHandler> handler = adoptNS([[MediaPlaybackMessageHandler alloc] initWithWKWebView:webView.get() finalMessageString:@"playing"]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"playingHandler"];
+    [handler setExpectedToHaveControlsManager:YES];
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"full-size-autoplaying-video-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&testedControlsManagerAfterPlaying);
+    TestWebKitAPI::Util::run(&receivedScriptMessage);
+}
+
 } // namespace TestWebKitAPI
 
 #endif // WK_API_ENABLED && PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/full-size-autoplaying-video-with-audio.html (0 => 203928)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/full-size-autoplaying-video-with-audio.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/full-size-autoplaying-video-with-audio.html	2016-07-30 00:11:27 UTC (rev 203928)
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <style>
+        video {
+            width: 100vw;
+            height: 100vh;
+        }
+    </style>
+    <script>
+    function finishTest() {
+        setTimeout(function() {
+            try {
+                window.webkit.messageHandlers.playingHandler.postMessage("playing");
+            } catch(e) { }
+        }, 0);
+    }
+   </script>
+</head>
+<body>
+    <video autoplay src="" webkit-playsinline _onplaying_=finishTest()></video>
+</body>
+</html>

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/skinny-autoplaying-video-with-audio.html (0 => 203928)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/skinny-autoplaying-video-with-audio.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/skinny-autoplaying-video-with-audio.html	2016-07-30 00:11:27 UTC (rev 203928)
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <style>
+        video {
+            width: 300vw;
+            height: 40vh;
+        }
+    </style>
+    <script>
+    function finishTest() {
+        setTimeout(function() {
+            try {
+                window.webkit.messageHandlers.playingHandler.postMessage("playing");
+            } catch(e) { }
+        }, 0);
+    }
+   </script>
+</head>
+<body>
+    <video autoplay src="" webkit-playsinline _onplaying_=finishTest()></video>
+</body>
+</html>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to