Title: [293231] trunk
Revision
293231
Author
akeer...@apple.com
Date
2022-04-22 10:46:54 -0700 (Fri, 22 Apr 2022)

Log Message

[iOS] Add find interaction API to WKWebView
https://bugs.webkit.org/show_bug.cgi?id=239612
rdar://88442918

Reviewed by Alex Christensen.

Source/WebKit:

Promote the `_findInteraction` and `_findInteractionEnabled` SPI to
`findInteraction` and `findInteractionEnabled` API.

In order to make this change, new UIKit objects and protocols must be
adopted. Existing (deprecated) protocol conformance is kept around to
avoid breaking internal clients.

* UIProcess/API/Cocoa/WKWebView.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView findInteractionEnabled]):
(-[WKWebView setFindInteractionEnabled:]):
(-[WKWebView findInteraction]):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:

Declare conformance to three protocols: _UITextSearching, UITextSearching, UIFindInteractionDelegate.

_UITextSearching: Conformance is kept around to avoid breaking internal clients.
UITextSearching: Conformance is declared for clients to migrate off of _UITextSearching.
UIFindInteractionDelegate: Conformance is necessary to begin a UIFindSession.

* UIProcess/API/ios/WKWebViewIOS.h:
* UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView _didCommitLoadForMainFrame]):

The "searchable object" does not need to be reset anymore, as UIKit
will do that in `-[WKWebView findInteraction:sessionForView:]` the next
time a find session begins.

(-[WKWebView _searchableObject]):
(-[WKWebView _setFindInteractionEnabled:]):
(-[WKWebView _findInteraction]):

It is safe to cast between the SPI and API version of this object. UIKit
has guaranteed compatibility.

(-[WKWebView offsetFromPosition:toPosition:inDocument:]):
(-[WKWebView compareFoundRange:toRange:inDocument:]):
(-[WKWebView performTextSearchWithQueryString:usingOptions:resultAggregator:]):
(-[WKWebView replaceFoundTextInRange:inDocument:withText:]):
(-[WKWebView decorateFoundTextRange:inDocument:usingStyle:]):
(-[WKWebView scrollRangeToVisible:inDocument:]):
(-[WKWebView findInteraction:sessionForView:]):
(-[WKWebView findInteraction:didBeginFindSession:]):

Custom content views do not need to be aware that a find session has
begun, as they do not draw an overlay.

(-[WKWebView findInteraction:didEndFindSession:]):

Custom content views do not need to be aware that a find session has
begun, as they do not draw an overlay.

* UIProcess/ios/WKContentViewInteraction.h:

Declare the old _UITextSearching methods explicitly, as we need to
maintain support for internal clients.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView performTextSearchWithQueryString:usingOptions:resultAggregator:]):
(-[WKContentView replaceFoundTextInRange:inDocument:withText:]):
(-[WKContentView decorateFoundTextRange:inDocument:usingStyle:]):
(-[WKContentView scrollRangeToVisible:inDocument:]):
(-[WKContentView offsetFromPosition:toPosition:inDocument:]):
(-[WKContentView compareFoundRange:toRange:inDocument:]):
* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView compareFoundRange:toRange:inDocument:]):
(-[WKPDFView performTextSearchWithQueryString:usingOptions:resultAggregator:]):
(-[WKPDFView decorateFoundTextRange:inDocument:usingStyle:]):

Tools:

Augment an existing API test to use the new API, in addition to the
existing SPI.

The find-and-replace test is updated to account for the fact that a
find interaction no longer exposes a searchableObject. Instead, use
test-only SPI on WKWebView to perform the replace.

* TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm:
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (293230 => 293231)


--- trunk/Source/WebKit/ChangeLog	2022-04-22 17:28:55 UTC (rev 293230)
+++ trunk/Source/WebKit/ChangeLog	2022-04-22 17:46:54 UTC (rev 293231)
@@ -1,3 +1,81 @@
+2022-04-22  Aditya Keerthi  <akeer...@apple.com>
+
+        [iOS] Add find interaction API to WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=239612
+        rdar://88442918
+
+        Reviewed by Alex Christensen.
+
+        Promote the `_findInteraction` and `_findInteractionEnabled` SPI to
+        `findInteraction` and `findInteractionEnabled` API.
+
+        In order to make this change, new UIKit objects and protocols must be
+        adopted. Existing (deprecated) protocol conformance is kept around to
+        avoid breaking internal clients.
+
+        * UIProcess/API/Cocoa/WKWebView.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView findInteractionEnabled]):
+        (-[WKWebView setFindInteractionEnabled:]):
+        (-[WKWebView findInteraction]):
+        * UIProcess/API/Cocoa/WKWebViewInternal.h:
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+
+        Declare conformance to three protocols: _UITextSearching, UITextSearching, UIFindInteractionDelegate.
+
+        _UITextSearching: Conformance is kept around to avoid breaking internal clients.
+        UITextSearching: Conformance is declared for clients to migrate off of _UITextSearching.
+        UIFindInteractionDelegate: Conformance is necessary to begin a UIFindSession.
+
+        * UIProcess/API/ios/WKWebViewIOS.h:
+        * UIProcess/API/ios/WKWebViewIOS.mm:
+        (-[WKWebView _didCommitLoadForMainFrame]):
+
+        The "searchable object" does not need to be reset anymore, as UIKit
+        will do that in `-[WKWebView findInteraction:sessionForView:]` the next
+        time a find session begins.
+
+        (-[WKWebView _searchableObject]):
+        (-[WKWebView _setFindInteractionEnabled:]):
+        (-[WKWebView _findInteraction]):
+
+        It is safe to cast between the SPI and API version of this object. UIKit
+        has guaranteed compatibility.
+
+        (-[WKWebView offsetFromPosition:toPosition:inDocument:]):
+        (-[WKWebView compareFoundRange:toRange:inDocument:]):
+        (-[WKWebView performTextSearchWithQueryString:usingOptions:resultAggregator:]):
+        (-[WKWebView replaceFoundTextInRange:inDocument:withText:]):
+        (-[WKWebView decorateFoundTextRange:inDocument:usingStyle:]):
+        (-[WKWebView scrollRangeToVisible:inDocument:]):
+        (-[WKWebView findInteraction:sessionForView:]):
+        (-[WKWebView findInteraction:didBeginFindSession:]):
+
+        Custom content views do not need to be aware that a find session has
+        begun, as they do not draw an overlay.
+
+        (-[WKWebView findInteraction:didEndFindSession:]):
+
+        Custom content views do not need to be aware that a find session has
+        begun, as they do not draw an overlay.
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+
+        Declare the old _UITextSearching methods explicitly, as we need to
+        maintain support for internal clients.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView performTextSearchWithQueryString:usingOptions:resultAggregator:]):
+        (-[WKContentView replaceFoundTextInRange:inDocument:withText:]):
+        (-[WKContentView decorateFoundTextRange:inDocument:usingStyle:]):
+        (-[WKContentView scrollRangeToVisible:inDocument:]):
+        (-[WKContentView offsetFromPosition:toPosition:inDocument:]):
+        (-[WKContentView compareFoundRange:toRange:inDocument:]):
+        * UIProcess/ios/WKPDFView.mm:
+        (-[WKPDFView compareFoundRange:toRange:inDocument:]):
+        (-[WKPDFView performTextSearchWithQueryString:usingOptions:resultAggregator:]):
+        (-[WKPDFView decorateFoundTextRange:inDocument:usingStyle:]):
+
 2022-04-22  Wenson Hsieh  <wenson_hs...@apple.com>
 
         [iOS] `-selectWordForReplacement` should select dictation alternatives that span multiple words

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.h (293230 => 293231)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.h	2022-04-22 17:28:55 UTC (rev 293230)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.h	2022-04-22 17:46:54 UTC (rev 293231)
@@ -33,6 +33,10 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
+#if TARGET_OS_IPHONE
+@class UIFindInteraction;
+#endif
+
 @class WKBackForwardList;
 @class WKBackForwardListItem;
 @class WKContentWorld;
@@ -646,6 +650,16 @@
 - (void)setMinimumViewportInset:(NSEdgeInsets)minimumViewportInset maximumViewportInset:(NSEdgeInsets)maximumViewportInset WK_API_AVAILABLE(macos(WK_MAC_TBA));
 #endif
 
+#if TARGET_OS_IPHONE
+
+/*! @abstract Enables the web view's built-in find interaction. */
+@property (nonatomic, readwrite, getter=isFindInteractionEnabled) BOOL findInteractionEnabled WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
+/*! @abstract If  @link findInteractionEnabled @/link is set to true, returns this web view's built-in find interaction. Otherwise, nil. */
+@property (nonatomic, nullable, readonly) UIFindInteraction *findInteraction WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
+#endif
+
 @end
 
 #if !TARGET_OS_IPHONE

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (293230 => 293231)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2022-04-22 17:28:55 UTC (rev 293230)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2022-04-22 17:46:54 UTC (rev 293231)
@@ -369,10 +369,7 @@
     _initialScaleFactor = 1;
     _allowsViewportShrinkToFit = defaultAllowsViewportShrinkToFit;
     _allowsLinkPreview = linkedOnOrAfterSDKWithBehavior(SDKAlignedBehavior::LinkPreviewEnabledByDefault);
-
-#if HAVE(UIFINDINTERACTION)
     _findInteractionEnabled = NO;
-#endif
 
     auto fastClickingEnabled = []() {
         if (NSNumber *enabledValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"WebKitFastClickingDisabled"])
@@ -1428,10 +1425,48 @@
 #pragma mark - iOS API
 
 #if PLATFORM(IOS_FAMILY)
+
 - (UIScrollView *)scrollView
 {
     return _scrollView.get();
 }
+
+- (BOOL)findInteractionEnabled
+{
+    return _findInteractionEnabled;
+}
+
+- (void)setFindInteractionEnabled:(BOOL)enabled
+{
+#if HAVE(UIFINDINTERACTION)
+    if (_findInteractionEnabled != enabled) {
+        _findInteractionEnabled = enabled;
+
+        if (enabled) {
+            if (!_findInteraction)
+                _findInteraction = adoptNS([[UIFindInteraction alloc] initWithSessionDelegate:self]);
+
+            [self addInteraction:_findInteraction.get()];
+        } else {
+            [self removeInteraction:_findInteraction.get()];
+            _findInteraction = nil;
+        }
+    }
+#else
+    UNUSED_PARAM(enabled);
+    UNUSED_VARIABLE(_findInteractionEnabled);
+#endif
+}
+
+- (UIFindInteraction *)findInteraction
+{
+#if HAVE(UIFINDINTERACTION)
+    return _findInteraction.get();
+#else
+    return nil;
+#endif
+}
+
 #endif // PLATFORM(IOS_FAMILY)
 
 #pragma mark - macOS API

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h (293230 => 293231)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h	2022-04-22 17:28:55 UTC (rev 293230)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h	2022-04-22 17:46:54 UTC (rev 293231)
@@ -162,9 +162,9 @@
     RetainPtr<WKFullScreenWindowController> _fullScreenWindowController;
 #endif
 
+    BOOL _findInteractionEnabled;
 #if HAVE(UIFINDINTERACTION)
-    RetainPtr<_UIFindInteraction> _findInteraction;
-    BOOL _findInteractionEnabled;
+    RetainPtr<UIFindInteraction> _findInteraction;
 #endif
 
     RetainPtr<_WKRemoteObjectRegistry> _remoteObjectRegistry;

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (293230 => 293231)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2022-04-22 17:28:55 UTC (rev 293230)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2022-04-22 17:46:54 UTC (rev 293231)
@@ -493,7 +493,7 @@
 #if TARGET_OS_IPHONE
 
 #if !TARGET_OS_TV && !TARGET_OS_WATCH && __has_include(<UIKit/_UITextSearching.h>)
-@interface WKWebView (WKPrivateIOS) <_UITextSearching>
+@interface WKWebView (WKPrivateIOS) <_UITextSearching, UITextSearching, UIFindInteractionDelegate>
 #else
 @interface WKWebView (WKPrivateIOS)
 #endif

Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.h (293230 => 293231)


--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.h	2022-04-22 17:28:55 UTC (rev 293230)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.h	2022-04-22 17:46:54 UTC (rev 293231)
@@ -135,7 +135,7 @@
 - (void)findPrevious:(id)sender;
 - (void)findAndReplace:(id)sender;
 
-- (id<_UITextSearching>)_searchableObject;
+- (id<UITextSearching>)_searchableObject;
 #endif
 
 - (void)_nextAccessoryTab:(id)sender;

Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm (293230 => 293231)


--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2022-04-22 17:28:55 UTC (rev 293230)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2022-04-22 17:46:54 UTC (rev 293231)
@@ -778,10 +778,8 @@
         [_scrollView _stopScrollingAndZoomingAnimations];
 
 #if HAVE(UIFINDINTERACTION)
-    if (_findInteractionEnabled) {
+    if (_findInteractionEnabled)
         [_findInteraction dismissFindNavigator];
-        [_findInteraction setSearchableObject:[self _searchableObject]];
-    }
 #endif
 }
 
@@ -2715,10 +2713,10 @@
 
 #if HAVE(UIFINDINTERACTION)
 
-- (id<_UITextSearching>)_searchableObject
+- (id<UITextSearching>)_searchableObject
 {
-    if ([_customContentView conformsToProtocol:@protocol(_UITextSearching)])
-        return (id<_UITextSearching>)_customContentView.get();
+    if ([_customContentView conformsToProtocol:@protocol(UITextSearching)])
+        return (id<UITextSearching>)_customContentView.get();
 
     return _contentView.get();
 }
@@ -3561,28 +3559,12 @@
 
 - (void)_setFindInteractionEnabled:(BOOL)enabled
 {
-    if (_findInteractionEnabled != enabled) {
-        _findInteractionEnabled = enabled;
-
-        if (enabled) {
-            if (!_findInteraction) {
-                ALLOW_DEPRECATED_DECLARATIONS_BEGIN
-                _findInteraction = adoptNS([[_UIFindInteraction alloc] init]);
-                ALLOW_DEPRECATED_DECLARATIONS_END
-                [_findInteraction setSearchableObject:[self _searchableObject]];
-            }
-
-            [self addInteraction:_findInteraction.get()];
-        } else {
-            [self removeInteraction:_findInteraction.get()];
-            _findInteraction = nil;
-        }
-    }
+    [self setFindInteractionEnabled:enabled];
 }
 
 - (_UIFindInteraction *)_findInteraction
 {
-    return _findInteraction.get();
+    return (_UIFindInteraction *)_findInteraction.get();
 }
 
 - (UITextRange *)selectedTextRange
@@ -3591,30 +3573,33 @@
 }
 
 ALLOW_DEPRECATED_IMPLEMENTATIONS_BEGIN
-- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition inDocument:(_UITextSearchDocumentIdentifier)document
+- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition inDocument:(UITextSearchDocumentIdentifier)document
 {
-    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
     return [_contentView offsetFromPosition:from toPosition:toPosition inDocument:document];
-    ALLOW_DEPRECATED_DECLARATIONS_END
 }
 ALLOW_DEPRECATED_IMPLEMENTATIONS_END
 
-- (NSComparisonResult)compareFoundRange:(UITextRange *)fromRange toRange:(UITextRange *)toRange inDocument:(_UITextSearchDocumentIdentifier)document
+- (NSComparisonResult)compareFoundRange:(UITextRange *)fromRange toRange:(UITextRange *)toRange inDocument:(UITextSearchDocumentIdentifier)document
 {
     return [_contentView compareFoundRange:fromRange toRange:toRange inDocument:document];
 }
 
-- (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(_UITextSearchOptions *)options resultAggregator:(id<_UITextSearchAggregator>)aggregator
+- (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(UITextSearchOptions *)options resultAggregator:(id<UITextSearchAggregator>)aggregator
 {
     [_contentView performTextSearchWithQueryString:string usingOptions:options resultAggregator:aggregator];
 }
 
-- (void)decorateFoundTextRange:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document usingStyle:(_UIFoundTextStyle)style
+- (void)replaceFoundTextInRange:(UITextRange *)range inDocument:(UITextSearchDocumentIdentifier)document withText:(NSString *)replacementText
 {
+    [_contentView replaceFoundTextInRange:range inDocument:document withText:replacementText];
+}
+
+- (void)decorateFoundTextRange:(UITextRange *)range inDocument:(UITextSearchDocumentIdentifier)document usingStyle:(UITextSearchFoundTextStyle)style
+{
     [_contentView decorateFoundTextRange:range inDocument:document usingStyle:style];
 }
 
-- (void)scrollRangeToVisible:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document
+- (void)scrollRangeToVisible:(UITextRange *)range inDocument:(UITextSearchDocumentIdentifier)document
 {
     [_contentView scrollRangeToVisible:range inDocument:document];
 }
@@ -3639,6 +3624,24 @@
     [_contentView requestRectForFoundTextRange:ranges completionHandler:completionHandler];
 }
 
+- (UIFindSession *)findInteraction:(UIFindInteraction *)interaction sessionForView:(UIView *)view
+{
+    auto findSession = adoptNS([[UITextSearchingFindSession alloc] initWithSearchableObject:[self _searchableObject]]);
+    return findSession.autorelease();
+}
+
+- (void)findInteraction:(UIFindInteraction *)interaction didBeginFindSession:(UIFindSession *)session
+{
+    if ([self _searchableObject] == _contentView.get())
+        [_contentView didBeginTextSearchOperation];
+}
+
+- (void)findInteraction:(UIFindInteraction *)interaction didEndFindSession:(UIFindSession *)session
+{
+    if ([self _searchableObject] == _contentView.get())
+        [_contentView didEndTextSearchOperation];
+}
+
 #endif // HAVE(UIFINDINTERACTION)
 
 @end // WKWebView (WKPrivateIOS)

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (293230 => 293231)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2022-04-22 17:28:55 UTC (rev 293230)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2022-04-22 17:46:54 UTC (rev 293231)
@@ -565,7 +565,7 @@
     , WKHoverPlatterDelegate
 #endif
 #if HAVE(UIFINDINTERACTION)
-    , _UITextSearching
+    , UITextSearching
 #endif
 >
 
@@ -797,7 +797,10 @@
 #endif
 
 #if HAVE(UIFINDINTERACTION)
-- (NSComparisonResult)compareFoundRange:(UITextRange *)fromRange toRange:(UITextRange *)toRange inDocument:(_UITextSearchDocumentIdentifier)document;
+- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition inDocument:(UITextSearchDocumentIdentifier)document;
+- (void)didBeginTextSearchOperation;
+- (void)didEndTextSearchOperation;
+
 - (void)requestRectForFoundTextRange:(UITextRange *)range completionHandler:(void (^)(CGRect))completionHandler;
 #endif
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (293230 => 293231)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-04-22 17:28:55 UTC (rev 293230)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-04-22 17:46:54 UTC (rev 293231)
@@ -10435,14 +10435,14 @@
     [self.webView._findInteraction presentFindNavigatorShowingReplace:YES];
 }
 
-- (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(_UITextSearchOptions *)options resultAggregator:(id<_UITextSearchAggregator>)aggregator
+- (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(UITextSearchOptions *)options resultAggregator:(id<UITextSearchAggregator>)aggregator
 {
     OptionSet<WebKit::FindOptions> findOptions;
     switch (options.wordMatchMethod) {
-    case _UITextSearchMatchMethodStartsWith:
+    case UITextSearchMatchMethodStartsWith:
         findOptions.add(WebKit::FindOptions::AtWordStarts);
         break;
-    case _UITextSearchMatchMethodFullWord:
+    case UITextSearchMatchMethodFullWord:
         findOptions.add({ WebKit::FindOptions::AtWordStarts, WebKit::FindOptions::AtWordEnds });
         break;
     default:
@@ -10464,7 +10464,7 @@
     });
 }
 
-- (void)replaceFoundTextInRange:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document withText:(NSString *)replacementText
+- (void)replaceFoundTextInRange:(UITextRange *)range inDocument:(UITextSearchDocumentIdentifier)document withText:(NSString *)replacementText
 {
     if (!self.supportsTextReplacement)
         return;
@@ -10476,7 +10476,7 @@
     _page->replaceFoundTextRangeWithString([foundTextRange webFoundTextRange], replacementText);
 }
 
-- (void)decorateFoundTextRange:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document usingStyle:(_UIFoundTextStyle)style
+- (void)decorateFoundTextRange:(UITextRange *)range inDocument:(UITextSearchDocumentIdentifier)document usingStyle:(UITextSearchFoundTextStyle)style
 {
     auto foundTextRange = dynamic_objc_cast<WKFoundTextRange>(range);
     if (!foundTextRange)
@@ -10483,15 +10483,15 @@
         return;
 
     auto decorationStyle = WebKit::FindDecorationStyle::Normal;
-    if (style == _UIFoundTextStyleFound)
+    if (style == UITextSearchFoundTextStyleFound)
         decorationStyle = WebKit::FindDecorationStyle::Found;
-    else if (style == _UIFoundTextStyleHighlighted)
+    else if (style == UITextSearchFoundTextStyleHighlighted)
         decorationStyle = WebKit::FindDecorationStyle::Highlighted;
 
     _page->decorateTextRangeWithStyle([foundTextRange webFoundTextRange], decorationStyle);
 }
 
-- (void)scrollRangeToVisible:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document
+- (void)scrollRangeToVisible:(UITextRange *)range inDocument:(UITextSearchDocumentIdentifier)document
 {
     if (auto foundTextRange = dynamic_objc_cast<WKFoundTextRange>(range))
         _page->scrollTextRangeToVisible([foundTextRange webFoundTextRange]);
@@ -10517,14 +10517,12 @@
     return self.webView._editable;
 }
 
-ALLOW_DEPRECATED_IMPLEMENTATIONS_BEGIN
-- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition inDocument:(_UITextSearchDocumentIdentifier)document
+- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition inDocument:(UITextSearchDocumentIdentifier)document
 {
     return [self offsetFromPosition:from toPosition:toPosition];
 }
-ALLOW_DEPRECATED_IMPLEMENTATIONS_END
 
-- (NSComparisonResult)compareFoundRange:(UITextRange *)fromRange toRange:(UITextRange *)toRange inDocument:(_UITextSearchDocumentIdentifier)document
+- (NSComparisonResult)compareFoundRange:(UITextRange *)fromRange toRange:(UITextRange *)toRange inDocument:(UITextSearchDocumentIdentifier)document
 {
     NSInteger offset = [self offsetFromPosition:fromRange.start toPosition:toRange.start];
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm (293230 => 293231)


--- trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm	2022-04-22 17:28:55 UTC (rev 293230)
+++ trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm	2022-04-22 17:46:54 UTC (rev 293231)
@@ -109,7 +109,7 @@
 
 @interface WKPDFView () <PDFHostViewControllerDelegate, WKActionSheetAssistantDelegate
 #if HAVE(UIFINDINTERACTION)
-    , _UITextSearching
+    , UITextSearching
 #endif
 >
 @end
@@ -135,7 +135,7 @@
     RetainPtr<WKKeyboardScrollViewAnimator> _keyboardScrollingAnimator;
     RetainPtr<WKShareSheet> _shareSheet;
 #if HAVE(UIFINDINTERACTION)
-    RetainPtr<id<_UITextSearchAggregator>> _searchAggregator;
+    RetainPtr<id<UITextSearchAggregator>> _searchAggregator;
     RetainPtr<NSString> _searchString;
 #endif
 }
@@ -688,7 +688,7 @@
     return [uiDelegate _dataDetectionContextForWebView:webView];
 }
 
-#pragma mark _UITextSearching
+#pragma mark UITextSearching
 
 #if HAVE(UIFINDINTERACTION)
 
@@ -697,7 +697,7 @@
     return nil;
 }
 
-- (NSComparisonResult)compareFoundRange:(UITextRange *)fromRange toRange:(UITextRange *)toRange inDocument:(_UITextSearchDocumentIdentifier)document
+- (NSComparisonResult)compareFoundRange:(UITextRange *)fromRange toRange:(UITextRange *)toRange inDocument:(UITextSearchDocumentIdentifier)document
 {
     auto from = dynamic_objc_cast<WKPDFFoundTextPosition>(fromRange.start);
     if (!from)
@@ -716,7 +716,7 @@
     return NSOrderedSame;
 }
 
-- (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(_UITextSearchOptions *)options resultAggregator:(id<_UITextSearchAggregator>)aggregator
+- (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(UITextSearchOptions *)options resultAggregator:(id<UITextSearchAggregator>)aggregator
 {
     [_hostViewController cancelFindString];
     _searchAggregator = aggregator;
@@ -724,9 +724,9 @@
     [_hostViewController findString:string withOptions:options.stringCompareOptions];
 }
 
-- (void)decorateFoundTextRange:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document usingStyle:(_UIFoundTextStyle)style
+- (void)decorateFoundTextRange:(UITextRange *)range inDocument:(UITextSearchDocumentIdentifier)document usingStyle:(UITextSearchFoundTextStyle)style
 {
-    if (style != _UIFoundTextStyleHighlighted)
+    if (style != UITextSearchFoundTextStyleHighlighted)
         return;
 
     auto foundTextRange = dynamic_objc_cast<WKPDFFoundTextRange>(range);

Modified: trunk/Tools/ChangeLog (293230 => 293231)


--- trunk/Tools/ChangeLog	2022-04-22 17:28:55 UTC (rev 293230)
+++ trunk/Tools/ChangeLog	2022-04-22 17:46:54 UTC (rev 293231)
@@ -1,3 +1,21 @@
+2022-04-22  Aditya Keerthi  <akeer...@apple.com>
+
+        [iOS] Add find interaction API to WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=239612
+        rdar://88442918
+
+        Reviewed by Alex Christensen.
+
+        Augment an existing API test to use the new API, in addition to the
+        existing SPI.
+
+        The find-and-replace test is updated to account for the fact that a
+        find interaction no longer exposes a searchableObject. Instead, use
+        test-only SPI on WKWebView to perform the replace.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm:
+        (TEST):
+
 2022-04-22  Wenson Hsieh  <wenson_hs...@apple.com>
 
         [iOS] `-selectWordForReplacement` should select dictation alternatives that span multiple words

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm (293230 => 293231)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm	2022-04-22 17:28:55 UTC (rev 293230)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm	2022-04-22 17:46:54 UTC (rev 293231)
@@ -530,13 +530,13 @@
 
     [webView _setEditable:NO];
     for (UITextRange *range in [ranges reverseObjectEnumerator])
-        [[[webView _findInteraction] searchableObject] replaceFoundTextInRange:range inDocument:nil withText:replacementString];
+        [webView replaceFoundTextInRange:range inDocument:nil withText:replacementString];
 
     EXPECT_WK_STREQ(originalContent, [webView stringByEvaluatingJavaScript:@"document.body.innerText"]);
 
     [webView _setEditable:YES];
     for (UITextRange *range in [ranges reverseObjectEnumerator])
-        [[[webView _findInteraction] searchableObject] replaceFoundTextInRange:range inDocument:nil withText:replacementString];
+        [webView replaceFoundTextInRange:range inDocument:nil withText:replacementString];
 
     EXPECT_WK_STREQ(replacedContent, [webView stringByEvaluatingJavaScript:@"document.body.innerText"]);
 }
@@ -552,6 +552,14 @@
 
     [webView _setFindInteractionEnabled:NO];
     EXPECT_NULL([webView _findInteraction]);
+
+    EXPECT_NULL([webView findInteraction]);
+
+    [webView setFindInteractionEnabled:YES];
+    EXPECT_NOT_NULL([webView findInteraction]);
+
+    [webView setFindInteractionEnabled:NO];
+    EXPECT_NULL([webView findInteraction]);
 }
 
 TEST(WebKit, RequestRectForFoundTextRange)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to