Changeset 127594 in webkit


Ignore:
Timestamp:
Sep 5, 2012 8:38:09 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[BlackBerry] Implement number of matches and current active match index for find-on-page
https://bugs.webkit.org/show_bug.cgi?id=95801

Patch by Andy Chen <andchen@rim.com> on 2012-09-05
Reviewed by Antonio Gomes.

  • Calculate current match index for find-on-page
  • Notify client when number of matches and current match index update.

PR 162090 162091.
Internally reviewed by Mike Fenton and Joe Mason

  • Api/WebPageClient.h:
  • WebKitSupport/InPageSearchManager.cpp:

(BlackBerry::WebKit::InPageSearchManager::DeferredScopeStringMatches::DeferredScopeStringMatches):
(BlackBerry::WebKit::InPageSearchManager::DeferredScopeStringMatches::doTimeout):
(InPageSearchManager::DeferredScopeStringMatches):
(BlackBerry::WebKit::InPageSearchManager::findNextString):
(BlackBerry::WebKit::InPageSearchManager::findAndMarkText):
(BlackBerry::WebKit::InPageSearchManager::scopeStringMatches):
(BlackBerry::WebKit::InPageSearchManager::scopeStringMatchesSoon):
(BlackBerry::WebKit::InPageSearchManager::callScopeStringMatches):

  • WebKitSupport/InPageSearchManager.h:

(InPageSearchManager):

Location:
trunk/Source/WebKit/blackberry
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/blackberry/Api/WebPageClient.h

    r127489 r127594  
    274274    virtual void requestUserMedia(const Platform::WebUserMediaRequest&) = 0;
    275275    virtual void cancelUserMediaRequest(const Platform::WebUserMediaRequest&) = 0;
     276    virtual void updateFindStringResult(int numMatches, int currentIndex) = 0;
    276277};
    277278} // namespace WebKit
  • trunk/Source/WebKit/blackberry/ChangeLog

    r127515 r127594  
     12012-09-05  Andy Chen  <andchen@rim.com>
     2
     3        [BlackBerry] Implement number of matches and current active match index for find-on-page
     4        https://bugs.webkit.org/show_bug.cgi?id=95801
     5
     6        Reviewed by Antonio Gomes.
     7
     8        - Calculate current match index for find-on-page
     9        - Notify client when number of matches and current match index update.
     10        PR 162090 162091.
     11        Internally reviewed by Mike Fenton and Joe Mason
     12
     13        * Api/WebPageClient.h:
     14        * WebKitSupport/InPageSearchManager.cpp:
     15        (BlackBerry::WebKit::InPageSearchManager::DeferredScopeStringMatches::DeferredScopeStringMatches):
     16        (BlackBerry::WebKit::InPageSearchManager::DeferredScopeStringMatches::doTimeout):
     17        (InPageSearchManager::DeferredScopeStringMatches):
     18        (BlackBerry::WebKit::InPageSearchManager::findNextString):
     19        (BlackBerry::WebKit::InPageSearchManager::findAndMarkText):
     20        (BlackBerry::WebKit::InPageSearchManager::scopeStringMatches):
     21        (BlackBerry::WebKit::InPageSearchManager::scopeStringMatchesSoon):
     22        (BlackBerry::WebKit::InPageSearchManager::callScopeStringMatches):
     23        * WebKitSupport/InPageSearchManager.h:
     24        (InPageSearchManager):
     25
    1262012-09-04  Rob Buis  <rbuis@rim.com>
    227
  • trunk/Source/WebKit/blackberry/WebKitSupport/InPageSearchManager.cpp

    r120005 r127594  
    4141class InPageSearchManager::DeferredScopeStringMatches {
    4242public:
    43     DeferredScopeStringMatches(InPageSearchManager* ipsm, Frame* scopingFrame, const String& text, bool reset)
     43    DeferredScopeStringMatches(InPageSearchManager* ipsm, Frame* scopingFrame, const String& text, bool reset, bool locateActiveMatchOnly)
    4444    : m_searchManager(ipsm)
    4545    , m_scopingFrame(scopingFrame)
     
    4747    , m_searchText(text)
    4848    , m_reset(reset)
     49    , m_locateActiveMatchOnly(locateActiveMatchOnly)
    4950    {
    5051        m_timer.startOneShot(0.0);
     
    5455    void doTimeout(Timer<DeferredScopeStringMatches>*)
    5556    {
    56         m_searchManager->callScopeStringMatches(this, m_scopingFrame, m_searchText, m_reset);
     57        m_searchManager->callScopeStringMatches(this, m_scopingFrame, m_searchText, m_reset, m_locateActiveMatchOnly);
    5758    }
    5859    InPageSearchManager* m_searchManager;
     
    6162    String m_searchText;
    6263    bool m_reset;
     64    bool m_locateActiveMatchOnly;
    6365};
    6466
     
    8991        cancelPendingScopingEffort();
    9092        m_activeSearchString = String();
     93        m_webPage->m_client->updateFindStringResult(m_activeMatchCount, m_activeMatchIndex);
    9194        return false;
    9295    }
     
    9497    if (!shouldSearchForText(text)) {
    9598        m_activeSearchString = text;
     99        m_webPage->m_client->updateFindStringResult(m_activeMatchCount, m_activeMatchIndex);
    96100        return false;
    97101    }
     
    121125
    122126    // If there is any active selection, new search should start from the beginning of it.
     127    bool startFromSelection = false;
    123128    VisibleSelection selection = m_webPage->focusedOrMainFrame()->selection()->selection();
    124129    if (!selection.isNone()) {
    125130        searchStartingPoint = selection.firstRange().get();
    126131        m_webPage->focusedOrMainFrame()->selection()->clear();
     132        startFromSelection = true;
    127133    }
    128134
    129135    Frame* currentActiveMatchFrame = selection.isNone() && m_activeMatch ? m_activeMatch->ownerDocument()->frame() : m_webPage->focusedOrMainFrame();
    130136
    131     if (findAndMarkText(text, searchStartingPoint.get(), currentActiveMatchFrame, findOptions, newSearch))
     137    if (findAndMarkText(text, searchStartingPoint.get(), currentActiveMatchFrame, findOptions, newSearch, startFromSelection))
    132138        return true;
    133139
     
    140146            // matches and we're not wrapping. We have searched every frame.
    141147            ASSERT(!wrap);
     148            m_webPage->m_client->updateFindStringResult(m_activeMatchCount, m_activeMatchIndex);
    142149            return false;
    143150        }
    144151
    145         if (findAndMarkText(text, 0, currentActiveMatchFrame, findOptions, newSearch))
     152        if (findAndMarkText(text, 0, currentActiveMatchFrame, findOptions, newSearch, startFromSelection))
    146153            return true;
    147154    } while (startFrame != currentActiveMatchFrame);
     
    149156    clearTextMatches();
    150157
    151     // FIXME: We need to notify client here.
     158    m_webPage->m_client->updateFindStringResult(m_activeMatchCount, m_activeMatchIndex);
    152159    return false;
    153160}
     
    169176}
    170177
    171 bool InPageSearchManager::findAndMarkText(const String& text, Range* range, Frame* frame, const FindOptions& options, bool isNewSearch)
     178bool InPageSearchManager::findAndMarkText(const String& text, Range* range, Frame* frame, const FindOptions& options, bool isNewSearch, bool startFromSelection)
    172179{
    173180    if (RefPtr<Range> match = frame->editor()->findStringAndScrollToVisible(text, range, options)) {
    174181        // Move the highlight to the new match.
    175182        setActiveMatchAndMarker(match);
    176 
    177         if (m_highlightAllMatches) {
    178             // FIXME: If it is a not new search, we need to calculate activeMatchIndex and notify client.
    179             if (isNewSearch)
    180                 scopeStringMatches(text, true /* reset */);
     183        if (isNewSearch) {
     184            scopeStringMatches(text, true /* reset */, false /* locateActiveMatchOnly */);
     185            return true;
     186        }
     187        if (startFromSelection || m_locatingActiveMatch) {
     188            // We are finding next, but
     189            // - starting from a new node, or
     190            // - last locating active match effort is not done yet
     191            if (!m_scopingComplete) {
     192                // Last scoping is not done yet, let's restart it.
     193                scopeStringMatches(text, true /* reset */, false /* locateActiveMatchOnly */);
     194            } else {
     195                // Last scoping is done, but we are jumping to somewhere instead of
     196                // searching one by one, or there is another locating active match effort,
     197                // let's start a scoping effort to locate active match only.
     198                scopeStringMatches(text, true /* reset */, true /* locateActiveMatchOnly */);
     199            }
    181200        } else {
    182             // When only showing single matches, cancel any scoping effort and ensure
    183             // only the single active match is marked.
    184             cancelPendingScopingEffort();
     201            // We are finding next one by one, let's calculate active match index
     202            // There is at least one match, because otherwise we won't get into this block,
     203            // so m_activeMatchIndex is at least one.
     204            ASSERT(m_activeMatchCount);
     205            if (!(options & WebCore::Backwards))
     206                m_activeMatchIndex = m_activeMatchIndex + 1 > m_activeMatchCount ? 1 : m_activeMatchIndex + 1;
     207            else
     208                m_activeMatchIndex = m_activeMatchIndex - 1 < 1 ? m_activeMatchCount : m_activeMatchIndex - 1;
     209            m_webPage->m_client->updateFindStringResult(m_activeMatchCount, m_activeMatchIndex);
     210        }
     211        if (!m_highlightAllMatches) {
     212            // When only showing single matches, the scoping effort won't highlight
     213            // all matches but count them.
    185214            m_webPage->m_page->unmarkAllTextMatches();
    186215            m_activeMatch->ownerDocument()->markers()->addTextMatchMarker(m_activeMatch.get(), true);
    187216            frame->editor()->setMarkedTextMatchesAreHighlighted(true /* highlight */);
    188             m_activeMatchCount = 1;
    189             m_activeMatchIndex = 1;
    190217        }
    191218
     
    240267}
    241268
    242 void InPageSearchManager::scopeStringMatches(const String& text, bool reset, Frame* scopingFrame)
     269void InPageSearchManager::scopeStringMatches(const String& text, bool reset, bool locateActiveMatchOnly, Frame* scopingFrame)
    243270{
    244271    if (reset) {
    245         m_activeMatchCount = 0;
     272        if (!locateActiveMatchOnly) {
     273            m_activeMatchCount = 0;
     274            m_scopingComplete = false;
     275        }
    246276        m_resumeScopingFromRange = 0;
    247         m_scopingComplete = false;
    248277        m_locatingActiveMatch = true;
     278        m_activeMatchIndex = 0;
    249279        // New search should always start from mainFrame.
    250         scopeStringMatchesSoon(m_webPage->mainFrame(), text, false /* reset */);
     280        scopeStringMatchesSoon(m_webPage->mainFrame(), text, false /* reset */, locateActiveMatchOnly);
    251281        return;
    252282    }
     
    285315            foundActiveMatch = true;
    286316            m_locatingActiveMatch = false;
     317            if (locateActiveMatchOnly) {
     318                m_activeMatchIndex += matchCount;
     319                m_webPage->m_client->updateFindStringResult(m_activeMatchCount, m_activeMatchIndex);
     320                return;
     321            }
    287322            m_activeMatchIndex = m_activeMatchCount + matchCount;
    288             // FIXME: We need to notify client with m_activeMatchIndex.
    289         }
    290         resultRange->ownerDocument()->markers()->addTextMatchMarker(resultRange.get(), foundActiveMatch);
     323        }
     324        if (!locateActiveMatchOnly && m_highlightAllMatches)
     325            resultRange->ownerDocument()->markers()->addTextMatchMarker(resultRange.get(), foundActiveMatch);
    291326
    292327        searchRange->setStart(resultRange->endContainer(ec), resultRange->endOffset(ec), ec);
     
    299334
    300335    if (matchCount > 0) {
    301         scopingFrame->editor()->setMarkedTextMatchesAreHighlighted(true /* highlight */);
    302         m_activeMatchCount += matchCount;
     336        if (locateActiveMatchOnly) {
     337            // We have not found it yet.
     338            // m_activeMatchIndex now temporarily remember where we left over in this time slot.
     339            m_activeMatchIndex += matchCount;
     340        } else {
     341            if (m_highlightAllMatches)
     342                scopingFrame->editor()->setMarkedTextMatchesAreHighlighted(true /* highlight */);
     343            m_activeMatchCount += matchCount;
     344            m_webPage->m_client->updateFindStringResult(m_activeMatchCount, m_activeMatchIndex);
     345        }
    303346    }
    304347
    305348    if (timeout)
    306         scopeStringMatchesSoon(scopingFrame, text, false /* reset */);
     349        scopeStringMatchesSoon(scopingFrame, text, false /* reset */, locateActiveMatchOnly);
    307350    else {
    308351        // Scoping is done for this frame.
     
    312355            return; // Scoping is done for all frames;
    313356        }
    314         scopeStringMatchesSoon(nextFrame, text, false /* reset */);
    315     }
    316 }
    317 
    318 void InPageSearchManager::scopeStringMatchesSoon(Frame* scopingFrame, const String& text, bool reset)
    319 {
    320     m_deferredScopingWork.append(new DeferredScopeStringMatches(this, scopingFrame, text, reset));
    321 }
    322 
    323 void InPageSearchManager::callScopeStringMatches(DeferredScopeStringMatches* caller, Frame* scopingFrame, const String& text, bool reset)
     357        scopeStringMatchesSoon(nextFrame, text, false /* reset */, locateActiveMatchOnly);
     358    }
     359}
     360
     361void InPageSearchManager::scopeStringMatchesSoon(Frame* scopingFrame, const String& text, bool reset, bool locateActiveMatchOnly)
     362{
     363    m_deferredScopingWork.append(new DeferredScopeStringMatches(this, scopingFrame, text, reset, locateActiveMatchOnly));
     364}
     365
     366void InPageSearchManager::callScopeStringMatches(DeferredScopeStringMatches* caller, Frame* scopingFrame, const String& text, bool reset, bool locateActiveMatchOnly)
    324367{
    325368    m_deferredScopingWork.remove(m_deferredScopingWork.find(caller));
    326     scopeStringMatches(text, reset, scopingFrame);
     369    scopeStringMatches(text, reset, locateActiveMatchOnly, scopingFrame);
    327370    delete caller;
    328371}
  • trunk/Source/WebKit/blackberry/WebKitSupport/InPageSearchManager.h

    r127040 r127594  
    4949    void clearTextMatches();
    5050    void setActiveMatchAndMarker(PassRefPtr<WebCore::Range>);
    51     bool findAndMarkText(const String&, WebCore::Range*, WebCore::Frame*, const WebCore::FindOptions&, bool);
     51    bool findAndMarkText(const String&, WebCore::Range*, WebCore::Frame*, const WebCore::FindOptions&, bool /* isNewSearch */, bool /* startFromSelection */);
    5252    bool shouldSearchForText(const String&);
    53     void scopeStringMatches(const String& text, bool reset, WebCore::Frame* scopingFrame = 0);
    54     void scopeStringMatchesSoon(WebCore::Frame* scopingFrame, const String& text, bool reset);
    55     void callScopeStringMatches(DeferredScopeStringMatches* caller, WebCore::Frame* scopingFrame, const String& text, bool reset);
     53    void scopeStringMatches(const String& text, bool reset, bool locateActiveMatchOnly, WebCore::Frame* scopingFrame = 0);
     54    void scopeStringMatchesSoon(WebCore::Frame* scopingFrame, const String& text, bool reset, bool locateActiveMatchOnly);
     55    void callScopeStringMatches(DeferredScopeStringMatches* caller, WebCore::Frame* scopingFrame, const String& text, bool reset, bool locateActiveMatchOnly);
    5656    void cancelPendingScopingEffort();
    5757
Note: See TracChangeset for help on using the changeset viewer.