Changeset 247490 in webkit
- Timestamp:
- Jul 16, 2019 12:46:32 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r247489 r247490 1 2019-07-16 Tim Horton <timothy_horton@apple.com> 2 3 NSTextFinder holes don't scroll with the page 4 https://bugs.webkit.org/show_bug.cgi?id=199815 5 <rdar://problem/52280514> 6 7 Reviewed by Simon Fraser. 8 9 * rendering/ScrollAlignment.h: 10 1 11 2019-07-16 Youenn Fablet <youenn@apple.com> 2 12 -
trunk/Source/WebCore/PAL/pal/spi/mac/NSTextFinderSPI.h
r238438 r247490 53 53 - (void)selectFindMatch:(id <NSTextFinderAsynchronousDocumentFindMatch>)findMatch completionHandler:(void (^)(void))completionHandler; 54 54 - (void)replaceMatches:(NSArray *)matches withString:(NSString *)replacementString inSelectionOnly:(BOOL)selectionOnly resultCollector:(void (^)(NSUInteger replacementCount))resultCollector; 55 - (void)scrollFindMatchToVisible:(id <NSTextFinderAsynchronousDocumentFindMatch>)findMatch; 55 56 56 57 @end -
trunk/Source/WebCore/rendering/ScrollAlignment.h
r220503 r247490 68 68 static const ScrollAlignment alignCenterIfNotVisible; 69 69 static const ScrollAlignment alignToEdgeIfNotVisible; 70 static const ScrollAlignment alignCenterIfNeeded;70 WEBCORE_EXPORT static const ScrollAlignment alignCenterIfNeeded; 71 71 WEBCORE_EXPORT static const ScrollAlignment alignToEdgeIfNeeded; 72 72 WEBCORE_EXPORT static const ScrollAlignment alignCenterAlways; -
trunk/Source/WebKit/ChangeLog
r247486 r247490 1 2019-07-16 Tim Horton <timothy_horton@apple.com> 2 3 NSTextFinder holes don't scroll with the page 4 https://bugs.webkit.org/show_bug.cgi?id=199815 5 <rdar://problem/52280514> 6 7 Reviewed by Simon Fraser. 8 9 * UIProcess/API/Cocoa/WKWebView.mm: 10 (-[WKWebView _usePlatformFindUI]): 11 (-[WKWebView _setUsePlatformFindUI:]): 12 (-[WKWebView _ensureTextFinderClient]): 13 Add a bit so that clients can choose whether they want our find UI, 14 which respects scrolling, or the system find UI, which works when 15 doing multi-document searches. Right now you can't have both. 16 17 (-[WKWebView scrollFindMatchToVisible:]): 18 Implement and plumb scrollFindMatchToVisible. 19 20 * UIProcess/API/Cocoa/WKWebViewPrivate.h: 21 * UIProcess/WebPageProxy.cpp: 22 (WebKit::WebPageProxy::indicateFindMatch): 23 * UIProcess/WebPageProxy.h: 24 * WebProcess/WebPage/WebPage.cpp: 25 (WebKit::WebPage::indicateFindMatch): 26 * WebProcess/WebPage/WebPage.h: 27 * WebProcess/WebPage/WebPage.messages.in: 28 Plumb indicateFindMatch to FindController. 29 30 * UIProcess/mac/WKTextFinderClient.h: 31 * UIProcess/mac/WKTextFinderClient.mm: 32 (-[WKTextFinderClient initWithPage:view:usePlatformFindUI:]): 33 Store whether or not we are using the platform find UI. 34 35 (-[WKTextFinderClient findMatchesForString:relativeToMatch:findOptions:maxResults:resultCollector:]): 36 If using WebKit find UI, turn on our UI in the options passed to findString[Matches]. 37 38 (-[WKTextFinderClient scrollFindMatchToVisible:]): 39 If using WebKit find UI, when the platform tells us to reveal a find match, indicate it. 40 41 (-[WKTextFinderClient didFindStringMatchesWithRects:didWrapAround:]): 42 If using WebKit find UI, lie to the platform and return no rects so that it doesn't paint a yellow rectangle. 43 44 (-[WKTextFinderClient getImageForMatchResult:completionHandler:]): 45 If using WebKit find UI, lie to the platform and return no image so that it doesn't paint a yellow rectangle. 46 47 (-[WKTextFinderClient initWithPage:view:]): Deleted. 48 49 * WebProcess/WebPage/FindController.cpp: 50 (WebKit::FindController::updateFindUIAfterPageScroll): 51 Make it possible to use our find UI with 'findStringMatches'; since the platform 52 find infrastrucutre depends on knowing about all matches up front, we need 53 to use 'findStringMatches' instead of 'findString', but we had never combined 54 that with our UI. Don't throw away the other matches when we indicate one, and 55 don't send DidFindString in the case we are coming from 'findStringMatches'. 56 This all needs a bit of cleanup in the future. 57 58 (WebKit::FindController::findString): 59 Tell updateFindUIAfterPageScroll that we are 'findString' so that it uses its normal behavior. 60 61 (WebKit::FindController::findStringMatches): 62 Tell updateFindUIAfterPageScroll that we are 'findStringMatches' so that it uses the adjusted behavior. 63 64 (WebKit::FindController::indicateFindMatch): 65 Add 'indicateFindMatch', which both selects the match and moves the indicator there. 66 67 * WebProcess/WebPage/FindController.h: 68 1 69 2019-07-16 Chris Dumez <cdumez@apple.com> 2 70 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r247436 r247490 274 274 RetainPtr<WKSafeBrowsingWarning> _safeBrowsingWarning; 275 275 276 BOOL _usePlatformFindUI; 277 276 278 #if PLATFORM(IOS_FAMILY) 277 279 RetainPtr<_WKRemoteObjectRegistry> _remoteObjectRegistry; … … 770 772 771 773 _iconLoadingDelegate = std::make_unique<WebKit::IconLoadingDelegate>(self); 774 775 _usePlatformFindUI = YES; 772 776 773 777 [self _setUpSQLiteDatabaseTrackerClient]; … … 4320 4324 #endif 4321 4325 4326 - (BOOL)_usePlatformFindUI 4327 { 4328 return _usePlatformFindUI; 4329 } 4330 4331 - (void)_setUsePlatformFindUI:(BOOL)usePlatformFindUI 4332 { 4333 _usePlatformFindUI = usePlatformFindUI; 4334 4335 if (_textFinderClient) 4336 [self _hideFindUI]; 4337 _textFinderClient = nil; 4338 } 4339 4322 4340 - (WKTextFinderClient *)_ensureTextFinderClient 4323 4341 { 4324 4342 if (!_textFinderClient) 4325 _textFinderClient = adoptNS([[WKTextFinderClient alloc] initWithPage:*_page view:self ]);4343 _textFinderClient = adoptNS([[WKTextFinderClient alloc] initWithPage:*_page view:self usePlatformFindUI:_usePlatformFindUI]); 4326 4344 return _textFinderClient.get(); 4327 4345 } … … 4335 4353 { 4336 4354 [[self _ensureTextFinderClient] replaceMatches:matches withString:replacementString inSelectionOnly:selectionOnly resultCollector:resultCollector]; 4355 } 4356 4357 - (void)scrollFindMatchToVisible:(id<NSTextFinderAsynchronousDocumentFindMatch>)match 4358 { 4359 [[self _ensureTextFinderClient] scrollFindMatchToVisible:match]; 4337 4360 } 4338 4361 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
r246931 r247490 359 359 @property (nonatomic, setter=_setThumbnailView:) _WKThumbnailView *_thumbnailView WK_API_AVAILABLE(macos(10.13.4)); 360 360 @property (nonatomic, setter=_setIgnoresAllEvents:) BOOL _ignoresAllEvents WK_API_AVAILABLE(macos(10.13.4)); 361 362 // Defaults to YES; if set to NO, WebKit will draw the grey wash and highlights itself. 363 @property (nonatomic, setter=_setUsePlatformFindUI:) BOOL _usePlatformFindUI WK_API_AVAILABLE(macos(WK_MAC_TBA)); 361 364 362 365 #endif -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r247400 r247490 3575 3575 } 3576 3576 3577 void WebPageProxy::indicateFindMatch(int32_t matchIndex) 3578 { 3579 m_process->send(Messages::WebPage::IndicateFindMatch(matchIndex), m_pageID); 3580 } 3581 3577 3582 void WebPageProxy::hideFindUI() 3578 3583 { -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r247460 r247490 984 984 void getImageForFindMatch(int32_t matchIndex); 985 985 void selectFindMatch(int32_t matchIndex); 986 void indicateFindMatch(int32_t matchIndex); 986 987 void didGetImageForFindMatch(const ShareableBitmap::Handle& contentImageHandle, uint32_t matchIndex); 987 988 void hideFindUI(); -
trunk/Source/WebKit/UIProcess/mac/WKTextFinderClient.h
r242339 r247490 39 39 @interface WKTextFinderClient : NSObject 40 40 41 - (instancetype)initWithPage:(WebKit::WebPageProxy&)page view:(NSView *)view ;41 - (instancetype)initWithPage:(WebKit::WebPageProxy&)page view:(NSView *)view usePlatformFindUI:(BOOL)usePlatformFindUI; 42 42 - (void)willDestroyView:(NSView *)view; 43 43 -
trunk/Source/WebKit/UIProcess/mac/WKTextFinderClient.mm
r242339 r247490 73 73 } 74 74 75 void didFindString(WebPageProxy*, const String&, const Vector<WebCore::IntRect>& matchRects, uint32_t, int32_t, bool didWrapAround) override 76 { 77 [m_textFinderClient didFindStringMatchesWithRects:{ matchRects } didWrapAround:didWrapAround]; 75 void didFindString(WebPageProxy*, const String&, const Vector<WebCore::IntRect>& matchRects, uint32_t matchCount, int32_t matchIndex, bool didWrapAround) override 76 { 77 Vector<Vector<WebCore::IntRect>> allMatches; 78 if (matchCount != static_cast<unsigned>(kWKMoreThanMaximumMatchCount)) { 79 // Synthesize a vector of match rects for all `matchCount` matches, 80 // filling in the actual rects for the one that we received. 81 // The rest will remain empty, but it's important to NSTextFinder 82 // that they at least exist. 83 allMatches.resize(matchCount); 84 allMatches[matchIndex].appendVector(matchRects); 85 } 86 87 [m_textFinderClient didFindStringMatchesWithRects:allMatches didWrapAround:didWrapAround]; 78 88 } 79 89 … … 139 149 140 150 @implementation WKTextFinderClient { 141 WebKit::WebPageProxy *_page;151 WebKit::WebPageProxy* _page; 142 152 NSView *_view; 143 153 Deque<WTF::Function<void(NSArray *, bool didWrap)>> _findReplyCallbacks; 144 154 Deque<WTF::Function<void(NSImage *)>> _imageReplyCallbacks; 145 } 146 147 - (instancetype)initWithPage:(WebKit::WebPageProxy&)page view:(NSView *)view 155 BOOL _usePlatformFindUI; 156 } 157 158 - (instancetype)initWithPage:(WebKit::WebPageProxy&)page view:(NSView *)view usePlatformFindUI:(BOOL)usePlatformFindUI 148 159 { 149 160 self = [super init]; … … 154 165 _page = &page; 155 166 _view = view; 167 _usePlatformFindUI = usePlatformFindUI; 156 168 157 169 _page->setFindMatchesClient(std::make_unique<WebKit::TextFinderFindClient>(self)); … … 203 215 kitFindOptions |= WebKit::FindOptionsAtWordStarts; 204 216 217 if (!_usePlatformFindUI) { 218 kitFindOptions |= WebKit::FindOptionsShowOverlay; 219 kitFindOptions |= WebKit::FindOptionsShowFindIndicator; 220 kitFindOptions |= WebKit::FindOptionsDetermineMatchIndex; 221 } 222 205 223 RetainPtr<NSProgress> progress = [NSProgress progressWithTotalUnitCount:1]; 206 224 auto copiedResultCollector = Block_copy(resultCollector); … … 236 254 } 237 255 256 - (void)scrollFindMatchToVisible:(id <NSTextFinderAsynchronousDocumentFindMatch>)findMatch 257 { 258 if (_usePlatformFindUI) 259 return; 260 261 ASSERT([findMatch isKindOfClass:[WKTextFinderMatch class]]); 262 263 WKTextFinderMatch *textFinderMatch = static_cast<WKTextFinderMatch *>(findMatch); 264 _page->indicateFindMatch(textFinderMatch.index); 265 } 266 238 267 #pragma mark - FindMatchesClient 239 268 … … 255 284 RetainPtr<NSMutableArray> matchObjects = adoptNS([[NSMutableArray alloc] initWithCapacity:matchCount]); 256 285 for (unsigned i = 0; i < matchCount; i++) { 257 RetainPtr<NSArray> nsMatchRects = arrayFromRects(rectsForMatches[i]); 286 RetainPtr<NSArray> nsMatchRects; 287 288 if (_usePlatformFindUI) 289 nsMatchRects = arrayFromRects(rectsForMatches[i]); 290 else 291 nsMatchRects = @[]; 258 292 RetainPtr<WKTextFinderMatch> match = adoptNS([[WKTextFinderMatch alloc] initWithClient:self view:_view index:i rects:nsMatchRects.get()]); 259 293 [matchObjects addObject:match.get()]; … … 279 313 - (void)getImageForMatchResult:(id <NSTextFinderAsynchronousDocumentFindMatch>)findMatch completionHandler:(void (^)(NSImage *generatedImage))completionHandler 280 314 { 315 if (!_usePlatformFindUI) { 316 completionHandler(nil); 317 return; 318 } 319 281 320 ASSERT([findMatch isKindOfClass:[WKTextFinderMatch class]]); 282 321 -
trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp
r246948 r247490 131 131 } 132 132 133 void FindController::updateFindUIAfterPageScroll(bool found, const String& string, FindOptions options, unsigned maxMatchCount, DidWrap didWrap )133 void FindController::updateFindUIAfterPageScroll(bool found, const String& string, FindOptions options, unsigned maxMatchCount, DidWrap didWrap, FindUIOriginator originator) 134 134 { 135 135 Frame* selectedFrame = frameWithSelection(m_webPage->corePage()); … … 191 191 } 192 192 193 m_findMatches.clear(); 194 Vector<IntRect> matchRects; 195 if (auto range = m_webPage->corePage()->selection().firstRange()) { 196 range->absoluteTextRects(matchRects); 197 m_findMatches.append(range); 198 } 199 200 m_webPage->send(Messages::WebPageProxy::DidFindString(string, matchRects, matchCount, m_foundStringMatchIndex, didWrap == DidWrap::Yes)); 193 // If updating UI after finding an individual match, update the current 194 // match rects and inform the UI process that we succeeded. 195 // If we're doing a multi-result search and just updating the indicator, 196 // this would blow away the results for the other matches. 197 // FIXME: This whole class needs a much clearer division between these two paths. 198 if (originator == FindUIOriginator::FindString) { 199 m_findMatches.clear(); 200 Vector<IntRect> matchRects; 201 if (auto range = m_webPage->corePage()->selection().firstRange()) { 202 range->absoluteTextRects(matchRects); 203 m_findMatches.append(range); 204 } 205 206 m_webPage->send(Messages::WebPageProxy::DidFindString(string, matchRects, matchCount, m_foundStringMatchIndex, didWrap == DidWrap::Yes)); 207 } 201 208 } 202 209 … … 268 275 RefPtr<WebPage> protectedWebPage = m_webPage; 269 276 m_webPage->drawingArea()->dispatchAfterEnsuringUpdatedScrollPosition([protectedWebPage, found, string, options, maxMatchCount, didWrap] () { 270 protectedWebPage->findController().updateFindUIAfterPageScroll(found, string, options, maxMatchCount, didWrap );277 protectedWebPage->findController().updateFindUIAfterPageScroll(found, string, options, maxMatchCount, didWrap, FindUIOriginator::FindString); 271 278 }); 272 279 } … … 287 294 288 295 m_webPage->send(Messages::WebPageProxy::DidFindStringMatches(string, matchRects, indexForSelection)); 296 297 if (!(options & FindOptionsShowOverlay || options & FindOptionsShowFindIndicator)) 298 return; 299 300 bool found = !m_findMatches.isEmpty(); 301 m_webPage->drawingArea()->dispatchAfterEnsuringUpdatedScrollPosition([protectedWebPage = makeRefPtr(m_webPage), found, string, options, maxMatchCount] () { 302 protectedWebPage->findController().updateFindUIAfterPageScroll(found, string, options, maxMatchCount, DidWrap::No, FindUIOriginator::FindStringMatches); 303 }); 289 304 } 290 305 … … 324 339 return; 325 340 frame->selection().setSelection(VisibleSelection(*m_findMatches[matchIndex])); 341 } 342 343 void FindController::indicateFindMatch(uint32_t matchIndex) 344 { 345 selectFindMatch(matchIndex); 346 347 Frame* selectedFrame = frameWithSelection(m_webPage->corePage()); 348 if (!selectedFrame) 349 return; 350 351 selectedFrame->selection().revealSelection(); 352 353 updateFindIndicator(*selectedFrame, !!m_findPageOverlay); 326 354 } 327 355 -
trunk/Source/WebKit/WebProcess/WebPage/FindController.h
r246948 r247490 60 60 void getImageForFindMatch(uint32_t matchIndex); 61 61 void selectFindMatch(uint32_t matchIndex); 62 void indicateFindMatch(uint32_t matchIndex); 62 63 void hideFindUI(); 63 64 void countStringMatches(const String&, FindOptions, unsigned maxMatchCount); … … 84 85 bool updateFindIndicator(WebCore::Frame& selectedFrame, bool isShowingOverlay, bool shouldAnimate = true); 85 86 86 void updateFindUIAfterPageScroll(bool found, const String&, FindOptions, unsigned maxMatchCount, WebCore::DidWrap); 87 enum class FindUIOriginator : uint8_t { FindString, FindStringMatches }; 88 void updateFindUIAfterPageScroll(bool found, const String&, FindOptions, unsigned maxMatchCount, WebCore::DidWrap, FindUIOriginator); 87 89 88 90 void willFindString(); -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r247472 r247490 4088 4088 } 4089 4089 4090 void WebPage::indicateFindMatch(uint32_t matchIndex) 4091 { 4092 findController().indicateFindMatch(matchIndex); 4093 } 4094 4090 4095 void WebPage::hideFindUI() 4091 4096 { -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r247472 r247490 1439 1439 void getImageForFindMatch(uint32_t matchIndex); 1440 1440 void selectFindMatch(uint32_t matchIndex); 1441 void indicateFindMatch(uint32_t matchIndex); 1441 1442 void hideFindUI(); 1442 1443 void countStringMatches(const String&, uint32_t findOptions, uint32_t maxMatchCount); -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
r247460 r247490 285 285 GetImageForFindMatch(uint32_t matchIndex) 286 286 SelectFindMatch(uint32_t matchIndex) 287 IndicateFindMatch(uint32_t matchIndex) 287 288 HideFindUI() 288 289 CountStringMatches(String string, uint32_t findOptions, unsigned maxMatchCount) -
trunk/Tools/ChangeLog
r247474 r247490 1 2019-07-16 Tim Horton <timothy_horton@apple.com> 2 3 NSTextFinder holes don't scroll with the page 4 https://bugs.webkit.org/show_bug.cgi?id=199815 5 <rdar://problem/52280514> 6 7 Reviewed by Simon Fraser. 8 9 * MiniBrowser/mac/WK2BrowserWindowController.m: 10 (-[MiniBrowserNSTextFinder performAction:]): 11 (-[WK2BrowserWindowController awakeFromNib]): 12 Adopt the WebKit UI in MiniBrowser. Also, override NSTextFinder's 13 -performAction: so that we can intercept the close action and 14 hide our own find UI, since there is no delegate for that action yet. 15 16 * TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm: 17 (TEST): 18 1 19 2019-07-15 Keith Miller <keith_miller@apple.com> 2 20 -
trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m
r242339 r247490 48 48 static const int testFooterBannerHeight = 58; 49 49 50 @interface MiniBrowserNSTextFinder : NSTextFinder 51 52 @property (nonatomic, copy) dispatch_block_t hideInterfaceCallback; 53 54 @end 55 56 @implementation MiniBrowserNSTextFinder 57 58 - (void)performAction:(NSTextFinderAction)op 59 { 60 [super performAction:op]; 61 62 if (op == NSTextFinderActionHideFindInterface && _hideInterfaceCallback) 63 _hideInterfaceCallback(); 64 } 65 66 @end 67 50 68 @interface WK2BrowserWindowController () <NSTextFinderBarContainer, WKNavigationDelegate, WKUIDelegate, _WKIconLoadingDelegate> 51 69 @end … … 59 77 BOOL _useShrinkToFit; 60 78 61 NSTextFinder *_textFinder;79 MiniBrowserNSTextFinder *_textFinder; 62 80 NSView *_textFindBarView; 63 81 BOOL _findBarVisible; … … 98 116 _zoomTextOnly = NO; 99 117 100 _textFinder = [[NSTextFinder alloc] init]; 118 _webView._usePlatformFindUI = NO; 119 120 _textFinder = [[MiniBrowserNSTextFinder alloc] init]; 101 121 _textFinder.incrementalSearchingEnabled = YES; 102 _textFinder.incrementalSearchingShouldDimContentView = YES;122 _textFinder.incrementalSearchingShouldDimContentView = NO; 103 123 _textFinder.client = _webView; 104 124 _textFinder.findBarContainer = self; 125 _textFinder.hideInterfaceCallback = ^{ 126 [_webView _hideFindUI]; 127 }; 105 128 } 106 129 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm
r242339 r247490 143 143 } 144 144 145 TEST(WebKit, FindInPageWithPlatformPresentation) 146 { 147 // This should be the same as above, but does not generate rects or images, so that AppKit won't paint its find UI. 148 149 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)]); 150 [webView _setOverrideDeviceScaleFactor:2]; 151 [webView _setUsePlatformFindUI:NO]; 152 153 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"lots-of-text" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 154 [webView loadRequest:request]; 155 [webView _test_waitForDidFinishNavigation]; 156 157 // Find all matches, but recieve no rects. 158 auto result = findMatches(webView.get(), @"Birthday"); 159 EXPECT_EQ((NSUInteger)360, [result.matches count]); 160 RetainPtr<FindMatch> match = [result.matches objectAtIndex:0]; 161 EXPECT_EQ((NSUInteger)0, [match textRects].count); 162 163 // Ensure that no image is generated. 164 __block bool generateTextImageDone = false; 165 [match generateTextImage:^(NSImage *image) { 166 EXPECT_EQ(image, nullptr); 167 generateTextImageDone = true; 168 }]; 169 TestWebKitAPI::Util::run(&generateTextImageDone); 170 171 // Ensure that we cap the number of matches. There are actually 1600, but we only get the first 1000. 172 result = findMatches(webView.get(), @" "); 173 EXPECT_EQ((NSUInteger)1000, [result.matches count]); 174 } 175 145 176 TEST(WebKit, FindInPageWrapping) 146 177 {
Note: See TracChangeset
for help on using the changeset viewer.