[webkit-changes] [WebKit/WebKit] a5fcaa: Adopt UIResponder API methods in lieu of handleKey...

Abrar Rahman Protyasha noreply at github.com
Mon Aug 21 22:02:14 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: a5fcaa3c441c0f15061f29b8bc50bcd8198eb28f
      https://github.com/WebKit/WebKit/commit/a5fcaa3c441c0f15061f29b8bc50bcd8198eb28f
  Author: Abrar Rahman Protyasha <a_protyasha at apple.com>
  Date:   2023-08-21 (Mon, 21 Aug 2023)

  Changed paths:
    M LayoutTests/fast/repaint/placeholder-after-caps-lock-hidden.html
    M Source/WebKit/Platform/spi/ios/UIKitSPI.h
    M Source/WebKit/UIProcess/API/ios/WKWebViewIOS.h
    M Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
    M Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

  Log Message:
  -----------
  Adopt UIResponder API methods in lieu of handleKeyUIEvent to respond to press events
https://bugs.webkit.org/show_bug.cgi?id=260217
rdar://100726289

Reviewed by Wenson Hsieh.

The handleKeyUIEvent: and _handleKeyUIEvent: SPI are both deprecated.
Instead, we choose to adopt the pressesBegan:, pressesChanged:,
pressesEnded:, and pressesCancelled: API in this commit. These methods
are forwarded events for handling in the same fashion as the SPI to be
removed.

* LayoutTests/fast/repaint/placeholder-after-caps-lock-hidden.html:

After the changes introduced in this patch, this test was dumping a lot
more painted rects. This was because previous key actions (`a`/`\b`)
were bleeding into the section of the test where we wanted to track
repaints (i.e. after the capslock indicator has been hidden).

We fix this by enforcing correct event ordering through appropriate async
usage of the UIHelper functions (i.e. awaiting `keyDown()` calls and the
resulting `keyUp` events).

* Source/WebKit/Platform/spi/ios/UIKitSPI.h:

1. Remove the deprecated SPI declarations.
2. Declare the UIPressInfo interface and some associated methods to
imbibe event information into a UIPress object.

* Source/WebKit/UIProcess/API/ios/WKWebViewIOS.h:
* Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView _tryToHandleKeyEventInCustomContentView:]):

Helper function to determine whether an event needs forwarding based on
whether or not a custom content view handles it. Helps deduplicate code.

(-[WKWebView pressesBegan:withEvent:]):
(-[WKWebView pressesChanged:withEvent:]):
(-[WKWebView pressesEnded:withEvent:]):
(-[WKWebView pressesCancelled:withEvent:]):
(-[WKWebView _handleKeyUIEvent:]): Deleted.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _tryToHandlePressesEvent:]):

Helper function to determine whether an event needs forwarding based on
whether or not an input peripheral handles it. Helps deduplicate code.

(-[WKContentView pressesBegan:withEvent:]):
(-[WKContentView pressesEnded:withEvent:]):
(-[WKContentView pressesChanged:withEvent:]):
(-[WKContentView pressesCancelled:withEvent:]):
(-[WKContentView _handleKeyUIEvent:]): Deleted.

(WTR::UIScriptControllerIOS::toggleCapsLock):
* Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::createUIPhysicalKeyboardEvent):
(WTR::UIScriptControllerIOS::toggleCapsLock):

The `toggleCapsLock` implementation required two broad changes to
maintain the existing toggle behavior:

1. Simply calling `pressesBegan:` on the `UIApplication` singleton does
not suffice in getting our synthetic keyboard event sent to the content
view's overridden `pressesBegan:` definition. To work around this, we
manually create a `UIPress` object with knowledge of our synthetic
keyboard event, and then send the press/event combination directly to
our content view's `pressesBegan:` overload. This maintains the existing
toggle behavior.

2. In inspecting the press/event combinations received when toggling the
capslock key with a hardware keyboard, it was noticed that on iOS we send
both a keyDown and a keyUp event with the appropriate modifier flag
information whenever we want to toggle capslock, with the former being
sent to `pressesBegan:` and the latter being sent to `pressesEnded:`.
As such, we generate a pair of keyboard events and call the appropriate
`presses[Began/Ended]:` method directly on our content view to reflect
this behavior.

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




More information about the webkit-changes mailing list