Skip to content

Commit

Permalink
[iOS][WK2] Add initial implementation for the Screen Orientation API
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=245999

Reviewed by Wenson Hsieh.

Add initial implementation for the Screen Orientation API on WebKit2 / iOS:
- https://w3c.github.io/screen-orientation/#dom-screenorientation-type
- https://w3c.github.io/screen-orientation/#angle-attribute-get-orientation-angle
- https://w3c.github.io/screen-orientation/#Screen-orientation-change

I tested manually on device that the API is working as intended.

The feature is still behind an experimental feature flag, off by defaut.

Things that are missing and will be implemented in a follow-up:
- Test harness changes for automated testing
- Pre-conditions for locking / unlocking (e.g. user gesture, full screen)

* Source/WebCore/Headers.cmake:
* Source/WebCore/PAL/pal/ios/UIKitSoftLink.h:
* Source/WebCore/PAL/pal/ios/UIKitSoftLink.mm:
* Source/WebCore/Sources.txt:
* Source/WebCore/SourcesCocoa.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/dom/Exception.h:
(WebCore::Exception::encode const):
(WebCore::Exception::decode):
* Source/WebCore/page/Page.cpp:
(WebCore::Page::Page):
(WebCore::Page::screenOrientationManager const):
* Source/WebCore/page/Page.h:
* Source/WebCore/page/PageConfiguration.cpp:
* Source/WebCore/page/PageConfiguration.h:
* Source/WebCore/page/ScreenOrientation.cpp:
(WebCore::ScreenOrientation::ScreenOrientation):
(WebCore::ScreenOrientation::~ScreenOrientation):
(WebCore::ScreenOrientation::manager const):
(WebCore::ScreenOrientation::lock):
(WebCore::ScreenOrientation::unlock):
(WebCore::ScreenOrientation::type const):
(WebCore::ScreenOrientation::angle const):
(WebCore::ScreenOrientation::visibilityStateChanged):
(WebCore::ScreenOrientation::shouldListenForChangeNotification const):
(WebCore::ScreenOrientation::screenOrientationDidChange):
(WebCore::ScreenOrientation::suspend):
(WebCore::ScreenOrientation::resume):
(WebCore::ScreenOrientation::stop):
* Source/WebCore/page/ScreenOrientation.h:
* Source/WebCore/page/ScreenOrientationLockType.h:
* Source/WebCore/page/ScreenOrientationType.h:
* Source/WebCore/platform/ScreenOrientationManager.h: Copied from Source/WebCore/page/ScreenOrientationLockType.h.
(WebCore::ScreenOrientationManager::~ScreenOrientationManager):
(WebCore::ScreenOrientationManager::Observer::~Observer):
* Source/WebCore/platform/ScreenOrientationProvider.cpp: Added.
(WebCore::globalProvider):
(WebCore::ScreenOrientationProvider::getOrCreate):
(WebCore::ScreenOrientationProvider::~ScreenOrientationProvider):
(WebCore::ScreenOrientationProvider::addObserver):
(WebCore::ScreenOrientationProvider::removeObserver):
(WebCore::ScreenOrientationProvider::screenOrientationDidChange):
(WebCore::ScreenOrientationProvider::currentOrientation):
(WebCore::ScreenOrientationProvider::platformCurrentOrientation):
(WebCore::ScreenOrientationProvider::platformStartListeningForChanges):
(WebCore::ScreenOrientationProvider::platformStopListeningForChanges):
(WebCore::ScreenOrientationProvider::platformDestroy):
* Source/WebCore/platform/ScreenOrientationProvider.h: Copied from Source/WebCore/page/ScreenOrientation.h.
(WebCore::ScreenOrientationProvider::Observer::~Observer):
* Source/WebCore/platform/ios/ScreenOrientationProviderIOS.mm: Added.
(currentOrientationFromCurrentUIDevice):
(-[WebScreenOrientationObserver initWithProvider:]):
(-[WebScreenOrientationObserver dealloc]):
(-[WebScreenOrientationObserver _screenOrientationDidChange]):
(WebCore::ScreenOrientationProvider::platformCurrentOrientation):
(WebCore::ScreenOrientationProvider::platformStartListeningForChanges):
(WebCore::ScreenOrientationProvider::platformStopListeningForChanges):
(WebCore::ScreenOrientationProvider::platformDestroy):
* Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProviderCocoa.cpp:
* Source/WebKit/CMakeLists.txt:
* Source/WebKit/DerivedSources-input.xcfilelist:
* Source/WebKit/DerivedSources-output.xcfilelist:
* Source/WebKit/DerivedSources.make:
* Source/WebKit/Sources.txt:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didAttachToRunningProcess):
(WebKit::WebPageProxy::resetState):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/WebScreenOrientationManagerProxy.cpp: Added.
(WebKit::WebScreenOrientationManagerProxy::WebScreenOrientationManagerProxy):
(WebKit::WebScreenOrientationManagerProxy::~WebScreenOrientationManagerProxy):
(WebKit::WebScreenOrientationManagerProxy::currentOrientation):
(WebKit::WebScreenOrientationManagerProxy::lock):
(WebKit::WebScreenOrientationManagerProxy::unlock):
(WebKit::WebScreenOrientationManagerProxy::screenOrientationDidChange):
(WebKit::WebScreenOrientationManagerProxy::setShouldSendChangeNotification):
* Source/WebKit/UIProcess/WebScreenOrientationManagerProxy.h: Copied from Source/WebCore/page/ScreenOrientation.h.
* Source/WebKit/UIProcess/WebScreenOrientationManagerProxy.messages.in: Copied from Source/WebCore/page/ScreenOrientationType.h.
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/WebCoreSupport/WebScreenOrientationManager.cpp: Added.
(WebKit::WebScreenOrientationManager::WebScreenOrientationManager):
(WebKit::WebScreenOrientationManager::~WebScreenOrientationManager):
(WebKit::WebScreenOrientationManager::currentOrientation):
(WebKit::WebScreenOrientationManager::orientationDidChange):
(WebKit::WebScreenOrientationManager::lock):
(WebKit::WebScreenOrientationManager::unlock):
(WebKit::WebScreenOrientationManager::addObserver):
(WebKit::WebScreenOrientationManager::removeObserver):
* Source/WebKit/WebProcess/WebCoreSupport/WebScreenOrientationManager.h: Copied from Source/WebCore/page/ScreenOrientationLockType.h.
* Source/WebKit/WebProcess/WebCoreSupport/WebScreenOrientationManager.messages.in: Copied from Source/WebCore/page/ScreenOrientationType.h.
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::m_appHighlightsVisible):
* Source/WebKit/WebProcess/WebPage/WebPage.h:

Canonical link: https://commits.webkit.org/255155@main
  • Loading branch information
cdumez committed Oct 5, 2022
1 parent 58c2188 commit c9b695e
Show file tree
Hide file tree
Showing 43 changed files with 1,172 additions and 19 deletions.
4 changes: 4 additions & 0 deletions Source/WebCore/Headers.cmake
Expand Up @@ -1224,6 +1224,8 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
page/RemoteDOMWindow.h
page/RemoteFrame.h
page/RenderingUpdateScheduler.h
page/ScreenOrientationLockType.h
page/ScreenOrientationType.h
page/ScrollBehavior.h
page/ScrollIntoViewOptions.h
page/ScrollLogicalPosition.h
Expand Down Expand Up @@ -1403,6 +1405,8 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/RemoteCommandListener.h
platform/RuntimeApplicationChecks.h
platform/SSLKeyGenerator.h
platform/ScreenOrientationManager.h
platform/ScreenOrientationProvider.h
platform/ScreenProperties.h
platform/ScriptExecutionContextIdentifier.h
platform/ScrollAlignment.h
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/PAL/pal/ios/UIKitSoftLink.h
Expand Up @@ -40,6 +40,7 @@ SOFT_LINK_CONSTANT_FOR_HEADER(PAL, UIKit, UIApplicationWillEnterForegroundNotifi
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, UIKit, UIApplicationDidBecomeActiveNotification, NSNotificationName)
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, UIKit, UIApplicationDidEnterBackgroundNotification, NSNotificationName)
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, UIKit, UIContentSizeCategoryDidChangeNotification, NSNotificationName)
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, UIKit, UIApplicationDidChangeStatusBarOrientationNotification, NSNotificationName)
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, UIKit, UIFontTextStyleCallout, UIFontTextStyle)
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, UIKit, UIPasteboardNameGeneral, UIPasteboardName)
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, UIKit, UITextEffectsBeneathStatusBarWindowLevel, UIWindowLevel)
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/PAL/pal/ios/UIKitSoftLink.mm
Expand Up @@ -40,6 +40,7 @@
SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, UIKit, UIApplicationDidBecomeActiveNotification, NSNotificationName)
SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, UIKit, UIApplicationDidEnterBackgroundNotification, NSNotificationName)
SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, UIKit, UIContentSizeCategoryDidChangeNotification, NSNotificationName)
SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, UIKit, UIApplicationDidChangeStatusBarOrientationNotification, NSNotificationName)
SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, UIKit, UIFontTextStyleCallout, UIFontTextStyle)
SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, UIKit, UIPasteboardNameGeneral, UIPasteboardName)
SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, UIKit, UITextEffectsBeneathStatusBarWindowLevel, UIWindowLevel)
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Sources.txt
Expand Up @@ -1964,6 +1964,7 @@ platform/ReferrerPolicy.cpp
platform/RemoteCommandListener.cpp
platform/RuntimeApplicationChecks.cpp
platform/SSLKeyGenerator.cpp
platform/ScreenOrientationProvider.cpp
platform/ScrollAlignment.cpp
platform/ScrollAnimation.cpp
platform/ScrollAnimationKinetic.cpp
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/SourcesCocoa.txt
Expand Up @@ -478,6 +478,7 @@ 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
16 changes: 14 additions & 2 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Expand Up @@ -1383,8 +1383,8 @@
460CBF361D4BCD0E0092E88E /* JSDOMWindowProperties.h in Headers */ = {isa = PBXBuildFile; fileRef = 460CBF341D4BCCFE0092E88E /* JSDOMWindowProperties.h */; };
460E3077222F4F03009A0606 /* DeviceOrientationOrMotionPermissionState.h in Headers */ = {isa = PBXBuildFile; fileRef = 465EDD9F222F4EC300B46E16 /* DeviceOrientationOrMotionPermissionState.h */; settings = {ATTRIBUTES = (Private, ); }; };
46218ACB1F72D64E00574FBE /* DOMHighResTimeStamp.h in Headers */ = {isa = PBXBuildFile; fileRef = 46E016AD1F72D61E00282B2C /* DOMHighResTimeStamp.h */; settings = {ATTRIBUTES = (Private, ); }; };
4625239E28E5034B00082F84 /* ScreenOrientationLockType.h in Headers */ = {isa = PBXBuildFile; fileRef = 4625239C28E5034A00082F84 /* ScreenOrientationLockType.h */; };
4625239F28E5034B00082F84 /* ScreenOrientationType.h in Headers */ = {isa = PBXBuildFile; fileRef = 4625239D28E5034B00082F84 /* ScreenOrientationType.h */; };
4625239E28E5034B00082F84 /* ScreenOrientationLockType.h in Headers */ = {isa = PBXBuildFile; fileRef = 4625239C28E5034A00082F84 /* ScreenOrientationLockType.h */; settings = {ATTRIBUTES = (Private, ); }; };
4625239F28E5034B00082F84 /* ScreenOrientationType.h in Headers */ = {isa = PBXBuildFile; fileRef = 4625239D28E5034B00082F84 /* ScreenOrientationType.h */; settings = {ATTRIBUTES = (Private, ); }; };
462553D428DD0FB400D48FCC /* WakeLockType.h in Headers */ = {isa = PBXBuildFile; fileRef = 462553D328DD0FB200D48FCC /* WakeLockType.h */; };
46273CAF260E59EF006FAA91 /* SWScriptStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 46273CAC260E59DF006FAA91 /* SWScriptStorage.h */; settings = {ATTRIBUTES = (Private, ); }; };
462C7F412756DBE400D083C8 /* WebLockIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 467802B22747118500DA9FB6 /* WebLockIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -1461,6 +1461,7 @@
46D0004026A0FEB300D1BF1E /* SubmitEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 46D0003E26A0FE6F00D1BF1E /* SubmitEvent.h */; };
46DA4A0227AB039300E375A8 /* TransferredMessagePort.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DA4A0027AB038D00E375A8 /* TransferredMessagePort.h */; settings = {ATTRIBUTES = (Private, ); }; };
46DBB6501AB8C96F00D9A813 /* PowerObserverMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DBB64E1AB8C96F00D9A813 /* PowerObserverMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
46DC53BF28EB3D65005376B0 /* ScreenOrientationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DC53BE28EB3D64005376B0 /* ScreenOrientationManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
46DD93D7269DE756001AFD88 /* BroadcastChannelIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DD93D5269DE74B001AFD88 /* BroadcastChannelIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
46DE9BB5269DF93E0024C5A6 /* BroadcastChannelRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DE9BB4269DF9320024C5A6 /* BroadcastChannelRegistry.h */; settings = {ATTRIBUTES = (Private, ); }; };
46DFF4981DC2603100B80B48 /* ShadowRootMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DFF4961DC2601300B80B48 /* ShadowRootMode.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand All @@ -1479,6 +1480,7 @@
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, ); }; };
46FCB6181A70820E00C5A21E /* DiagnosticLoggingKeys.h in Headers */ = {isa = PBXBuildFile; fileRef = CD37B37515C1A7E1006DC898 /* DiagnosticLoggingKeys.h */; settings = {ATTRIBUTES = (Private, ); }; };
46FEFBC826DD67A200B0C488 /* StructuredSerializeOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 46FEFBC626DD678200B0C488 /* StructuredSerializeOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
475C89A42650AC3C00F3B456 /* FormattingGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = 475C89A32650AC3B00F3B456 /* FormattingGeometry.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -9646,6 +9648,7 @@
46D0003F26A0FE7000D1BF1E /* SubmitEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SubmitEvent.idl; sourceTree = "<group>"; };
46DA4A0027AB038D00E375A8 /* TransferredMessagePort.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TransferredMessagePort.h; sourceTree = "<group>"; };
46DBB64E1AB8C96F00D9A813 /* PowerObserverMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PowerObserverMac.h; sourceTree = "<group>"; };
46DC53BE28EB3D64005376B0 /* ScreenOrientationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScreenOrientationManager.h; sourceTree = "<group>"; };
46DD93D5269DE74B001AFD88 /* BroadcastChannelIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BroadcastChannelIdentifier.h; sourceTree = "<group>"; };
46DE9BB4269DF9320024C5A6 /* BroadcastChannelRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BroadcastChannelRegistry.h; sourceTree = "<group>"; };
46DFF4961DC2601300B80B48 /* ShadowRootMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShadowRootMode.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9683,6 +9686,9 @@
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>"; };
46FEFBC626DD678200B0C488 /* StructuredSerializeOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StructuredSerializeOptions.h; sourceTree = "<group>"; };
46FEFBC726DD678300B0C488 /* StructuredSerializeOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = StructuredSerializeOptions.idl; sourceTree = "<group>"; };
475C89A32650AC3B00F3B456 /* FormattingGeometry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormattingGeometry.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -27546,6 +27552,7 @@
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 @@ -31006,6 +31013,9 @@
CDFC360418CA61C20026E56F /* RemoteCommandListener.h */,
A18F7A351ECA73640059E1E1 /* RuntimeApplicationChecks.cpp */,
293EAE1E1356B2FE0067ACF9 /* RuntimeApplicationChecks.h */,
46DC53BE28EB3D64005376B0 /* ScreenOrientationManager.h */,
46F9E4D828EB873900A84782 /* ScreenOrientationProvider.cpp */,
46F9E4D928EB873900A84782 /* ScreenOrientationProvider.h */,
C1E1D235203DF15400584665 /* ScreenProperties.h */,
411223B8260244FE00B0A0B6 /* ScriptExecutionContextIdentifier.h */,
BC8AE34C12EA096A00EB3AE6 /* ScrollableArea.cpp */,
Expand Down Expand Up @@ -38207,6 +38217,8 @@
073955BB27AB277F009A08D2 /* ScreenCaptureKitSharingSessionManager.h in Headers */,
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
27 changes: 27 additions & 0 deletions Source/WebCore/dom/Exception.h
Expand Up @@ -42,6 +42,8 @@ class Exception {
Exception isolatedCopy() const & { return Exception { m_code, m_message.isolatedCopy() }; }
Exception isolatedCopy() && { return Exception { m_code, WTFMove(m_message).isolatedCopy() }; }

template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static std::optional<Exception> decode(Decoder&);
private:
ExceptionCode m_code;
String m_message;
Expand All @@ -53,4 +55,29 @@ inline Exception::Exception(ExceptionCode code, String message)
{
}

template<class Encoder>
void Exception::encode(Encoder& encoder) const
{
encoder << m_code << m_message;
}

template<class Decoder>
std::optional<Exception> Exception::decode(Decoder& decoder)
{
std::optional<ExceptionCode> code;
decoder >> code;
if (!code)
return std::nullopt;

std::optional<String> message;
decoder >> message;
if (!message)
return std::nullopt;

return Exception {
*code,
WTFMove(*message)
};
}

} // namespace WebCore
6 changes: 6 additions & 0 deletions Source/WebCore/page/Page.cpp
Expand Up @@ -306,6 +306,7 @@ Page::Page(PageConfiguration&& pageConfiguration)
, m_pluginInfoProvider(*WTFMove(pageConfiguration.pluginInfoProvider))
, m_storageNamespaceProvider(*WTFMove(pageConfiguration.storageNamespaceProvider))
, m_userContentProvider(WTFMove(pageConfiguration.userContentProvider))
, m_screenOrientationManager(WTFMove(pageConfiguration.screenOrientationManager))
, m_visitedLinkStore(*WTFMove(pageConfiguration.visitedLinkStore))
, m_broadcastChannelRegistry(WTFMove(pageConfiguration.broadcastChannelRegistry))
, m_sessionID(pageConfiguration.sessionID)
Expand Down Expand Up @@ -4025,4 +4026,9 @@ void Page::repaintAnimatedImages()
view->repaintVisibleImageAnimationsIncludingSubframes();
}

ScreenOrientationManager* Page::screenOrientationManager() const
{
return m_screenOrientationManager.get();
}

} // namespace WebCore
4 changes: 4 additions & 0 deletions Source/WebCore/page/Page.h
Expand Up @@ -155,6 +155,7 @@ class ProgressTracker;
class RenderObject;
class ResourceUsageOverlay;
class RenderingUpdateScheduler;
class ScreenOrientationManager;
class ScrollLatchingController;
class ScrollingCoordinator;
class ServicesOverlayController;
Expand Down Expand Up @@ -783,6 +784,8 @@ class Page : public Supplementable<Page>, public CanMakeWeakPtr<Page> {
WEBCORE_EXPORT UserContentProvider& userContentProvider();
WEBCORE_EXPORT void setUserContentProvider(Ref<UserContentProvider>&&);

ScreenOrientationManager* screenOrientationManager() const;

VisitedLinkStore& visitedLinkStore();
WEBCORE_EXPORT void setVisitedLinkStore(Ref<VisitedLinkStore>&&);

Expand Down Expand Up @@ -1197,6 +1200,7 @@ class Page : public Supplementable<Page>, public CanMakeWeakPtr<Page> {
Ref<PluginInfoProvider> m_pluginInfoProvider;
Ref<StorageNamespaceProvider> m_storageNamespaceProvider;
Ref<UserContentProvider> m_userContentProvider;
WeakPtr<ScreenOrientationManager> m_screenOrientationManager;
Ref<VisitedLinkStore> m_visitedLinkStore;
Ref<BroadcastChannelRegistry> m_broadcastChannelRegistry;
RefPtr<WheelEventTestMonitor> m_wheelEventTestMonitor;
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/page/PageConfiguration.cpp
Expand Up @@ -43,6 +43,7 @@
#include "PerformanceLoggingClient.h"
#include "PluginInfoProvider.h"
#include "ProgressTrackerClient.h"
#include "ScreenOrientationManager.h"
#include "SocketProvider.h"
#include "SpeechRecognitionProvider.h"
#include "SpeechSynthesisClient.h"
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/page/PageConfiguration.h
Expand Up @@ -68,6 +68,7 @@ class PaymentCoordinatorClient;
class PerformanceLoggingClient;
class PluginInfoProvider;
class ProgressTrackerClient;
class ScreenOrientationManager;
class SocketProvider;
class SpeechRecognitionProvider;
class SpeechSynthesisClient;
Expand Down Expand Up @@ -133,6 +134,7 @@ class PageConfiguration {
Ref<UserContentProvider> userContentProvider;
RefPtr<VisitedLinkStore> visitedLinkStore;
Ref<BroadcastChannelRegistry> broadcastChannelRegistry;
WeakPtr<ScreenOrientationManager> screenOrientationManager;

#if ENABLE(DEVICE_ORIENTATION) && PLATFORM(IOS_FAMILY)
RefPtr<DeviceOrientationUpdateProvider> deviceOrientationUpdateProvider;
Expand Down
106 changes: 103 additions & 3 deletions Source/WebCore/page/ScreenOrientation.cpp
Expand Up @@ -27,6 +27,7 @@
#include "ScreenOrientation.h"

#include "Document.h"
#include "Event.h"
#include "EventNames.h"
#include "JSDOMPromiseDeferred.h"
#include <wtf/IsoMallocInlines.h>
Expand All @@ -45,37 +46,136 @@ Ref<ScreenOrientation> ScreenOrientation::create(Document* document)
ScreenOrientation::ScreenOrientation(Document* document)
: ActiveDOMObject(document)
{
if (shouldListenForChangeNotification()) {
if (auto* manager = this->manager())
manager->addObserver(*this);
}
}

ScreenOrientation::~ScreenOrientation()
{
if (auto* manager = this->manager())
manager->removeObserver(*this);
}

Document* ScreenOrientation::document() const
{
return downcast<Document>(scriptExecutionContext());
}

void ScreenOrientation::lock(LockType, Ref<DeferredPromise>&& promise)
ScreenOrientationManager* ScreenOrientation::manager() const
{
promise->reject(Exception { NotSupportedError });
auto* document = this->document();
if (!document)
return nullptr;
auto* page = document->page();
return page ? page->screenOrientationManager() : nullptr;
}

void ScreenOrientation::lock(LockType lockType, Ref<DeferredPromise>&& promise)
{
auto* manager = this->manager();
if (!manager) {
promise->reject(Exception { InvalidStateError, "No browsing context"_s });
return;
}
manager->lock(lockType, [promise = WTFMove(promise)](std::optional<Exception>&& exception) {
if (exception)
promise->reject(WTFMove(*exception));
else
promise->resolve();
});
}

void ScreenOrientation::unlock()
{
if (auto* manager = this->manager())
manager->unlock();
}

auto ScreenOrientation::type() const -> Type
{
return Type::PortraitPrimary;
auto* manager = this->manager();
if (!manager)
return Type::PortraitPrimary;
return manager->currentOrientation();
}

uint16_t ScreenOrientation::angle() const
{
auto* manager = this->manager();
if (!manager)
return 0;

// The angle should depend on the device's natural orientation. We currently
// consider Portrait as the natural orientation.
switch (manager->currentOrientation()) {
case Type::PortraitPrimary:
return 0;
case Type::PortraitSecondary:
return 180;
case Type::LandscapePrimary:
return 90;
case Type::LandscapeSecondary:
return 270;
}
ASSERT_NOT_REACHED();
return 0;
}

void ScreenOrientation::visibilityStateChanged()
{
auto* document = this->document();
if (!document)
return;
auto* manager = this->manager();
if (!manager)
return;

if (shouldListenForChangeNotification())
manager->addObserver(*this);
else
manager->removeObserver(*this);
}

bool ScreenOrientation::shouldListenForChangeNotification() const
{
auto* document = this->document();
if (!document || !document->frame())
return false;
return document->visibilityState() == VisibilityState::Visible;
}

void ScreenOrientation::screenOrientationDidChange(ScreenOrientationType)
{
dispatchEvent(Event::create(eventNames().changeEvent, Event::CanBubble::No, Event::IsCancelable::No));
}

const char* ScreenOrientation::activeDOMObjectName() const
{
return "ScreenOrientation";
}

void ScreenOrientation::suspend(ReasonForSuspension)
{
if (auto* manager = this->manager())
manager->removeObserver(*this);
}

void ScreenOrientation::resume()
{
if (!shouldListenForChangeNotification())
return;
if (auto* manager = this->manager())
manager->addObserver(*this);
}

void ScreenOrientation::stop()
{
if (auto* manager = this->manager())
manager->removeObserver(*this);
}

bool ScreenOrientation::virtualHasPendingActivity() const
{
return m_hasChangeEventListener;
Expand Down

0 comments on commit c9b695e

Please sign in to comment.