[webkit-changes] [WebKit/WebKit] 8284b3: Stop overriding -[UIResponder _characterInRelation...

Wenson Hsieh noreply at github.com
Thu Nov 16 14:53:56 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 8284b38b4eb51acd82731c4e97579b3f1bd786a5
      https://github.com/WebKit/WebKit/commit/8284b38b4eb51acd82731c4e97579b3f1bd786a5
  Author: Wenson Hsieh <wenson_hsieh at apple.com>
  Date:   2023-11-16 (Thu, 16 Nov 2023)

  Changed paths:
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
    M Tools/TestRunnerShared/spi/UIKitSPIForTesting.h
    M Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm

  Log Message:
  -----------
  Stop overriding -[UIResponder _characterInRelationToCaretSelection:] in WKContentView
https://bugs.webkit.org/show_bug.cgi?id=264918
rdar://118028374

Reviewed by Tim Horton.

Stop overriding `UIResponder`'s default implementation of `-_characterInRelationToCaretSelection:`.
This internal method is consulted to determine what characters exist 1 character after and up to 2
characters before the start of the current selection, and is used to drive various keyboard-related
behaviors such as autocapitalization, autocorrection, dictation and smart spaces.

This is currently broken for WebKit2 unless we override this method with our custom logic, since the
default method in `UIResponder` uses several `UITextInput` methods that are (mostly) empty stubs in
WebKit2:

```
-positionFromPosition:offset:
-textRangeFromPosition:toPosition:
-textInRange:
```

...while a fully-fleshed-out implementation is incompatible with the fact that the real layout
information and DOM positions are inaccessible from the app process, we can still make UIKit return
the right answer using those above methods, by synchronously returning fake `UITextPosition` objects
that represent text positions at offsets relative to the start or end of the selection.

We then implement `-textInRange:`, and have it return cached values for the characters before or
after the start of the selection, using the same post-layout data that we're currently returning in
our custom implementation of `-_characterInRelationToCaretSelection:`.

Test: KeyboardInputTests.CharactersAroundCaretSelection

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(positionWithOffsetFrom):
(anchorsAndOffset):
(textRelativeToSelectionStart):
(-[WKRelativeTextPosition initWithAnchors:offset:]):
(-[WKRelativeTextPosition isRelativeToStart]):
(-[WKRelativeTextPosition description]):

Add a `UITextPosition` subclass that represents a position located at some character offset,
relative to either the selection start, or end, or both (in the case of a caret selection).

(-[WKRelativeTextRange initWithStart:end:]):
(-[WKRelativeTextRange start]):
(-[WKRelativeTextRange end]):
(-[WKRelativeTextRange isEmpty]):
(-[WKRelativeTextRange description]):

Add a `UITextRange` subclass that represents two visible positions, anchored relative to the start
or end of a text range.

(-[WKContentView textInRange:]):
(-[WKContentView textRangeFromPosition:toPosition:]):
(-[WKContentView positionFromPosition:offset:]):
(+[WKTextRange textRangeWithState:isRange:isEditable:startRect:endRect:selectionRects:selectedTextLength:]):
(-[WKTextRange start]):
(-[WKTextRange end]):
(-[WKContentView _characterInRelationToCaretSelection:]): Deleted.

Stop implementing this internal method.

* Tools/TestRunnerShared/spi/UIKitSPIForTesting.h:
* Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:

Add an API test to exercise the change by using the previously-overridden method.

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




More information about the webkit-changes mailing list