Bug 102869 - Implement the Screen Orientation API
Summary: Implement the Screen Orientation API
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL: https://w3c.github.io/screen-orientation
Keywords: InRadar, WebExposed
: 125914 212931 215124 (view as bug list)
Depends on: 245799 245804 245999 246103 246302 246435 246528 246545 246548 246556
Blocks: 254863
  Show dependency treegraph
 
Reported: 2012-11-20 21:13 PST by Ryuan Choi
Modified: 2023-04-04 01:06 PDT (History)
34 users (show)

See Also:


Attachments
initial version (71.02 KB, patch)
2014-03-31 21:02 PDT, Ryuan Choi
benjamin: review-
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from webkit-ews-03 for mac-mountainlion (543.39 KB, application/zip)
2014-03-31 22:58 PDT, Build Bot
no flags Details
Archive of layout-test-results from webkit-ews-08 for mac-mountainlion (504.67 KB, application/zip)
2014-03-31 23:51 PDT, Build Bot
no flags Details
Archive of layout-test-results from webkit-ews-11 for mac-mountainlion-wk2 (559.44 KB, application/zip)
2014-04-01 00:21 PDT, Build Bot
no flags Details
Archive of layout-test-results from webkit-ews-09 for mac-mountainlion-wk2 (557.32 KB, application/zip)
2014-04-01 01:21 PDT, Build Bot
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ryuan Choi 2012-11-20 21:13:17 PST
Adding screen orientation
Comment 1 Alexey Proskuryakov 2012-11-21 14:51:45 PST
Has this feature been announced on webkit-dev? I couldn't quickly find such an e-mail.
Comment 2 Ryuan Choi 2012-11-22 01:41:48 PST
(In reply to comment #1)
> Has this feature been announced on webkit-dev? I couldn't quickly find such an e-mail.

Sorry for the late. I announced now.
Comment 3 Ryuan Choi 2014-03-31 21:02:53 PDT
Created attachment 228239 [details]
initial version
Comment 4 Ryuan Choi 2014-03-31 21:05:00 PDT
*** Bug 125914 has been marked as a duplicate of this bug. ***
Comment 5 Build Bot 2014-03-31 22:58:42 PDT
Comment on attachment 228239 [details]
initial version

Attachment 228239 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/5073369552650240

New failing tests:
screen_orientation/screenorientation-api.html
screen_orientation/consecutive-locking.html
screen_orientation/orientation-change-event.html
Comment 6 Build Bot 2014-03-31 22:58:49 PDT
Created attachment 228242 [details]
Archive of layout-test-results from webkit-ews-03 for mac-mountainlion

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: webkit-ews-03  Port: mac-mountainlion  Platform: Mac OS X 10.8.5
Comment 7 Build Bot 2014-03-31 23:50:59 PDT
Comment on attachment 228239 [details]
initial version

Attachment 228239 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/6228977748279296

New failing tests:
screen_orientation/screenorientation-api.html
screen_orientation/consecutive-locking.html
screen_orientation/orientation-change-event.html
Comment 8 Build Bot 2014-03-31 23:51:08 PDT
Created attachment 228247 [details]
Archive of layout-test-results from webkit-ews-08 for mac-mountainlion

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: webkit-ews-08  Port: mac-mountainlion  Platform: Mac OS X 10.8.5
Comment 9 Build Bot 2014-04-01 00:21:17 PDT
Comment on attachment 228239 [details]
initial version

Attachment 228239 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/4550764374523904

New failing tests:
platform/mac/fast/scrolling/scroll-iframe-latched-mainframe.html
platform/mac/fast/scrolling/scroll-select-latched-mainframe.html
screen_orientation/screenorientation-api.html
screen_orientation/consecutive-locking.html
screen_orientation/orientation-change-event.html
platform/mac/fast/scrolling/scroll-div-latched-mainframe.html
Comment 10 Build Bot 2014-04-01 00:21:25 PDT
Created attachment 228249 [details]
Archive of layout-test-results from webkit-ews-11 for mac-mountainlion-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: webkit-ews-11  Port: mac-mountainlion-wk2  Platform: Mac OS X 10.8.5
Comment 11 Build Bot 2014-04-01 01:21:26 PDT
Comment on attachment 228239 [details]
initial version

Attachment 228239 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/6046627127099392

New failing tests:
platform/mac/fast/scrolling/scroll-iframe-latched-mainframe.html
platform/mac/fast/scrolling/scroll-select-latched-mainframe.html
screen_orientation/screenorientation-api.html
screen_orientation/consecutive-locking.html
screen_orientation/orientation-change-event.html
platform/mac/fast/scrolling/scroll-div-latched-mainframe.html
Comment 12 Build Bot 2014-04-01 01:21:35 PDT
Created attachment 228255 [details]
Archive of layout-test-results from webkit-ews-09 for mac-mountainlion-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: webkit-ews-09  Port: mac-mountainlion-wk2  Platform: Mac OS X 10.8.5
Comment 13 Benjamin Poulain 2014-04-05 13:50:07 PDT
Comment on attachment 228239 [details]
initial version

View in context: https://bugs.webkit.org/attachment.cgi?id=228239&action=review

I only quickly skimmed over the patch, some comments bellow. This needs some serious cleanup.

> Source/WebCore/ChangeLog:7
> +

Here you should give: 
-An URL to the latest spec or draft (preferably the dated version).
-What is the status of support from other engines.
-Explain the architecture of your change.

> Source/WebCore/Modules/screenorientation/ScreenOrientationController.h:46
> +    void setClientForTest(ScreenOrientationClient*);
> +    bool hasClientForTest() const { return m_hasClientForTest; }

This is not a good way to test features like this.

You should have the mock object in the WebKit layer.

> Source/WebCore/bindings/js/JSScreenCustom.cpp:37
> +JSValue JSScreen::lockOrientation(ExecState* exec)

Why do you need a custom wrapper for this? If it is just for the promise, maybe we should extend the code generator?

> Source/WebCore/page/Screen.cpp:130
> +    static NeverDestroyed<AtomicString> portrait("portrait", AtomicString::ConstructFromLiteral);
> +    static NeverDestroyed<AtomicString> portraitPrimary("portrait-primary", AtomicString::ConstructFromLiteral);
> +    static NeverDestroyed<AtomicString> portraitSecondary("portrait-secondary", AtomicString::ConstructFromLiteral);
> +    static NeverDestroyed<AtomicString> landscape("landscape", AtomicString::ConstructFromLiteral);
> +    static NeverDestroyed<AtomicString> landscapePrimary("landscape-primary", AtomicString::ConstructFromLiteral);
> +    static NeverDestroyed<AtomicString> landscapeSecondary("landscape-secondary", AtomicString::ConstructFromLiteral);
> +    static NeverDestroyed<AtomicString> any("any", AtomicString::ConstructFromLiteral);

Why do you use AtomicStrings here?

> Source/WebCore/page/Screen.cpp:187
> +    for (unsigned i = 0; i < length; ++i) {
> +        if (map[i].name == orientationString) {

This is what compile time hash map are for.

> Source/WebCore/page/Screen.h:50
> +    enum ScreenOrientation {

If this is an exhaustive list, this should be a typed enum.
Comment 14 Ryuan Choi 2014-04-06 22:58:07 PDT
(In reply to comment #13)
> (From update of attachment 228239 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=228239&action=review
> 
> I only quickly skimmed over the patch, some comments bellow. This needs some serious cleanup.
> 
> > Source/WebCore/ChangeLog:7
> > +
> 
> Here you should give: 
> -An URL to the latest spec or draft (preferably the dated version).
> -What is the status of support from other engines.
> -Explain the architecture of your change.
> 
First, thanks for the review.

I will revise the patch with your comments and latest spec/draft.

FYI, latest draft is below.
It was updated once more so patch is bit different with the below spec.

https://dvcs.w3.org/hg/screen-orientation/raw-file/tip/Overview.html

> > Source/WebCore/Modules/screenorientation/ScreenOrientationController.h:46
> > +    void setClientForTest(ScreenOrientationClient*);
> > +    bool hasClientForTest() const { return m_hasClientForTest; }
> 
> This is not a good way to test features like this.
> 
> You should have the mock object in the WebKit layer.
OK, I will try.

> 
> > Source/WebCore/bindings/js/JSScreenCustom.cpp:37
> > +JSValue JSScreen::lockOrientation(ExecState* exec)
> 
> Why do you need a custom wrapper for this? If it is just for the promise, maybe we should extend the code generator?

I am not familiar with code generator but I will check.

> 
> > Source/WebCore/page/Screen.cpp:130
> > +    static NeverDestroyed<AtomicString> portrait("portrait", AtomicString::ConstructFromLiteral);
> > +    static NeverDestroyed<AtomicString> portraitPrimary("portrait-primary", AtomicString::ConstructFromLiteral);
> > +    static NeverDestroyed<AtomicString> portraitSecondary("portrait-secondary", AtomicString::ConstructFromLiteral);
> > +    static NeverDestroyed<AtomicString> landscape("landscape", AtomicString::ConstructFromLiteral);
> > +    static NeverDestroyed<AtomicString> landscapePrimary("landscape-primary", AtomicString::ConstructFromLiteral);
> > +    static NeverDestroyed<AtomicString> landscapeSecondary("landscape-secondary", AtomicString::ConstructFromLiteral);
> > +    static NeverDestroyed<AtomicString> any("any", AtomicString::ConstructFromLiteral);
> 
> Why do you use AtomicStrings here?
> 
> > Source/WebCore/page/Screen.cpp:187
> > +    for (unsigned i = 0; i < length; ++i) {
> > +        if (map[i].name == orientationString) {
> 
> This is what compile time hash map are for.
> 
I will change them to String and try to use hash map.

> > Source/WebCore/page/Screen.h:50
> > +    enum ScreenOrientation {
> 
> If this is an exhaustive list, this should be a typed enum.

I tried enum class but it requires operator&() .
If it is more preferred to add bit operator(), I will do it.
Comment 15 Rodney Rehm 2016-04-18 05:17:15 PDT
Why hasn't there been any movement on this in 2 years?

The specification has moved - https://w3c.github.io/screen-orientation/ - it's still a Working Draft. An implementation landed in Blink in late 2015: https://bugs.chromium.org/p/chromium/issues/detail?id=162827

According to http://caniuse.com/#feat=screen-orientation and https://developer.mozilla.org/en-US/docs/Web/API/Screen/lockOrientation#Browser_compatibility this is even available in IE11, only WebKit is lacking support.
Comment 16 Radar WebKit Bug Importer 2017-02-08 13:02:03 PST
<rdar://problem/30427070>
Comment 17 Simon Fraser (smfr) 2017-02-08 15:27:48 PST
Please also add this to features.json (can be in a separate patch).
Comment 18 Alexey Proskuryakov 2020-06-08 17:14:41 PDT
*** Bug 212931 has been marked as a duplicate of this bug. ***
Comment 19 Blake Buell 2020-06-24 08:28:12 PDT
Any ETA? This would be extremely useful for standalone web apps.
Comment 20 Jakub G (dailymotion) 2021-05-25 05:59:54 PDT
Note since this shipped with Chromium Edge, Safari is the last one remaining for compatibility (It even has partial support in IE11).

https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation
https://caniuse.com/screen-orientation
Comment 21 Sam Sneddon [:gsnedders] 2021-07-31 15:08:01 PDT
*** Bug 215124 has been marked as a duplicate of this bug. ***
Comment 22 Ben Frain 2022-03-29 03:02:34 PDT
Just to add this is extremely frustrating to still, in 2022, need to add forks in the code for the older API purely for Safari.

Would love to see this in Safari. 

Could anyone on the WebKit team provide a rough ETA?
Comment 23 Kim 2022-06-08 14:29:32 PDT
There should one unified API to query screen orientation.

https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation

As usual, (cough x2... hopefully Safari is not the new IE) Safari or webkit based browser is the only one not supporting this useful API.
https://caniuse.com/?search=screen.orientation



Using the following matchMedia to detect orientation poses a lot of bugs when attempt to support consistent experience across for both android and ios devices as android keyboard wasn't overlayed like ios device

> Note: This feature does not correspond to device orientation. Opening the soft keyboard on many devices in portrait orientation will cause the viewport to become wider than it is tall, thereby causing the browser to use landscape styles instead of portrait.


```
window.matchMedia("(orientation: portrait)");
```

https://developer.mozilla.org/en-US/docs/Web/CSS/@media/orientation
https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Testing_media_queries
Comment 24 Chris Dumez 2022-10-18 08:45:07 PDT
Resolved via subtasks.