Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 851a94731a2a59de7b93907417f505c76b1082ea
      
https://github.com/WebKit/WebKit/commit/851a94731a2a59de7b93907417f505c76b1082ea
  Author: Wenson Hsieh <wenson_hs...@apple.com>
  Date:   2024-01-22 (Mon, 22 Jan 2024)

  Changed paths:
    M Source/WebKit/Shared/ios/WebAutocorrectionContext.h
    M Source/WebKit/Shared/ios/WebAutocorrectionContext.serialization.in
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
    M Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
    M Tools/TestRunnerShared/spi/UIKitSPIForTesting.h
    M Tools/TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm
    M Tools/TestWebKitAPI/cocoa/TestWKWebView.h
    M Tools/TestWebKitAPI/cocoa/TestWKWebView.mm

  Log Message:
  -----------
  [iOS] [UIAsyncTextInput] WKWebView AutoFill input assistant item doesn't show 
up in the keyboard
https://bugs.webkit.org/show_bug.cgi?id=267865
rdar://121160501

Reviewed by Aditya Keerthi and Abrar Rahman Protyasha.

When async text input is enabled, we use 
`-requestTextContextForAutocorrectionWithCompletionHandler:`
to surface autocorrection context information to UIKit. The conversion from
`WebAutocorrectionContext::markedTextRange` to 
`DocumentEditingContext::selectedRangeInMarkedText`
is currently straightforward:

```
editingContext.selectedRangeInMarkedText = {
    .location = correctionContext.selectedRangeInMarkedText.location,
    .length = correctionContext.selectedRangeInMarkedText.length
};
```

…however, this hides a subtle bug, since the "not found" location of 
`markedTextRange` (an
`EditingRange`) is represented using `WTF::notFound`, while the 
`selectedRangeInMarkedText`
represents "not found" with `NSNotFound`, directly mirroring `NSRange`. The 
`NSRange` operator in
`EditingRange` is aware of this difference:

```
operator NSRange() const
{
    if (location == notFound)
        return NSMakeRange(NSNotFound, 0);
    return NSMakeRange(location, length);
}
```

…but we don't use it in the above code since we set the location and length 
directly. Fix this by
simply mapping `notFound` to `NSNotFound` when creating the platform context in 
the async text input
codepath.

Test: AutocorrectionTests.AutocorrectionContextBeforeAndAfterEditing

* Source/WebKit/Shared/ios/WebAutocorrectionContext.h:
* Source/WebKit/Shared/ios/WebAutocorrectionContext.serialization.in:

While we're here, also rename `markedTextRange` to `selectedRangeInMarkedText`, 
to clarify what this
range actually represents.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView requestTextContextForAutocorrectionWithCompletionHandler:]):
(+[WKAutocorrectionContext autocorrectionContextWithWebContext:]):
* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::autocorrectionContext):
* Tools/TestRunnerShared/spi/UIKitSPIForTesting.h:
* Tools/TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm:

Augment an existing API test to also verify that when there's no IME 
composition range, `markedText`
is `nil` and `selectedRangeInMarkedText` is exactly equal to `{ NSNotFound, 0 
}`.

* Tools/TestWebKitAPI/cocoa/TestWKWebView.h:
* Tools/TestWebKitAPI/cocoa/TestWKWebView.mm:
(-[WKWebView autocorrectionContext]):

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


_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to