Skip to content

Commit

Permalink
Videos disappear when switching from landscape to portrait on cnn.com
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259666
rdar://112416568

Reviewed by Eric Carlson.

On CNN.com, the JS listens for the window `resize` event instead of the orientation change
event and queries `screen.orientation.angle` when this event is fired to determine if we're
in landscape or portrait.

The issue is that Safari has very special handling to deal with rotation (_beginAnimatedResizeWithUpdates
& _endAnimatedResize), where it temporarily overrides the screen orientation. While `window.orientation`
was properly handling this (making sure `window.orientation` stays consistent with the viewport size),
`window.screen.orientation.angle` wasn't. As a result, we'd fire a resize event for the rotation but
the value returned by `window.screen.orientation.angle` would be inconsistent, causing CNN.com to make
the wrong decision and not removing a CSS class when it should have. This was the root cause of the bug.

To address the issue, I am updating `window.screen.orientation` to get its orientation from the same
place as `window.orientation`, instead of the ScreenOrientationProvider, which didn't properly deal
with Safari animated resizing. This actually simplifies the code a lot and gets rid of the bug.

* LayoutTests/fast/screen-orientation/orientation-in-resize-event-expected.txt: Added.
* LayoutTests/fast/screen-orientation/orientation-in-resize-event.html: Added.
* LayoutTests/platform/glib/TestExpectations:
* LayoutTests/platform/mac/TestExpectations:
* Source/WebCore/Headers.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/SourcesCocoa.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/platform/ScreenOrientationProvider.cpp: Removed.
* Source/WebCore/platform/ScreenOrientationProvider.h: Removed.
* Source/WebCore/platform/ios/ScreenOrientationProviderIOS.mm: Removed.
* Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::setCocoaView):
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didAttachToRunningProcess):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/WebScreenOrientationManagerProxy.cpp:
(WebKit::toString):
(WebKit::WebScreenOrientationManagerProxy::WebScreenOrientationManagerProxy):
(WebKit::WebScreenOrientationManagerProxy::~WebScreenOrientationManagerProxy):
(WebKit::WebScreenOrientationManagerProxy::currentOrientation):
(WebKit::WebScreenOrientationManagerProxy::setCurrentOrientation):
(WebKit::WebScreenOrientationManagerProxy::lock):
(WebKit::WebScreenOrientationManagerProxy::setShouldSendChangeNotification):
(WebKit::WebScreenOrientationManagerProxy::screenOrientationDidChange): Deleted.
(WebKit::WebScreenOrientationManagerProxy::platformInitialize): Deleted.
(WebKit::WebScreenOrientationManagerProxy::platformDestroy): Deleted.
* Source/WebKit/UIProcess/WebScreenOrientationManagerProxy.h:
* Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::toScreenOrientationType):
(WebKit::WebPageProxy::setDeviceOrientation):
* Source/WebKit/UIProcess/ios/WebScreenOrientationManagerProxyIOS.mm:
(WebKit::WebScreenOrientationManagerProxy::platformInitialize): Deleted.
(WebKit::WebScreenOrientationManagerProxy::platformDestroy): Deleted.
(WebKit::WebScreenOrientationManagerProxy::setWindow): Deleted.
(WebKit::WebScreenOrientationManagerProxy::webViewDidMoveToWindow): Deleted.

Canonical link: https://commits.webkit.org/266531@main
  • Loading branch information
cdumez committed Aug 3, 2023
1 parent 9798e76 commit 9f56887
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 388 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Checks that screen.orientation.type returns an up-to-date value in the 'resize' event listener.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS wasPortrait is true
Simulating rotation to landscape
* in resize event listener
PASS isLandscape is true
PASS successfullyParsed is true

TEST COMPLETE

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
<html>
<head>
<meta name="viewport" content="initial-scale=1.0">
<script src="../../resources/js-test.js"></script
</head>
<body>
<script>
description("Checks that screen.orientation.type returns an up-to-date value in the 'resize' event listener.");
jsTestIsAsync = true;

function getRotationUIScript()
{
return `
(function() {
uiController.simulateRotationLikeSafari('landscape-right', function() {
uiController.doAfterVisibleContentRectUpdate(function () {
uiController.uiScriptComplete();
})
});
})();`
}

let wasPortrait = screen.orientation.type.startsWith("portrait");
shouldBeTrue("wasPortrait");
onload = () => {
debug("Simulating rotation to landscape");
testRunner.runUIScript(getRotationUIScript(), function(result) { });
};

onresize = (e) => {
let isLandscapeSize = window.innerWidth > window.innerHeight;
if (!isLandscapeSize)
return;

debug("* in resize event listener");
isLandscape = screen.orientation.type.startsWith("landscape");
shouldBeTrue("isLandscape");
finishJSTest();
};
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions LayoutTests/platform/glib/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ media/video-controller-currentTime-rate.html [ Pass ]
webaudio/codec-tests/aac/vbr-128kbps-44khz.html [ Pass ]
webaudio/codec-tests/mp3/128kbps-44khz.html [ Pass ]

# uiController.simulateRotationLikeSafari() is not implemented on glib ports.
fast/screen-orientation/orientation-in-resize-event.html [ Skip ]

# Pass since r273206
imported/w3c/web-platform-tests/css/css-sizing/range-percent-intrinsic-size-2.html
imported/w3c/web-platform-tests/css/css-sizing/range-percent-intrinsic-size-2a.html
Expand Down
3 changes: 3 additions & 0 deletions LayoutTests/platform/mac/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ accessibility/aria-switch-sends-notification.html
accessibility/combo-box-collapsed-selection-changed.html
accessibility/multiselect-list-reports-active-option.html

# uiController.simulateRotationLikeSafari() is not implemented on macOS.
fast/screen-orientation/orientation-in-resize-event.html [ Skip ]

# Need to implement AccessibilityUIElement::clearSelectedChildren()
accessibility/aria-listbox-clear-selection-crash.html
accessibility/listbox-clear-selection.html
Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,6 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/RemoteCommandListener.h
platform/RuntimeApplicationChecks.h
platform/ScreenOrientationManager.h
platform/ScreenOrientationProvider.h
platform/ScreenProperties.h
platform/ScriptExecutionContextIdentifier.h
platform/ScrollAlignment.h
Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/Sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,6 @@ platform/RemoteCommandListener.cpp
platform/RunLoopObserver.cpp
platform/RuntimeApplicationChecks.cpp
platform/ScreenOrientationManager.cpp
platform/ScreenOrientationProvider.cpp
platform/ScrollAlignment.cpp
platform/ScrollAnimation.cpp
platform/ScrollAnimationKeyboard.cpp
Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/SourcesCocoa.txt
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ platform/ios/PlatformScreenIOS.mm
platform/ios/PlaybackSessionInterfaceAVKit.mm @no-unify
platform/ios/PreviewConverterIOS.mm
platform/ios/QuickLook.mm
platform/ios/ScreenOrientationProviderIOS.mm
platform/ios/ScrollAnimatorIOS.mm
platform/ios/ScrollViewIOS.mm
platform/ios/ScrollbarThemeIOS.mm
Expand Down
8 changes: 0 additions & 8 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,6 @@
46EF142D1F97B7D800C2A524 /* ServiceWorkerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 46EF14241F97B7BA00C2A524 /* ServiceWorkerClient.h */; };
46EFAF121E5FB9F100E7F34B /* LowPowerModeNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46EFAF101E5FB9E100E7F34B /* LowPowerModeNotifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
46F02A1A23737F8300106A64 /* EventLoop.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B0ABCA123679AB300B45085 /* EventLoop.h */; settings = {ATTRIBUTES = (Private, ); }; };
46F9E4DA28EB874200A84782 /* ScreenOrientationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 46F9E4D928EB873900A84782 /* ScreenOrientationProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
46FC422A29084F4B00773DD5 /* MainThreadStylePropertyMapReadOnly.h in Headers */ = {isa = PBXBuildFile; fileRef = 46FC422929084F4400773DD5 /* MainThreadStylePropertyMapReadOnly.h */; };
46FCB6181A70820E00C5A21E /* DiagnosticLoggingKeys.h in Headers */ = {isa = PBXBuildFile; fileRef = CD37B37515C1A7E1006DC898 /* DiagnosticLoggingKeys.h */; settings = {ATTRIBUTES = (Private, ); }; };
46FE73D22968E52000B8064C /* GameControllerHapticEngines.h in Headers */ = {isa = PBXBuildFile; fileRef = 46FE73D02968E51F00B8064C /* GameControllerHapticEngines.h */; };
Expand Down Expand Up @@ -10538,9 +10537,6 @@
46EFAF0F1E5FB9E100E7F34B /* LowPowerModeNotifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LowPowerModeNotifier.cpp; sourceTree = "<group>"; };
46EFAF101E5FB9E100E7F34B /* LowPowerModeNotifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LowPowerModeNotifier.h; sourceTree = "<group>"; };
46F91BC91FCDD0FE001599C3 /* JSWorkerNavigatorCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWorkerNavigatorCustom.cpp; sourceTree = "<group>"; };
46F9E4D828EB873900A84782 /* ScreenOrientationProvider.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ScreenOrientationProvider.cpp; sourceTree = "<group>"; };
46F9E4D928EB873900A84782 /* ScreenOrientationProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScreenOrientationProvider.h; sourceTree = "<group>"; };
46F9E4DB28EB875400A84782 /* ScreenOrientationProviderIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScreenOrientationProviderIOS.mm; sourceTree = "<group>"; };
46FC422829084F4400773DD5 /* MainThreadStylePropertyMapReadOnly.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MainThreadStylePropertyMapReadOnly.cpp; sourceTree = "<group>"; };
46FC422929084F4400773DD5 /* MainThreadStylePropertyMapReadOnly.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MainThreadStylePropertyMapReadOnly.h; sourceTree = "<group>"; };
46FE73D02968E51F00B8064C /* GameControllerHapticEngines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameControllerHapticEngines.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -29486,7 +29482,6 @@
A1C150771E3F2B3E0032C98C /* PreviewConverterIOS.mm */,
A15E31F11E0CB0AA004B371C /* QuickLook.h */,
A15E31F21E0CB0AA004B371C /* QuickLook.mm */,
46F9E4DB28EB875400A84782 /* ScreenOrientationProviderIOS.mm */,
0F17747E1378B771009DA76A /* ScrollAnimatorIOS.h */,
0F17747F1378B772009DA76A /* ScrollAnimatorIOS.mm */,
44C991850F3D1EBE00586670 /* ScrollbarThemeIOS.h */,
Expand Down Expand Up @@ -33027,8 +33022,6 @@
293EAE1E1356B2FE0067ACF9 /* RuntimeApplicationChecks.h */,
4644219928F5181900FE48C6 /* ScreenOrientationManager.cpp */,
46DC53BE28EB3D64005376B0 /* ScreenOrientationManager.h */,
46F9E4D828EB873900A84782 /* ScreenOrientationProvider.cpp */,
46F9E4D928EB873900A84782 /* ScreenOrientationProvider.h */,
C1E1D235203DF15400584665 /* ScreenProperties.h */,
411223B8260244FE00B0A0B6 /* ScriptExecutionContextIdentifier.h */,
BC8AE34C12EA096A00EB3AE6 /* ScrollableArea.cpp */,
Expand Down Expand Up @@ -40547,7 +40540,6 @@
46AD2CD028E4FD5100040F10 /* ScreenOrientation.h in Headers */,
4625239E28E5034B00082F84 /* ScreenOrientationLockType.h in Headers */,
46DC53BF28EB3D65005376B0 /* ScreenOrientationManager.h in Headers */,
46F9E4DA28EB874200A84782 /* ScreenOrientationProvider.h in Headers */,
4625239F28E5034B00082F84 /* ScreenOrientationType.h in Headers */,
C1E1D236203DF15400584665 /* ScreenProperties.h in Headers */,
A84D82C111D3474800972990 /* ScriptableDocumentParser.h in Headers */,
Expand Down
99 changes: 0 additions & 99 deletions Source/WebCore/platform/ScreenOrientationProvider.cpp

This file was deleted.

80 changes: 0 additions & 80 deletions Source/WebCore/platform/ScreenOrientationProvider.h

This file was deleted.

Loading

0 comments on commit 9f56887

Please sign in to comment.