Skip to content

Commit

Permalink
[iOS] Stop conforming to private UIKit ObjC protocols when "Async UIK…
Browse files Browse the repository at this point in the history
…it Interactions" is enabled

https://bugs.webkit.org/show_bug.cgi?id=263813
rdar://117611037

Reviewed by Aditya Keerthi.

Refactor UIKit async interaction support:

•   Rename `HAVE(UI_ASYNC_TEXT_INPUT)` to `HAVE(UI_ASYNC_TEXT_INTERACTION)`, and guard compile-time
    enablement on the availability of `UIAsyncTextInteraction.h`. This allows us to remain source-
    compatible with versions of UIKit that have slightly-older versions of `UIAsyncTextInput.h`,
    that are missing a declaration of `UITextReplacementOptions`.

•   Stop declaring conformance at compile-time to the following 5 SPI protocols, from UIKit:
      • `UIWKInteractionViewProtocol`
      • `UITextInputPrivate`
      • `UITextAutoscrolling`
      • `UITextInputMultiDocument`
      • `UITextInputTranslationSupport`
    ...and instead, conform to these protocols only when the `UseAsyncUIKitInteractions` internal
    preference is disabled.

•   Make this logic run once, immediately upon content view initialization, to limit any risk that
    any logic that depends on the content view conforming to any of these protocols might be broken
    after this refactoring.

This will put us in a position where we can easily test against versions of UIKit that have system
support for `UIAsyncTextInput`, while revealing any interactions or features that might still be
relying on the 5 protocols listed above. It also puts us in a better position to completely remove
reliance on those protocols once the `UseAsyncUIKitInteractions` preference is enabled by default,
simply by removing the logic to establish conformance at runtime.

* Source/WTF/wtf/PlatformHave.h:
* Source/WebCore/platform/ios/WebEvent.mm:
* Source/WebCore/platform/ios/WebEventPrivate.h:
* Source/WebKit/Platform/spi/ios/UIKitSPI.h:
* Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h:
* Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm:
(-[WKWebView _requestDocumentContext:completionHandler:]): Deleted.
(-[WKWebView _adjustSelectionWithDelta:completionHandler:]): Deleted.
(-[WKWebView applyAutocorrection:toString:withCompletionHandler:]): Deleted.
(-[WKWebView applyAutocorrection:toString:isCandidate:withCompletionHandler:]): Deleted.
* Source/WebKit/UIProcess/ios/WKContentView.mm:
(-[WKContentView _commonInitializationWithProcessPool:configuration:]):
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _updateRuntimeProtocolConformanceIfNeeded]):
(-[WKContentView setUpInteraction]):
(-[WKContentView _interpretKeyEvent:isCharEvent:]):
(-[WKContentView _ensureBinaryCompatibilityWithAsyncInteractionsIfNeeded]): Deleted.

Rename this to `-_updateRuntimeProtocolConformanceIfNeeded`, to better reflect its new role, now
that it adds protocol conformance to several legacy UIKit protocols at runtime.

* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::dispatchWheelEventWithoutScrolling):
* Tools/TestRunnerShared/spi/UIKitSPIForTesting.h:

Move the protocol declarations out of `UIKitSPI.h`, and into `UIKitSPIForTesting.h`.

* Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:
(-[TestWKWebView synchronouslyRequestDocumentContext:]):
(-[TestWKWebView synchronouslyAdjustSelectionWithDelta:]):
* Tools/TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm:
* Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptControllerIOS::applyAutocorrection):

Adjust some test infrastructure to stop using the deleted testing hooks, and instead just call into
`WKContentView` directly, like most of the other API tests already do.

Canonical link: https://commits.webkit.org/270027@main
  • Loading branch information
whsieh committed Oct 31, 2023
1 parent 54e6bfa commit 00b1201
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 97 deletions.
4 changes: 4 additions & 0 deletions Source/WTF/wtf/PlatformHave.h
Original file line number Diff line number Diff line change
Expand Up @@ -1667,3 +1667,7 @@
#if !PLATFORM(APPLETV) && !PLATFORM(WATCHOS) && __has_include(<UIKit/_UITextCursorDragAnimator.h>)
#define HAVE_UI_TEXT_CURSOR_DRAG_ANIMATOR 1
#endif

#if __has_include(<UIKit/UIAsyncTextInteraction.h>)
#define HAVE_UI_ASYNC_TEXT_INTERACTION 1
#endif
6 changes: 3 additions & 3 deletions Source/WebCore/platform/ios/WebEvent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
using WebCore::windowsKeyCodeForCharCode;

@implementation WebEvent {
#if HAVE(UI_ASYNC_TEXT_INPUT)
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
RetainPtr<UIKeyEvent> _originalUIKeyEvent;
#endif
}
Expand Down Expand Up @@ -493,7 +493,7 @@ + (WebEventFlags)modifierFlags

@end

#if HAVE(UI_ASYNC_TEXT_INPUT)
#if HAVE(UI_ASYNC_TEXT_INTERACTION)

@implementation WebEvent (UIAsyncTextInputSupport)

Expand Down Expand Up @@ -553,6 +553,6 @@ - (UIKeyEvent *)originalUIKeyEvent

@end

#endif // HAVE(UI_ASYNC_TEXT_INPUT)
#endif // HAVE(UI_ASYNC_TEXT_INTERACTION)

#endif // PLATFORM(IOS_FAMILY)
4 changes: 2 additions & 2 deletions Source/WebCore/platform/ios/WebEventPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#import <WebCore/WebEvent.h>

#if HAVE(UI_ASYNC_TEXT_INPUT)
#if HAVE(UI_ASYNC_TEXT_INTERACTION)

@class UIKeyEvent;

Expand All @@ -38,4 +38,4 @@

@end

#endif // HAVE(UI_ASYNC_TEXT_INPUT)
#endif // HAVE(UI_ASYNC_TEXT_INTERACTION)
9 changes: 1 addition & 8 deletions Source/WebKit/Platform/spi/ios/UIKitSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
#import <UIKit/_UITextDragCaretView.h>
#endif

#if HAVE(UI_ASYNC_TEXT_INPUT)
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
#import <UIKit/UIAsyncTextInput.h>
#import <UIKit/UIKeyEventContext.h>
#endif
Expand Down Expand Up @@ -713,11 +713,6 @@ typedef NS_ENUM(NSInteger, UIWKGestureType) {
@class UIWKDocumentContext;

@protocol UIWKInteractionViewProtocol
#if HAVE(UI_WK_DOCUMENT_CONTEXT)
- (void)adjustSelectionWithDelta:(NSRange)deltaRange completionHandler:(void (^)(void))completionHandler;
- (void)requestDocumentContext:(UIWKDocumentRequest *)request completionHandler:(void (^)(UIWKDocumentContext *))completionHandler;
- (void)selectPositionAtPoint:(CGPoint)point withContextRequest:(UIWKDocumentRequest *)request completionHandler:(void (^)(UIWKDocumentContext *))completionHandler;
#endif

- (void)changeSelectionWithGestureAt:(CGPoint)point withGesture:(UIWKGestureType)gestureType withState:(UIGestureRecognizerState)state;
- (void)changeSelectionWithTouchAt:(CGPoint)point withSelectionTouch:(UIWKSelectionTouch)touch baseIsStart:(BOOL)baseIsStart withFlags:(UIWKSelectionFlags)flags;
Expand All @@ -729,8 +724,6 @@ typedef NS_ENUM(NSInteger, UIWKGestureType) {

- (void)requestAutocorrectionRectsForString:(NSString *)input withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForInput))completionHandler;

- (void)applyAutocorrection:(NSString *)correction toString:(NSString *)input withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForCorrection))completionHandler;

- (NSString *)markedText;
- (BOOL)hasMarkedText;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,10 @@
- (void)_focusTextInputContext:(_WKTextInputContext *)context placeCaretAt:(CGPoint)point completionHandler:(void (^)(UIResponder<UITextInput> *))completionHandler;
- (void)_willBeginTextInteractionInTextInputContext:(_WKTextInputContext *)context;
- (void)_didFinishTextInteractionInTextInputContext:(_WKTextInputContext *)context;
- (void)_requestDocumentContext:(UIWKDocumentRequest *)request completionHandler:(void (^)(UIWKDocumentContext *))completionHandler;
- (void)_adjustSelectionWithDelta:(NSRange)deltaRange completionHandler:(void (^)(void))completionHandler;
- (void)setTimePickerValueToHour:(NSInteger)hour minute:(NSInteger)minute;
- (double)timePickerValueHour;
- (double)timePickerValueMinute;

- (void)applyAutocorrection:(NSString *)newString toString:(NSString *)oldString withCompletionHandler:(void (^)(void))completionHandler;
- (void)applyAutocorrection:(NSString *)newString toString:(NSString *)oldString isCandidate:(BOOL)isCandidate withCompletionHandler:(void (^)(void))completionHandler;

- (NSDictionary *)_propertiesOfLayerWithID:(unsigned long long)layerID;
- (void)_simulateElementAction:(_WKElementActionType)actionType atLocation:(CGPoint)location;
- (void)_simulateLongPressActionAtLocation:(CGPoint)location;
Expand Down
33 changes: 0 additions & 33 deletions Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,6 @@ - (void)_didFinishTextInteractionInTextInputContext:(_WKTextInputContext *)conte
[_contentView _didFinishTextInteractionInTextInputContext:context];
}

- (void)_requestDocumentContext:(UIWKDocumentRequest *)request completionHandler:(void (^)(UIWKDocumentContext *))completionHandler
{
#if HAVE(UI_WK_DOCUMENT_CONTEXT)
[_contentView requestDocumentContext:request completionHandler:completionHandler];
#else
completionHandler(nil);
#endif
}

- (void)_adjustSelectionWithDelta:(NSRange)deltaRange completionHandler:(void (^)(void))completionHandler
{
#if HAVE(UI_WK_DOCUMENT_CONTEXT)
[_contentView adjustSelectionWithDelta:deltaRange completionHandler:completionHandler];
#else
completionHandler();
#endif
}

- (BOOL)_mayContainEditableElementsInRect:(CGRect)rect
{
#if ENABLE(EDITABLE_REGION)
Expand All @@ -134,21 +116,6 @@ - (void)keyboardAccessoryBarPrevious
[_contentView accessoryTab:NO];
}

- (void)applyAutocorrection:(NSString *)newString toString:(NSString *)oldString withCompletionHandler:(void (^)(void))completionHandler
{
[_contentView applyAutocorrection:newString toString:oldString withCompletionHandler:[capturedCompletionHandler = makeBlockPtr(completionHandler)] (UIWKAutocorrectionRects *rects) {
capturedCompletionHandler();
}];
}

- (void)applyAutocorrection:(NSString *)newString toString:(NSString *)oldString isCandidate:(BOOL)isCandidate withCompletionHandler:(void (^)(void))completionHandler
{
[_contentView applyAutocorrection:newString toString:oldString isCandidate:isCandidate withCompletionHandler:[capturedCompletionHandler = makeBlockPtr(completionHandler)] (UIWKAutocorrectionRects *rects) {
capturedCompletionHandler();
}];
}


- (void)dismissFormAccessoryView
{
[_contentView dismissFormAccessoryView];
Expand Down
3 changes: 3 additions & 0 deletions Source/WebKit/UIProcess/ios/WKContentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ - (instancetype)_commonInitializationWithProcessPool:(WebKit::WebProcessPool&)pr

_page = processPool.createWebPage(*_pageClient, WTFMove(configuration));
_page->initializeWebPage();

[self _updateRuntimeProtocolConformanceIfNeeded];

_page->setIntrinsicDeviceScaleFactor(WebCore::screenScaleFactor([UIScreen mainScreen]));
_page->setUseFixedLayout(true);
_page->setScreenIsBeingCaptured([[[self window] screen] isCaptured]);
Expand Down
11 changes: 8 additions & 3 deletions Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,22 +559,22 @@ struct ImageAnalysisContextMenuActionData {
WebCore::FloatRect _imageAnalysisInteractionBounds;
std::optional<WebKit::RemoveBackgroundData> _removeBackgroundData;
#endif
#if HAVE(UI_ASYNC_TEXT_INPUT)
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
__weak id<UIAsyncTextInputDelegate> _asyncSystemInputDelegate;
#endif
}

@end

@interface WKContentView (WKInteraction) <UIGestureRecognizerDelegate, UITextAutoscrolling, UITextInputMultiDocument, UITextInputPrivate, WKFormAccessoryViewDelegate, WKTouchEventsGestureRecognizerDelegate, UIWKInteractionViewProtocol, _UITextInputTranslationSupport, WKActionSheetAssistantDelegate, WKFileUploadPanelDelegate, WKKeyboardScrollViewAnimatorDelegate, WKDeferringGestureRecognizerDelegate
@interface WKContentView (WKInteraction) <UIGestureRecognizerDelegate, UITextInput, WKFormAccessoryViewDelegate, WKTouchEventsGestureRecognizerDelegate, WKActionSheetAssistantDelegate, WKFileUploadPanelDelegate, WKKeyboardScrollViewAnimatorDelegate, WKDeferringGestureRecognizerDelegate
#if HAVE(CONTACTSUI)
, WKContactPickerDelegate
#endif
#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
, WKShareSheetDelegate
#endif
#if ENABLE(DRAG_SUPPORT)
, UIDragInteractionDelegate, UIDropInteractionDelegate
, UIDropInteractionDelegate
#endif
, WKTouchActionGestureRecognizerDelegate
#if HAVE(UIFINDINTERACTION)
Expand All @@ -585,6 +585,8 @@ struct ImageAnalysisContextMenuActionData {
#endif
#if HAVE(UI_ASYNC_DRAG_INTERACTION)
, _UIAsyncDragInteractionDelegate
#elif ENABLE(DRAG_SUPPORT)
, UIDragInteractionDelegate
#endif
>

Expand All @@ -608,6 +610,7 @@ struct ImageAnalysisContextMenuActionData {
@property (nonatomic, readonly) CGRect tapHighlightViewRect;
@property (nonatomic, readonly) UIGestureRecognizer *imageAnalysisGestureRecognizer;
@property (nonatomic, readonly, getter=isKeyboardScrollingAnimationRunning) BOOL keyboardScrollingAnimationRunning;
@property (nonatomic, readonly) UIView *unscaledView;

#if ENABLE(DATALIST_ELEMENT)
@property (nonatomic, strong) UIView <WKFormControl> *dataListTextSuggestionsInputView;
Expand Down Expand Up @@ -762,6 +765,8 @@ FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW)
- (void)_didExitFullscreen;
#endif

- (void)_updateRuntimeProtocolConformanceIfNeeded;

- (void)_requestTextInputContextsInRect:(CGRect)rect completionHandler:(void (^)(NSArray<_WKTextInputContext *> *))completionHandler;
- (void)_focusTextInputContext:(_WKTextInputContext *)context placeCaretAt:(CGPoint)point completionHandler:(void (^)(UIResponder<UITextInput> *))completionHandler;
- (void)_willBeginTextInteractionInTextInputContext:(_WKTextInputContext *)context;
Expand Down
82 changes: 47 additions & 35 deletions Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
#define UIWKDocumentRequestAutocorrectedRanges (1 << 7)
#endif

#if HAVE(UI_ASYNC_TEXT_INPUT)
#if HAVE(UI_ASYNC_TEXT_INTERACTION)

@interface WKUITextSelectionRect : UITextSelectionRect
+ (instancetype)selectionRectWithCGRect:(CGRect)rect;
Expand Down Expand Up @@ -232,7 +232,7 @@ - (CGRect)rect

@end

#endif // HAVE(UI_ASYNC_TEXT_INPUT)
#endif // HAVE(UI_ASYNC_TEXT_INTERACTION)

#if HAVE(LINK_PREVIEW) && USE(UICONTEXTMENU)
static NSString * const webkitShowLinkPreviewsPreferenceKey = @"WebKitShowLinkPreviews";
Expand Down Expand Up @@ -974,37 +974,51 @@ - (BOOL)_shouldUseTextCursorDragAnimator
#endif
}

- (void)_ensureBinaryCompatibilityWithAsyncInteractionsIfNeeded
- (void)_updateRuntimeProtocolConformanceIfNeeded
{
static std::once_flag onceFlag;
std::call_once(onceFlag, ^{
#if HAVE(UI_ASYNC_TEXT_INPUT)
if (_page->preferences().useAsyncUIKitInteractions()) {
class_addProtocol(self.class, @protocol(UIAsyncTextInput));
unsigned methodCount = 0;
using MethodDescriptionList = objc_method_description[];
auto methods = std::unique_ptr<MethodDescriptionList, WTF::SystemFree<MethodDescriptionList>> {
protocol_copyMethodDescriptionList(@protocol(UIAsyncTextInput), NO, YES, &methodCount)
};
for (unsigned i = 0; i < methodCount; i++) {
if (![self.class instancesRespondToSelector:methods[i].name])
RELEASE_LOG_ERROR(TextInteraction, "Warning: -[UIAsyncTextInput %s] is unimplemented", sel_getName(methods[i].name));
}
static bool hasUpdatedProtocolConformance = false;
if (std::exchange(hasUpdatedProtocolConformance, true))
return;

bool shouldConformToLegacyPrivateProtocols = true;
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
if (_page->preferences().useAsyncUIKitInteractions()) {
RELEASE_LOG(TextInteraction, "Conforming to UIAsyncTextInput");
class_addProtocol(self.class, @protocol(UIAsyncTextInput));
unsigned methodCount = 0;
using MethodDescriptionList = objc_method_description[];
auto methods = std::unique_ptr<MethodDescriptionList, WTF::SystemFree<MethodDescriptionList>> {
protocol_copyMethodDescriptionList(@protocol(UIAsyncTextInput), NO, YES, &methodCount)
};
for (unsigned i = 0; i < methodCount; i++) {
if (![self.class instancesRespondToSelector:methods[i].name])
RELEASE_LOG_ERROR(TextInteraction, "Warning: -[UIAsyncTextInput %s] is unimplemented", sel_getName(methods[i].name));
}
#endif // HAVE(UI_ASYNC_TEXT_INPUT)
shouldConformToLegacyPrivateProtocols = false;
}
#endif // HAVE(UI_ASYNC_TEXT_INTERACTION)

if (shouldConformToLegacyPrivateProtocols) {
RELEASE_LOG(TextInteraction, "Conforming to legacy UIKit interaction and text input protocols");
class_addProtocol(self.class, @protocol(UIWKInteractionViewProtocol));
class_addProtocol(self.class, @protocol(UITextInputPrivate));
class_addProtocol(self.class, @protocol(UITextAutoscrolling));
class_addProtocol(self.class, @protocol(UITextInputMultiDocument));
class_addProtocol(self.class, @protocol(_UITextInputTranslationSupport));
}

#if USE(UICONTEXTMENU)
if (!self._shouldUseUIContextMenuAsyncConfiguration) {
// Only fall back to the legacy asynchronous delegate method when UI_CONTEXT_MENU_ASYNC_CONFIGURATION
// is set, if the requisite class is unavailable at runtime (i.e. older builds that do not have the
// changes in <rdar://112292302>.
auto legacyAsyncConfigurationSelector = @selector(_contextMenuInteraction:configurationForMenuAtLocation:completion:);
auto internalAsyncConfigurationSelector = @selector(_internalContextMenuInteraction:configurationForMenuAtLocation:completion:);
auto internalMethod = class_getInstanceMethod(self.class, internalAsyncConfigurationSelector);
auto internalImplementation = method_getImplementation(internalMethod);
class_addMethod(self.class, legacyAsyncConfigurationSelector, internalImplementation, method_getTypeEncoding(internalMethod));
}
if (!self._shouldUseUIContextMenuAsyncConfiguration) {
// Only fall back to the legacy asynchronous delegate method when UI_CONTEXT_MENU_ASYNC_CONFIGURATION
// is set, if the requisite class is unavailable at runtime (i.e. older builds that do not have the
// changes in <rdar://112292302>.
auto legacyAsyncConfigurationSelector = @selector(_contextMenuInteraction:configurationForMenuAtLocation:completion:);
auto internalAsyncConfigurationSelector = @selector(_internalContextMenuInteraction:configurationForMenuAtLocation:completion:);
auto internalMethod = class_getInstanceMethod(self.class, internalAsyncConfigurationSelector);
auto internalImplementation = method_getImplementation(internalMethod);
class_addMethod(self.class, legacyAsyncConfigurationSelector, internalImplementation, method_getTypeEncoding(internalMethod));
}
#endif // USE(UICONTEXTMENU)
});
}

- (void)setUpInteraction
Expand All @@ -1016,8 +1030,6 @@ - (void)setUpInteraction
if (_hasSetUpInteractions)
return;

[self _ensureBinaryCompatibilityWithAsyncInteractionsIfNeeded];

_cachedHasCustomTintColor = std::nullopt;

if (!_interactionViewsContainerView) {
Expand Down Expand Up @@ -6771,14 +6783,14 @@ - (BOOL)_interpretKeyEvent:(::WebEvent *)event isCharEvent:(BOOL)isCharEvent
if ([_keyboardScrollingAnimator beginWithEvent:event] || [_keyboardScrollingAnimator scrollTriggeringKeyIsPressed])
return YES;

#if HAVE(UI_ASYNC_TEXT_INPUT)
#if HAVE(UI_ASYNC_TEXT_INTERACTION)
if (auto systemDelegate = retainPtr(_asyncSystemInputDelegate)) {
auto context = adoptNS([allocUIKeyEventContextInstance() initWithKeyEvent:event.originalUIKeyEvent]);
[context setDocumentIsEditable:_page->editorState().isContentEditable];
[context setShouldInsertChar:isCharEvent];
return [systemDelegate deferEventHandlingToSystemWithContext:context.get()];
}
#endif // HAVE(UI_ASYNC_TEXT_INPUT)
#endif // HAVE(UI_ASYNC_TEXT_INTERACTION)

if (event.keyboardFlags & WebEventKeyboardInputModifierFlagsChanged)
return NO;
Expand Down Expand Up @@ -12016,7 +12028,7 @@ - (void)willDismissEditMenuWithAnimator:(id<UIEditMenuInteractionAnimating>)anim

#endif // HAVE(UI_EDIT_MENU_INTERACTION)

#if HAVE(UI_ASYNC_TEXT_INPUT)
#if HAVE(UI_ASYNC_TEXT_INTERACTION)

#pragma mark - UIAsyncTextInput (and related)

Expand Down Expand Up @@ -12069,7 +12081,7 @@ - (UIView *)textInputView
return self;
}

#endif // HAVE(UI_ASYNC_TEXT_INPUT)
#endif // HAVE(UI_ASYNC_TEXT_INTERACTION)

@end

Expand Down
9 changes: 9 additions & 0 deletions Tools/TestRunnerShared/spi/UIKitSPIForTesting.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ typedef NS_ENUM(NSInteger, UIWKGestureType) {
- (BOOL)textInteractionGesture:(UIWKGestureType)gesture shouldBeginAtPoint:(CGPoint)point;
- (void)replaceDictatedText:(NSString *)oldText withText:(NSString *)newText;
- (NSArray<NSTextAlternatives *> *)alternativesForSelectedText;

- (void)applyAutocorrection:(NSString *)correction toString:(NSString *)input shouldUnderline:(BOOL)shouldUnderline withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForCorrection))completionHandler;

#if HAVE(UI_WK_DOCUMENT_CONTEXT)
- (void)requestDocumentContext:(UIWKDocumentRequest *)request completionHandler:(void (^)(UIWKDocumentContext *))completionHandler;
- (void)adjustSelectionWithDelta:(NSRange)deltaRange completionHandler:(void (^)(void))completionHandler;
- (void)selectPositionAtPoint:(CGPoint)point withContextRequest:(UIWKDocumentRequest *)request completionHandler:(void (^)(UIWKDocumentContext *))completionHandler;
#endif

@property (nonatomic, readonly) NSString *selectedText;

@optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ - (UIWKDocumentContext *)synchronouslyRequestDocumentContext:(UIWKDocumentReques
{
__block bool finished = false;
__block RetainPtr<UIWKDocumentContext> result;
[self _requestDocumentContext:request completionHandler:^(UIWKDocumentContext *context) {
[self.textInputContentView requestDocumentContext:request completionHandler:^(UIWKDocumentContext *context) {
result = context;
finished = true;
}];
Expand All @@ -161,7 +161,7 @@ - (UIWKDocumentContext *)synchronouslyRequestDocumentContext:(UIWKDocumentReques
- (void)synchronouslyAdjustSelectionWithDelta:(NSRange)range
{
__block bool finished = false;
[self _adjustSelectionWithDelta:range completionHandler:^() {
[self.textInputContentView adjustSelectionWithDelta:range completionHandler:^{
finished = true;
}];
TestWebKitAPI::Util::run(&finished);
Expand Down Expand Up @@ -1568,7 +1568,7 @@ static void checkThatAllCharacterRectsAreConsistentWithSelectionRects(TestWKWebV
[webView waitForNextPresentationUpdate];

__block bool appliedAutocorrection = false;
[webView applyAutocorrection:@"San Francisco" toString:@"sanfrancisco" isCandidate:YES withCompletionHandler:^{
[[webView textInputContentView] applyAutocorrection:@"San Francisco" toString:@"sanfrancisco" shouldUnderline:YES withCompletionHandler:^(UIWKAutocorrectionRects *) {
appliedAutocorrection = true;
}];

Expand All @@ -1584,7 +1584,7 @@ static void checkThatAllCharacterRectsAreConsistentWithSelectionRects(TestWKWebV
[contentView insertText:@" atfer"];

appliedAutocorrection = false;
[webView applyAutocorrection:@"after" toString:@"atfer" isCandidate:YES withCompletionHandler:^{
[[webView textInputContentView] applyAutocorrection:@"after" toString:@"atfer" shouldUnderline:YES withCompletionHandler:^(UIWKAutocorrectionRects *) {
appliedAutocorrection = true;
}];

Expand Down
Loading

0 comments on commit 00b1201

Please sign in to comment.