Skip to content

Commit

Permalink
[iOS] Support text selection and interaction using UIAsyncTextInterac…
Browse files Browse the repository at this point in the history
…tion

https://bugs.webkit.org/show_bug.cgi?id=264094
rdar://117857833

Reviewed by Aditya Keerthi.

Implement the remaining set of methods on `WKTextInteractionWrapper`, in the case where the wrapper
is backed by `UIAsyncTextInteraction`. This enables basic text interactions (such as multi-tap,
range adjustment, and tap-and-half gestures), as well as context menu interactions for links and
images in the page, and finally the ability to temporarily suppress the text selection when we're
either inside of a hidden editable container, or while the selection is inside of a scrolling
overflow container.

Depends on the changes in rdar://117831560 as well.

* Source/WebKit/Platform/spi/ios/UIKitSPI.h:
* Source/WebKit/UIProcess/ios/WKTextInteractionWrapper.mm:
(-[WKTextInteractionWrapper activateSelection]):
(-[WKTextInteractionWrapper deactivateSelection]):
(-[WKTextInteractionWrapper selectionChanged]):
(-[WKTextInteractionWrapper setGestureRecognizers]):
(-[WKTextInteractionWrapper willStartScrollingOverflow]):
(-[WKTextInteractionWrapper didEndScrollingOverflow]):
(-[WKTextInteractionWrapper willStartScrollingOrZooming]):
(-[WKTextInteractionWrapper didEndScrollingOrZooming]):
(-[WKTextInteractionWrapper contextMenuInteraction]):
(-[WKTextInteractionWrapper setExternalContextMenuInteractionDelegate:]):

Canonical link: https://commits.webkit.org/270296@main
  • Loading branch information
whsieh committed Nov 7, 2023
1 parent 6fa5837 commit 3805718
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Source/WebKit/Platform/spi/ios/UIKitSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,27 @@ typedef NS_ENUM(NSUInteger, _UIScrollDeviceCategory) {
@end
#endif

#if HAVE(UI_ASYNC_TEXT_INTERACTION)

@interface UIAsyncTextInteraction (Staging_117831560)

- (void)presentEditMenuForSelection;
- (void)dismissEditMenuForSelection;

- (void)selectionChanged;
- (void)editabilityChanged;

@property (nonatomic, readonly) UITextSelectionDisplayInteraction *textSelectionDisplayInteraction;

#if USE(UICONTEXTMENU)
@property (nonatomic, weak) id<UIContextMenuInteractionDelegate> contextMenuInteractionDelegate;
@property (nonatomic, readonly) UIContextMenuInteraction *contextMenuInteraction;
#endif

@end

#endif // HAVE(UI_ASYNC_TEXT_INTERACTION)

WTF_EXTERN_C_BEGIN

BOOL UIKeyboardEnabledInputModesAllowOneToManyShortcuts(void);
Expand Down
33 changes: 33 additions & 0 deletions Source/WebKit/UIProcess/ios/WKTextInteractionWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,67 @@ - (UIWKTextInteractionAssistant *)textInteractionAssistant
- (void)activateSelection
{
[_textInteractionAssistant activateSelection];
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
[_asyncTextInteraction textSelectionDisplayInteraction].activated = YES;
#endif
}

- (void)deactivateSelection
{
[_textInteractionAssistant deactivateSelection];
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
[_asyncTextInteraction textSelectionDisplayInteraction].activated = NO;
#endif
}

- (void)selectionChanged
{
[_textInteractionAssistant selectionChanged];
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
[_asyncTextInteraction selectionChanged];
#endif
}

- (void)setGestureRecognizers
{
[_textInteractionAssistant setGestureRecognizers];
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
[_asyncTextInteraction editabilityChanged];
#endif
}

- (void)willStartScrollingOverflow
{
[_textInteractionAssistant willStartScrollingOverflow];
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
[_asyncTextInteraction dismissEditMenuForSelection];
[_asyncTextInteraction textSelectionDisplayInteraction].activated = NO;
#endif
}

- (void)didEndScrollingOverflow
{
[_textInteractionAssistant didEndScrollingOverflow];
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
[_asyncTextInteraction presentEditMenuForSelection];
[_asyncTextInteraction textSelectionDisplayInteraction].activated = YES;
#endif
}

- (void)willStartScrollingOrZooming
{
[_textInteractionAssistant willStartScrollingOrZooming];
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
[_asyncTextInteraction dismissEditMenuForSelection];
#endif
}

- (void)didEndScrollingOrZooming
{
[_textInteractionAssistant didEndScrollingOrZooming];
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
[_asyncTextInteraction presentEditMenuForSelection];
#endif
}

- (void)selectionChangedWithGestureAt:(CGPoint)point withGesture:(UIWKGestureType)gestureType withState:(UIGestureRecognizerState)gestureState withFlags:(UIWKSelectionFlags)flags
Expand Down Expand Up @@ -190,12 +216,19 @@ - (void)selectAll:(id)sender

- (UIContextMenuInteraction *)contextMenuInteraction
{
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
if (_asyncTextInteraction)
return [_asyncTextInteraction contextMenuInteraction];
#endif
return [_textInteractionAssistant contextMenuInteraction];
}

- (void)setExternalContextMenuInteractionDelegate:(id<UIContextMenuInteractionDelegate>)delegate
{
[_textInteractionAssistant setExternalContextMenuInteractionDelegate:delegate];
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
[_asyncTextInteraction setContextMenuInteractionDelegate:delegate];
#endif
}

#endif // USE(UICONTEXTMENU)
Expand Down

0 comments on commit 3805718

Please sign in to comment.