-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Use dedicated API to know if fullscreen/pointerlock can be requested #19758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fullscreen can be requested during transient activation not just while handling an input event, so check for that on browsers that support it.
|
@juj WDYT? I'm not really an html5 expert but it seems reasonable. Also seems hard to write a test for :( |
| if (navigator.userActivation) { | ||
| // Use transient activation status for browsers that support it | ||
| return navigator.userActivation.isActive; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
canPerformEventHandlerRequests: function() {
// Verify against transient activation status from UserActivation API
// whether it is possible to perform a request here without needing to defer. See
// https://developer.mozilla.org/en-US/docs/Web/Security/User_activation#transient_activation
// and https://caniuse.com/mdn-api_useractivation
// At the time of writing, Firefox does not support this API: https://bugzilla.mozilla.org/show_bug.cgi?id=1791079
return navigator.userActivation?.isActive
|| (JSEvents.inEventHandler && JSEvents.currentEventHandler.allowsDeferredCalls);
}It would be interesting to experiment with a micro code-size improvement to remove JSEvents.inEventHandler and JSEvents.currentEventHandler.allowsDeferredCalls altogether when targeting only browsers that are guaranteed to support UserActivation API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't generally allow optional chaining in the generated JS yet, but perhaps we should. If we can show that closure that lower it to ES5 as needed that would be great... let me see if I can confirm that now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the comment lines. Let me know when you've decided about the optional chaining operator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can land this now and consider it as part of the motivation for landing #19772
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm not sure I understand. Do you mean using the optional chaining in the PR and wait for #19772 completion to merge this PR? Or the opposite (not using the optional chaining here)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that I think we should land this PR now, as is
|
LGTM modulo that comment above. Maybe this will further enable a nice simplification of otherwise hairy logic in the HTML5 API by enabling us to tear down the previous manual check logic. |
Fullscreen/pointerlock can be requested during transient activation not just while handling an input event, so check for that on browsers that support it (all but Firefox it seems).
These changes make it possible for the fullscreen switch to happen instantaneously on apps that treat the input events outside the event handler (like SDL2 for instance).