[webkit-changes] [WebKit/WebKit] 7fe518: [macOS] `buttons` property is incorrect for mouse ...

Abrar Rahman Protyasha noreply at github.com
Tue Feb 4 10:34:32 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 7fe5188140a77ecb76871d468ce78cab83cd0dfb
      https://github.com/WebKit/WebKit/commit/7fe5188140a77ecb76871d468ce78cab83cd0dfb
  Author: Abrar Rahman Protyasha <a_protyasha at apple.com>
  Date:   2025-02-04 (Tue, 04 Feb 2025)

  Changed paths:
    M LayoutTests/fast/events/fire-mousedown-while-pressing-mouse-button.html
    A LayoutTests/fast/events/mouse-event-buttons-expected.txt
    A LayoutTests/fast/events/mouse-event-buttons.html
    M LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_attributes_mouse-right-expected.txt
    M LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_attributes_mouse-right-nonstandard-expected.txt
    M LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_attributes_pen-right-expected.txt
    M LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_attributes_pen-right-nonstandard-expected.txt
    M LayoutTests/imported/w3c/web-platform-tests/uievents/mouse/synthetic-mouse-enter-leave-over-out-button-state-after-target-removed.tentative_buttonType=MIDDLE&button=1&buttons=4-expected.txt
    M LayoutTests/platform/ios/TestExpectations
    A LayoutTests/platform/mac-wk1/fast/events/mouse-event-buttons-expected.txt
    M LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/uievents/mouse/synthetic-mouse-enter-leave-over-out-button-state-after-target-removed.tentative_buttonType=MIDDLE&button=1&buttons=4-expected.txt
    M LayoutTests/platform/win/TestExpectations
    M LayoutTests/platform/wpe/TestExpectations
    M Source/WebCore/dom/MouseEvent.cpp
    M Source/WebCore/dom/MouseEvent.h
    M Tools/DumpRenderTree/mac/EventSendingController.mm
    M Tools/WebKitTestRunner/EventSenderProxy.h
    M Tools/WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm
    M Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj
    A Tools/WebKitTestRunner/cocoa/EventSenderProxyCocoa.mm
    M Tools/WebKitTestRunner/mac/EventSenderProxy.mm

  Log Message:
  -----------
  [macOS] `buttons` property is incorrect for mouse events generated through the EventSender interface
https://bugs.webkit.org/show_bug.cgi?id=267801
rdar://121296080

Reviewed by Wenson Hsieh.

Currently, `eventSender.mouseDown(2)` produces a `mousedown` event with
a `buttons` value of 4, rather than 2. This is because the button number
ordering as prescribed by the DOM spec (Left=0, Middle=1, Right=2) does
not exactly map to the bit order for button presence in the `buttons`
value where, instead, Left=Bit0, Right=Bit1, and Middle=Bit2, c.f.
https://w3c.github.io/uievents/#dom-mouseevent-buttons.

Our `buttons` value was wrong because we were simply shifting left based
on the former order. This patch addresses this error by accounting for
the change in order for the `buttons` value, inspired by a similar bug
fix for webdriver in 283790 at main. We do so by tracking active button
presses in a map keyed by (known) WebCore::MouseButton values, and then
safely building up the appropriate `buttons` value by following the
latter order. To facilitate this new tracking, we introduce the
`buttonAsShort()` helper on `MouseButton`. When we get a button number
from EventSender, we can convert this number to a known MouseButton case,
instead of having to define and use yet another local `MouseButton`
enumeration.

* LayoutTests/fast/events/fire-mousedown-while-pressing-mouse-button.html:

Correct the same (wrong) assumption we made in WKTR.

* LayoutTests/fast/events/mouse-event-buttons-expected.txt: Added.
* LayoutTests/fast/events/mouse-event-buttons.html: Added.

New test to sanity check the `buttons` values when doing mouse
interactions through EventSender.

* LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_attributes_mouse-right-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_attributes_mouse-right-nonstandard-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_attributes_pen-right-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_attributes_pen-right-nonstandard-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/uievents/mouse/synthetic-mouse-enter-leave-over-out-button-state-after-target-removed.tentative_buttonType=MIDDLE&button=1&buttons=4-expected.txt:

Adjust test results because we now reflect the correct `buttons` value.

* LayoutTests/platform/ios/TestExpectations:
* LayoutTests/platform/mac-wk1/fast/events/mouse-event-buttons-expected.txt: Added.
* LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/uievents/mouse/synthetic-mouse-enter-leave-over-out-button-state-after-target-removed.tentative_buttonType=MIDDLE&button=1&buttons=4-expected.txt:
* LayoutTests/platform/win/TestExpectations:
* LayoutTests/platform/wpe/TestExpectations:
* Source/WebCore/dom/MouseEvent.cpp:
(WebCore::MouseEvent::buttonFromShort):
(WebCore::MouseEvent::button const):
* Source/WebCore/dom/MouseEvent.h:
* Tools/DumpRenderTree/mac/EventSendingController.mm:
(eventTypeForMouseButtonAndAction):
(swizzledEventPressedMouseButtons):
(-[EventSendingController mouseDown:withModifiers:]):
(-[EventSendingController mouseUp:withModifiers:]):

Drive-by cleanup: Make `MouseAction` an enum class.

* Tools/WebKitTestRunner/EventSenderProxy.h:

Keep the data type for m_mouseButtonsCurrentlyDown unchanged for
non-Cocoa ports, since said ports compute the `buttons` value
differently.

(WTR::EventSenderProxy::mouseButtonsCurrentlyDown const): Deleted.
* Tools/WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm:
* Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
* Tools/WebKitTestRunner/cocoa/EventSenderProxyCocoa.mm: Added.
(WTR::EventSenderProxy::mouseButtonsCurrentlyDown const):

File containing Cocoa-specific EventSenderProxy code. Currently only
populated by ::mouseButtonsCurrentlyDown(), but we should move more code
in here.

* Tools/WebKitTestRunner/mac/EventSenderProxy.mm:
(WTR::eventTypeForMouseButtonAndAction):
(WTR::EventSenderProxy::EventSenderProxy):
(WTR::EventSenderProxy::mouseDown):
(WTR::EventSenderProxy::mouseUp):
(): Deleted.

Drive-by cleanup: Make `MouseAction` an enum class.
Canonical link: https://commits.webkit.org/289800@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