Changeset 247490 in webkit


Ignore:
Timestamp:
Jul 16, 2019 12:46:32 PM (5 years ago)
Author:
timothy_horton@apple.com
Message:

NSTextFinder holes don't scroll with the page
https://bugs.webkit.org/show_bug.cgi?id=199815
<rdar://problem/52280514>

Reviewed by Simon Fraser.

Source/WebCore:

  • rendering/ScrollAlignment.h:

Source/WebKit:

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _usePlatformFindUI]):
(-[WKWebView _setUsePlatformFindUI:]):
(-[WKWebView _ensureTextFinderClient]):
Add a bit so that clients can choose whether they want our find UI,
which respects scrolling, or the system find UI, which works when
doing multi-document searches. Right now you can't have both.

(-[WKWebView scrollFindMatchToVisible:]):
Implement and plumb scrollFindMatchToVisible.

  • UIProcess/API/Cocoa/WKWebViewPrivate.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::indicateFindMatch):

  • UIProcess/WebPageProxy.h:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::indicateFindMatch):

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

Plumb indicateFindMatch to FindController.

  • UIProcess/mac/WKTextFinderClient.h:
  • UIProcess/mac/WKTextFinderClient.mm:

(-[WKTextFinderClient initWithPage:view:usePlatformFindUI:]):
Store whether or not we are using the platform find UI.

(-[WKTextFinderClient findMatchesForString:relativeToMatch:findOptions:maxResults:resultCollector:]):
If using WebKit find UI, turn on our UI in the options passed to findString[Matches].

(-[WKTextFinderClient scrollFindMatchToVisible:]):
If using WebKit find UI, when the platform tells us to reveal a find match, indicate it.

(-[WKTextFinderClient didFindStringMatchesWithRects:didWrapAround:]):
If using WebKit find UI, lie to the platform and return no rects so that it doesn't paint a yellow rectangle.

(-[WKTextFinderClient getImageForMatchResult:completionHandler:]):
If using WebKit find UI, lie to the platform and return no image so that it doesn't paint a yellow rectangle.

(-[WKTextFinderClient initWithPage:view:]): Deleted.

  • WebProcess/WebPage/FindController.cpp:

(WebKit::FindController::updateFindUIAfterPageScroll):
Make it possible to use our find UI with 'findStringMatches'; since the platform
find infrastrucutre depends on knowing about all matches up front, we need
to use 'findStringMatches' instead of 'findString', but we had never combined
that with our UI. Don't throw away the other matches when we indicate one, and
don't send DidFindString in the case we are coming from 'findStringMatches'.
This all needs a bit of cleanup in the future.

(WebKit::FindController::findString):
Tell updateFindUIAfterPageScroll that we are 'findString' so that it uses its normal behavior.

(WebKit::FindController::findStringMatches):
Tell updateFindUIAfterPageScroll that we are 'findStringMatches' so that it uses the adjusted behavior.

(WebKit::FindController::indicateFindMatch):
Add 'indicateFindMatch', which both selects the match and moves the indicator there.

  • WebProcess/WebPage/FindController.h:

Tools:

  • MiniBrowser/mac/WK2BrowserWindowController.m:

(-[MiniBrowserNSTextFinder performAction:]):
(-[WK2BrowserWindowController awakeFromNib]):
Adopt the WebKit UI in MiniBrowser. Also, override NSTextFinder's
-performAction: so that we can intercept the close action and
hide our own find UI, since there is no delegate for that action yet.

  • TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm:

(TEST):

Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r247489 r247490  
     12019-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
    1112019-07-16  Youenn Fablet  <youenn@apple.com>
    212
  • trunk/Source/WebCore/PAL/pal/spi/mac/NSTextFinderSPI.h

    r238438 r247490  
    5353- (void)selectFindMatch:(id <NSTextFinderAsynchronousDocumentFindMatch>)findMatch completionHandler:(void (^)(void))completionHandler;
    5454- (void)replaceMatches:(NSArray *)matches withString:(NSString *)replacementString inSelectionOnly:(BOOL)selectionOnly resultCollector:(void (^)(NSUInteger replacementCount))resultCollector;
     55- (void)scrollFindMatchToVisible:(id <NSTextFinderAsynchronousDocumentFindMatch>)findMatch;
    5556
    5657@end
  • trunk/Source/WebCore/rendering/ScrollAlignment.h

    r220503 r247490  
    6868    static const ScrollAlignment alignCenterIfNotVisible;
    6969    static const ScrollAlignment alignToEdgeIfNotVisible;
    70     static const ScrollAlignment alignCenterIfNeeded;
     70    WEBCORE_EXPORT static const ScrollAlignment alignCenterIfNeeded;
    7171    WEBCORE_EXPORT static const ScrollAlignment alignToEdgeIfNeeded;
    7272    WEBCORE_EXPORT static const ScrollAlignment alignCenterAlways;
  • trunk/Source/WebKit/ChangeLog

    r247486 r247490  
     12019-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
    1692019-07-16  Chris Dumez  <cdumez@apple.com>
    270
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r247436 r247490  
    274274    RetainPtr<WKSafeBrowsingWarning> _safeBrowsingWarning;
    275275
     276    BOOL _usePlatformFindUI;
     277
    276278#if PLATFORM(IOS_FAMILY)
    277279    RetainPtr<_WKRemoteObjectRegistry> _remoteObjectRegistry;
     
    770772
    771773    _iconLoadingDelegate = std::make_unique<WebKit::IconLoadingDelegate>(self);
     774
     775    _usePlatformFindUI = YES;
    772776
    773777    [self _setUpSQLiteDatabaseTrackerClient];
     
    43204324#endif
    43214325
     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
    43224340- (WKTextFinderClient *)_ensureTextFinderClient
    43234341{
    43244342    if (!_textFinderClient)
    4325         _textFinderClient = adoptNS([[WKTextFinderClient alloc] initWithPage:*_page view:self]);
     4343        _textFinderClient = adoptNS([[WKTextFinderClient alloc] initWithPage:*_page view:self usePlatformFindUI:_usePlatformFindUI]);
    43264344    return _textFinderClient.get();
    43274345}
     
    43354353{
    43364354    [[self _ensureTextFinderClient] replaceMatches:matches withString:replacementString inSelectionOnly:selectionOnly resultCollector:resultCollector];
     4355}
     4356
     4357- (void)scrollFindMatchToVisible:(id<NSTextFinderAsynchronousDocumentFindMatch>)match
     4358{
     4359    [[self _ensureTextFinderClient] scrollFindMatchToVisible:match];
    43374360}
    43384361
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h

    r246931 r247490  
    359359@property (nonatomic, setter=_setThumbnailView:) _WKThumbnailView *_thumbnailView WK_API_AVAILABLE(macos(10.13.4));
    360360@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));
    361364
    362365#endif
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r247400 r247490  
    35753575}
    35763576
     3577void WebPageProxy::indicateFindMatch(int32_t matchIndex)
     3578{
     3579    m_process->send(Messages::WebPage::IndicateFindMatch(matchIndex), m_pageID);
     3580}
     3581
    35773582void WebPageProxy::hideFindUI()
    35783583{
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r247460 r247490  
    984984    void getImageForFindMatch(int32_t matchIndex);
    985985    void selectFindMatch(int32_t matchIndex);
     986    void indicateFindMatch(int32_t matchIndex);
    986987    void didGetImageForFindMatch(const ShareableBitmap::Handle& contentImageHandle, uint32_t matchIndex);
    987988    void hideFindUI();
  • trunk/Source/WebKit/UIProcess/mac/WKTextFinderClient.h

    r242339 r247490  
    3939@interface WKTextFinderClient : NSObject
    4040
    41 - (instancetype)initWithPage:(WebKit::WebPageProxy&)page view:(NSView *)view;
     41- (instancetype)initWithPage:(WebKit::WebPageProxy&)page view:(NSView *)view usePlatformFindUI:(BOOL)usePlatformFindUI;
    4242- (void)willDestroyView:(NSView *)view;
    4343
  • trunk/Source/WebKit/UIProcess/mac/WKTextFinderClient.mm

    r242339 r247490  
    7373    }
    7474
    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];
    7888    }
    7989
     
    139149
    140150@implementation WKTextFinderClient {
    141     WebKit::WebPageProxy *_page;
     151    WebKit::WebPageProxy* _page;
    142152    NSView *_view;
    143153    Deque<WTF::Function<void(NSArray *, bool didWrap)>> _findReplyCallbacks;
    144154    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
    148159{
    149160    self = [super init];
     
    154165    _page = &page;
    155166    _view = view;
     167    _usePlatformFindUI = usePlatformFindUI;
    156168   
    157169    _page->setFindMatchesClient(std::make_unique<WebKit::TextFinderFindClient>(self));
     
    203215        kitFindOptions |= WebKit::FindOptionsAtWordStarts;
    204216
     217    if (!_usePlatformFindUI) {
     218        kitFindOptions |= WebKit::FindOptionsShowOverlay;
     219        kitFindOptions |= WebKit::FindOptionsShowFindIndicator;
     220        kitFindOptions |= WebKit::FindOptionsDetermineMatchIndex;
     221    }
     222
    205223    RetainPtr<NSProgress> progress = [NSProgress progressWithTotalUnitCount:1];
    206224    auto copiedResultCollector = Block_copy(resultCollector);
     
    236254}
    237255
     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
    238267#pragma mark - FindMatchesClient
    239268
     
    255284    RetainPtr<NSMutableArray> matchObjects = adoptNS([[NSMutableArray alloc] initWithCapacity:matchCount]);
    256285    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 = @[];
    258292        RetainPtr<WKTextFinderMatch> match = adoptNS([[WKTextFinderMatch alloc] initWithClient:self view:_view index:i rects:nsMatchRects.get()]);
    259293        [matchObjects addObject:match.get()];
     
    279313- (void)getImageForMatchResult:(id <NSTextFinderAsynchronousDocumentFindMatch>)findMatch completionHandler:(void (^)(NSImage *generatedImage))completionHandler
    280314{
     315    if (!_usePlatformFindUI) {
     316        completionHandler(nil);
     317        return;
     318    }
     319
    281320    ASSERT([findMatch isKindOfClass:[WKTextFinderMatch class]]);
    282321
  • trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp

    r246948 r247490  
    131131}
    132132
    133 void FindController::updateFindUIAfterPageScroll(bool found, const String& string, FindOptions options, unsigned maxMatchCount, DidWrap didWrap)
     133void FindController::updateFindUIAfterPageScroll(bool found, const String& string, FindOptions options, unsigned maxMatchCount, DidWrap didWrap, FindUIOriginator originator)
    134134{
    135135    Frame* selectedFrame = frameWithSelection(m_webPage->corePage());
     
    191191        }
    192192
    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        }
    201208    }
    202209
     
    268275    RefPtr<WebPage> protectedWebPage = m_webPage;
    269276    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);
    271278    });
    272279}
     
    287294
    288295    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    });
    289304}
    290305
     
    324339        return;
    325340    frame->selection().setSelection(VisibleSelection(*m_findMatches[matchIndex]));
     341}
     342
     343void 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);
    326354}
    327355
  • trunk/Source/WebKit/WebProcess/WebPage/FindController.h

    r246948 r247490  
    6060    void getImageForFindMatch(uint32_t matchIndex);
    6161    void selectFindMatch(uint32_t matchIndex);
     62    void indicateFindMatch(uint32_t matchIndex);
    6263    void hideFindUI();
    6364    void countStringMatches(const String&, FindOptions, unsigned maxMatchCount);
     
    8485    bool updateFindIndicator(WebCore::Frame& selectedFrame, bool isShowingOverlay, bool shouldAnimate = true);
    8586
    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);
    8789
    8890    void willFindString();
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r247472 r247490  
    40884088}
    40894089
     4090void WebPage::indicateFindMatch(uint32_t matchIndex)
     4091{
     4092    findController().indicateFindMatch(matchIndex);
     4093}
     4094
    40904095void WebPage::hideFindUI()
    40914096{
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r247472 r247490  
    14391439    void getImageForFindMatch(uint32_t matchIndex);
    14401440    void selectFindMatch(uint32_t matchIndex);
     1441    void indicateFindMatch(uint32_t matchIndex);
    14411442    void hideFindUI();
    14421443    void countStringMatches(const String&, uint32_t findOptions, uint32_t maxMatchCount);
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r247460 r247490  
    285285    GetImageForFindMatch(uint32_t matchIndex)
    286286    SelectFindMatch(uint32_t matchIndex)
     287    IndicateFindMatch(uint32_t matchIndex)
    287288    HideFindUI()
    288289    CountStringMatches(String string, uint32_t findOptions, unsigned maxMatchCount)
  • trunk/Tools/ChangeLog

    r247474 r247490  
     12019-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
    1192019-07-15  Keith Miller  <keith_miller@apple.com>
    220
  • trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m

    r242339 r247490  
    4848static const int testFooterBannerHeight = 58;
    4949
     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
    5068@interface WK2BrowserWindowController () <NSTextFinderBarContainer, WKNavigationDelegate, WKUIDelegate, _WKIconLoadingDelegate>
    5169@end
     
    5977    BOOL _useShrinkToFit;
    6078
    61     NSTextFinder *_textFinder;
     79    MiniBrowserNSTextFinder *_textFinder;
    6280    NSView *_textFindBarView;
    6381    BOOL _findBarVisible;
     
    98116    _zoomTextOnly = NO;
    99117
    100     _textFinder = [[NSTextFinder alloc] init];
     118    _webView._usePlatformFindUI = NO;
     119
     120    _textFinder = [[MiniBrowserNSTextFinder alloc] init];
    101121    _textFinder.incrementalSearchingEnabled = YES;
    102     _textFinder.incrementalSearchingShouldDimContentView = YES;
     122    _textFinder.incrementalSearchingShouldDimContentView = NO;
    103123    _textFinder.client = _webView;
    104124    _textFinder.findBarContainer = self;
     125    _textFinder.hideInterfaceCallback = ^{
     126        [_webView _hideFindUI];
     127    };
    105128}
    106129
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm

    r242339 r247490  
    143143}
    144144
     145TEST(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
    145176TEST(WebKit, FindInPageWrapping)
    146177{
Note: See TracChangeset for help on using the changeset viewer.