⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 286641 in webkit


Ignore:
Timestamp:
Dec 7, 2021, 9:30:53 PM (5 years ago)
Author:
Aditya Keerthi
Message:

[iOS] Add initial support for find-in-page SPI
https://bugs.webkit.org/show_bug.cgi?id=233915
rdar://86140501

Reviewed by Wenson Hsieh.

Source/WebKit:

Expose new find-in-page SPI for use by clients.

  • Platform/spi/ios/UIKitSPI.h:
  • UIProcess/API/Cocoa/WKWebViewPrivate.h:
  • UIProcess/API/ios/WKWebViewIOS.mm:

(-[WKWebView selectedTextRange]):
(-[WKWebView offsetFromPosition:toPosition:inDocument:]):
(-[WKWebView performTextSearchWithQueryString:usingOptions:resultAggregator:]):
(-[WKWebView decorateFoundTextRange:inDocument:usingStyle:]):
(-[WKWebView clearAllDecoratedFoundText]):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::findRectsForStringMatches):
(WebKit::WebPageProxy::hideFindIndicator):

  • UIProcess/WebPageProxy.h:
  • UIProcess/ios/WKContentViewInteraction.h:
  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView offsetFromPosition:toPosition:]):

The implementation here is needed to determine the relative ordering of
two search results.

(-[WKContentView performTextSearchWithQueryString:usingOptions:resultAggregator:]):

Call into the WebProcess to perform the search, and asynchronously
mark the search as complete.

A search result is represented as a WKFoundTextRange, and contains
two pieces of information.

  1. A rect – so that clients can determine whether or not the result is visible.
  1. An index – to allow for highlighting of a result and to enable determining relative ordering between two results.

(-[WKContentView decorateFoundTextRange:usingStyle:]):
(-[WKContentView clearAllDecoratedFoundText]):
(+[WKFoundTextRange foundTextRangeWithRect:index:]):
(-[WKFoundTextRange start]):
(-[WKFoundTextRange end]):
(-[WKFoundTextRange isEmpty]):
(+[WKFoundTextPosition textPositionWithIndex:]):

  • WebProcess/WebPage/FindController.cpp:

(WebKit::FindController::findString):

Prevent Editor from revealing the selection on all platforms, as the
existing call to didFindString is now responsible for revealing
selection on all platforms.

(WebKit::FindController::findRectsForStringMatches):

Gather rects for all search results and return them to the UIProcess.

(WebKit::FindController::indicateFindMatch):

This method was previously unused on iOS, and required some changes
to work correctly.

Wrap the call to select the current match with calls to
{will|did}FindString to account for iOS specific selection behavior.
See the existing comment in didFindString for more details.

No behavior change on other platforms, since willFindString is empty,
and didFindString now reveals the selection.

(WebKit::FindController::didFindString):

  • WebProcess/WebPage/FindController.h:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::findRectsForStringMatches):
(WebKit::WebPage::hideFindIndicator):

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:

Added two new WebPage messages.

  1. findRectsForStringMatches returns an vector of string match rects for use in the UIProcess.
  1. Expose hideFindIndicator via IPC so that the UIProcess can hide the indicator without dismissing the overlay entirely.

Source/WTF:

  • wtf/PlatformHave.h:

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm:

(-[TestSearchAggregator initWithCompletionHandler:]):
(-[TestSearchAggregator foundRange:forSearchString:inDocument:]):
(-[TestSearchAggregator finishedSearching]):
(TEST):

Added an API test to verify that search results are found correctly.

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r286640 r286641  
     12021-12-07  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        [iOS] Add initial support for find-in-page SPI
     4        https://bugs.webkit.org/show_bug.cgi?id=233915
     5        rdar://86140501
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        * wtf/PlatformHave.h:
     10
    1112021-12-07  Wenson Hsieh  <wenson_hsieh@apple.com>
    212
  • trunk/Source/WTF/wtf/PlatformHave.h

    r286465 r286641  
    11121112#define HAVE_SANDBOX_STATE_FLAGS 1
    11131113#endif
     1114
     1115#if ((PLATFORM(IOS) || PLATFORM(MACCATALYST)) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 160000)
     1116#define HAVE_UIFINDINTERACTION 1
     1117#endif
  • trunk/Source/WebKit/ChangeLog

    r286640 r286641  
     12021-12-07  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        [iOS] Add initial support for find-in-page SPI
     4        https://bugs.webkit.org/show_bug.cgi?id=233915
     5        rdar://86140501
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Expose new find-in-page SPI for use by clients.
     10
     11        * Platform/spi/ios/UIKitSPI.h:
     12        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
     13        * UIProcess/API/ios/WKWebViewIOS.mm:
     14        (-[WKWebView selectedTextRange]):
     15        (-[WKWebView offsetFromPosition:toPosition:inDocument:]):
     16        (-[WKWebView performTextSearchWithQueryString:usingOptions:resultAggregator:]):
     17        (-[WKWebView decorateFoundTextRange:inDocument:usingStyle:]):
     18        (-[WKWebView clearAllDecoratedFoundText]):
     19        * UIProcess/WebPageProxy.cpp:
     20        (WebKit::WebPageProxy::findRectsForStringMatches):
     21        (WebKit::WebPageProxy::hideFindIndicator):
     22        * UIProcess/WebPageProxy.h:
     23        * UIProcess/ios/WKContentViewInteraction.h:
     24        * UIProcess/ios/WKContentViewInteraction.mm:
     25        (-[WKContentView offsetFromPosition:toPosition:]):
     26
     27        The implementation here is needed to determine the relative ordering of
     28        two search results.
     29
     30        (-[WKContentView performTextSearchWithQueryString:usingOptions:resultAggregator:]):
     31
     32        Call into the WebProcess to perform the search, and asynchronously
     33        mark the search as complete.
     34
     35        A search result is represented as a WKFoundTextRange, and contains
     36        two pieces of information.
     37
     38        1. A rect – so that clients can determine whether or not the result
     39           is visible.
     40
     41        2. An index – to allow for highlighting of a result and to enable
     42           determining relative ordering between two results.
     43
     44        (-[WKContentView decorateFoundTextRange:usingStyle:]):
     45        (-[WKContentView clearAllDecoratedFoundText]):
     46        (+[WKFoundTextRange foundTextRangeWithRect:index:]):
     47        (-[WKFoundTextRange start]):
     48        (-[WKFoundTextRange end]):
     49        (-[WKFoundTextRange isEmpty]):
     50        (+[WKFoundTextPosition textPositionWithIndex:]):
     51        * WebProcess/WebPage/FindController.cpp:
     52        (WebKit::FindController::findString):
     53
     54        Prevent Editor from revealing the selection on all platforms, as the
     55        existing call to didFindString is now responsible for revealing
     56        selection on all platforms.
     57
     58        (WebKit::FindController::findRectsForStringMatches):
     59
     60        Gather rects for all search results and return them to the UIProcess.
     61
     62        (WebKit::FindController::indicateFindMatch):
     63
     64        This method was previously unused on iOS, and required some changes
     65        to work correctly.
     66
     67        Wrap the call to select the current match with calls to
     68        {will|did}FindString to account for iOS specific selection behavior.
     69        See the existing comment in didFindString for more details.
     70
     71        No behavior change on other platforms, since willFindString is empty,
     72        and didFindString now reveals the selection.
     73
     74        (WebKit::FindController::didFindString):
     75        * WebProcess/WebPage/FindController.h:
     76        * WebProcess/WebPage/WebPage.cpp:
     77        (WebKit::WebPage::findRectsForStringMatches):
     78        (WebKit::WebPage::hideFindIndicator):
     79        * WebProcess/WebPage/WebPage.h:
     80        * WebProcess/WebPage/WebPage.messages.in:
     81
     82        Added two new WebPage messages.
     83
     84        1. findRectsForStringMatches returns an vector of string match rects
     85           for use in the UIProcess.
     86
     87        2. Expose hideFindIndicator via IPC so that the UIProcess can hide
     88           the indicator without dismissing the overlay entirely.
     89
    1902021-12-07  Wenson Hsieh  <wenson_hsieh@apple.com>
    291
  • trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h

    r284062 r286641  
    131131#endif
    132132
     133#if HAVE(UIFINDINTERACTION)
     134#import <UIKit/_UITextSearching.h>
     135#endif
     136
    133137#if __has_include(<UIKit/UITargetedPreview_Private.h>)
    134138#import <UIKit/UITargetedPreview_Private.h>
     
    284288- (UIEventButtonMask)_buttonMask;
    285289@end
     290
     291#if HAVE(UIFINDINTERACTION)
     292
     293typedef NS_ENUM(NSUInteger, _UIFoundTextStyle) {
     294    _UIFoundTextStyleNormal,
     295    _UIFoundTextStyleFound,
     296    _UIFoundTextStyleHighlighted,
     297};
     298
     299typedef NS_ENUM(NSInteger, _UITextSearchMatchMethod) {
     300    _UITextSearchMatchMethodContains,
     301    _UITextSearchMatchMethodStartsWith,
     302    _UITextSearchMatchMethodFullWord,
     303};
     304
     305typedef id<NSCoding, NSCopying> _UITextSearchDocumentIdentifier;
     306
     307@interface _UITextSearchOptions : NSObject
     308@property (nonatomic, readonly) _UITextSearchMatchMethod wordMatchMethod;
     309@property (nonatomic, readonly) NSStringCompareOptions stringCompareOptions;
     310@end
     311
     312@protocol _UITextSearchAggregator <NSObject>
     313- (void)foundRange:(UITextRange *)range forSearchString:(NSString *)string inDocument:(_UITextSearchDocumentIdentifier)document;
     314- (void)finishedSearching;
     315@end
     316
     317@protocol _UITextSearching <NSObject>
     318
     319@property (readonly) UITextRange *selectedTextRange;
     320
     321- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition inDocument:(_UITextSearchDocumentIdentifier)document;
     322
     323- (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(_UITextSearchOptions *)options resultAggregator:(id<_UITextSearchAggregator>)aggregator;
     324
     325- (void)decorateFoundTextRange:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document usingStyle:(_UIFoundTextStyle)style;
     326
     327- (void)clearAllDecoratedFoundText;
     328
     329@end
     330
     331#endif // HAVE(UIFINDINTERACTION)
    286332
    287333typedef enum {
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h

    r285949 r286641  
    2424 */
    2525
     26#if TARGET_OS_IPHONE
     27#if __has_include(<UIKit/_UITextSearching.h>)
     28#import <UIKit/_UITextSearching.h>
     29#endif
     30#endif
     31
    2632#import <WebKit/WKDataDetectorTypes.h>
    2733#import <WebKit/WKWebView.h>
     
    421427#if TARGET_OS_IPHONE
    422428
     429#if __has_include(<UIKit/_UITextSearching.h>)
     430@interface WKWebView (WKPrivateIOS) <_UITextSearching>
     431#else
    423432@interface WKWebView (WKPrivateIOS)
     433#endif
    424434
    425435#if !TARGET_OS_TV && !TARGET_OS_WATCH
  • trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm

    r286552 r286641  
    34823482}
    34833483
     3484#if HAVE(UIFINDINTERACTION)
     3485
     3486- (UITextRange *)selectedTextRange
     3487{
     3488    return nil;
     3489}
     3490
     3491- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition inDocument:(_UITextSearchDocumentIdentifier)document
     3492{
     3493    return [_contentView offsetFromPosition:from toPosition:toPosition];
     3494}
     3495
     3496- (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(_UITextSearchOptions *)options resultAggregator:(id<_UITextSearchAggregator>)aggregator
     3497{
     3498    [_contentView performTextSearchWithQueryString:string usingOptions:options resultAggregator:aggregator];
     3499}
     3500
     3501- (void)decorateFoundTextRange:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document usingStyle:(_UIFoundTextStyle)style
     3502{
     3503    [_contentView decorateFoundTextRange:range usingStyle:style];
     3504}
     3505
     3506- (void)clearAllDecoratedFoundText
     3507{
     3508    [_contentView clearAllDecoratedFoundText];
     3509}
     3510
     3511#endif // HAVE(UIFINDINTERACTION)
     3512
    34843513@end // WKWebView (WKPrivateIOS)
    34853514
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r286640 r286641  
    42744274}
    42754275
     4276void WebPageProxy::findRectsForStringMatches(const String& string, OptionSet<WebKit::FindOptions> options, unsigned maxMatchCount, CompletionHandler<void(Vector<WebCore::FloatRect>&&)>&& callbackFunction)
     4277{
     4278    sendWithAsyncReply(Messages::WebPage::FindRectsForStringMatches(string, options, maxMatchCount), WTFMove(callbackFunction));
     4279}
     4280
    42764281void WebPageProxy::getImageForFindMatch(int32_t matchIndex)
    42774282{
     
    42924297{
    42934298    send(Messages::WebPage::HideFindUI());
     4299}
     4300
     4301void WebPageProxy::hideFindIndicator()
     4302{
     4303    send(Messages::WebPage::HideFindIndicator());
    42944304}
    42954305
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r286640 r286641  
    12011201    void findString(const String&, OptionSet<FindOptions>, unsigned maxMatchCount, CompletionHandler<void(bool)>&& = [](bool) { });
    12021202    void findStringMatches(const String&, OptionSet<FindOptions>, unsigned maxMatchCount);
     1203    void findRectsForStringMatches(const String&, OptionSet<WebKit::FindOptions>, unsigned maxMatchCount, CompletionHandler<void(Vector<WebCore::FloatRect>&&)>&&);
    12031204    void getImageForFindMatch(int32_t matchIndex);
    12041205    void selectFindMatch(int32_t matchIndex);
     
    12061207    void didGetImageForFindMatch(const ShareableBitmap::Handle& contentImageHandle, uint32_t matchIndex);
    12071208    void hideFindUI();
     1209    void hideFindIndicator();
    12081210    void countStringMatches(const String&, OptionSet<FindOptions>, unsigned maxMatchCount);
    12091211    void replaceMatches(Vector<uint32_t>&& matchIndices, const String& replacementText, bool selectionOnly, CompletionHandler<void(uint64_t)>&&);
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r286632 r286641  
    410410#endif
    411411
     412#if HAVE(UIFINDINTERACTION)
     413    RetainPtr<UITextRange> _foundHighlightedTextRange;
     414#endif
     415
    412416    BOOL _isEditable;
    413417    BOOL _showingTextStyleOptions;
     
    712716- (void)clearTextIndicator:(WebCore::TextIndicatorDismissalAnimation)animation;
    713717
     718#if HAVE(UIFINDINTERACTION)
     719- (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(_UITextSearchOptions *)options resultAggregator:(id<_UITextSearchAggregator>)aggregator;
     720- (void)decorateFoundTextRange:(UITextRange *)range usingStyle:(_UIFoundTextStyle)style;
     721- (void)clearAllDecoratedFoundText;
     722#endif
     723
    714724@property (nonatomic, readonly) BOOL _shouldUseContextMenus;
    715725@property (nonatomic, readonly) BOOL _shouldUseContextMenusForFormControls;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r286632 r286641  
    402402@end
    403403
     404#if HAVE(UIFINDINTERACTION)
     405
     406@interface WKFoundTextRange : UITextRange
     407
     408@property (nonatomic) CGRect rect;
     409@property (nonatomic) NSUInteger index;
     410
     411+ (WKFoundTextRange *)foundTextRangeWithRect:(CGRect)rect index:(NSUInteger)index;
     412
     413@end
     414
     415@interface WKFoundTextPosition : UITextPosition
     416
     417@property (nonatomic) NSUInteger index;
     418
     419+ (WKFoundTextPosition *)textPositionWithIndex:(NSUInteger)index;
     420
     421@end
     422
     423#endif
     424
    404425@interface WKAutocorrectionRects : UIWKAutocorrectionRects
    405426+ (WKAutocorrectionRects *)autocorrectionRectsWithFirstCGRect:(CGRect)firstRect lastCGRect:(CGRect)lastRect;
     
    52395260- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition
    52405261{
     5262#if HAVE(UIFINDINTERACTION)
     5263    if ([from isKindOfClass:[WKFoundTextPosition class]] && [toPosition isKindOfClass:[WKFoundTextPosition class]])
     5264        return ((WKFoundTextPosition *)from).index - ((WKFoundTextPosition *)toPosition).index;
     5265#endif
     5266
    52415267    return 0;
    52425268}
     
    99509976}
    99519977
     9978#if HAVE(UIFINDINTERACTION)
     9979
     9980- (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(_UITextSearchOptions *)options resultAggregator:(id<_UITextSearchAggregator>)aggregator
     9981{
     9982    // FIXME: (rdar://86140673) Account for _UITextSearchOptions when performing the search.
     9983    OptionSet<WebKit::FindOptions> findOptions;
     9984    findOptions.add(WebKit::FindOptions::ShowOverlay);
     9985
     9986    _page->findRectsForStringMatches(string, findOptions, 1000, [string, aggregator = retainPtr(aggregator)](const Vector<WebCore::FloatRect>& rects) {
     9987        NSUInteger index = 0;
     9988        for (auto& rect : rects) {
     9989            WKFoundTextRange *range = [WKFoundTextRange foundTextRangeWithRect:rect index:index];
     9990            [aggregator foundRange:range forSearchString:string inDocument:nil];
     9991            index++;
     9992        }
     9993
     9994        [aggregator finishedSearching];
     9995    });
     9996}
     9997
     9998- (void)decorateFoundTextRange:(UITextRange *)range usingStyle:(_UIFoundTextStyle)style
     9999{
     10000    if (![range isKindOfClass:[WKFoundTextRange class]])
     10001        return;
     10002
     10003    if (style == _UIFoundTextStyleHighlighted) {
     10004        _foundHighlightedTextRange = range;
     10005        WKFoundTextRange *foundRange = (WKFoundTextRange *)range;
     10006        _page->indicateFindMatch(foundRange.index);
     10007    } else if (style == _UIFoundTextStyleFound && _foundHighlightedTextRange == range)
     10008        _page->hideFindIndicator();
     10009}
     10010
     10011- (void)clearAllDecoratedFoundText
     10012{
     10013    _foundHighlightedTextRange = nil;
     10014    _page->hideFindUI();
     10015}
     10016
     10017#endif // HAVE(UIFINDINTERACTION)
     10018
    995210019#if ENABLE(IMAGE_ANALYSIS)
    995310020
     
    1180611873@end
    1180711874
     11875#if HAVE(UIFINDINTERACTION)
     11876
     11877@implementation WKFoundTextRange
     11878
     11879+ (WKFoundTextRange *)foundTextRangeWithRect:(CGRect)rect index:(NSUInteger)index
     11880{
     11881    auto range = adoptNS([[WKFoundTextRange alloc] init]);
     11882    [range setRect:rect];
     11883    [range setIndex:index];
     11884    return range.autorelease();
     11885}
     11886
     11887- (WKFoundTextPosition *)start
     11888{
     11889    WKFoundTextPosition *position = [WKFoundTextPosition textPositionWithIndex:self.index];
     11890    return position;
     11891}
     11892
     11893- (UITextPosition *)end
     11894{
     11895    return self.start;
     11896}
     11897
     11898- (BOOL)isEmpty
     11899{
     11900    return NO;
     11901}
     11902
     11903@end
     11904
     11905@implementation WKFoundTextPosition
     11906
     11907+ (WKFoundTextPosition *)textPositionWithIndex:(NSUInteger)index
     11908{
     11909    auto pos = adoptNS([[WKFoundTextPosition alloc] init]);
     11910    [pos setIndex:index];
     11911    return pos.autorelease();
     11912}
     11913
     11914@end
     11915
     11916#endif
     11917
    1180811918@implementation WKAutocorrectionRects
    1180911919
  • trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp

    r285655 r286641  
    4040#include <WebCore/FrameSelection.h>
    4141#include <WebCore/FrameView.h>
     42#include <WebCore/GeometryUtilities.h>
    4243#include <WebCore/GraphicsContext.h>
    4344#include <WebCore/ImageOverlay.h>
     
    236237    // we need to avoid sending the non-painted selection change to the UI process
    237238    // so that it does not clear the selection out from under us.
    238 #if PLATFORM(IOS_FAMILY)
     239    //
     240    // To share logic between platforms, prevent Editor from revealing the selection
     241    // and reveal the selection in FindController::didFindString.
    239242    coreOptions.add(DoNotRevealSelection);
    240 #endif
    241243
    242244    willFindString();
     
    302304}
    303305
     306void FindController::findRectsForStringMatches(const String& string, OptionSet<FindOptions> options, unsigned maxMatchCount, CompletionHandler<void(Vector<FloatRect>&&)>&& completionHandler)
     307{
     308    auto result = m_webPage->corePage()->findTextMatches(string, core(options), maxMatchCount);
     309    m_findMatches = WTFMove(result.ranges);
     310
     311    auto rects = m_findMatches.map([&] (auto& range) {
     312        FloatRect rect = unionRect(RenderObject::absoluteTextRects(range));
     313        return range.startContainer().document().frame()->view()->contentsToRootView(rect);
     314    });
     315
     316    completionHandler(WTFMove(rects));
     317
     318    if (!options.contains(FindOptions::ShowOverlay) && !options.contains(FindOptions::ShowFindIndicator))
     319        return;
     320
     321    bool found = !m_findMatches.isEmpty();
     322    m_webPage->drawingArea()->dispatchAfterEnsuringUpdatedScrollPosition([protectedWebPage = RefPtr { m_webPage }, found, string, options, maxMatchCount] () {
     323        protectedWebPage->findController().updateFindUIAfterPageScroll(found, string, options, maxMatchCount, DidWrap::No, FindUIOriginator::FindStringMatches);
     324    });
     325}
     326
    304327void FindController::getImageForFindMatch(uint32_t matchIndex)
    305328{
     
    345368void FindController::indicateFindMatch(uint32_t matchIndex)
    346369{
     370    willFindString();
     371
    347372    selectFindMatch(matchIndex);
    348373
     
    351376        return;
    352377
    353     selectedFrame->selection().revealSelection();
     378    didFindString();
    354379
    355380    updateFindIndicator(*selectedFrame, !!m_findPageOverlay);
     
    413438void FindController::didFindString()
    414439{
     440    Frame* selectedFrame = frameWithSelection(m_webPage->corePage());
     441    if (!selectedFrame)
     442        return;
     443
     444    selectedFrame->selection().revealSelection();
    415445}
    416446
  • trunk/Source/WebKit/WebProcess/WebPage/FindController.h

    r265199 r286641  
    6161    void findString(const String&, OptionSet<FindOptions>, unsigned maxMatchCount, CompletionHandler<void(bool)>&&);
    6262    void findStringMatches(const String&, OptionSet<FindOptions>, unsigned maxMatchCount);
     63    void findRectsForStringMatches(const String&, OptionSet<WebKit::FindOptions>, unsigned maxMatchCount, CompletionHandler<void(Vector<WebCore::FloatRect>&&)>&&);
    6364    void getImageForFindMatch(uint32_t matchIndex);
    6465    void selectFindMatch(uint32_t matchIndex);
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r286632 r286641  
    47174717}
    47184718
     4719void WebPage::findRectsForStringMatches(const String& string, OptionSet<FindOptions> options, uint32_t maxMatchCount, CompletionHandler<void(Vector<FloatRect>&&)>&& completionHandler)
     4720{
     4721    findController().findRectsForStringMatches(string, options, maxMatchCount, WTFMove(completionHandler));
     4722}
     4723
     4724void WebPage::hideFindIndicator()
     4725{
     4726    findController().hideFindIndicator();
     4727}
     4728
    47194729void WebPage::getImageForFindMatch(uint32_t matchIndex)
    47204730{
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r286632 r286641  
    17641764    void countStringMatches(const String&, OptionSet<FindOptions>, uint32_t maxMatchCount);
    17651765    void replaceMatches(const Vector<uint32_t>& matchIndices, const String& replacementText, bool selectionOnly, CompletionHandler<void(uint64_t)>&&);
     1766    void findRectsForStringMatches(const String&, OptionSet<FindOptions>, uint32_t maxMatchCount, CompletionHandler<void(Vector<WebCore::FloatRect>&&)>&&);
     1767    void hideFindIndicator();
    17661768
    17671769#if USE(COORDINATED_GRAPHICS)
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r286505 r286641  
    313313    CountStringMatches(String string, OptionSet<WebKit::FindOptions> findOptions, unsigned maxMatchCount)
    314314    ReplaceMatches(Vector<uint32_t> matchIndices, String replacementText, bool selectionOnly) -> (uint64_t numberOfReplacements) Async
     315
     316    FindRectsForStringMatches(String string, OptionSet<WebKit::FindOptions> findOptions, unsigned maxMatchCount) -> (Vector<WebCore::FloatRect> matches) Async
     317    HideFindIndicator()
    315318   
    316319    AddMIMETypeWithCustomContentProvider(String mimeType)
  • trunk/Tools/ChangeLog

    r286640 r286641  
     12021-12-07  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        [iOS] Add initial support for find-in-page SPI
     4        https://bugs.webkit.org/show_bug.cgi?id=233915
     5        rdar://86140501
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm:
     10        (-[TestSearchAggregator initWithCompletionHandler:]):
     11        (-[TestSearchAggregator foundRange:forSearchString:inDocument:]):
     12        (-[TestSearchAggregator finishedSearching]):
     13        (TEST):
     14
     15        Added an API test to verify that search results are found correctly.
     16
    1172021-12-07  Wenson Hsieh  <wenson_hsieh@apple.com>
    218
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm

    r278575 r286641  
    3131#import "WKWebViewConfigurationExtras.h"
    3232#import <WebKit/WKWebViewPrivate.h>
     33#import <wtf/BlockPtr.h>
    3334#import <wtf/RetainPtr.h>
     35
     36#if PLATFORM(IOS_FAMILY)
     37#import "UIKitSPI.h"
     38#endif
    3439
    3540#if !PLATFORM(IOS_FAMILY)
     
    322327
    323328#endif // !PLATFORM(IOS_FAMILY)
     329
     330#if HAVE(UIFINDINTERACTION)
     331
     332@interface TestTextSearchOptions : NSObject
     333@property (nonatomic, readonly) _UITextSearchMatchMethod wordMatchMethod;
     334@property (nonatomic, readonly) NSStringCompareOptions stringCompareOptions;
     335@end
     336
     337@implementation TestTextSearchOptions
     338@end
     339
     340@interface TestSearchAggregator : NSObject <_UITextSearchAggregator>
     341
     342@property (readonly) NSUInteger count;
     343
     344- (instancetype)initWithCompletionHandler:(dispatch_block_t)completionHandler;
     345
     346@end
     347
     348@implementation TestSearchAggregator {
     349    BlockPtr<void()> _completionHandler;
     350}
     351
     352- (instancetype)initWithCompletionHandler:(dispatch_block_t)completionHandler
     353{
     354    if (!(self = [super init]))
     355        return nil;
     356
     357    _count = 0;
     358    _completionHandler = makeBlockPtr(completionHandler);
     359
     360    return self;
     361}
     362
     363- (void)foundRange:(UITextRange *)range forSearchString:(NSString *)string inDocument:(_UITextSearchDocumentIdentifier)document
     364{
     365    _count++;
     366}
     367
     368- (void)finishedSearching
     369{
     370    if (_completionHandler)
     371        _completionHandler();
     372}
     373
     374@end
     375
     376TEST(WebKit, FindInPage)
     377{
     378    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]);
     379
     380    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"lots-of-text" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     381    [webView loadRequest:request];
     382    [webView _test_waitForDidFinishNavigation];
     383
     384    __block bool finishedSearching = false;
     385    RetainPtr aggregator = adoptNS([[TestSearchAggregator alloc] initWithCompletionHandler:^{
     386        finishedSearching = true;
     387    }]);
     388
     389    // FIXME: (rdar://86140914) Use _UITextSearchOptions directly when the symbol is exported.
     390    [webView performTextSearchWithQueryString:@"Birthday" usingOptions:(_UITextSearchOptions *)[[TestTextSearchOptions alloc] init] resultAggregator:aggregator.get()];
     391
     392    TestWebKitAPI::Util::run(&finishedSearching);
     393
     394    EXPECT_EQ([aggregator count], 360UL);
     395}
     396
     397#endif // HAVE(UIFINDINTERACTION)
Note: See TracChangeset for help on using the changeset viewer.