Changeset 286641 in webkit
- Timestamp:
- Dec 7, 2021, 9:30:53 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 17 edited
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/wtf/PlatformHave.h (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/Platform/spi/ios/UIKitSPI.h (modified) (2 diffs)
-
Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (modified) (2 diffs)
-
Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm (modified) (1 diff)
-
Source/WebKit/UIProcess/WebPageProxy.cpp (modified) (2 diffs)
-
Source/WebKit/UIProcess/WebPageProxy.h (modified) (2 diffs)
-
Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (modified) (2 diffs)
-
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (modified) (4 diffs)
-
Source/WebKit/WebProcess/WebPage/FindController.cpp (modified) (6 diffs)
-
Source/WebKit/WebProcess/WebPage/FindController.h (modified) (1 diff)
-
Source/WebKit/WebProcess/WebPage/WebPage.cpp (modified) (1 diff)
-
Source/WebKit/WebProcess/WebPage/WebPage.h (modified) (1 diff)
-
Source/WebKit/WebProcess/WebPage/WebPage.messages.in (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r286640 r286641 1 2021-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 1 11 2021-12-07 Wenson Hsieh <wenson_hsieh@apple.com> 2 12 -
trunk/Source/WTF/wtf/PlatformHave.h
r286465 r286641 1112 1112 #define HAVE_SANDBOX_STATE_FLAGS 1 1113 1113 #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 1 2021-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 1 90 2021-12-07 Wenson Hsieh <wenson_hsieh@apple.com> 2 91 -
trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h
r284062 r286641 131 131 #endif 132 132 133 #if HAVE(UIFINDINTERACTION) 134 #import <UIKit/_UITextSearching.h> 135 #endif 136 133 137 #if __has_include(<UIKit/UITargetedPreview_Private.h>) 134 138 #import <UIKit/UITargetedPreview_Private.h> … … 284 288 - (UIEventButtonMask)_buttonMask; 285 289 @end 290 291 #if HAVE(UIFINDINTERACTION) 292 293 typedef NS_ENUM(NSUInteger, _UIFoundTextStyle) { 294 _UIFoundTextStyleNormal, 295 _UIFoundTextStyleFound, 296 _UIFoundTextStyleHighlighted, 297 }; 298 299 typedef NS_ENUM(NSInteger, _UITextSearchMatchMethod) { 300 _UITextSearchMatchMethodContains, 301 _UITextSearchMatchMethodStartsWith, 302 _UITextSearchMatchMethodFullWord, 303 }; 304 305 typedef 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) 286 332 287 333 typedef enum { -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
r285949 r286641 24 24 */ 25 25 26 #if TARGET_OS_IPHONE 27 #if __has_include(<UIKit/_UITextSearching.h>) 28 #import <UIKit/_UITextSearching.h> 29 #endif 30 #endif 31 26 32 #import <WebKit/WKDataDetectorTypes.h> 27 33 #import <WebKit/WKWebView.h> … … 421 427 #if TARGET_OS_IPHONE 422 428 429 #if __has_include(<UIKit/_UITextSearching.h>) 430 @interface WKWebView (WKPrivateIOS) <_UITextSearching> 431 #else 423 432 @interface WKWebView (WKPrivateIOS) 433 #endif 424 434 425 435 #if !TARGET_OS_TV && !TARGET_OS_WATCH -
trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm
r286552 r286641 3482 3482 } 3483 3483 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 3484 3513 @end // WKWebView (WKPrivateIOS) 3485 3514 -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r286640 r286641 4274 4274 } 4275 4275 4276 void 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 4276 4281 void WebPageProxy::getImageForFindMatch(int32_t matchIndex) 4277 4282 { … … 4292 4297 { 4293 4298 send(Messages::WebPage::HideFindUI()); 4299 } 4300 4301 void WebPageProxy::hideFindIndicator() 4302 { 4303 send(Messages::WebPage::HideFindIndicator()); 4294 4304 } 4295 4305 -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r286640 r286641 1201 1201 void findString(const String&, OptionSet<FindOptions>, unsigned maxMatchCount, CompletionHandler<void(bool)>&& = [](bool) { }); 1202 1202 void findStringMatches(const String&, OptionSet<FindOptions>, unsigned maxMatchCount); 1203 void findRectsForStringMatches(const String&, OptionSet<WebKit::FindOptions>, unsigned maxMatchCount, CompletionHandler<void(Vector<WebCore::FloatRect>&&)>&&); 1203 1204 void getImageForFindMatch(int32_t matchIndex); 1204 1205 void selectFindMatch(int32_t matchIndex); … … 1206 1207 void didGetImageForFindMatch(const ShareableBitmap::Handle& contentImageHandle, uint32_t matchIndex); 1207 1208 void hideFindUI(); 1209 void hideFindIndicator(); 1208 1210 void countStringMatches(const String&, OptionSet<FindOptions>, unsigned maxMatchCount); 1209 1211 void replaceMatches(Vector<uint32_t>&& matchIndices, const String& replacementText, bool selectionOnly, CompletionHandler<void(uint64_t)>&&); -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
r286632 r286641 410 410 #endif 411 411 412 #if HAVE(UIFINDINTERACTION) 413 RetainPtr<UITextRange> _foundHighlightedTextRange; 414 #endif 415 412 416 BOOL _isEditable; 413 417 BOOL _showingTextStyleOptions; … … 712 716 - (void)clearTextIndicator:(WebCore::TextIndicatorDismissalAnimation)animation; 713 717 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 714 724 @property (nonatomic, readonly) BOOL _shouldUseContextMenus; 715 725 @property (nonatomic, readonly) BOOL _shouldUseContextMenusForFormControls; -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r286632 r286641 402 402 @end 403 403 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 404 425 @interface WKAutocorrectionRects : UIWKAutocorrectionRects 405 426 + (WKAutocorrectionRects *)autocorrectionRectsWithFirstCGRect:(CGRect)firstRect lastCGRect:(CGRect)lastRect; … … 5239 5260 - (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition 5240 5261 { 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 5241 5267 return 0; 5242 5268 } … … 9950 9976 } 9951 9977 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 9952 10019 #if ENABLE(IMAGE_ANALYSIS) 9953 10020 … … 11806 11873 @end 11807 11874 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 11808 11918 @implementation WKAutocorrectionRects 11809 11919 -
trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp
r285655 r286641 40 40 #include <WebCore/FrameSelection.h> 41 41 #include <WebCore/FrameView.h> 42 #include <WebCore/GeometryUtilities.h> 42 43 #include <WebCore/GraphicsContext.h> 43 44 #include <WebCore/ImageOverlay.h> … … 236 237 // we need to avoid sending the non-painted selection change to the UI process 237 238 // 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. 239 242 coreOptions.add(DoNotRevealSelection); 240 #endif241 243 242 244 willFindString(); … … 302 304 } 303 305 306 void 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 304 327 void FindController::getImageForFindMatch(uint32_t matchIndex) 305 328 { … … 345 368 void FindController::indicateFindMatch(uint32_t matchIndex) 346 369 { 370 willFindString(); 371 347 372 selectFindMatch(matchIndex); 348 373 … … 351 376 return; 352 377 353 selectedFrame->selection().revealSelection();378 didFindString(); 354 379 355 380 updateFindIndicator(*selectedFrame, !!m_findPageOverlay); … … 413 438 void FindController::didFindString() 414 439 { 440 Frame* selectedFrame = frameWithSelection(m_webPage->corePage()); 441 if (!selectedFrame) 442 return; 443 444 selectedFrame->selection().revealSelection(); 415 445 } 416 446 -
trunk/Source/WebKit/WebProcess/WebPage/FindController.h
r265199 r286641 61 61 void findString(const String&, OptionSet<FindOptions>, unsigned maxMatchCount, CompletionHandler<void(bool)>&&); 62 62 void findStringMatches(const String&, OptionSet<FindOptions>, unsigned maxMatchCount); 63 void findRectsForStringMatches(const String&, OptionSet<WebKit::FindOptions>, unsigned maxMatchCount, CompletionHandler<void(Vector<WebCore::FloatRect>&&)>&&); 63 64 void getImageForFindMatch(uint32_t matchIndex); 64 65 void selectFindMatch(uint32_t matchIndex); -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r286632 r286641 4717 4717 } 4718 4718 4719 void 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 4724 void WebPage::hideFindIndicator() 4725 { 4726 findController().hideFindIndicator(); 4727 } 4728 4719 4729 void WebPage::getImageForFindMatch(uint32_t matchIndex) 4720 4730 { -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r286632 r286641 1764 1764 void countStringMatches(const String&, OptionSet<FindOptions>, uint32_t maxMatchCount); 1765 1765 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(); 1766 1768 1767 1769 #if USE(COORDINATED_GRAPHICS) -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
r286505 r286641 313 313 CountStringMatches(String string, OptionSet<WebKit::FindOptions> findOptions, unsigned maxMatchCount) 314 314 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() 315 318 316 319 AddMIMETypeWithCustomContentProvider(String mimeType) -
trunk/Tools/ChangeLog
r286640 r286641 1 2021-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 1 17 2021-12-07 Wenson Hsieh <wenson_hsieh@apple.com> 2 18 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm
r278575 r286641 31 31 #import "WKWebViewConfigurationExtras.h" 32 32 #import <WebKit/WKWebViewPrivate.h> 33 #import <wtf/BlockPtr.h> 33 34 #import <wtf/RetainPtr.h> 35 36 #if PLATFORM(IOS_FAMILY) 37 #import "UIKitSPI.h" 38 #endif 34 39 35 40 #if !PLATFORM(IOS_FAMILY) … … 322 327 323 328 #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 376 TEST(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.