Title: [109506] trunk/Source/WebKit/blackberry
Revision
109506
Author
[email protected]
Date
2012-03-01 22:10:34 -0800 (Thu, 01 Mar 2012)

Log Message

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

Patch by Andy Chen <[email protected]> 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:

Modified Paths

Diff

Modified: trunk/Source/WebKit/blackberry/Api/WebPage.cpp (109505 => 109506)


--- trunk/Source/WebKit/blackberry/Api/WebPage.cpp	2012-03-02 05:56:38 UTC (rev 109505)
+++ trunk/Source/WebKit/blackberry/Api/WebPage.cpp	2012-03-02 06:10:34 UTC (rev 109506)
@@ -5585,5 +5585,11 @@
     m_needTouchEvents = value;
 }
 
+void WebPagePrivate::frameUnloaded(const Frame* frame)
+{
+    m_inputHandler->frameUnloaded(frame);
+    m_inPageSearchManager->frameUnloaded(frame);
 }
+
 }
+}

Modified: trunk/Source/WebKit/blackberry/Api/WebPage_p.h (109505 => 109506)


--- trunk/Source/WebKit/blackberry/Api/WebPage_p.h	2012-03-02 05:56:38 UTC (rev 109505)
+++ trunk/Source/WebKit/blackberry/Api/WebPage_p.h	2012-03-02 06:10:34 UTC (rev 109506)
@@ -392,6 +392,8 @@
     // Clean up any document related data we might be holding.
     void clearDocumentData(const WebCore::Document*);
 
+    void frameUnloaded(const WebCore::Frame*);
+
     static WebCore::RenderLayer* enclosingPositionedAncestorOrSelfIfPositioned(WebCore::RenderLayer*);
     static WebCore::RenderLayer* enclosingFixedPositionedAncestorOrSelfIfFixedPositioned(WebCore::RenderLayer*);
 

Modified: trunk/Source/WebKit/blackberry/ChangeLog (109505 => 109506)


--- trunk/Source/WebKit/blackberry/ChangeLog	2012-03-02 05:56:38 UTC (rev 109505)
+++ trunk/Source/WebKit/blackberry/ChangeLog	2012-03-02 06:10:34 UTC (rev 109506)
@@ -1,3 +1,35 @@
+2012-03-01  Andy Chen  <[email protected]>
+
+        [BlackBerry] Implement features for find-in-page
+        https://bugs.webkit.org/show_bug.cgi?id=79820
+
+        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:
+
 2012-03-01  Charles Wei  <[email protected]>
 
         [BlackBerry] Web Notification crashes the browser.

Modified: trunk/Source/WebKit/blackberry/WebCoreSupport/FrameLoaderClientBlackBerry.cpp (109505 => 109506)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/FrameLoaderClientBlackBerry.cpp	2012-03-02 05:56:38 UTC (rev 109505)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/FrameLoaderClientBlackBerry.cpp	2012-03-02 06:10:34 UTC (rev 109506)
@@ -790,7 +790,7 @@
 
 void FrameLoaderClientBlackBerry::dispatchWillClose()
 {
-    m_webPagePrivate->m_inputHandler->frameUnloaded(m_frame);
+    m_webPagePrivate->frameUnloaded(m_frame);
 }
 
 void FrameLoaderClientBlackBerry::setMainDocumentError(DocumentLoader*, const ResourceError& error)
@@ -926,7 +926,7 @@
     if (m_frame->document())
         m_webPagePrivate->clearDocumentData(m_frame->document());
 
-    m_webPagePrivate->m_inputHandler->frameUnloaded(m_frame);
+    m_webPagePrivate->frameUnloaded(m_frame);
     m_webPagePrivate->m_client->notifyFrameDetached(m_frame);
 }
 

Modified: trunk/Source/WebKit/blackberry/WebKitSupport/DOMSupport.cpp (109505 => 109506)


--- trunk/Source/WebKit/blackberry/WebKitSupport/DOMSupport.cpp	2012-03-02 05:56:38 UTC (rev 109505)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/DOMSupport.cpp	2012-03-02 06:10:34 UTC (rev 109506)
@@ -399,6 +399,14 @@
     return selection;
 }
 
+// This function is copied from WebCore/page/Page.cpp.
+Frame* incrementFrame(Frame* curr, bool forward, bool wrapFlag)
+{
+    return forward
+        ? curr->tree()->traverseNextWithWrap(wrapFlag)
+        : curr->tree()->traversePreviousWithWrap(wrapFlag);
+}
+
 } // DOMSupport
 } // WebKit
 } // BlackBerry

Modified: trunk/Source/WebKit/blackberry/WebKitSupport/DOMSupport.h (109505 => 109506)


--- trunk/Source/WebKit/blackberry/WebKitSupport/DOMSupport.h	2012-03-02 05:56:38 UTC (rev 109505)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/DOMSupport.h	2012-03-02 06:10:34 UTC (rev 109506)
@@ -81,6 +81,8 @@
 
 WebCore::VisibleSelection visibleSelectionForClosestActualWordStart(const WebCore::VisibleSelection&);
 
+WebCore::Frame* incrementFrame(WebCore::Frame* curr, bool forward, bool wrapFlag);
+
 } // DOMSupport
 } // WebKit
 } // BlackBerry

Modified: trunk/Source/WebKit/blackberry/WebKitSupport/InPageSearchManager.cpp (109505 => 109506)


--- trunk/Source/WebKit/blackberry/WebKitSupport/InPageSearchManager.cpp	2012-03-02 05:56:38 UTC (rev 109505)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/InPageSearchManager.cpp	2012-03-02 06:10:34 UTC (rev 109506)
@@ -19,6 +19,7 @@
 #include "config.h"
 #include "InPageSearchManager.h"
 
+#include "DOMSupport.h"
 #include "Document.h"
 #include "DocumentMarkerController.h"
 #include "Editor.h"
@@ -51,43 +52,124 @@
         return false;
     }
 
-    if (m_activeSearchString != text) {
-        clearTextMatches();
+    if (!shouldSearchForText(text)) {
         m_activeSearchString = text;
-        m_activeMatchCount = m_webPage->m_page->markAllMatchesForText(text, WebCore::CaseInsensitive, true, TextMatchMarkerLimit);
-    } else
-        setMarkerActive(m_activeMatch.get(), false);
-
-    if (!m_activeMatchCount)
         return false;
+    }
 
-    const FindOptions findOptions = (forward ? 0 : WebCore::Backwards)
-        | WebCore::CaseInsensitive
-        | WebCore::WrapAround; // TODO should wrap around in page, not in frame
+    // Validate the range in case any node has been removed since last search.
+    if (m_activeMatch && !m_activeMatch->boundaryPointsValid())
+        m_activeMatch = 0;
 
-    // TODO StartInSelection
+    RefPtr<Range> searchStartingPoint(m_activeMatch);
+    if (m_activeSearchString != text) { // Start a new search.
+        m_activeSearchString = text;
+        m_webPage->m_page->unmarkAllTextMatches();
+        m_activeMatchCount = m_webPage->m_page->markAllMatchesForText(text, CaseInsensitive, true /* shouldHighlight */, TextMatchMarkerLimit);
+        if (!m_activeMatchCount) {
+            clearTextMatches();
+            return false;
+        }
+    } else { // Search same string for next occurrence.
+        setMarkerActive(m_activeMatch.get(), false /* active */);
+        // Searching for same string should start from the end of last match.
+        if (m_activeMatch) {
+            if (forward)
+                searchStartingPoint->setStart(searchStartingPoint->endPosition());
+            else
+                searchStartingPoint->setEnd(searchStartingPoint->startPosition());
+        }
+    }
 
-    m_activeMatch = m_webPage->mainFrame()->editor()->findStringAndScrollToVisible(text, m_activeMatch.get(), findOptions);
-    setMarkerActive(m_activeMatch.get(), true);
+    // If there is any active selection, new search should start from the beginning of it.
+    VisibleSelection selection = m_webPage->focusedOrMainFrame()->selection()->selection();
+    if (!selection.isNone()) {
+        searchStartingPoint = selection.firstRange().get();
+        m_webPage->focusedOrMainFrame()->selection()->clear();
+    }
 
+    Frame* currentActiveMatchFrame = selection.isNone() && m_activeMatch ? m_activeMatch->ownerDocument()->frame() : m_webPage->focusedOrMainFrame();
+
+    const FindOptions findOptions = (forward ? 0 : Backwards)
+        | CaseInsensitive
+        | StartInSelection;
+
+    if (findAndMarkText(text, searchStartingPoint.get(), currentActiveMatchFrame, findOptions))
+        return true;
+
+    Frame* startFrame = currentActiveMatchFrame;
+    do {
+        currentActiveMatchFrame = DOMSupport::incrementFrame(currentActiveMatchFrame, forward, true /* wrapFlag */);
+        if (findAndMarkText(text, 0, currentActiveMatchFrame, findOptions))
+            return true;
+    } while (currentActiveMatchFrame && startFrame != currentActiveMatchFrame);
+
+    clearTextMatches();
+
+    ASSERT_NOT_REACHED();
+    return false;
+}
+
+bool InPageSearchManager::shouldSearchForText(const String& text)
+{
+    if (text == m_activeSearchString)
+        return m_activeMatchCount;
+
+    // If the previous search string is prefix of new search string,
+    // don't search if the previous one has zero result.
+    if (!m_activeMatchCount
+        && m_activeSearchString.length()
+        && text.length() > m_activeSearchString.length()
+        && m_activeSearchString == text.substring(0, m_activeSearchString.length()))
+        return false;
     return true;
 }
 
+bool InPageSearchManager::findAndMarkText(const String& text, Range* range, Frame* frame, const FindOptions& options)
+{
+    m_activeMatch = frame->editor()->findStringAndScrollToVisible(text, range, options);
+    if (m_activeMatch) {
+        setMarkerActive(m_activeMatch.get(), true /* active */);
+        return true;
+    }
+    return false;
+}
+
 void InPageSearchManager::clearTextMatches()
 {
     m_webPage->m_page->unmarkAllTextMatches();
     m_activeMatch = 0;
 }
 
-void InPageSearchManager::setMarkerActive(WebCore::Range* range, bool active)
+void InPageSearchManager::setMarkerActive(Range* range, bool active)
 {
     if (!range)
         return;
-    WebCore::Document* doc = m_webPage->mainFrame()->document();
+    Document* doc = m_activeMatch->ownerDocument();
     if (!doc)
         return;
     doc->markers()->setMarkersActive(range, active);
 }
 
+void InPageSearchManager::frameUnloaded(const Frame* frame)
+{
+    if (!m_activeMatch) {
+        if (m_webPage->mainFrame() == frame && m_activeSearchString.length())
+            m_activeSearchString = String();
+        return;
+    }
+
+    Frame* currentActiveMatchFrame = m_activeMatch->ownerDocument()->frame();
+    if (currentActiveMatchFrame == frame) {
+        m_activeMatch = 0;
+        m_activeSearchString = String();
+        m_activeMatchCount = 0;
+        // FIXME: We need to notify client here.
+        if (frame == m_webPage->mainFrame()) // Don't need to unmark because the page will be destroyed.
+            return;
+        m_webPage->m_page->unmarkAllTextMatches();
+    }
 }
+
 }
+}

Modified: trunk/Source/WebKit/blackberry/WebKitSupport/InPageSearchManager.h (109505 => 109506)


--- trunk/Source/WebKit/blackberry/WebKitSupport/InPageSearchManager.h	2012-03-02 05:56:38 UTC (rev 109505)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/InPageSearchManager.h	2012-03-02 06:10:34 UTC (rev 109506)
@@ -19,12 +19,13 @@
 #ifndef InPageSearchManager_h
 #define InPageSearchManager_h
 
+#include "FindOptions.h"
 #include "WTFString.h"
 
-#include <wtf/RefPtr.h>
-
 namespace WebCore {
+class Frame;
 class Range;
+class VisibleSelection;
 }
 
 namespace BlackBerry {
@@ -39,10 +40,13 @@
     ~InPageSearchManager();
 
     bool findNextString(const String& text, bool forward);
+    void frameUnloaded(const WebCore::Frame*);
 
 private:
     void clearTextMatches();
-    void setMarkerActive(WebCore::Range*, bool active);
+    void setMarkerActive(WebCore::Range*, bool);
+    bool findAndMarkText(const String&, WebCore::Range*, WebCore::Frame*, const WebCore::FindOptions&);
+    bool shouldSearchForText(const String&);
 
     WebPagePrivate* m_webPage;
     RefPtr<WebCore::Range> m_activeMatch;

Modified: trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp (109505 => 109506)


--- trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp	2012-03-02 05:56:38 UTC (rev 109505)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp	2012-03-02 06:10:34 UTC (rev 109506)
@@ -710,7 +710,7 @@
         ensureFocusTextElementVisible(centerInView ? CenterAlways : CenterIfNeeded);
 }
 
-void InputHandler::frameUnloaded(Frame* frame)
+void InputHandler::frameUnloaded(const Frame* frame)
 {
     if (!isActiveTextEdit())
         return;

Modified: trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h (109505 => 109506)


--- trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h	2012-03-02 05:56:38 UTC (rev 109505)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h	2012-03-02 06:10:34 UTC (rev 109506)
@@ -60,7 +60,7 @@
     void nodeFocused(WebCore::Node*);
     void nodeTextChanged(const WebCore::Node*);
     void selectionChanged();
-    void frameUnloaded(WebCore::Frame*);
+    void frameUnloaded(const WebCore::Frame*);
 
     bool handleKeyboardInput(const BlackBerry::Platform::KeyboardEvent&, bool changeIsPartOfComposition = false);
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to