Changeset 214893 in webkit for trunk/Source/WebCore/page/Page.cpp


Ignore:
Timestamp:
Apr 4, 2017, 12:59:52 PM (8 years ago)
Author:
[email protected]
Message:

[Mac] -[WKWebView findMatchesForString:relativeToMatch:findOptions:maxResults:resultCollector:] invokes the resultCollector with didWrap = NO even when it wraps
https://bugs.webkit.org/show_bug.cgi?id=165801
<rdar://problem/29649535>

Reviewed by Wenson Hsieh.

New API tests: WebKit2.FindInPageWrapping*

Previously, when doing an incremental find that wrapped, we would
say that it did not, leading NSTextFinder to not provide its usual
wrapping UI, and other clients of the NSTextFinderClient protocol to
get confused by the lack of wrapping.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::didFindString):

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • UIProcess/API/APIFindClient.h:

(API::FindClient::didFindString):

  • UIProcess/API/C/WKPage.cpp:

(WKPageSetPageFindClient):

  • UIProcess/Cocoa/FindClient.h:
  • UIProcess/Cocoa/FindClient.mm:

(WebKit::FindClient::didFindString):

  • WebProcess/WebPage/FindController.cpp:

(WebKit::FindController::updateFindUIAfterPageScroll):
(WebKit::FindController::findString):

  • WebProcess/WebPage/FindController.h:

Plumb DidWrap from FindController's call to findString back through
the DidFindString message.

  • UIProcess/mac/WKTextFinderClient.mm:

(-[WKTextFinderClient didFindStringMatchesWithRects:didWrapAround:]):
(-[WKTextFinderClient didFindStringMatchesWithRects:]): Deleted.
Make use of the new DidWrap information to stop lying to NSTextFinder
about whether a wrap actually occurred.

  • page/FrameTree.cpp:

(WebCore::FrameTree::traverseNextWithWrap):
(WebCore::FrameTree::traversePreviousWithWrap):
(WebCore::FrameTree::traverseNextInPostOrderWithWrap):

  • page/FrameTree.h:

Add CanWrap and DidWrap boolean enums, and add an optional out argument
to traverse*WithWrap indicating whether a wrap actually occurred.

  • history/CachedPage.cpp:

(WebCore::firePageShowAndPopStateEvents):

  • history/PageCache.cpp:

(WebCore::destroyRenderTree):
Adjust to the new CanWrap enum.

  • page/Page.cpp:

(WebCore::incrementFrame):
(WebCore::Page::findString):
(WebCore::Page::findStringMatchingRanges):
(WebCore::Page::rangeOfString):
(WebCore::Page::findMatchesForText):
(WebCore::Page::unmarkAllTextMatches):

  • page/Page.h:

Adjust to the new CanWrap enum, and optionally plumb DidWrap through
to callers of findString().

  • WebView/WebView.mm:

(incrementFrame):
Adjust to the new CanWrap enum.

  • TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm:

(TEST):
Add some tests for wrapping finds.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/page/Page.cpp

    r214621 r214893  
    648648}
    649649
    650 static Frame* incrementFrame(Frame* curr, bool forward, bool wrapFlag)
     650static Frame* incrementFrame(Frame* curr, bool forward, CanWrap canWrap, DidWrap* didWrap = nullptr)
    651651{
    652652    return forward
    653         ? curr->tree().traverseNextWithWrap(wrapFlag)
    654         : curr->tree().traversePreviousWithWrap(wrapFlag);
    655 }
    656 
    657 bool Page::findString(const String& target, FindOptions options)
     653        ? curr->tree().traverseNext(canWrap, didWrap)
     654        : curr->tree().traversePrevious(canWrap, didWrap);
     655}
     656
     657bool Page::findString(const String& target, FindOptions options, DidWrap* didWrap)
    658658{
    659659    if (target.isEmpty())
    660660        return false;
    661661
    662     bool shouldWrap = options & WrapAround;
     662    CanWrap canWrap = options & WrapAround ? CanWrap::Yes : CanWrap::No;
    663663    Frame* frame = &focusController().focusedOrMainFrame();
    664664    Frame* startFrame = frame;
     
    670670            return true;
    671671        }
    672         frame = incrementFrame(frame, !(options & Backwards), shouldWrap);
     672        frame = incrementFrame(frame, !(options & Backwards), canWrap, didWrap);
    673673    } while (frame && frame != startFrame);
    674674
    675675    // Search contents of startFrame, on the other side of the selection that we did earlier.
    676676    // We cheat a bit and just research with wrap on
    677     if (shouldWrap && !startFrame->selection().isNone()) {
     677    if (canWrap == CanWrap::Yes && !startFrame->selection().isNone()) {
     678        if (didWrap)
     679            *didWrap = DidWrap::Yes;
    678680        bool found = startFrame->editor().findString(target, options | WrapAround | StartInSelection);
    679681        focusController().setFocusedFrame(frame);
     
    694696        if (frame->selection().isRange())
    695697            frameWithSelection = frame;
    696         frame = incrementFrame(frame, true, false);
     698        frame = incrementFrame(frame, true, CanWrap::No);
    697699    } while (frame);
    698700
     
    736738        return nullptr;
    737739
    738     bool shouldWrap = options & WrapAround;
     740    CanWrap canWrap = options & WrapAround ? CanWrap::Yes : CanWrap::No;
    739741    Frame* frame = referenceRange ? referenceRange->ownerDocument().frame() : &mainFrame();
    740742    Frame* startFrame = frame;
     
    743745            return resultRange;
    744746
    745         frame = incrementFrame(frame, !(options & Backwards), shouldWrap);
     747        frame = incrementFrame(frame, !(options & Backwards), canWrap);
    746748    } while (frame && frame != startFrame);
    747749
    748750    // Search contents of startFrame, on the other side of the reference range that we did earlier.
    749751    // We cheat a bit and just search again with wrap on.
    750     if (shouldWrap && referenceRange) {
     752    if (canWrap == CanWrap::Yes && referenceRange) {
    751753        if (RefPtr<Range> resultRange = startFrame->editor().rangeOfString(target, referenceRange, options | WrapAround | StartInSelection))
    752754            return resultRange;
     
    768770            frame->editor().setMarkedTextMatchesAreHighlighted(shouldHighlightMatches == HighlightMatches);
    769771        matchCount += frame->editor().countMatchesForText(target, 0, options, maxMatchCount ? (maxMatchCount - matchCount) : 0, shouldMarkMatches == MarkMatches, 0);
    770         frame = incrementFrame(frame, true, false);
     772        frame = incrementFrame(frame, true, CanWrap::No);
    771773    } while (frame);
    772774
     
    789791    do {
    790792        frame->document()->markers().removeMarkers(DocumentMarker::TextMatch);
    791         frame = incrementFrame(frame, true, false);
     793        frame = incrementFrame(frame, true, CanWrap::No);
    792794    } while (frame);
    793795}
Note: See TracChangeset for help on using the changeset viewer.