[webkit-changes] [WebKit/WebKit] 0f59c6: [Cocoa] Refactor NSTextAlternatives handling to su...

Wenson Hsieh noreply at github.com
Sat Jan 13 20:13:33 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 0f59c6ab400c43fcd1fca9ab7f4e981721f3fa65
      https://github.com/WebKit/WebKit/commit/0f59c6ab400c43fcd1fca9ab7f4e981721f3fa65
  Author: Wenson Hsieh <wenson_hsieh at apple.com>
  Date:   2024-01-13 (Sat, 13 Jan 2024)

  Changed paths:
    M Source/WebCore/PAL/pal/spi/cocoa/NSAttributedStringSPI.h
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/editing/cocoa/AlternativeTextContextController.h
    M Source/WebCore/editing/cocoa/AlternativeTextContextController.mm
    M Source/WebCore/editing/cocoa/AlternativeTextUIController.h
    M Source/WebCore/editing/cocoa/AlternativeTextUIController.mm
    M Source/WebCore/editing/mac/TextAlternativeWithRange.h
    M Source/WebCore/editing/mac/TextAlternativeWithRange.mm
    A Source/WebCore/platform/cocoa/PlatformTextAlternatives.h
    M Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h
    M Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm
    M Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm
    M Source/WebKit/UIProcess/PageClient.h
    M Source/WebKit/UIProcess/WebPageProxy.h
    M Source/WebKit/UIProcess/ios/PageClientImplIOS.h
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
    M Source/WebKitLegacy/mac/WebView/WebView.mm

  Log Message:
  -----------
  [Cocoa] Refactor NSTextAlternatives handling to support other text alternative classes
https://bugs.webkit.org/show_bug.cgi?id=267479
rdar://120931128

Reviewed by Ryosuke Niwa.

Make it possible to use alternative classes (other than `NSTextAlternatives`) to represent text
alternatives when using dictation or scribble. To do this, we add a new typedef,
`PlatformTextAlternatives`, that represents the appropriate platform-specific text alternative class
to use, and deploy it throughout WebCore and WebKit.

* Source/WebCore/PAL/pal/spi/cocoa/NSAttributedStringSPI.h:

Remove a soft-linked symbol that's no longer necessary.

* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/editing/cocoa/AlternativeTextContextController.h:
* Source/WebCore/editing/cocoa/AlternativeTextContextController.mm:
(WebCore::AlternativeTextContextController::addAlternatives):
(WebCore::AlternativeTextContextController::replaceAlternatives):
(WebCore::AlternativeTextContextController::alternativesForContext const):

Deploy `PlatformTextAlternatives` in place of `NSTextAlternatives`.

* Source/WebCore/editing/cocoa/AlternativeTextUIController.h:
* Source/WebCore/editing/cocoa/AlternativeTextUIController.mm:
(WebCore::AlternativeTextUIController::addAlternatives):
(WebCore::AlternativeTextUIController::replaceAlternatives):
(WebCore::AlternativeTextUIController::alternativesForContext):
(WebCore::AlternativeTextUIController::showAlternatives):
(WebCore::AlternativeTextUIController::handleAcceptedAlternative):
* Source/WebCore/editing/mac/TextAlternativeWithRange.h:
* Source/WebCore/editing/mac/TextAlternativeWithRange.mm:
(WebCore::TextAlternativeWithRange::TextAlternativeWithRange):
* Source/WebCore/platform/cocoa/PlatformTextAlternatives.h: Copied from Source/WebCore/editing/mac/TextAlternativeWithRange.h.
* Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h:
* Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm:
(WebKit::PageClientImplCocoa::addDictationAlternatives):
(WebKit::PageClientImplCocoa::replaceDictationAlternatives):
(WebKit::PageClientImplCocoa::platformDictationAlternatives):
* Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::platformDictationAlternatives):
* Source/WebKit/UIProcess/PageClient.h:
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/ios/PageClientImplIOS.h:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView alternativesForSelectedText]):

It's possible for UIKit to ask for `NSTextAlternatives` in some configurations, despite the actual
`PlatformTextAlternatives` class being available (in particular, when async text input is disabled).
Maintain binary compatibility in this case by converting from `PlatformTextAlternative` back to
`NSTextAlternative` if needed.

(-[WKContentView insertText:alternatives:style:]):
(-[WKContentView addTextAlternatives:]):

Similar to the above; maintain binary compatibility in the case where async text input is disabled,
by converting `NSTextAlternatives` to `PlatformTextAlternatives` if needed.

(-[WKContentView removeEmojiAlternatives]):
* Source/WebKitLegacy/mac/WebView/WebView.mm:

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




More information about the webkit-changes mailing list