Skip to content

Commit

Permalink
[UIAsyncTextInput] Adopt new unprefixed responder action names
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265117
rdar://118631896

Reviewed by Megan Gardner.

Adopt the following unprefixed responder action selector names:

`-_addShortcut:`            →    `-addShortcut:`
`-_define:`                 →    `-define:`
`-_promptForReplace:`       →    `-promptForReplace:`
`-_share:`                  →    `-share:`
`-_translate:`              →    `-translate:`
`-_transliterateChinese:`   →    `-transliterateChinese:`
`-_findSelected:`           →    `-findSelected:`

...while maintaining compatibility with the legacy, underscore-prefixed versions.

* Source/WebKit/Platform/spi/ios/UIKitSPI.h:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _lookupForWebView:]):

Since `-_lookup:` was only used as an alias for `_define:`, there's no new, unprefixed name that
corresponds to this selector. Instead, we simply call through to `-defineForWebView:`.

(-[WKContentView defineForWebView:]):
(-[WKContentView _shareForWebView:]):
(-[WKContentView shareForWebView:]):
(-[WKContentView _translateForWebView:]):
(-[WKContentView translateForWebView:]):
(-[WKContentView _addShortcutForWebView:]):
(-[WKContentView addShortcutForWebView:]):
(-[WKContentView _promptForReplaceForWebView:]):
(-[WKContentView promptForReplaceForWebView:]):

Add the corresponding unprefixed `-actionForWebView:` methods on the content view as well, and make
the legacy underscore-prefixed methods wrap these new names (while release asserting that the async
text input feature flag is disabled).

(-[WKContentView _transliterateChineseForWebView:]):
(-[WKContentView transliterateChineseForWebView:]):
(-[WKContentView canPerformActionForWebView:withSender:]):
(-[WKContentView _defineForWebView:]):
(-[WKContentView _findSelectedForWebView:]):
(-[WKContentView findSelectedForWebView:]):

Canonical link: https://commits.webkit.org/271119@main
  • Loading branch information
whsieh committed Nov 26, 2023
1 parent 0a64dd5 commit 8c078c7
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 8 deletions.
15 changes: 15 additions & 0 deletions Source/WebKit/Platform/spi/ios/UIKitSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,21 @@ typedef struct {

#endif // HAVE(UI_ASYNC_TEXT_INTERACTION)

@interface UIResponder (Staging_118307086)

- (void)addShortcut:(id)sender;
- (void)define:(id)sender;
- (void)promptForReplace:(id)sender;
- (void)share:(id)sender;
- (void)translate:(id)sender;
- (void)transliterateChinese:(id)sender;

#if HAVE(UIFINDINTERACTION)
- (void)findSelected:(id)sender;
#endif

@end

WTF_EXTERN_C_BEGIN

BOOL UIKeyboardEnabledInputModesAllowOneToManyShortcuts(void);
Expand Down
7 changes: 7 additions & 0 deletions Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ typedef std::pair<WebKit::InteractionInformationRequest, InteractionInformationC
#if HAVE(UIFINDINTERACTION)
#define FOR_EACH_FIND_WKCONTENTVIEW_ACTION(M) \
M(useSelectionForFind) \
M(findSelected) \
M(_findSelected)
#else
#define FOR_EACH_FIND_WKCONTENTVIEW_ACTION(M)
Expand All @@ -171,12 +172,18 @@ typedef std::pair<WebKit::InteractionInformationRequest, InteractionInformationC
#define FOR_EACH_WKCONTENTVIEW_ACTION(M) \
FOR_EACH_INSERT_TEXT_FROM_CAMERA_WKCONTENTVIEW_ACTION(M) \
FOR_EACH_FIND_WKCONTENTVIEW_ACTION(M) \
M(addShortcut) \
M(_addShortcut) \
M(define) \
M(_define) \
M(_lookup) \
M(translate) \
M(_translate) \
M(promptForReplace) \
M(_promptForReplace) \
M(share) \
M(_share) \
M(transliterateChinese) \
M(_transliterateChinese) \
M(_nextAccessoryTab) \
M(_previousAccessoryTab) \
Expand Down
67 changes: 59 additions & 8 deletions Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3964,6 +3964,13 @@ - (void)_action:(id)sender \
#undef FORWARD_ACTION_TO_WKWEBVIEW

- (void)_lookupForWebView:(id)sender
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

[self defineForWebView:sender];
}

- (void)defineForWebView:(id)sender
{
_page->getSelectionContext([view = retainPtr(self)](const String& selectedText, const String& textBefore, const String& textAfter) {
if (!selectedText)
Expand All @@ -3988,6 +3995,13 @@ - (void)_lookupForWebView:(id)sender
}

- (void)_shareForWebView:(id)sender
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

[self shareForWebView:sender];
}

- (void)shareForWebView:(id)sender
{
RetainPtr<WKContentView> view = self;
_page->getSelectionOrContentsAsString([view](const String& string) {
Expand All @@ -4003,6 +4017,13 @@ - (void)_shareForWebView:(id)sender
}

- (void)_translateForWebView:(id)sender
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

[self translateForWebView:sender];
}

- (void)translateForWebView:(id)sender
{
_page->getSelectionOrContentsAsString([weakSelf = WeakObjCPtr<WKContentView>(self)] (const String& string) {
if (!weakSelf)
Expand All @@ -4023,6 +4044,13 @@ - (void)_translateForWebView:(id)sender
}

- (void)_addShortcutForWebView:(id)sender
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

[self addShortcutForWebView:sender];
}

- (void)addShortcutForWebView:(id)sender
{
if (!_page->editorState().visualData)
return;
Expand Down Expand Up @@ -4077,6 +4105,13 @@ - (void)replaceText:(NSString *)text withText:(NSString *)word
}

- (void)_promptForReplaceForWebView:(id)sender
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

[self promptForReplaceForWebView:sender];
}

- (void)promptForReplaceForWebView:(id)sender
{
if (!_page->editorState().postLayoutData)
return;
Expand All @@ -4088,6 +4123,13 @@ - (void)_promptForReplaceForWebView:(id)sender
}

- (void)_transliterateChineseForWebView:(id)sender
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

[self transliterateChineseForWebView:sender];
}

- (void)transliterateChineseForWebView:(id)sender
{
if (!_page->editorState().postLayoutData)
return;
Expand Down Expand Up @@ -4399,7 +4441,7 @@ - (BOOL)canPerformActionForWebView:(SEL)action withSender:(id)sender
return editorState.selectionIsRange;
}

if (action == @selector(_define:)) {
if (action == @selector(_define:) || action == @selector(define:)) {
if (editorState.isInPasswordField || !editorState.selectionIsRange)
return NO;

Expand Down Expand Up @@ -4430,14 +4472,14 @@ - (BOOL)canPerformActionForWebView:(SEL)action withSender:(id)sender
return editorState.selectionIsRange;
}

if (action == @selector(_share:)) {
if (action == @selector(_share:) || action == @selector(share:)) {
if (editorState.isInPasswordField || !editorState.selectionIsRange)
return NO;

return editorState.postLayoutData && editorState.postLayoutData->selectedTextLength > 0;
}

if (action == @selector(_addShortcut:)) {
if (action == @selector(_addShortcut:) || action == @selector(addShortcut:)) {
if (editorState.isInPasswordField || !editorState.selectionIsRange)
return NO;

Expand All @@ -4452,22 +4494,22 @@ - (BOOL)canPerformActionForWebView:(SEL)action withSender:(id)sender
return YES;
}

if (action == @selector(_promptForReplace:)) {
if (action == @selector(_promptForReplace:) || action == @selector(promptForReplace:)) {
if (!editorState.selectionIsRange || !editorState.postLayoutData || !editorState.postLayoutData->isReplaceAllowed || ![[UIKeyboardImpl activeInstance] autocorrectSpellingEnabled])
return NO;
if ([[self selectedText] _containsCJScriptsOnly])
return NO;
return YES;
}

if (action == @selector(_transliterateChinese:)) {
if (action == @selector(_transliterateChinese:) || action == @selector(transliterateChinese:)) {
if (!editorState.selectionIsRange || !editorState.postLayoutData || !editorState.postLayoutData->isReplaceAllowed || ![[UIKeyboardImpl activeInstance] autocorrectSpellingEnabled])
return NO;
return UIKeyboardEnabledInputModesAllowChineseTransliterationForText([self selectedText]);
}

#if HAVE(TRANSLATION_UI_SERVICES)
if (action == @selector(_translate:)) {
if (action == @selector(_translate:) || action == @selector(translate:)) {
if (!PAL::isTranslationUIServicesFrameworkAvailable() || ![PAL::getLTUITranslationViewControllerClass() isAvailable])
return NO;
return !editorState.isInPasswordField && editorState.selectionIsRange;
Expand Down Expand Up @@ -4525,7 +4567,7 @@ - (BOOL)canPerformActionForWebView:(SEL)action withSender:(id)sender
#endif // ENABLE(IMAGE_ANALYSIS)

#if HAVE(UIFINDINTERACTION)
if (action == @selector(useSelectionForFind:) || action == @selector(_findSelected:)) {
if (action == @selector(useSelectionForFind:) || action == @selector(findSelected:) || action == @selector(_findSelected:)) {
if (!self.webView._findInteractionEnabled)
return NO;

Expand Down Expand Up @@ -4659,7 +4701,9 @@ - (void)_showDictionary:(NSString *)text

- (void)_defineForWebView:(id)sender
{
[self _lookupForWebView:sender];
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

[self _defineForWebView:sender];
}

- (void)accessibilityRetrieveSpeakSelectionContent
Expand Down Expand Up @@ -11458,6 +11502,13 @@ - (void)useSelectionForFindForWebView:(id)sender
}

- (void)_findSelectedForWebView:(id)sender
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

[self findSelectedForWebView:sender];
}

- (void)findSelectedForWebView:(id)sender
{
[self useSelectionForFindForWebView:sender];
[self.webView find:sender];
Expand Down

0 comments on commit 8c078c7

Please sign in to comment.