Skip to content

Commit

Permalink
[iOS] Remove several unused SPI method implementations in WKContentView
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=260271

Reviewed by Aditya Keerthi.

Remove a couple of unused SPI method implementations:
```
-[UIWKInteractionViewProtocol requestRectsToEvadeForSelectionCommandsWithCompletionHandler:]
-[UIWKInteractionViewProtocol selectWordBackward]
```

...as well as an unused SPI method declaration:

```
-[UIWKInteractionViewProtocol clearSelection]
```

* Source/WebKit/Platform/spi/ios/UIKitSPI.h:
* Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h:
* Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm:
(-[WKWebView selectWordBackwardForTesting]):

Turn this into a testing-only SPI method, instead of using the SPI declaration from conforming to
`UIWKInteractionViewProtocol`.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView requestPreferredArrowDirectionForEditMenuWithCompletionHandler:]):
(-[WKContentView selectWordBackwardForTesting]):
(-[WKContentView selectWordBackward]): Deleted.
(-[WKContentView requestRectsToEvadeForSelectionCommandsWithCompletionHandler:]): Deleted.

This method is no longer needed, since iOS 16+ has support for modern edit menus and uses the method
`-requestPreferredArrowDirectionForEditMenuWithCompletionHandler:` instead.

(-[WKContentView _requestEvasionRectsAboveSelectionIfNeeded:]): Deleted.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm:
* Tools/TestWebKitAPI/ios/UIKitSPI.h:

Canonical link: https://commits.webkit.org/266953@main
  • Loading branch information
whsieh committed Aug 16, 2023
1 parent 153a083 commit a597bab
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 37 deletions.
2 changes: 0 additions & 2 deletions Source/WebKit/Platform/spi/ios/UIKitSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,6 @@ typedef NS_ENUM(NSInteger, UIWKGestureType) {
- (void)insertTextPlaceholderWithSize:(CGSize)size completionHandler:(void (^)(UITextPlaceholder *))completionHandler;
- (void)removeTextPlaceholder:(UITextPlaceholder *)placeholder willInsertText:(BOOL)willInsertText completionHandler:(void (^)(void))completionHandler;

- (void)clearSelection;
- (void)replaceDictatedText:(NSString *)oldText withText:(NSString *)newText;
- (void)requestDictationContext:(void (^)(NSString *selectedText, NSString *prefixText, NSString *postfixText))completionHandler;
- (BOOL)pointIsNearMarkedText:(CGPoint)point;
Expand All @@ -866,7 +865,6 @@ typedef NS_ENUM(NSInteger, UIWKGestureType) {
- (void)replaceText:(NSString *)text withText:(NSString *)word;
- (void)selectWordForReplacement;
- (BOOL)isReplaceAllowed;
- (void)selectWordBackward;
- (UIView *)unscaledView;
- (CGFloat)inverseScale;
- (CGRect)unobscuredContentRect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
- (void)setSelectedColorForColorPicker:(UIColor *)color;
- (void)_selectDataListOption:(int)optionIndex;
- (BOOL)_isShowingDataListSuggestions;
- (void)selectWordBackwardForTesting;

- (BOOL)_mayContainEditableElementsInRect:(CGRect)rect;
- (void)_requestTextInputContextsInRect:(CGRect)rect completionHandler:(void (^)(NSArray<_WKTextInputContext *> *))completionHandler;
Expand Down
5 changes: 5 additions & 0 deletions Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ - (void)_willBeginTextInteractionInTextInputContext:(_WKTextInputContext *)conte
[_contentView _willBeginTextInteractionInTextInputContext:context];
}

- (void)selectWordBackwardForTesting
{
[_contentView selectWordBackwardForTesting];
}

- (void)_didFinishTextInteractionInTextInputContext:(_WKTextInputContext *)context
{
[_contentView _didFinishTextInteractionInTextInputContext:context];
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW)

@interface WKContentView (WKTesting)

- (void)selectWordBackwardForTesting;
- (void)_simulateElementAction:(_WKElementActionType)actionType atLocation:(CGPoint)location;
- (void)_simulateLongPressActionAtLocation:(CGPoint)location;
- (void)_simulateTextEntered:(NSString *)text;
Expand Down
48 changes: 18 additions & 30 deletions Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3748,12 +3748,6 @@ - (void)replaceText:(NSString *)text withText:(NSString *)word
_page->replaceSelectedText(text, word);
}

- (void)selectWordBackward
{
_autocorrectionContextNeedsUpdate = YES;
_page->selectWordBackward();
}

- (void)_promptForReplaceForWebView:(id)sender
{
if (!_page->editorState().postLayoutData)
Expand Down Expand Up @@ -4770,43 +4764,27 @@ - (void)requestAutocorrectionRectsForString:(NSString *)input withCompletionHand
#if HAVE(UI_EDIT_MENU_INTERACTION)

- (void)requestPreferredArrowDirectionForEditMenuWithCompletionHandler:(void(^)(UIEditMenuArrowDirection))completion
{
[self _requestEvasionRectsAboveSelectionIfNeeded:[completion = makeBlockPtr(completion)](const Vector<WebCore::FloatRect>& rects) {
completion(rects.isEmpty() ? UIEditMenuArrowDirectionAutomatic : UIEditMenuArrowDirectionUp);
}];
}

#endif

- (void)requestRectsToEvadeForSelectionCommandsWithCompletionHandler:(void(^)(NSArray<NSValue *> *rects))completion
{
[self _requestEvasionRectsAboveSelectionIfNeeded:[completion = makeBlockPtr(completion)](const Vector<WebCore::FloatRect>& rects) {
completion(createNSArray(rects).get());
}];
}

- (void)_requestEvasionRectsAboveSelectionIfNeeded:(CompletionHandler<void(const Vector<WebCore::FloatRect>&)>&&)completion
{
if ([self _shouldSuppressSelectionCommands]) {
completion({ });
completion(UIEditMenuArrowDirectionAutomatic);
return;
}

auto requestRectsToEvadeIfNeeded = [startTime = ApproximateTime::now(), weakSelf = WeakObjCPtr<WKContentView>(self), completion = WTFMove(completion)]() mutable {
auto requestRectsToEvadeIfNeeded = [startTime = ApproximateTime::now(), weakSelf = WeakObjCPtr<WKContentView>(self), completion = makeBlockPtr(completion)]() mutable {
auto strongSelf = weakSelf.get();
if (!strongSelf) {
completion({ });
completion(UIEditMenuArrowDirectionAutomatic);
return;
}

if ([strongSelf webView]._editable) {
completion({ });
completion(UIEditMenuArrowDirectionAutomatic);
return;
}

auto focusedElementType = strongSelf->_focusedElementInformation.elementType;
if (focusedElementType != WebKit::InputType::ContentEditable && focusedElementType != WebKit::InputType::TextArea) {
completion({ });
completion(UIEditMenuArrowDirectionAutomatic);
return;
}

Expand All @@ -4815,16 +4793,18 @@ - (void)_requestEvasionRectsAboveSelectionIfNeeded:(CompletionHandler<void(const
WorkQueue::main().dispatchAfter(delayBeforeShowingEditMenu, [completion = WTFMove(completion), weakSelf]() mutable {
auto strongSelf = weakSelf.get();
if (!strongSelf) {
completion({ });
completion(UIEditMenuArrowDirectionAutomatic);
return;
}

if (!strongSelf->_page) {
completion({ });
completion(UIEditMenuArrowDirectionAutomatic);
return;
}

strongSelf->_page->requestEvasionRectsAboveSelection(WTFMove(completion));
strongSelf->_page->requestEvasionRectsAboveSelection([completion = WTFMove(completion)](auto& rects) mutable {
completion(rects.isEmpty() ? UIEditMenuArrowDirectionAutomatic : UIEditMenuArrowDirectionUp);
});
});
};

Expand All @@ -4835,6 +4815,8 @@ - (void)_requestEvasionRectsAboveSelectionIfNeeded:(CompletionHandler<void(const
#endif
}

#endif // HAVE(UI_EDIT_MENU_INTERACTION)

#if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)

- (UIMenu *)removeBackgroundMenu
Expand Down Expand Up @@ -11754,6 +11736,12 @@ - (void)willDismissEditMenuWithAnimator:(id<UIEditMenuInteractionAnimating>)anim

@implementation WKContentView (WKTesting)

- (void)selectWordBackwardForTesting
{
_autocorrectionContextNeedsUpdate = YES;
_page->selectWordBackward();
}

- (void)_doAfterReceivingEditDragSnapshotForTesting:(dispatch_block_t)action
{
#if ENABLE(DRAG_SUPPORT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ - (CGRect)waitForFirstSelectionRectToChange:(CGRect)previousRect
[webView evaluateJavaScript:@"document.body.focus()" completionHandler:nil];
[webView _synchronouslyExecuteEditCommand:@"InsertText" argument:@"Hello world"];

[contentView selectWordBackward];
[webView selectWordBackwardForTesting];
[contentView setMarkedText:@"world" selectedRange:NSMakeRange(0, 5)];
[webView waitForNextPresentationUpdate];
{
Expand Down Expand Up @@ -461,7 +461,7 @@ - (CGRect)waitForFirstSelectionRectToChange:(CGRect)previousRect
[webView _synchronouslyExecuteEditCommand:@"InsertText" argument:@"Hello world"];

auto *contentView = [webView textInputContentView];
[contentView selectWordBackward];
[webView selectWordBackwardForTesting];
[contentView setMarkedText:@"world" selectedRange:NSMakeRange(0, 5)];
[webView collapseToEnd];

Expand Down
5 changes: 3 additions & 2 deletions Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#import "TestWKWebView.h"
#import "UserInterfaceSwizzler.h"
#import <WebKit/WKWebViewPrivate.h>
#import <WebKit/WKWebViewPrivateForTesting.h>
#import <wtf/Vector.h>

#if PLATFORM(IOS_FAMILY)
Expand Down Expand Up @@ -469,7 +470,7 @@ static void checkContentViewHasTextWithFailureDescription(TestWKWebView *webView
[webView _synchronouslyExecuteEditCommand:@"InsertText" argument:@"Hello world"];

auto *contentView = [webView textInputContentView];
[contentView selectWordBackward];
[webView selectWordBackwardForTesting];
[contentView setMarkedText:@"world" selectedRange:NSMakeRange(0, 5)];
[webView waitForNextPresentationUpdate];

Expand Down Expand Up @@ -513,7 +514,7 @@ static void checkContentViewHasTextWithFailureDescription(TestWKWebView *webView
[webView _synchronouslyExecuteEditCommand:@"InsertText" argument:@"Hello world"];

auto *contentView = [webView textInputContentView];
[contentView selectWordBackward];
[webView selectWordBackwardForTesting];
[contentView setMarkedText:@"world" selectedRange:NSMakeRange(0, 5)];
[webView waitForNextPresentationUpdate];

Expand Down
1 change: 0 additions & 1 deletion Tools/TestWebKitAPI/ios/UIKitSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ typedef NS_ENUM(NSInteger, UIWKGestureType) {
- (void)pasteWithCompletionHandler:(void (^)(void))completionHandler;
- (void)requestAutocorrectionRectsForString:(NSString *)input withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForInput))completionHandler;
- (void)requestAutocorrectionContextWithCompletionHandler:(void (^)(UIWKAutocorrectionContext *autocorrectionContext))completionHandler;
- (void)selectWordBackward;
- (void)selectPositionAtPoint:(CGPoint)point completionHandler:(void (^)(void))completionHandler;
- (void)selectTextWithGranularity:(UITextGranularity)granularity atPoint:(CGPoint)point completionHandler:(void (^)(void))completionHandler;
- (void)updateSelectionWithExtentPoint:(CGPoint)point completionHandler:(void (^)(BOOL selectionEndIsMoving))completionHandler;
Expand Down

0 comments on commit a597bab

Please sign in to comment.