Changeset 109506 in webkit


Ignore:
Timestamp:
Mar 1, 2012 10:10:34 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[BlackBerry] Implement features for find-in-page
https://bugs.webkit.org/show_bug.cgi?id=79820

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

  • Make it be able to search text around the whole page instead of single frame.
  • Make it be able to start new search from active selection and last active match.

No new tests as this patch doesn't change behavior.

  • Api/WebPage.cpp:

(BlackBerry::WebKit::WebPagePrivate::frameUnloaded):

  • Api/WebPage_p.h:
  • WebCoreSupport/FrameLoaderClientBlackBerry.cpp:

(WebCore::FrameLoaderClientBlackBerry::dispatchWillClose):
(WebCore::FrameLoaderClientBlackBerry::detachedFromParent2):

  • WebKitSupport/DOMSupport.cpp:

(BlackBerry::WebKit::DOMSupport::incrementFrame):

  • WebKitSupport/DOMSupport.h:
  • WebKitSupport/InPageSearchManager.cpp:

(BlackBerry::WebKit::InPageSearchManager::findNextString):
(BlackBerry::WebKit::InPageSearchManager::shouldSearchForText):
(BlackBerry::WebKit::InPageSearchManager::findAndMarkText):
(BlackBerry::WebKit::InPageSearchManager::setMarkerActive):
(BlackBerry::WebKit::InPageSearchManager::frameUnloaded):

  • WebKitSupport/InPageSearchManager.h:
  • WebKitSupport/InputHandler.cpp:

(BlackBerry::WebKit::InputHandler::frameUnloaded):

  • WebKitSupport/InputHandler.h:
Location:
trunk/Source/WebKit/blackberry
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/blackberry/Api/WebPage.cpp

    r109150 r109506  
    55865586}
    55875587
    5588 }
    5589 }
     5588void WebPagePrivate::frameUnloaded(const Frame* frame)
     5589{
     5590    m_inputHandler->frameUnloaded(frame);
     5591    m_inPageSearchManager->frameUnloaded(frame);
     5592}
     5593
     5594}
     5595}
  • trunk/Source/WebKit/blackberry/Api/WebPage_p.h

    r109051 r109506  
    393393    void clearDocumentData(const WebCore::Document*);
    394394
     395    void frameUnloaded(const WebCore::Frame*);
     396
    395397    static WebCore::RenderLayer* enclosingPositionedAncestorOrSelfIfPositioned(WebCore::RenderLayer*);
    396398    static WebCore::RenderLayer* enclosingFixedPositionedAncestorOrSelfIfFixedPositioned(WebCore::RenderLayer*);
  • trunk/Source/WebKit/blackberry/ChangeLog

    r109475 r109506  
     12012-03-01  Andy Chen  <andchen@rim.com>
     2
     3        [BlackBerry] Implement features for find-in-page
     4        https://bugs.webkit.org/show_bug.cgi?id=79820
     5
     6        Reviewed by Antonio Gomes.
     7
     8        - Make it be able to search text around the whole page instead of single frame.
     9        - Make it be able to start new search from active selection and last active match.
     10
     11        No new tests as this patch doesn't change behavior.
     12
     13        * Api/WebPage.cpp:
     14        (BlackBerry::WebKit::WebPagePrivate::frameUnloaded):
     15        * Api/WebPage_p.h:
     16        * WebCoreSupport/FrameLoaderClientBlackBerry.cpp:
     17        (WebCore::FrameLoaderClientBlackBerry::dispatchWillClose):
     18        (WebCore::FrameLoaderClientBlackBerry::detachedFromParent2):
     19        * WebKitSupport/DOMSupport.cpp:
     20        (BlackBerry::WebKit::DOMSupport::incrementFrame):
     21        * WebKitSupport/DOMSupport.h:
     22        * WebKitSupport/InPageSearchManager.cpp:
     23        (BlackBerry::WebKit::InPageSearchManager::findNextString):
     24        (BlackBerry::WebKit::InPageSearchManager::shouldSearchForText):
     25        (BlackBerry::WebKit::InPageSearchManager::findAndMarkText):
     26        (BlackBerry::WebKit::InPageSearchManager::setMarkerActive):
     27        (BlackBerry::WebKit::InPageSearchManager::frameUnloaded):
     28        * WebKitSupport/InPageSearchManager.h:
     29        * WebKitSupport/InputHandler.cpp:
     30        (BlackBerry::WebKit::InputHandler::frameUnloaded):
     31        * WebKitSupport/InputHandler.h:
     32
    1332012-03-01  Charles Wei  <charles.wei@torchmobile.com.cn>
    234
  • trunk/Source/WebKit/blackberry/WebCoreSupport/FrameLoaderClientBlackBerry.cpp

    r108763 r109506  
    791791void FrameLoaderClientBlackBerry::dispatchWillClose()
    792792{
    793     m_webPagePrivate->m_inputHandler->frameUnloaded(m_frame);
     793    m_webPagePrivate->frameUnloaded(m_frame);
    794794}
    795795
     
    927927        m_webPagePrivate->clearDocumentData(m_frame->document());
    928928
    929     m_webPagePrivate->m_inputHandler->frameUnloaded(m_frame);
     929    m_webPagePrivate->frameUnloaded(m_frame);
    930930    m_webPagePrivate->m_client->notifyFrameDetached(m_frame);
    931931}
  • trunk/Source/WebKit/blackberry/WebKitSupport/DOMSupport.cpp

    r109430 r109506  
    400400}
    401401
     402// This function is copied from WebCore/page/Page.cpp.
     403Frame* incrementFrame(Frame* curr, bool forward, bool wrapFlag)
     404{
     405    return forward
     406        ? curr->tree()->traverseNextWithWrap(wrapFlag)
     407        : curr->tree()->traversePreviousWithWrap(wrapFlag);
     408}
     409
    402410} // DOMSupport
    403411} // WebKit
  • trunk/Source/WebKit/blackberry/WebKitSupport/DOMSupport.h

    r109284 r109506  
    8282WebCore::VisibleSelection visibleSelectionForClosestActualWordStart(const WebCore::VisibleSelection&);
    8383
     84WebCore::Frame* incrementFrame(WebCore::Frame* curr, bool forward, bool wrapFlag);
     85
    8486} // DOMSupport
    8587} // WebKit
  • trunk/Source/WebKit/blackberry/WebKitSupport/InPageSearchManager.cpp

    r107736 r109506  
    2020#include "InPageSearchManager.h"
    2121
     22#include "DOMSupport.h"
    2223#include "Document.h"
    2324#include "DocumentMarkerController.h"
     
    5253    }
    5354
    54     if (m_activeSearchString != text) {
    55         clearTextMatches();
     55    if (!shouldSearchForText(text)) {
    5656        m_activeSearchString = text;
    57         m_activeMatchCount = m_webPage->m_page->markAllMatchesForText(text, WebCore::CaseInsensitive, true, TextMatchMarkerLimit);
    58     } else
    59         setMarkerActive(m_activeMatch.get(), false);
     57        return false;
     58    }
    6059
    61     if (!m_activeMatchCount)
     60    // Validate the range in case any node has been removed since last search.
     61    if (m_activeMatch && !m_activeMatch->boundaryPointsValid())
     62        m_activeMatch = 0;
     63
     64    RefPtr<Range> searchStartingPoint(m_activeMatch);
     65    if (m_activeSearchString != text) { // Start a new search.
     66        m_activeSearchString = text;
     67        m_webPage->m_page->unmarkAllTextMatches();
     68        m_activeMatchCount = m_webPage->m_page->markAllMatchesForText(text, CaseInsensitive, true /* shouldHighlight */, TextMatchMarkerLimit);
     69        if (!m_activeMatchCount) {
     70            clearTextMatches();
     71            return false;
     72        }
     73    } else { // Search same string for next occurrence.
     74        setMarkerActive(m_activeMatch.get(), false /* active */);
     75        // Searching for same string should start from the end of last match.
     76        if (m_activeMatch) {
     77            if (forward)
     78                searchStartingPoint->setStart(searchStartingPoint->endPosition());
     79            else
     80                searchStartingPoint->setEnd(searchStartingPoint->startPosition());
     81        }
     82    }
     83
     84    // If there is any active selection, new search should start from the beginning of it.
     85    VisibleSelection selection = m_webPage->focusedOrMainFrame()->selection()->selection();
     86    if (!selection.isNone()) {
     87        searchStartingPoint = selection.firstRange().get();
     88        m_webPage->focusedOrMainFrame()->selection()->clear();
     89    }
     90
     91    Frame* currentActiveMatchFrame = selection.isNone() && m_activeMatch ? m_activeMatch->ownerDocument()->frame() : m_webPage->focusedOrMainFrame();
     92
     93    const FindOptions findOptions = (forward ? 0 : Backwards)
     94        | CaseInsensitive
     95        | StartInSelection;
     96
     97    if (findAndMarkText(text, searchStartingPoint.get(), currentActiveMatchFrame, findOptions))
     98        return true;
     99
     100    Frame* startFrame = currentActiveMatchFrame;
     101    do {
     102        currentActiveMatchFrame = DOMSupport::incrementFrame(currentActiveMatchFrame, forward, true /* wrapFlag */);
     103        if (findAndMarkText(text, 0, currentActiveMatchFrame, findOptions))
     104            return true;
     105    } while (currentActiveMatchFrame && startFrame != currentActiveMatchFrame);
     106
     107    clearTextMatches();
     108
     109    ASSERT_NOT_REACHED();
     110    return false;
     111}
     112
     113bool InPageSearchManager::shouldSearchForText(const String& text)
     114{
     115    if (text == m_activeSearchString)
     116        return m_activeMatchCount;
     117
     118    // If the previous search string is prefix of new search string,
     119    // don't search if the previous one has zero result.
     120    if (!m_activeMatchCount
     121        && m_activeSearchString.length()
     122        && text.length() > m_activeSearchString.length()
     123        && m_activeSearchString == text.substring(0, m_activeSearchString.length()))
    62124        return false;
     125    return true;
     126}
    63127
    64     const FindOptions findOptions = (forward ? 0 : WebCore::Backwards)
    65         | WebCore::CaseInsensitive
    66         | WebCore::WrapAround; // TODO should wrap around in page, not in frame
    67 
    68     // TODO StartInSelection
    69 
    70     m_activeMatch = m_webPage->mainFrame()->editor()->findStringAndScrollToVisible(text, m_activeMatch.get(), findOptions);
    71     setMarkerActive(m_activeMatch.get(), true);
    72 
    73     return true;
     128bool InPageSearchManager::findAndMarkText(const String& text, Range* range, Frame* frame, const FindOptions& options)
     129{
     130    m_activeMatch = frame->editor()->findStringAndScrollToVisible(text, range, options);
     131    if (m_activeMatch) {
     132        setMarkerActive(m_activeMatch.get(), true /* active */);
     133        return true;
     134    }
     135    return false;
    74136}
    75137
     
    80142}
    81143
    82 void InPageSearchManager::setMarkerActive(WebCore::Range* range, bool active)
     144void InPageSearchManager::setMarkerActive(Range* range, bool active)
    83145{
    84146    if (!range)
    85147        return;
    86     WebCore::Document* doc = m_webPage->mainFrame()->document();
     148    Document* doc = m_activeMatch->ownerDocument();
    87149    if (!doc)
    88150        return;
     
    90152}
    91153
     154void InPageSearchManager::frameUnloaded(const Frame* frame)
     155{
     156    if (!m_activeMatch) {
     157        if (m_webPage->mainFrame() == frame && m_activeSearchString.length())
     158            m_activeSearchString = String();
     159        return;
     160    }
     161
     162    Frame* currentActiveMatchFrame = m_activeMatch->ownerDocument()->frame();
     163    if (currentActiveMatchFrame == frame) {
     164        m_activeMatch = 0;
     165        m_activeSearchString = String();
     166        m_activeMatchCount = 0;
     167        // FIXME: We need to notify client here.
     168        if (frame == m_webPage->mainFrame()) // Don't need to unmark because the page will be destroyed.
     169            return;
     170        m_webPage->m_page->unmarkAllTextMatches();
     171    }
     172}
     173
    92174}
    93175}
  • trunk/Source/WebKit/blackberry/WebKitSupport/InPageSearchManager.h

    r107736 r109506  
    2020#define InPageSearchManager_h
    2121
     22#include "FindOptions.h"
    2223#include "WTFString.h"
    2324
    24 #include <wtf/RefPtr.h>
    25 
    2625namespace WebCore {
     26class Frame;
    2727class Range;
     28class VisibleSelection;
    2829}
    2930
     
    4041
    4142    bool findNextString(const String& text, bool forward);
     43    void frameUnloaded(const WebCore::Frame*);
    4244
    4345private:
    4446    void clearTextMatches();
    45     void setMarkerActive(WebCore::Range*, bool active);
     47    void setMarkerActive(WebCore::Range*, bool);
     48    bool findAndMarkText(const String&, WebCore::Range*, WebCore::Frame*, const WebCore::FindOptions&);
     49    bool shouldSearchForText(const String&);
    4650
    4751    WebPagePrivate* m_webPage;
  • trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp

    r109284 r109506  
    711711}
    712712
    713 void InputHandler::frameUnloaded(Frame* frame)
     713void InputHandler::frameUnloaded(const Frame* frame)
    714714{
    715715    if (!isActiveTextEdit())
  • trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h

    r108702 r109506  
    6161    void nodeTextChanged(const WebCore::Node*);
    6262    void selectionChanged();
    63     void frameUnloaded(WebCore::Frame*);
     63    void frameUnloaded(const WebCore::Frame*);
    6464
    6565    bool handleKeyboardInput(const BlackBerry::Platform::KeyboardEvent&, bool changeIsPartOfComposition = false);
Note: See TracChangeset for help on using the changeset viewer.