Changeset 140000 in webkit


Ignore:
Timestamp:
Jan 17, 2013 10:56:28 AM (11 years ago)
Author:
Lucas Forschler
Message:

Merged r139796. <rdar://problem/12597159>

Location:
tags/Safari-537.26.1
Files:
23 edited
1 copied

Legend:

Unmodified
Added
Removed
  • tags/Safari-537.26.1/Source/WebCore/ChangeLog

    r139910 r140000  
     12013-01-17  Lucas Forschler  <lforschler@apple.com>
     2
     3        Merge r139796
     4
     5    2013-01-15  Enrica Casucci  <enrica@apple.com>
     6
     7            Add a new set of WebKit2 APIs for text search and
     8            search results management.
     9            https://bugs.webkit.org/show_bug.cgi?id=106834.
     10            <rdar://problem/12597159>
     11
     12            Reviewed by Simon Fraser.
     13
     14            Adding new API to perform text search in WebKit2 without using
     15            the stock UI. The new interface provides all the information
     16            necessary to write a custom UI for search.
     17
     18            Added new TextWebKitAPI test.
     19
     20            * WebCore.exp.in: Added new exported methods.
     21            * editing/Editor.cpp:
     22            (WebCore::Editor::countMatchesForText): Added new parameter to store
     23            all the ranges relative to the matches found.
     24            * editing/Editor.h: Modified the interface of countMatchesForText and removed
     25            the other definition of countMatchesForText with a different signature.
     26            * page/Page.cpp:
     27            (WebCore::Page::findStringMatchingRanges): Added.
     28            (WebCore::Page::markAllMatchesForText): Changed to use the new unified
     29            countMatchesForText.
     30            * page/Page.h:
     31
    1322013-01-16  Lucas Forschler  <lforschler@apple.com>
    233
  • tags/Safari-537.26.1/Source/WebCore/WebCore.exp.in

    r139412 r140000  
    763763__ZN7WebCore4Page22nonFastScrollableRectsEPKNS_5FrameE
    764764__ZN7WebCore4Page23clearUndoRedoOperationsEv
     765__ZN7WebCore4Page24findStringMatchingRangesERKN3WTF6StringEjiPNS1_6VectorINS1_6RefPtrINS_5RangeEEELm0EEERi
    765766__ZN7WebCore4Page24resumeScriptedAnimationsEv
    766767__ZN7WebCore4Page24scrollingStateTreeAsTextEv
     
    839840__ZN7WebCore6Editor18confirmCompositionEv
    840841__ZN7WebCore6Editor18insertDictatedTextERKN3WTF6StringERKNS1_6VectorINS_20DictationAlternativeELm0EEEPNS_5EventE
    841 __ZN7WebCore6Editor19countMatchesForTextERKN3WTF6StringEPNS_5RangeEjjb
    842842__ZN7WebCore6Editor19deleteWithDirectionENS_18SelectionDirectionENS_15TextGranularityEbb
    843843__ZN7WebCore6Editor19insertUnorderedListEv
     
    869869__ZN7WebCore6Editor7commandERKN3WTF6StringE
    870870__ZN7WebCore6Editor7outdentEv
     871__ZN7WebCore6Editor19countMatchesForTextERKN3WTF6StringEPNS_5RangeEjjbPNS1_6VectorINS1_6RefPtrIS5_EELm0EEE
    871872__ZN7WebCore6JSNode6s_infoE
    872873__ZN7WebCore6Region5uniteERKS0_
  • tags/Safari-537.26.1/Source/WebCore/editing/Editor.cpp

    r139412 r140000  
    27432743}
    27442744
    2745 unsigned Editor::countMatchesForText(const String& target, FindOptions options, unsigned limit, bool markMatches)
    2746 {
    2747     return countMatchesForText(target, 0, options, limit, markMatches);
    2748 }
    2749 
    2750 unsigned Editor::countMatchesForText(const String& target, Range* range, FindOptions options, unsigned limit, bool markMatches)
     2745unsigned Editor::countMatchesForText(const String& target, Range* range, FindOptions options, unsigned limit, bool markMatches, Vector<RefPtr<Range> >* matches)
    27512746{
    27522747    if (target.isEmpty())
     
    27802775
    27812776        ++matchCount;
     2777        if (matches)
     2778            matches->append(resultRange);
     2779       
    27822780        if (markMatches)
    27832781            m_frame->document()->markers()->addMarker(resultRange.get(), DocumentMarker::TextMatch);
     
    27982796    } while (true);
    27992797
    2800     if (markMatches) {
     2798    if (markMatches || matches) {
    28012799        // Do a "fake" paint in order to execute the code that computes the rendered rect for each text match.
    28022800        if (m_frame->view() && m_frame->contentRenderer()) {
  • tags/Safari-537.26.1/Source/WebCore/editing/Editor.h

    r139412 r140000  
    362362    void respondToChangedSelection(const VisibleSelection& oldSelection, FrameSelection::SetSelectionOptions);
    363363    bool shouldChangeSelection(const VisibleSelection& oldSelection, const VisibleSelection& newSelection, EAffinity, bool stillSelecting) const;
    364     unsigned countMatchesForText(const String&, FindOptions, unsigned limit, bool markMatches);
    365     unsigned countMatchesForText(const String&, Range*, FindOptions, unsigned limit, bool markMatches);
     364    unsigned countMatchesForText(const String&, Range*, FindOptions, unsigned limit, bool markMatches, Vector<RefPtr<Range> >*);
    366365    bool markedTextMatchesAreHighlighted() const;
    367366    void setMarkedTextMatchesAreHighlighted(bool);
  • tags/Safari-537.26.1/Source/WebCore/page/Page.cpp

    r139589 r140000  
    570570}
    571571
     572void Page::findStringMatchingRanges(const String& target, FindOptions options, int limit, Vector<RefPtr<Range> >* matchRanges, int& indexForSelection)
     573{
     574    indexForSelection = 0;
     575    if (!mainFrame())
     576        return;
     577
     578    Frame* frame = mainFrame();
     579    Frame* frameWithSelection = 0;
     580    do {
     581        frame->editor()->countMatchesForText(target, 0, options, limit ? (limit - matchRanges->size()) : 0, true, matchRanges);
     582        if (frame->selection()->isRange())
     583            frameWithSelection = frame;
     584        frame = incrementFrame(frame, true, false);
     585    } while (frame);
     586
     587    if (matchRanges->isEmpty())
     588        return;
     589
     590    if (frameWithSelection) {
     591        indexForSelection = NoMatchBeforeUserSelection;
     592        RefPtr<Range> selectedRange = frameWithSelection->selection()->selection().firstRange();
     593        for (size_t i = 0; i < matchRanges->size(); ++i) {
     594            ExceptionCode ec;
     595            if (selectedRange->compareBoundaryPoints(Range::START_TO_END, matchRanges->at(i).get(), ec) < 0) {
     596                indexForSelection = i;
     597                break;
     598            }
     599        }
     600    }
     601}
     602
    572603PassRefPtr<Range> Page::rangeOfString(const String& target, Range* referenceRange, FindOptions options)
    573604{
     
    613644    do {
    614645        frame->editor()->setMarkedTextMatchesAreHighlighted(shouldHighlight);
    615         matches += frame->editor()->countMatchesForText(target, options, limit ? (limit - matches) : 0, true);
     646        matches += frame->editor()->countMatchesForText(target, 0, options, limit ? (limit - matches) : 0, true, 0);
    616647        frame = incrementFrame(frame, true, false);
    617648    } while (frame);
  • tags/Safari-537.26.1/Source/WebCore/page/Page.h

    r138991 r140000  
    237237        void unmarkAllTextMatches();
    238238
     239        // find all the Ranges for the matching text.
     240        // Upon return, indexForSelection will be one of the following:
     241        // 0 if there is no user selection
     242        // the index of the first range after the user selection
     243        // NoMatchBeforeUserSelection if there is no matching text after the user selection.
     244        enum { NoMatchBeforeUserSelection = -1 };
     245        void findStringMatchingRanges(const String&, FindOptions, int maxCount, Vector<RefPtr<Range> >*, int& indexForSelection);
    239246#if PLATFORM(MAC)
    240247        void addSchedulePair(PassRefPtr<SchedulePair>);
  • tags/Safari-537.26.1/Source/WebKit/mac/ChangeLog

    r139324 r140000  
     12013-01-17  Lucas Forschler  <lforschler@apple.com>
     2
     3        Merge r139796
     4
     5    2013-01-15  Enrica Casucci  <enrica@apple.com>
     6
     7            Add a new set of WebKit2 APIs for text search and
     8            search results management.
     9            https://bugs.webkit.org/show_bug.cgi?id=106834.
     10            <rdar://problem/12597159>
     11
     12            Reviewed by Simon Fraser.
     13
     14            Adding new API to perform text search in WebKit2 without using
     15            the stock UI. The new interface provides all the information
     16            necessary to write a custom UI for search.
     17
     18            Added new TextWebKitAPI test.
     19
     20            * WebView/WebHTMLView.mm:
     21            (-[WebHTMLView countMatchesForText:inDOMRange:options:limit:markMatches:]):
     22            Modified to reflect the changes to Editor::countMatchesForText interface.
     23
    1242013-01-10  Zan Dobersek  <zandobersek@gmail.com>
    225
  • tags/Safari-537.26.1/Source/WebKit/mac/WebView/WebHTMLView.mm

    r135882 r140000  
    62156215        return 0;
    62166216
    6217     return coreFrame->editor()->countMatchesForText(string, core(range), coreOptions(options), limit, markMatches);
     6217    return coreFrame->editor()->countMatchesForText(string, core(range), coreOptions(options), limit, markMatches, 0);
    62186218}
    62196219
  • tags/Safari-537.26.1/Source/WebKit2/ChangeLog

    r139910 r140000  
     12013-01-17  Lucas Forschler  <lforschler@apple.com>
     2
     3        Merge r139796
     4
     5    2013-01-15  Enrica Casucci  <enrica@apple.com>
     6
     7            Add a new set of WebKit2 APIs for text search and
     8            search results management.
     9            https://bugs.webkit.org/show_bug.cgi?id=106834.
     10            <rdar://problem/12597159>
     11
     12            Reviewed by Simon Fraser.
     13
     14            Adding new API to perform text search in WebKit2 without using
     15            the stock UI. The new interface provides all the information
     16            necessary to write a custom UI for search. The main logic is
     17            implemented in the new functions added to FindController.
     18
     19            Added new TextWebKitAPI test.
     20
     21            * UIProcess/API/C/WKPage.cpp:
     22            (WKPageFindStringMatches): Added.
     23            (WKPageGetImageForFindMatch): Added.
     24            (WKPageSelectFindMatch): Added.
     25            (WKPageSetPageFindMatchesClient): Added.
     26            * UIProcess/API/C/WKPage.h: Added the new API definitions.
     27            * UIProcess/WebFindClient.cpp: Added new client callbacks.
     28            (WebKit::WebFindMatchesClient::didFindStringMatches):
     29            (WebKit::WebFindMatchesClient::didGetImageForMatchResult):
     30            * UIProcess/WebFindClient.h:
     31            (WebFindMatchesClient): Added.
     32            * UIProcess/WebPageProxy.cpp: Added proxy methods.
     33            (WebKit::WebPageProxy::initializeFindMatchesClient):
     34            (WebKit::WebPageProxy::findStringMatches):
     35            (WebKit::WebPageProxy::getImageForFindMatch):
     36            (WebKit::WebPageProxy::selectFindMatch):
     37            (WebKit::WebPageProxy::didGetImageForFindMatch):
     38            (WebKit::WebPageProxy::didFindStringMatches):
     39            * UIProcess/WebPageProxy.h:
     40            * UIProcess/WebPageProxy.messages.in:
     41            * WebProcess/WebPage/FindController.cpp:
     42            (WebKit::FindController::findStringMatches): Finds all the matching
     43            text according to the find options. All the matching text ranges are
     44            stored in a vector until the next call to findStringMatches or until
     45            hideFindUI is called. The message that is sent back to the UI process
     46            contains a vector containing an entry for each find match (i.e. for each
     47            range) and each entry is represented by a vector of the corresponding
     48            text rects. It also returns the index in the vector of matches corresponding
     49            to the first match after the user selection.
     50            If there is no selection the index is always 0 and if there are no
     51            matches after the user selection, the index returned is -1.
     52            (WebKit::FindController::getFindIndicatorBitmapAndRect): Helper function
     53            to share code between updateFindIndicator and getImageForFindMatch.
     54            (WebKit::FindController::getImageForFindMatch): Creates the image corresponding
     55            to the text matched at the given match index.
     56            (WebKit::FindController::selectFindMatch): creates a selection for the range
     57            corresponding to the given match index.
     58            (WebKit::FindController::hideFindUI): Added logic to clear the vector
     59            of matched ranges.
     60            (WebKit::FindController::updateFindIndicator): Updated to use the
     61            new helper function getFindIndicatorBitmapAndRect.
     62            * WebProcess/WebPage/FindController.h:
     63            * WebProcess/WebPage/WebPage.cpp:
     64            (WebKit::WebPage::findStringMatches):
     65            (WebKit::WebPage::getImageForFindMatch):
     66            (WebKit::WebPage::selectFindMatch):
     67            * WebProcess/WebPage/WebPage.h:
     68            * WebProcess/WebPage/WebPage.messages.in:
     69
    1702013-01-16  Lucas Forschler  <lforschler@apple.com>
    271
  • tags/Safari-537.26.1/Source/WebKit2/UIProcess/API/C/WKPage.cpp

    r139023 r140000  
    494494}
    495495
     496void WKPageFindStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
     497{
     498    toImpl(pageRef)->findStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
     499}
     500
     501void WKPageGetImageForFindMatch(WKPageRef pageRef, int32_t matchIndex)
     502{
     503    toImpl(pageRef)->getImageForFindMatch(matchIndex);
     504}
     505
     506void WKPageSelectFindMatch(WKPageRef pageRef, int32_t matchIndex)
     507{
     508    toImpl(pageRef)->selectFindMatch(matchIndex);
     509}
     510
    496511void WKPageFindString(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
    497512{
     
    519534{
    520535    toImpl(pageRef)->initializeFindClient(wkClient);
     536}
     537
     538void WKPageSetPageFindMatchesClient(WKPageRef pageRef, const WKPageFindMatchesClient* wkClient)
     539{
     540    toImpl(pageRef)->initializeFindMatchesClient(wkClient);
    521541}
    522542
  • tags/Safari-537.26.1/Source/WebKit2/UIProcess/API/C/WKPage.h

    r138388 r140000  
    317317};
    318318
     319// Find match client.
     320typedef void (*WKPageDidFindStringMatchesCallback)(WKPageRef page, WKStringRef string, WKArrayRef matches, int firstIndex, const void* clientInfo);
     321typedef void (*WKPageDidGetImageForMatchResultCallback)(WKPageRef page, WKImageRef image, uint32_t index, const void* clientInfo);
     322
     323struct WKPageFindMatchesClient {
     324    int                                                                 version;
     325    const void *                                                        clientInfo;
     326    WKPageDidFindStringMatchesCallback                                  didFindStringMatches;
     327    WKPageDidGetImageForMatchResultCallback                             didGetImageForMatchResult;
     328};
     329typedef struct WKPageFindMatchesClient WKPageFindMatchesClient;
     330
     331enum { kWKPageFindMatchesClientCurrentVersion = 0 };
     332
    319333// ContextMenu client
    320334typedef void (*WKPageGetContextMenuFromProposedContextMenuCallback)(WKPageRef page, WKArrayRef proposedMenu, WKArrayRef* newMenu, WKHitTestResultRef hitTestResult, WKTypeRef userData, const void* clientInfo);
     
    453467WK_EXPORT void WKPageHideFindUI(WKPageRef page);
    454468WK_EXPORT void WKPageCountStringMatches(WKPageRef page, WKStringRef string, WKFindOptions findOptions, unsigned maxMatchCount);
     469WK_EXPORT void WKPageFindStringMatches(WKPageRef page, WKStringRef string, WKFindOptions findOptions, unsigned maxMatchCount);
     470WK_EXPORT void WKPageGetImageForFindMatch(WKPageRef page, int32_t matchIndex);
     471WK_EXPORT void WKPageSelectFindMatch(WKPageRef page, int32_t matchIndex);
    455472
    456473WK_EXPORT void WKPageSetPageContextMenuClient(WKPageRef page, const WKPageContextMenuClient* client);
    457474WK_EXPORT void WKPageSetPageFindClient(WKPageRef page, const WKPageFindClient* client);
     475WK_EXPORT void WKPageSetPageFindMatchesClient(WKPageRef page, const WKPageFindMatchesClient* client);
    458476WK_EXPORT void WKPageSetPageFormClient(WKPageRef page, const WKPageFormClient* client);
    459477WK_EXPORT void WKPageSetPageLoaderClient(WKPageRef page, const WKPageLoaderClient* client);
  • tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebFindClient.cpp

    r95901 r140000  
    5656}
    5757
     58void WebFindMatchesClient::didFindStringMatches(WebPageProxy* page, const String& string, ImmutableArray* matches, int firstIndex)
     59{
     60    if (!m_client.didFindStringMatches)
     61        return;
     62
     63    m_client.didFindStringMatches(toAPI(page), toAPI(string.impl()), toAPI(matches), firstIndex, m_client.clientInfo);
     64}
     65
     66void WebFindMatchesClient::didGetImageForMatchResult(WebPageProxy* page, WebImage* image, uint32_t index)
     67{
     68    if (!m_client.didGetImageForMatchResult)
     69        return;
     70    m_client.didGetImageForMatchResult(toAPI(page), toAPI(image), index, m_client.clientInfo);
     71}
     72
    5873} // namespace WebKit
    5974
  • tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebFindClient.h

    r95901 r140000  
    3333namespace WebKit {
    3434
     35class ImmutableArray;
    3536class WebPageProxy;
     37class WebImage;
    3638
    3739class WebFindClient : public APIClient<WKPageFindClient, kWKPageFindClientCurrentVersion> {
     
    4244};
    4345
     46class WebFindMatchesClient : public APIClient<WKPageFindMatchesClient, kWKPageFindMatchesClientCurrentVersion> {
     47public:
     48    void didFindStringMatches(WebPageProxy*, const String&, ImmutableArray*, int);
     49    void didGetImageForMatchResult(WebPageProxy*, WebImage*, uint32_t);
     50};
     51
    4452} // namespace WebKit
    4553
  • tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r139341 r140000  
    3535#include "EventDispatcherMessages.h"
    3636#include "FindIndicator.h"
     37#include "ImmutableArray.h"
    3738#include "Logging.h"
    3839#include "MessageID.h"
     
    368369}
    369370
     371void WebPageProxy::initializeFindMatchesClient(const WKPageFindMatchesClient* client)
     372{
     373    m_findMatchesClient.initialize(client);
     374}
     375
    370376#if ENABLE(CONTEXT_MENUS)
    371377void WebPageProxy::initializeContextMenuClient(const WKPageContextMenuClient* client)
     
    16831689}
    16841690
     1691void WebPageProxy::findStringMatches(const String& string, FindOptions options, unsigned maxMatchCount)
     1692{
     1693    if (string.isEmpty()) {
     1694        didFindStringMatches(string, Vector<Vector<WebCore::IntRect> > (), 0);
     1695        return;
     1696    }
     1697
     1698    m_process->send(Messages::WebPage::FindStringMatches(string, options, maxMatchCount), m_pageID);
     1699}
     1700
    16851701void WebPageProxy::findString(const String& string, FindOptions options, unsigned maxMatchCount)
    16861702{
     
    16891705    else
    16901706        m_process->send(Messages::WebPage::FindString(string, options, maxMatchCount), m_pageID);
     1707}
     1708
     1709void WebPageProxy::getImageForFindMatch(int32_t matchIndex)
     1710{
     1711    m_process->send(Messages::WebPage::GetImageForFindMatch(matchIndex), m_pageID);
     1712}
     1713
     1714void WebPageProxy::selectFindMatch(int32_t matchIndex)
     1715{
     1716    m_process->send(Messages::WebPage::SelectFindMatch(matchIndex), m_pageID);
    16911717}
    16921718
     
    30253051}
    30263052
     3053void WebPageProxy::didGetImageForFindMatch(const ShareableBitmap::Handle& contentImageHandle, uint32_t matchIndex)
     3054{
     3055    m_findMatchesClient.didGetImageForMatchResult(this, WebImage::create(ShareableBitmap::create(contentImageHandle)).get(), matchIndex);
     3056}
     3057
    30273058void WebPageProxy::setFindIndicator(const FloatRect& selectionRectInWindowCoordinates, const Vector<FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, const ShareableBitmap::Handle& contentImageHandle, bool fadeOut, bool animate)
    30283059{
     
    30343065{
    30353066    m_findClient.didFindString(this, string, matchCount);
     3067}
     3068
     3069void WebPageProxy::didFindStringMatches(const String& string, Vector<Vector<WebCore::IntRect> > matchRects, int32_t firstIndexAfterSelection)
     3070{
     3071    Vector<RefPtr<APIObject> > matches;
     3072    matches.reserveInitialCapacity(matchRects.size());
     3073
     3074    for (size_t i = 0; i < matchRects.size(); ++i) {
     3075        const Vector<WebCore::IntRect>& rects = matchRects[i];
     3076        size_t numRects = matchRects[i].size();
     3077        Vector<RefPtr<APIObject> > apiRects;
     3078        apiRects.reserveInitialCapacity(numRects);
     3079
     3080        for (size_t i = 0; i < numRects; ++i)
     3081            apiRects.uncheckedAppend(WebRect::create(toAPI(rects[i])));
     3082        matches.uncheckedAppend(ImmutableArray::adopt(apiRects));
     3083    }
     3084    m_findMatchesClient.didFindStringMatches(this, string, ImmutableArray::adopt(matches).get(), firstIndexAfterSelection);
    30363085}
    30373086
  • tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebPageProxy.h

    r139910 r140000  
    278278#endif
    279279    void initializeFindClient(const WKPageFindClient*);
     280    void initializeFindMatchesClient(const WKPageFindMatchesClient*);
    280281    void initializeFormClient(const WKPageFormClient*);
    281282    void initializeLoaderClient(const WKPageLoaderClient*);
     
    537538    // Find.
    538539    void findString(const String&, FindOptions, unsigned maxMatchCount);
     540    void findStringMatches(const String&, FindOptions, unsigned maxMatchCount);
     541    void getImageForFindMatch(int32_t matchIndex);
     542    void selectFindMatch(int32_t matchIndex);
     543    void didGetImageForFindMatch(const ShareableBitmap::Handle& contentImageHandle, uint32_t matchIndex);
    539544    void hideFindUI();
    540545    void countStringMatches(const String&, FindOptions, unsigned maxMatchCount);
     
    543548    void didFindString(const String&, uint32_t matchCount);
    544549    void didFailToFindString(const String&);
     550    void didFindStringMatches(const String&, Vector<Vector<WebCore::IntRect> > matchRects, int32_t firstIndexAfterSelection);
    545551
    546552    void getContentsAsString(PassRefPtr<StringCallback>);
     
    10441050    WebUIClient m_uiClient;
    10451051    WebFindClient m_findClient;
     1052    WebFindMatchesClient m_findMatchesClient;
    10461053#if ENABLE(CONTEXT_MENUS)
    10471054    WebPageContextMenuClient m_contextMenuClient;
  • tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebPageProxy.messages.in

    r139341 r140000  
    214214    DidFindString(WTF::String string, uint32_t matchCount)
    215215    DidFailToFindString(WTF::String string)
     216    DidFindStringMatches(WTF::String string, Vector<Vector<WebCore::IntRect> > matches, int32_t firstIndexAfterSelection)
     217    DidGetImageForFindMatch(WebKit::ShareableBitmap::Handle contentImageHandle, uint32_t matchIndex)
    216218
    217219    # PopupMenu messages
  • tags/Safari-537.26.1/Source/WebKit2/WebProcess/WebPage/FindController.cpp

    r138466 r140000  
    194194}
    195195
     196void FindController::findStringMatches(const String& string, FindOptions options, unsigned maxMatchCount)
     197{
     198    m_findMatches.clear();
     199    int indexForSelection;
     200
     201    m_webPage->corePage()->findStringMatchingRanges(string, core(options), maxMatchCount, &m_findMatches, indexForSelection);
     202
     203    Vector<Vector<IntRect> > matchRects;
     204    for (size_t i = 0; i < m_findMatches.size(); ++i) {
     205        Vector<IntRect> rects;
     206        m_findMatches[i]->textRects(rects);
     207        matchRects.append(rects);
     208    }
     209
     210    m_webPage->send(Messages::WebPageProxy::DidFindStringMatches(string, matchRects, indexForSelection));
     211}
     212
     213bool FindController::getFindIndicatorBitmapAndRect(Frame* frame, ShareableBitmap::Handle& handle, IntRect& selectionRect)
     214{
     215    selectionRect = enclosingIntRect(frame->selection()->bounds());
     216
     217    // Selection rect can be empty for matches that are currently obscured from view.
     218    if (selectionRect.isEmpty())
     219        return false;
     220
     221    IntSize backingStoreSize = selectionRect.size();
     222    backingStoreSize.scale(m_webPage->corePage()->deviceScaleFactor());
     223
     224    // Create a backing store and paint the find indicator text into it.
     225    RefPtr<ShareableBitmap> findIndicatorTextBackingStore = ShareableBitmap::createShareable(backingStoreSize, ShareableBitmap::SupportsAlpha);
     226    if (!findIndicatorTextBackingStore)
     227        return false;
     228
     229    OwnPtr<GraphicsContext> graphicsContext = findIndicatorTextBackingStore->createGraphicsContext();
     230    graphicsContext->scale(FloatSize(m_webPage->corePage()->deviceScaleFactor(), m_webPage->corePage()->deviceScaleFactor()));
     231
     232    IntRect paintRect = selectionRect;
     233    paintRect.move(frame->view()->frameRect().x(), frame->view()->frameRect().y());
     234    paintRect.move(-frame->view()->scrollOffset());
     235
     236    graphicsContext->translate(-paintRect.x(), -paintRect.y());
     237    frame->view()->setPaintBehavior(PaintBehaviorSelectionOnly | PaintBehaviorForceBlackText | PaintBehaviorFlattenCompositingLayers);
     238    frame->document()->updateLayout();
     239
     240    frame->view()->paint(graphicsContext.get(), paintRect);
     241    frame->view()->setPaintBehavior(PaintBehaviorNormal);
     242
     243    if (!findIndicatorTextBackingStore->createHandle(handle))
     244        return false;
     245    return true;
     246}
     247
     248void FindController::getImageForFindMatch(uint32_t matchIndex)
     249{
     250    if (matchIndex >= m_findMatches.size())
     251        return;
     252    Frame* frame = m_findMatches[matchIndex]->startContainer()->document()->frame();
     253    if (!frame)
     254        return;
     255
     256    VisibleSelection oldSelection = frame->selection()->selection();
     257    frame->selection()->setSelection(VisibleSelection(m_findMatches[matchIndex].get()));
     258
     259    IntRect selectionRect;
     260    ShareableBitmap::Handle handle;
     261    getFindIndicatorBitmapAndRect(frame, handle, selectionRect);
     262
     263    frame->selection()->setSelection(oldSelection);
     264
     265    m_webPage->send(Messages::WebPageProxy::DidGetImageForFindMatch(handle, matchIndex));
     266}
     267
     268void FindController::selectFindMatch(uint32_t matchIndex)
     269{
     270    if (matchIndex >= m_findMatches.size())
     271        return;
     272    Frame* frame = m_findMatches[matchIndex]->startContainer()->document()->frame();
     273    if (!frame)
     274        return;
     275    frame->selection()->setSelection(VisibleSelection(m_findMatches[matchIndex].get()));
     276}
     277
    196278void FindController::hideFindUI()
    197279{
     280    m_findMatches.clear();
    198281    if (m_findPageOverlay)
    199282        m_webPage->uninstallPageOverlay(m_findPageOverlay, false);
     
    214297        return false;
    215298
    216     IntRect selectionRect = enclosingIntRect(selectedFrame->selection()->bounds());
    217    
    218     // Selection rect can be empty for matches that are currently obscured from view.
    219     if (selectionRect.isEmpty())
     299    IntRect selectionRect;
     300    ShareableBitmap::Handle handle;
     301    if (!getFindIndicatorBitmapAndRect(selectedFrame, handle, selectionRect))
    220302        return false;
    221303
    222304    // We want the selection rect in window coordinates.
    223305    IntRect selectionRectInWindowCoordinates = selectedFrame->view()->contentsToWindow(selectionRect);
    224    
     306
    225307    Vector<FloatRect> textRects;
    226308    selectedFrame->selection()->getClippedVisibleTextRectangles(textRects);
    227 
    228     IntSize backingStoreSize = selectionRect.size();
    229     backingStoreSize.scale(m_webPage->corePage()->deviceScaleFactor());
    230 
    231     // Create a backing store and paint the find indicator text into it.
    232     RefPtr<ShareableBitmap> findIndicatorTextBackingStore = ShareableBitmap::createShareable(backingStoreSize, ShareableBitmap::SupportsAlpha);
    233     if (!findIndicatorTextBackingStore)
    234         return false;
    235    
    236     OwnPtr<GraphicsContext> graphicsContext = findIndicatorTextBackingStore->createGraphicsContext();
    237     graphicsContext->scale(FloatSize(m_webPage->corePage()->deviceScaleFactor(), m_webPage->corePage()->deviceScaleFactor()));
    238 
    239     IntRect paintRect = selectionRect;
    240     paintRect.move(selectedFrame->view()->frameRect().x(), selectedFrame->view()->frameRect().y());
    241     paintRect.move(-selectedFrame->view()->scrollOffset());
    242 
    243     graphicsContext->translate(-paintRect.x(), -paintRect.y());
    244     selectedFrame->view()->setPaintBehavior(PaintBehaviorSelectionOnly | PaintBehaviorForceBlackText | PaintBehaviorFlattenCompositingLayers);
    245     selectedFrame->document()->updateLayout();
    246 
    247     selectedFrame->view()->paint(graphicsContext.get(), paintRect);
    248     selectedFrame->view()->setPaintBehavior(PaintBehaviorNormal);
    249    
    250     ShareableBitmap::Handle handle;
    251     if (!findIndicatorTextBackingStore->createHandle(handle))
    252         return false;
    253309
    254310    // We want the text rects in selection rect coordinates.
  • tags/Safari-537.26.1/Source/WebKit2/WebProcess/WebPage/FindController.h

    r115681 r140000  
    2828
    2929#include "PageOverlay.h"
     30#include "ShareableBitmap.h"
    3031#include "WebFindOptions.h"
    3132#include <WebCore/IntRect.h>
     
    3637namespace WebCore {
    3738    class Frame;
     39    class Range;
    3840}
    3941
     
    5052
    5153    void findString(const String&, FindOptions, unsigned maxMatchCount);
     54    void findStringMatches(const String&, FindOptions, unsigned maxMatchCount);
     55    void getImageForFindMatch(uint32_t matchIndex);
     56    void selectFindMatch(uint32_t matchIndex);
    5257    void hideFindUI();
    5358    void countStringMatches(const String&, FindOptions, unsigned maxMatchCount);
     
    6974
    7075    Vector<WebCore::IntRect> rectsForTextMatches();
     76    bool getFindIndicatorBitmapAndRect(WebCore::Frame*, ShareableBitmap::Handle&, WebCore::IntRect& selectionRect);
    7177    bool updateFindIndicator(WebCore::Frame* selectedFrame, bool isShowingOverlay, bool shouldAnimate = true);
    7278
     
    8086    bool m_isShowingFindIndicator;
    8187    WebCore::IntRect m_findIndicatorRect;
     88    Vector<RefPtr<WebCore::Range> > m_findMatches;
    8289};
    8390
  • tags/Safari-537.26.1/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r139910 r140000  
    26822682}
    26832683
     2684void WebPage::findStringMatches(const String& string, uint32_t options, uint32_t maxMatchCount)
     2685{
     2686    m_findController.findStringMatches(string, static_cast<FindOptions>(options), maxMatchCount);
     2687}
     2688
     2689void WebPage::getImageForFindMatch(uint32_t matchIndex)
     2690{
     2691    m_findController.getImageForFindMatch(matchIndex);
     2692}
     2693
     2694void WebPage::selectFindMatch(uint32_t matchIndex)
     2695{
     2696    m_findController.selectFindMatch(matchIndex);
     2697}
     2698
    26842699void WebPage::hideFindUI()
    26852700{
  • tags/Safari-537.26.1/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r139910 r140000  
    735735
    736736    void findString(const String&, uint32_t findOptions, uint32_t maxMatchCount);
     737    void findStringMatches(const String&, uint32_t findOptions, uint32_t maxMatchCount);
     738    void getImageForFindMatch(uint32_t matchIndex);
     739    void selectFindMatch(uint32_t matchIndex);
    737740    void hideFindUI();
    738741    void countStringMatches(const String&, uint32_t findOptions, uint32_t maxMatchCount);
  • tags/Safari-537.26.1/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r139910 r140000  
    152152    # Find.
    153153    FindString(WTF::String string, uint32_t findOptions, unsigned maxMatchCount)
     154    FindStringMatches(WTF::String string, uint32_t findOptions, unsigned maxMatchCount)
     155    GetImageForFindMatch(uint32_t matchIndex)
     156    SelectFindMatch(uint32_t matchIndex)
    154157    HideFindUI()
    155158    CountStringMatches(WTF::String string, uint32_t findOptions, unsigned maxMatchCount)
  • tags/Safari-537.26.1/Tools/ChangeLog

    r139613 r140000  
     12013-01-17  Lucas Forschler  <lforschler@apple.com>
     2
     3        Merge r139796
     4
     5    2013-01-15  Enrica Casucci  <enrica@apple.com>
     6
     7            Add a new set of WebKit2 APIs for text search and
     8            search results management.
     9            https://bugs.webkit.org/show_bug.cgi?id=106834.
     10            <rdar://problem/12597159>
     11
     12            Added new test for the new WebKit2 API for
     13            text search.
     14
     15            Reviewed by Simon Fraser.
     16
     17            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     18            * TestWebKitAPI/Tests/WebKit2/FindMatches.mm: Added.
     19
    1202013-01-14  Andrey Lushnikov  <lushnikov@chromium.org>
    221
  • tags/Safari-537.26.1/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r139012 r140000  
    178178                C0C5D3C61459912900A802A6 /* GetBackingScaleFactor_Bundle.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */; };
    179179                C507E8A714C6545B005D6B3B /* InspectorBar.mm in Sources */ = {isa = PBXBuildFile; fileRef = C507E8A614C6545B005D6B3B /* InspectorBar.mm */; };
     180                C51AFB99169F49FF009CCF66 /* FindMatches.mm in Sources */ = {isa = PBXBuildFile; fileRef = C51AFB98169F49FF009CCF66 /* FindMatches.mm */; };
    180181                C540F776152E4DA000A40C8C /* SimplifyMarkup.mm in Sources */ = {isa = PBXBuildFile; fileRef = C540F775152E4DA000A40C8C /* SimplifyMarkup.mm */; };
    181182                C540F784152E5A9A00A40C8C /* verboseMarkup.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C540F783152E5A7800A40C8C /* verboseMarkup.html */; };
     
    446447                C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GetBackingScaleFactor_Bundle.mm; sourceTree = "<group>"; };
    447448                C507E8A614C6545B005D6B3B /* InspectorBar.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InspectorBar.mm; sourceTree = "<group>"; };
     449                C51AFB98169F49FF009CCF66 /* FindMatches.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FindMatches.mm; sourceTree = "<group>"; };
    448450                C540F775152E4DA000A40C8C /* SimplifyMarkup.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SimplifyMarkup.mm; sourceTree = "<group>"; };
    449451                C540F783152E5A7800A40C8C /* verboseMarkup.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = verboseMarkup.html; sourceTree = "<group>"; };
     
    615617                                BCC8B95A12611F4700DE46A4 /* FailedLoad.cpp */,
    616618                                1A02C84E125D4A8400E3F4BD /* Find.cpp */,
     619                                C51AFB98169F49FF009CCF66 /* FindMatches.mm */,
    617620                                1ADBEFAD130C689C00D61D19 /* ForceRepaint.cpp */,
    618621                                BCBD370F125AA2EB00D2C29F /* FrameMIMETypeHTML.cpp */,
     
    10591062                                BC9099941256ACF100083756 /* WKStringJSString.cpp in Sources */,
    10601063                                265AF55015D1E48A00B0CB4A /* WTFString.cpp in Sources */,
     1064                                C51AFB99169F49FF009CCF66 /* FindMatches.mm in Sources */,
    10611065                        );
    10621066                        runOnlyForDeploymentPostprocessing = 0;
Note: See TracChangeset for help on using the changeset viewer.