Changeset 203928 in webkit
- Timestamp:
- Jul 29, 2016 5:11:27 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r203924 r203928 1 2016-07-29 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Media controls are not displayed for some autoplaying videos at certain browser dimensions 4 https://bugs.webkit.org/show_bug.cgi?id=160360 5 <rdar://problem/27179484> 6 7 Reviewed by Myles C. Maxfield. 8 9 Previously, if a video's aspect ratio fell outside of the range [0.5, 1.8], we would 10 not consider it main content and would subsequently not show media controls for it. 11 This meant that on many websites that scale video dimensions to match the mainframe, 12 if the mainframe is too wide (e.g. full bounds on a widescreen display) we would not 13 consider the video to be main content. To fix this, we only consider aspect ratio to 14 be a requirement if the video does not already take up most of the space in the 15 mainframe. 16 17 Covered by two new TestWebKitAPI unit tests. 18 19 * html/MediaElementSession.cpp: 20 (WebCore::isElementLargeRelativeToMainFrame): 21 (WebCore::isElementLargeEnoughForMainContent): 22 1 23 2016-07-29 Zalan Bujtas <zalan@apple.com> 2 24 -
trunk/Source/WebCore/html/MediaElementSession.cpp
r203765 r203928 600 600 } 601 601 602 static bool isElementLargeRelativeToMainFrame(const HTMLMediaElement& element) 603 { 604 static const double minimumPercentageOfMainFrameAreaForMainContent = 0.9; 605 auto* renderer = element.renderer(); 606 if (!renderer) 607 return false; 608 609 auto* documentFrame = element.document().frame(); 610 if (!documentFrame) 611 return false; 612 613 if (!documentFrame->mainFrame().view()) 614 return false; 615 616 auto& mainFrameView = *documentFrame->mainFrame().view(); 617 auto maxVisibleClientWidth = std::min(renderer->clientWidth().toInt(), mainFrameView.visibleWidth()); 618 auto maxVisibleClientHeight = std::min(renderer->clientHeight().toInt(), mainFrameView.visibleHeight()); 619 620 return maxVisibleClientWidth * maxVisibleClientHeight > minimumPercentageOfMainFrameAreaForMainContent * mainFrameView.visibleWidth() * mainFrameView.visibleHeight(); 621 } 622 602 623 static bool isElementLargeEnoughForMainContent(const HTMLMediaElement& element) 603 624 { 604 625 static const double elementMainContentAreaMinimum = 400 * 300; 605 626 static const double maximumAspectRatio = 1.8; // Slightly larger than 16:9. 606 static const double minimumAspectRatio = .5; // Slightly smaller than 16:9.627 static const double minimumAspectRatio = .5; // Slightly smaller than 9:16. 607 628 608 629 // Elements which have not yet been laid out, or which are not yet in the DOM, cannot be main content. … … 615 636 double area = width * height; 616 637 double aspectRatio = width / height; 617 return area >= elementMainContentAreaMinimum && aspectRatio >= minimumAspectRatio && aspectRatio <= maximumAspectRatio; 638 639 if (area < elementMainContentAreaMinimum) 640 return false; 641 642 if (aspectRatio >= minimumAspectRatio && aspectRatio <= maximumAspectRatio) 643 return true; 644 645 return isElementLargeRelativeToMainFrame(element); 618 646 } 619 647 -
trunk/Tools/ChangeLog
r203915 r203928 1 2016-07-29 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Media controls are not displayed for some autoplaying videos at certain browser dimensions 4 https://bugs.webkit.org/show_bug.cgi?id=160360 5 <rdar://problem/27179484> 6 7 Reviewed by Myles C. Maxfield. 8 9 Adds two tests verifying that videos may be considered main content as long as they 10 are large enough and cover a majority of the mainframe's viewport. 11 12 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 13 * TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm: 14 (TestWebKitAPI::TEST): 15 * TestWebKitAPI/Tests/WebKit2Cocoa/full-size-autoplaying-video-with-audio.html: Added. 16 * TestWebKitAPI/Tests/WebKit2Cocoa/skinny-autoplaying-video-with-audio.html: Added. 17 1 18 2016-07-29 Mark Lam <mark.lam@apple.com> 2 19 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r203842 r203928 436 436 E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */; }; 437 437 E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */; }; 438 F4F405BC1D4C0D1C007A9707 /* full-size-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */; }; 439 F4F405BD1D4C0D1C007A9707 /* skinny-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */; }; 438 440 F660AA1115A5F631003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */; }; 439 441 F660AA1515A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA1415A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp */; }; … … 505 507 dstSubfolderSpec = 7; 506 508 files = ( 509 F4F405BC1D4C0D1C007A9707 /* full-size-autoplaying-video-with-audio.html in Copy Resources */, 510 F4F405BD1D4C0D1C007A9707 /* skinny-autoplaying-video-with-audio.html in Copy Resources */, 507 511 515BE16F1D428BB100DD7C68 /* StoreBlobToBeDeleted.html in Copy Resources */, 508 512 2E1DFDF11D42E1E400714A00 /* large-video-seek-to-beginning-and-play-after-ending.html in Copy Resources */, … … 1084 1088 E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoop.cpp; sourceTree = "<group>"; }; 1085 1089 F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; }; 1090 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>"; }; 1091 F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "skinny-autoplaying-video-with-audio.html"; sourceTree = "<group>"; }; 1086 1092 F660AA0C15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback.cpp; sourceTree = "<group>"; }; 1087 1093 F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback_Bundle.cpp; sourceTree = "<group>"; }; … … 1357 1363 isa = PBXGroup; 1358 1364 children = ( 1365 F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */, 1366 F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */, 1359 1367 2E1DFDF01D42E14400714A00 /* large-video-seek-to-beginning-and-play-after-ending.html */, 1360 1368 2E1B7B011D41B1B3007558B4 /* large-video-hides-controls-after-seek-to-end.html */, -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm
r203905 r203928 416 416 } 417 417 418 TEST(VideoControlsManager, VideoControlsManagerLongSkinnyVideoInWideMainFrame) 419 { 420 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 421 configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone; 422 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 1600, 800) configuration:configuration.get()]); 423 RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]); 424 [[window contentView] addSubview:webView.get()]; 425 426 RetainPtr<MediaPlaybackMessageHandler> handler = adoptNS([[MediaPlaybackMessageHandler alloc] initWithWKWebView:webView.get() finalMessageString:@"playing"]); 427 [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"playingHandler"]; 428 [handler setExpectedToHaveControlsManager:NO]; 429 430 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"skinny-autoplaying-video-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 431 [webView loadRequest:request]; 432 433 TestWebKitAPI::Util::run(&testedControlsManagerAfterPlaying); 434 TestWebKitAPI::Util::run(&receivedScriptMessage); 435 } 436 437 TEST(VideoControlsManager, VideoControlsManagerFullSizeVideoInWideMainFrame) 438 { 439 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 440 configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone; 441 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 1600, 800) configuration:configuration.get()]); 442 RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]); 443 [[window contentView] addSubview:webView.get()]; 444 445 RetainPtr<MediaPlaybackMessageHandler> handler = adoptNS([[MediaPlaybackMessageHandler alloc] initWithWKWebView:webView.get() finalMessageString:@"playing"]); 446 [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"playingHandler"]; 447 [handler setExpectedToHaveControlsManager:YES]; 448 449 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"full-size-autoplaying-video-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 450 [webView loadRequest:request]; 451 452 TestWebKitAPI::Util::run(&testedControlsManagerAfterPlaying); 453 TestWebKitAPI::Util::run(&receivedScriptMessage); 454 } 455 418 456 } // namespace TestWebKitAPI 419 457
Note: See TracChangeset
for help on using the changeset viewer.