[webkit-changes] [WebKit/WebKit] 2ec55e: Add unadjustedMovement option to requestPointerLock

James Howard noreply at github.com
Wed Mar 20 04:37:22 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 2ec55eb4e151f9387e8becd4bf9a9bbae1a61aef
      https://github.com/WebKit/WebKit/commit/2ec55eb4e151f9387e8becd4bf9a9bbae1a61aef
  Author: James Howard <jameshoward at mac.com>
  Date:   2024-03-20 (Wed, 20 Mar 2024)

  Changed paths:
    M LayoutTests/fast/js-promise/js-promise-invalid-context-access.html
    M LayoutTests/http/tests/pointer-lock/iframe-sandboxed-nested-disallow-then-allow-pointer-lock.html
    M LayoutTests/http/tests/pointer-lock/iframe-sandboxed.html
    M LayoutTests/http/tests/pointer-lock/requestPointerLock-can-not-transfer-between-documents.html
    A LayoutTests/imported/w3c/web-platform-tests/pointerlock/pointerlock_promise-expected.txt
    A LayoutTests/imported/w3c/web-platform-tests/pointerlock/pointerlock_promise.html
    A LayoutTests/imported/w3c/web-platform-tests/pointerlock/pointerlock_unadjustedMovement-expected.txt
    A LayoutTests/imported/w3c/web-platform-tests/pointerlock/pointerlock_unadjustedMovement.html
    A LayoutTests/imported/w3c/web-platform-tests/pointerlock/pointerlock_without_gesture-expected.txt
    A LayoutTests/imported/w3c/web-platform-tests/pointerlock/pointerlock_without_gesture.html
    A LayoutTests/platform/gtk/imported/w3c/web-platform-tests/pointerlock/pointerlock_unadjustedMovement-expected.txt
    M LayoutTests/platform/ios/TestExpectations
    A LayoutTests/platform/mac/pointer-lock/pointer-lock-option-unadjusted-movement-expected.txt
    M LayoutTests/platform/wpe/TestExpectations
    M LayoutTests/pointer-lock/lock-element-not-in-dom.html
    M LayoutTests/pointer-lock/locked-element-removed-from-dom.html
    A LayoutTests/pointer-lock/pending-locked-element-removed-from-dom-expected.txt
    A LayoutTests/pointer-lock/pending-locked-element-removed-from-dom.html
    A LayoutTests/pointer-lock/pointer-lock-option-unadjusted-movement-expected.txt
    A LayoutTests/pointer-lock/pointer-lock-option-unadjusted-movement.html
    M Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
    M Source/WTF/wtf/PlatformHave.h
    M Source/WebCore/CMakeLists.txt
    M Source/WebCore/DerivedSources-input.xcfilelist
    M Source/WebCore/DerivedSources-output.xcfilelist
    M Source/WebCore/DerivedSources.make
    M Source/WebCore/Headers.cmake
    M Source/WebCore/Sources.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/dom/Element+PointerLock.idl
    M Source/WebCore/dom/Element.cpp
    M Source/WebCore/dom/Element.h
    A Source/WebCore/dom/PointerLockOptions.h
    A Source/WebCore/dom/PointerLockOptions.idl
    M Source/WebCore/page/PointerLockController.cpp
    M Source/WebCore/page/PointerLockController.h
    M Source/WebCore/platform/PlatformMouseEvent.h
    M Source/WebCore/platform/mac/PlatformEventFactoryMac.h
    M Source/WebCore/platform/mac/PlatformEventFactoryMac.mm
    M Source/WebKit/Shared/WebEvent.serialization.in
    M Source/WebKit/Shared/WebEventConversion.cpp
    M Source/WebKit/Shared/WebMouseEvent.cpp
    M Source/WebKit/Shared/WebMouseEvent.h
    M Source/WebKit/Shared/mac/WebEventFactory.mm
    M Source/WebKit/UIProcess/WebPageProxy.cpp

  Log Message:
  -----------
  Add unadjustedMovement option to requestPointerLock
https://bugs.webkit.org/show_bug.cgi?id=218054

Reviewed by Simon Fraser and Abrar Rahman Protyasha.

This change implements the proposed modifications to the pointerlock
spec described in https://github.com/w3c/pointerlock/pull/49/. The new
behavior is controlled by the Runtime Flag PointerLockOptionsEnabled.

When the flag is set, all WebKit platforms receive the ability to return
a promise from requestPointerLock, which can be rejected with
DOMExceptions describing why pointer lock couldn't be obtained.

On macOS only, all mouse move events are annotated with unaccelerated
movement, which is readily available on NSEvent (since macOS 10.15).
When unadjustedMovement is requested via PointerLockOptions (and
PointerLockOptionsEnabled is set), the unaccelerated values are provided
in the movementX/Y attributes on MouseEvents.

On other platforms, the promise returned from requestPointerLock can be
used to learn that unadjustedMovement is not implemented for them
(again, when PointerLockOptionsEnabled is set).

When PointerLockOptionsEnabled is not set, requestPointerLock behaves as
before: it does not return a promise and any options passed are ignored,
meaning accelerated mouse motion will always be provided.

* LayoutTests/fast/js-promise/js-promise-invalid-context-access.html:
* LayoutTests/http/tests/pointer-lock/iframe-sandboxed-nested-disallow-then-allow-pointer-lock.html:
* LayoutTests/http/tests/pointer-lock/iframe-sandboxed.html:
* LayoutTests/http/tests/pointer-lock/requestPointerLock-can-not-transfer-between-documents.html:
* LayoutTests/pointer-lock/lock-element-not-in-dom.html:
* LayoutTests/pointer-lock/locked-element-removed-from-dom.html:
Handle promise rejection if returned from requestPointerLock.

* LayoutTests/platform/gtk/imported/w3c/web-platform-tests/pointerlock/pointerlock_unadjustedMovement-expected.txt:
unadjustedMovement: true is unsupported so far on GTK, add expectation for that failure.
* LayoutTests/platform/ios/TestExpectations:
Add link to webkit.org/b/216621 for missing pointer lock support on iOS.
* LayoutTests/platform/mac/pointer-lock/pointer-lock-option-unadjusted-movement-expected.txt:
Mac platform supports unadjustedMovement and so its test output acknowledges this.
* LayoutTests/platform/wpe/TestExpectations:
Skip new wpt pointerlock tests on wpe because wpe does not support pointer lock at all (webkit.org/b/204001)

* LayoutTests/pointer-lock/pointer-lock-option-unadjusted-movement-expected.txt: Added.
* LayoutTests/pointer-lock/pointer-lock-option-unadjusted-movement.html: Added.
Added tests for the unadjustedMovement option and the promise return value.

* LayoutTests/pointer-lock/pending-locked-element-removed-from-dom-expected.txt: Added.
* LayoutTests/pointer-lock/pending-locked-element-removed-from-dom.html: Added.
Added test for the promise return value in the specific case of an element being removed while pointer lock is pending.

* LayoutTests/imported/w3c/web-platform-tests/pointerlock/pointerlock_promise-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/pointerlock/pointerlock_promise.html: Added.
WPT test that verifies requestPointerLock returns a promise.

* LayoutTests/imported/w3c/web-platform-tests/pointerlock/pointerlock_unadjustedMovement-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/pointerlock/pointerlock_unadjustedMovement.html: Added.
WPT test that verifies that unadjustedMovement option is handled according to the spec.

* LayoutTests/imported/w3c/web-platform-tests/pointerlock/pointerlock_without_activation-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/pointerlock/pointerlock_without_activation.html: Added.
WPT test that verifies that if requestPointerLock is called without user gesture that the returned promise is rejected
with NotAllowedError.

* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: Added PointerLockOptionsEnabled

* Source/WTF/wtf/PlatformHave.h: Added HAVE_MOUSE_UNACCELERATED_MOVEMENT for Mac

* Source/WebCore/CMakeLists.txt: Added JSPointerLockOptions.cpp
* Source/WebCore/DerivedSources-input.xcfilelist: Added PointerLockOptions.idl
* Source/WebCore/DerivedSources-output.xcfilelist: Added JSPointerLockOptions.cpp
* Source/WebCore/DerivedSources.make: Added JSPointerLockOptions.cpp
* Source/WebCore/Headers.cmake: Added PointerLockOptions.h
* Source/WebCore/Sources.txt: Added JSPointerLockOptions.cpp
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/dom/Element+PointerLock.idl: Add PointerLockOptions and promise.
* Source/WebCore/dom/PointerLockOptions.h: Added.
* Source/WebCore/dom/PointerLockOptions.idl: Added.

* Source/WebCore/dom/Element.cpp:
(WebCore::Element::requestPointerLock):
Pass options and return promise from requestPointerLock if
PointerLockOptionsEnabled runtime flag is set.

* Source/WebCore/dom/Element.h: Update requestPointerLock signature

* Source/WebCore/page/PointerLockController.cpp:
(WebCore::UnadjustedMovementPlatformMouseEvent::UnadjustedMovementPlatformMouseEvent):
Added utility class to set PlatformMouseEvent movement to unadjusted movement.

(WebCore::PointerLockController::~PointerLockController):
Added empty destructor because DeferredPromise is a forward declaration in the header.

(WebCore::PointerLockController::requestPointerLock):
Resolve or reject promise with appropriate DOMException.

(WebCore::PointerLockController::didAcquirePointerLock):
Resolve promise if needed.

(WebCore::PointerLockController::didNotAcquirePointerLock):
Reject promise if needed (e.g. missing focus).

(WebCore::PointerLockController::dispatchLockedMouseEvent):
Send unadjusted movement delta if requested.

(WebCore::PointerLockController::clearElement):
Clear promise if saved

(WebCore::PointerLockController::supportsUnadjustedMovement):
Returns whether the unadjustedMovement option can be enabled.
requestPointerLock needs to reject its promise if unadjustedMovement is
true but the browser doesn't support that mode.

* Source/WebCore/page/PointerLockController.h:
Update requestPointerLock signature.
Add supportsUnadjustedMovement static method.

* Source/WebCore/platform/PlatformMouseEvent.h:
(WebCore::PlatformMouseEvent::unadjustedMovementDelta const):
Add accessor for unaccelerated pointer movement.

* Source/WebCore/platform/mac/PlatformEventFactoryMac.h:
Export WebCore::unadjustedMovementForEvent for use by WebKit::WebEventFactory::createWebMouseEvent.
* Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:
(WebCore::unadjustedMovementForEvent):
Ask NSEvent for unaccelerated mouse movement.
(WebCore::PlatformMouseEventBuilder::PlatformMouseEventBuilder):
Set unaccelerated mouse movement on PlatformMouseEvent as unadjustedMovementDelta.

* Source/WebKit/Shared/WebEvent.serialization.in:
* Source/WebKit/Shared/WebEventConversion.cpp:
(WebKit::WebKit2PlatformMouseEvent::WebKit2PlatformMouseEvent):
* Source/WebKit/Shared/WebMouseEvent.cpp:
(WebKit::WebMouseEvent::WebMouseEvent):
* Source/WebKit/Shared/WebMouseEvent.h:
Added unadjustedMovementDelta to WebMouseEvent. All platforms get the
field, but it's only set on Mac for now.

* Source/WebKit/Shared/mac/WebEventFactory.mm:
(WebKit::WebEventFactory::createWebMouseEvent):
Ask NSEvent for unaccelerated mouse movement.

* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didAllowPointerLock):
(WebKit::WebPageProxy::didDenyPointerLock):
Remove ASSERT(m_isPointerLockPending && !m_isPointerLocked). Because
didAllow/DenyPointerLock are not necessarily called synchronously by the
UI Delegate, it is possible that the page itself has cancelled a pending
pointer lock prior to the UI delegate making its decision to allow or
deny pointer lock (e.g. by removing the target element). Instead, handle
whatever cleanup actions are necessary based on the current state of
m_isPointerLockPending and m_isPointerLocked individually.

Canonical link: https://commits.webkit.org/276399@main



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list