Source/WebKit2: [Qt][WK2] Add experimental API to find text from page
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Jan 2013 15:05:35 +0000 (15:05 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Jan 2013 15:05:35 +0000 (15:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=96481

Patch by Heikki Paajanen <heikki.paajanen@palm.com> on 2013-01-02
Reviewed by Jocelyn Turcotte.

Expose findString and PageFindClient provided functionality to QtQuick
applications.

* Target.pri:
* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::initialize):
(QQuickWebViewExperimental::findText):
(QQuickWebViewPrivate::didFindString):
* UIProcess/API/qt/qquickwebview_p.h:
(WebKit):
* UIProcess/API/qt/qquickwebview_p_p.h:
(QQuickWebViewPrivate):
* UIProcess/API/qt/tests/qmltests/WebView/tst_findText.qml: Added.
* UIProcess/qt/QtWebPageFindClient.cpp: Added.
(WebKit):
(WebKit::QtWebPageFindClient::QtWebPageFindClient):
(WebKit::QtWebPageFindClient::didFindString):
(WebKit::toQtWebPageFindClient):
(WebKit::QtWebPageFindClient::didFailToFindString):
* UIProcess/qt/QtWebPageFindClient.h: Added.
(WebKit):
(QtWebPageFindClient):

Tools: [Qt][WK2] Add simple UI to find text from page
https://bugs.webkit.org/show_bug.cgi?id=96481

Patch by Heikki Paajanen <heikki.paajanen@palm.com> on 2013-01-02
Reviewed by Jocelyn Turcotte.

Find bar that slides between navigation bar and WebView.

* MiniBrowser/qt/BrowserWindow.cpp:
(BrowserWindow::toggleFind):
* MiniBrowser/qt/BrowserWindow.h:
(BrowserWindow):
* MiniBrowser/qt/MiniBrowser.qrc:
* MiniBrowser/qt/MiniBrowserApplication.cpp:
(MiniBrowserApplication::notify):
* MiniBrowser/qt/icons/find.png: Added.
* MiniBrowser/qt/qml/BrowserWindow.qml:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@138618 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/Target.pri
Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_findText.qml [new file with mode: 0644]
Source/WebKit2/UIProcess/qt/QtWebPageFindClient.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/qt/QtWebPageFindClient.h [new file with mode: 0644]
Tools/ChangeLog
Tools/MiniBrowser/qt/BrowserWindow.cpp
Tools/MiniBrowser/qt/BrowserWindow.h
Tools/MiniBrowser/qt/MiniBrowser.qrc
Tools/MiniBrowser/qt/MiniBrowserApplication.cpp
Tools/MiniBrowser/qt/icons/find.png [new file with mode: 0644]
Tools/MiniBrowser/qt/qml/BrowserWindow.qml

index 1d1981b..6bf142c 100644 (file)
@@ -1,3 +1,33 @@
+2013-01-02  Heikki Paajanen  <heikki.paajanen@palm.com>
+
+        [Qt][WK2] Add experimental API to find text from page
+        https://bugs.webkit.org/show_bug.cgi?id=96481
+
+        Reviewed by Jocelyn Turcotte.
+
+        Expose findString and PageFindClient provided functionality to QtQuick
+        applications.
+
+        * Target.pri:
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::initialize):
+        (QQuickWebViewExperimental::findText):
+        (QQuickWebViewPrivate::didFindString):
+        * UIProcess/API/qt/qquickwebview_p.h:
+        (WebKit):
+        * UIProcess/API/qt/qquickwebview_p_p.h:
+        (QQuickWebViewPrivate):
+        * UIProcess/API/qt/tests/qmltests/WebView/tst_findText.qml: Added.
+        * UIProcess/qt/QtWebPageFindClient.cpp: Added.
+        (WebKit):
+        (WebKit::QtWebPageFindClient::QtWebPageFindClient):
+        (WebKit::QtWebPageFindClient::didFindString):
+        (WebKit::toQtWebPageFindClient):
+        (WebKit::QtWebPageFindClient::didFailToFindString):
+        * UIProcess/qt/QtWebPageFindClient.h: Added.
+        (WebKit):
+        (QtWebPageFindClient):
+
 2013-01-02  Christophe Dumez  <christophe.dumez@intel.com>
 
         Regression(r138607): Causes crashes related to WebIconDatabase
index 648f817..64b77cc 100644 (file)
@@ -826,6 +826,7 @@ have?(QTQUICK) {
         UIProcess/qt/QtDialogRunner.h \
         UIProcess/qt/QtDownloadManager.h \
         UIProcess/qt/QtPageClient.h \
+        UIProcess/qt/QtWebPageFindClient.h \
         UIProcess/qt/QtWebPageLoadClient.h \
         UIProcess/qt/QtWebPagePolicyClient.h \
         UIProcess/qt/QtWebPageSGNode.h \
@@ -854,6 +855,7 @@ have?(QTQUICK) {
         UIProcess/qt/QtDialogRunner.cpp \
         UIProcess/qt/QtDownloadManager.cpp \
         UIProcess/qt/QtPageClient.cpp \
+        UIProcess/qt/QtWebPageFindClient.cpp \
         UIProcess/qt/QtWebPageLoadClient.cpp \
         UIProcess/qt/QtWebPagePolicyClient.cpp \
         UIProcess/qt/QtWebPageSGNode.cpp \
index f234891..555780e 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (c) 2012 Hewlett-Packard Development Company, L.P.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
 #include "QtWebError.h"
 #include "QtWebIconDatabaseClient.h"
 #include "QtWebPageEventHandler.h"
+#include "QtWebPageFindClient.h"
 #include "QtWebPageLoadClient.h"
 #include "QtWebPagePolicyClient.h"
 #include "WebBackForwardList.h"
+#include "WebFindOptions.h"
 #if ENABLE(INSPECTOR_SERVER)
 #include "WebInspectorProxy.h"
 #include "WebInspectorServer.h"
@@ -65,6 +68,7 @@
 #include <WKSerializedScriptValue.h>
 #include <WebCore/IntPoint.h>
 #include <WebCore/IntRect.h>
+#include <limits>
 #include <wtf/Assertions.h>
 #include <wtf/MainThread.h>
 #include <wtf/Vector.h>
@@ -307,6 +311,7 @@ void QQuickWebViewPrivate::initialize(WKContextRef contextRef, WKPageGroupRef pa
     QQuickWebPagePrivate* const pageViewPrivate = pageView.data()->d;
     pageViewPrivate->initialize(webPageProxy.get());
 
+    pageFindClient.reset(new QtWebPageFindClient(toAPI(webPageProxy.get()), q_ptr));
     pageLoadClient.reset(new QtWebPageLoadClient(toAPI(webPageProxy.get()), q_ptr));
     pagePolicyClient.reset(new QtWebPagePolicyClient(toAPI(webPageProxy.get()), q_ptr));
     pageUIClient.reset(new QtWebPageUIClient(toAPI(webPageProxy.get()), q_ptr));
@@ -1247,6 +1252,26 @@ void QQuickWebViewExperimental::evaluateJavaScript(const QString& script, const
     d_ptr->webPageProxy.get()->runJavaScriptInMainFrame(script, ScriptValueCallback::create(closure, javaScriptCallback));
 }
 
+void QQuickWebViewExperimental::findText(const QString& string, FindFlags options)
+{
+    Q_D(QQuickWebView);
+    if (string.isEmpty()) {
+        d->webPageProxy->hideFindUI();
+        return;
+    }
+    WebKit::FindOptions wkOptions = WebKit::FindOptionsCaseInsensitive;
+    if (options & FindCaseSensitively)
+        wkOptions = static_cast<WebKit::FindOptions>(wkOptions & ~WebKit::FindOptionsCaseInsensitive);
+    if (options & FindBackward)
+        wkOptions = static_cast<WebKit::FindOptions>(wkOptions | FindOptionsBackwards);
+    if (options & FindWrapsAroundDocument)
+        wkOptions = static_cast<WebKit::FindOptions>(wkOptions | FindOptionsWrapAround);
+    if (options & FindHighlightAllOccurrences)
+        wkOptions = static_cast<WebKit::FindOptions>(wkOptions | FindOptionsShowHighlight);
+
+    d->webPageProxy->findString(string, wkOptions, std::numeric_limits<unsigned>::max() - 1);
+}
+
 QList<QUrl> QQuickWebViewExperimental::userScripts() const
 {
     Q_D(const QQuickWebView);
@@ -2009,6 +2034,12 @@ void QQuickWebView::setAllowAnyHTTPSCertificateForLocalHost(bool allow)
     d->m_allowAnyHTTPSCertificateForLocalHost = allow;
 }
 
+void QQuickWebViewPrivate::didFindString(unsigned matchCount)
+{
+    Q_Q(QQuickWebView);
+    emit q->experimental()->textFound(matchCount);
+}
+
 /*!
     \qmlsignal WebView::onLoadingChanged(loadRequest)
 
index 1b372fa..338a112 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (c) 2012 Hewlett-Packard Development Company, L.P.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -51,6 +52,7 @@ namespace WebKit {
 struct QtRefCountedNetworkRequestData;
 class PageViewportControllerClientQt;
 class QtWebPageLoadClient;
+class QtWebPageFindClient;
 class QtWebPagePolicyClient;
 class QtWebPageUIClient;
 }
@@ -220,6 +222,7 @@ private:
     friend class QWebKitTest;
     friend class WebKit::PageViewportControllerClientQt;
     friend class WebKit::QtWebPageLoadClient;
+    friend class WebKit::QtWebPageFindClient;
     friend class WebKit::QtWebPagePolicyClient;
     friend class WebKit::QtWebPageUIClient;
     friend class WTR::PlatformWebView;
@@ -277,12 +280,21 @@ class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
     Q_PROPERTY(QList<QUrl> userScripts READ userScripts WRITE setUserScripts NOTIFY userScriptsChanged)
     Q_PROPERTY(QUrl remoteInspectorUrl READ remoteInspectorUrl NOTIFY remoteInspectorUrlChanged FINAL)
     Q_ENUMS(NavigationRequestActionExperimental)
+    Q_FLAGS(FindFlags)
 
 public:
     enum NavigationRequestActionExperimental {
         DownloadRequest = QQuickWebView::IgnoreRequest - 1
     };
 
+    enum FindFlag {
+        FindCaseSensitively = 1 << 0,
+        FindBackward = 1 << 1,
+        FindWrapsAroundDocument = 1 << 2,
+        FindHighlightAllOccurrences = 1 << 3
+    };
+    Q_DECLARE_FLAGS(FindFlags, FindFlag)
+
     virtual ~QQuickWebViewExperimental();
 
     QQmlComponent* alertDialog() const;
@@ -349,6 +361,7 @@ public Q_SLOTS:
     void goForwardTo(int index);
     void postMessage(const QString&);
     void evaluateJavaScript(const QString& script, const QJSValue& value = QJSValue());
+    void findText(const QString& string, FindFlags options = 0);
 
 Q_SIGNALS:
     void loadVisuallyCommitted();
@@ -373,6 +386,7 @@ Q_SIGNALS:
     void userScriptsChanged();
     void preferredMinimumContentsWidthChanged();
     void remoteInspectorUrlChanged();
+    void textFound(int matchCount);
 
 private:
     QQuickWebViewExperimental(QQuickWebView* webView, QQuickWebViewPrivate* webViewPrivate);
@@ -387,4 +401,6 @@ private:
     Q_DECLARE_PUBLIC(QQuickWebView)
 };
 
+Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickWebViewExperimental::FindFlags)
+
 #endif // qquickwebview_p_h
index 8445fe2..a0ca69a 100644 (file)
@@ -84,6 +84,8 @@ public:
     virtual void loadDidFail(const WebKit::QtWebError& error);
     virtual void handleMouseEvent(QMouseEvent*);
 
+    void didFindString(unsigned matchCount);
+
     virtual void didChangeViewportProperties(const WebCore::ViewportAttributes& attr) { }
 
     int loadProgress() const { return m_loadProgress; }
@@ -166,6 +168,7 @@ protected:
     OwnPtr<QWebPreferences> preferences;
 
     QScopedPointer<WebKit::QtWebPageLoadClient> pageLoadClient;
+    QScopedPointer<WebKit::QtWebPageFindClient> pageFindClient;
     QScopedPointer<WebKit::QtWebPagePolicyClient> pagePolicyClient;
     QScopedPointer<WebKit::QtWebPageUIClient> pageUIClient;
 
diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_findText.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_findText.qml
new file mode 100644 (file)
index 0000000..f1ea15c
--- /dev/null
@@ -0,0 +1,145 @@
+import QtQuick 2.0
+import QtTest 1.0
+import QtWebKit 3.0
+import QtWebKit.experimental 1.0
+import "../common"
+
+TestWebView {
+    id: webView
+    width: 400
+    height: 300
+
+    property int matchCount: -1
+    property bool findFailed: false
+    function clear() {
+        textFoundSpy.clear()
+        findFailed = false
+        matchCount = -1
+    }
+
+    SignalSpy {
+        id: textFoundSpy
+        target: webView.experimental
+        signalName: "textFound"
+    }
+
+    experimental.onTextFound: {
+        webView.matchCount = matchCount
+        findFailed = matchCount == 0
+    }
+    TestCase {
+        name: "WebViewFindText"
+
+        function test_findText() {
+            var findFlags = WebViewExperimental.FindHighlightAllOccurrences |
+                              WebViewExperimental.FindCaseSensitively
+            webView.clear()
+            webView.url = Qt.resolvedUrl("../common/test1.html")
+            verify(webView.waitForLoadSucceeded())
+            webView.experimental.findText("Hello", findFlags)
+            textFoundSpy.wait()
+            compare(textFoundSpy.count, 1)
+            compare(matchCount, 1)
+        }
+        function test_findTextCaseInsensitive() {
+            var findFlags = 0
+
+            webView.clear()
+            webView.url = Qt.resolvedUrl("../common/test1.html")
+            verify(webView.waitForLoadSucceeded())
+            webView.experimental.findText("heLLo", findFlags)
+            textFoundSpy.wait()
+            compare(textFoundSpy.count, 1)
+            compare(matchCount, 1)
+        }
+        function test_findTextManyMatches() {
+            var findFlags = WebViewExperimental.FindHighlightAllOccurrences
+            webView.clear()
+            webView.url = Qt.resolvedUrl("../common/test4.html")
+            verify(webView.waitForLoadSucceeded())
+            webView.experimental.findText("bla", findFlags)
+            textFoundSpy.wait()
+            compare(textFoundSpy.count, 1)
+            compare(matchCount, 100)
+        }
+        function test_findTextBackward() {
+            var findFlags = WebViewExperimental.FindHighlightAllOccurrences
+            webView.clear()
+            webView.url = Qt.resolvedUrl("../common/test4.html")
+            verify(webView.waitForLoadSucceeded())
+            webView.experimental.findText("bla0", findFlags)
+            textFoundSpy.wait()
+            compare(textFoundSpy.count, 1)
+            compare(matchCount, 10)
+            for(var i=0; i < 9; i++) {
+                webView.experimental.findText("bla0", findFlags)
+                textFoundSpy.wait()
+            }
+            compare(textFoundSpy.count, 10)
+            webView.experimental.findText("bla0", findFlags)
+            textFoundSpy.wait()
+            compare(textFoundSpy.count, 11)
+            compare(findFailed, true)
+
+            webView.clear()
+            findFlags |= WebViewExperimental.FindBackward
+            webView.experimental.findText("bla0", findFlags)
+            textFoundSpy.wait()
+            compare(textFoundSpy.count, 1)
+        }
+        function test_findTextFailNoWrap() {
+            var findFlags = WebViewExperimental.FindHighlightAllOccurrences
+            webView.clear()
+            webView.url = Qt.resolvedUrl("../common/test4.html")
+            verify(webView.waitForLoadSucceeded())
+            webView.experimental.findText("bla0", findFlags)
+            textFoundSpy.wait()
+            compare(textFoundSpy.count, 1)
+            compare(matchCount, 10)
+            for(var i=0; i < 9; i++) {
+                webView.experimental.findText("bla0", findFlags)
+                textFoundSpy.wait()
+            }
+            compare(textFoundSpy.count, 10)
+            webView.experimental.findText("bla0", findFlags)
+            textFoundSpy.wait()
+            compare(textFoundSpy.count, 11)
+            compare(findFailed, true)
+        }
+        function test_findTextWrap() {
+            var findFlags = WebViewExperimental.FindHighlightAllOccurrences
+            findFlags |= WebViewExperimental.FindWrapsAroundDocument
+            webView.clear()
+            webView.url = Qt.resolvedUrl("../common/test4.html")
+            verify(webView.waitForLoadSucceeded())
+            webView.experimental.findText("bla0", findFlags)
+            textFoundSpy.wait()
+            compare(textFoundSpy.count, 1)
+            compare(matchCount, 10)
+            for(var i=0; i < 19; i++) {
+                webView.experimental.findText("bla0", findFlags)
+                textFoundSpy.wait()
+            }
+            compare(textFoundSpy.count, 20)
+        }
+        function test_findTextFailCaseSensitive() {
+            var findFlags = WebViewExperimental.FindCaseSensitively
+            webView.clear()
+            webView.url = Qt.resolvedUrl("../common/test1.html")
+            verify(webView.waitForLoadSucceeded())
+            webView.experimental.findText("heLLo", findFlags)
+            textFoundSpy.wait()
+            compare(textFoundSpy.count, 1)
+            compare(findFailed, true)
+        }
+        function test_findTextNotFound() {
+            webView.clear()
+            webView.url = Qt.resolvedUrl("../common/test1.html")
+            verify(webView.waitForLoadSucceeded())
+            webView.experimental.findText("string-that-is-not-threre")
+            textFoundSpy.wait()
+            compare(textFoundSpy.count, 1)
+            compare(findFailed, true)
+        }
+    }
+}
diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageFindClient.cpp b/Source/WebKit2/UIProcess/qt/QtWebPageFindClient.cpp
new file mode 100644 (file)
index 0000000..85e1e68
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2012 Hewlett-Packard Development Company, L.P.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "QtWebPageFindClient.h"
+
+#include "qquickwebview_p_p.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+QtWebPageFindClient::QtWebPageFindClient(WKPageRef pageRef, QQuickWebView* webView)
+    : m_webView(webView)
+{
+    WKPageFindClient findClient;
+    memset(&findClient, 0, sizeof(WKPageFindClient));
+    findClient.version = kWKPageFindClientCurrentVersion;
+    findClient.clientInfo = this;
+    findClient.didFindString = didFindString;
+    findClient.didFailToFindString = didFailToFindString;
+    WKPageSetPageFindClient(pageRef, &findClient);
+}
+
+void QtWebPageFindClient::didFindString(unsigned matchCount)
+{
+    m_webView->d_func()->didFindString(matchCount);
+}
+
+static QtWebPageFindClient* toQtWebPageFindClient(const void* clientInfo)
+{
+    ASSERT(clientInfo);
+    return reinterpret_cast<QtWebPageFindClient*>(const_cast<void*>(clientInfo));
+}
+
+void QtWebPageFindClient::didFindString(WKPageRef page, WKStringRef string, unsigned matchCount, const void* clientInfo)
+{
+    toQtWebPageFindClient(clientInfo)->didFindString(matchCount);
+}
+
+void QtWebPageFindClient::didFailToFindString(WKPageRef page, WKStringRef string, const void* clientInfo)
+{
+    toQtWebPageFindClient(clientInfo)->didFindString(0);
+}
+
+} // namespace Webkit
diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageFindClient.h b/Source/WebKit2/UIProcess/qt/QtWebPageFindClient.h
new file mode 100644 (file)
index 0000000..55c0272
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012 Hewlett-Packard Development Company, L.P.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef QtWebPageFindClient_h
+#define QtWebPageFindClient_h
+
+#include <WKPage.h>
+#include <wtf/text/WTFString.h>
+
+class QQuickWebView;
+
+namespace WebKit {
+
+class QtWebPageFindClient {
+public:
+    QtWebPageFindClient(WKPageRef, QQuickWebView*);
+
+private:
+
+    void didFindString(unsigned matchCount);
+
+    // WKPageFindClient callbacks.
+    static void didFindString(WKPageRef, WKStringRef, unsigned matchCount, const void* clientInfo);
+    static void didFailToFindString(WKPageRef, WKStringRef, const void* clientInfo);
+
+    QQuickWebView* m_webView;
+};
+
+} // namespace Webkit
+
+#endif // QtWebPageFindClient_h
index 94971ee..33c247a 100644 (file)
@@ -1,3 +1,22 @@
+2013-01-02  Heikki Paajanen  <heikki.paajanen@palm.com>
+
+        [Qt][WK2] Add simple UI to find text from page
+        https://bugs.webkit.org/show_bug.cgi?id=96481
+
+        Reviewed by Jocelyn Turcotte.
+
+        Find bar that slides between navigation bar and WebView.
+
+        * MiniBrowser/qt/BrowserWindow.cpp:
+        (BrowserWindow::toggleFind):
+        * MiniBrowser/qt/BrowserWindow.h:
+        (BrowserWindow):
+        * MiniBrowser/qt/MiniBrowser.qrc:
+        * MiniBrowser/qt/MiniBrowserApplication.cpp:
+        (MiniBrowserApplication::notify):
+        * MiniBrowser/qt/icons/find.png: Added.
+        * MiniBrowser/qt/qml/BrowserWindow.qml:
+
 2013-01-02  Christophe Dumez  <christophe.dumez@intel.com>
 
         Regression(r138603): Caused 2 webkitpy tests to fail
index d9de519..e56b799 100644 (file)
@@ -104,6 +104,11 @@ void BrowserWindow::focusAddressBar()
     QMetaObject::invokeMethod(rootObject(), "focusAddressBar", Qt::DirectConnection);
 }
 
+void BrowserWindow::toggleFind()
+{
+    QMetaObject::invokeMethod(rootObject(), "toggleFind", Qt::DirectConnection);
+}
+
 BrowserWindow* BrowserWindow::newWindow(const QString& url)
 {
     BrowserWindow* window = new BrowserWindow(m_windowOptions);
index 0f30e2c..e761764 100644 (file)
@@ -45,6 +45,7 @@ public:
     void load(const QString& url);
     void reload();
     void focusAddressBar();
+    void toggleFind();
     QQuickWebView* webView() const;
     QQuickWebViewExperimental* webViewExperimental() const;
 
index e21eef3..3fa6208 100644 (file)
@@ -4,6 +4,7 @@
         <file>icons/checkbox_unchecked.png</file>
         <file>icons/contents_width.png</file>
         <file>icons/favicon.png</file>
+        <file>icons/find.png</file>
         <file>icons/folder.png</file>
         <file>icons/info.png</file>
         <file>icons/next.png</file>
index d54cd66..accefe6 100644 (file)
@@ -123,6 +123,10 @@ bool MiniBrowserApplication::notify(QObject* target, QEvent* event)
             browserWindow->focusAddressBar();
             return true;
         }
+        if ((keyEvent->key() == Qt::Key_F && keyEvent->modifiers() == Qt::ControlModifier) || keyEvent->key() == Qt::Key_F3) {
+            browserWindow->toggleFind();
+            return true;
+        }
     }
 
     if (event->type() == QEvent::KeyRelease && static_cast<QKeyEvent*>(event)->key() == Qt::Key_Control) {
diff --git a/Tools/MiniBrowser/qt/icons/find.png b/Tools/MiniBrowser/qt/icons/find.png
new file mode 100644 (file)
index 0000000..b76afa3
Binary files /dev/null and b/Tools/MiniBrowser/qt/icons/find.png differ
index e52b2f4..b4b5bc0 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
  * Copyright (C) 2010 University of Szeged
+ * Copyright (c) 2012 Hewlett-Packard Development Company, L.P.
  *
  * All rights reserved.
  *
@@ -54,7 +55,163 @@ Rectangle {
         addressLine.forceActiveFocus()
         addressLine.selectAll()
     }
+    function toggleFind() {
+        findBar.toggle()
+    }
+    Rectangle {
+        id: findBar
+        z: webView.z + 1
+        y: navigationBar.y
+        anchors {
+            left: parent.left
+            right: parent.right
+        }
+        height: navigationBar.height
+        color: "#efefef"
+        visible: y > navigationBar.y
+
+        Behavior on y {NumberAnimation {duration: 250}}
+
+        function toggle() {
+            if (y == navigationBar.y) {
+                findTextInput.forceActiveFocus()
+                y += height
+            } else {
+                webView.forceActiveFocus()
+                y = navigationBar.y
+                find("",0);
+            }
+        }
 
+        function find(str, options) {
+            var findOptions = options | WebViewExperimental.FindHighlightAllOccurrences
+            findOptions |= WebViewExperimental.FindWrapsAroundDocument
+            webView.experimental.findText(str, findOptions)
+        }
+
+        Connections {
+            target: webView.experimental
+            onTextFound: {
+                failedOverlay.visible = matchCount == 0
+            }
+        }
+        Item {
+            anchors.fill: parent
+            Rectangle {
+                id: inputArea
+                height: 26
+                anchors {
+                    left: parent.left
+                    right: prevButton.left
+                    margins: 6
+                    verticalCenter: parent.verticalCenter
+                }
+                color: "white"
+                border.width: 1
+                border.color: "#bfbfbf"
+                radius: 3
+                Rectangle {
+                    id: failedOverlay
+                    anchors.fill: parent
+                    color: "red"
+                    opacity: 0.5
+                    radius: 6
+                    visible: false
+                }
+                TextInput {
+                    id: findTextInput
+                    clip: true
+                    selectByMouse: true
+                    horizontalAlignment: TextInput.AlignLeft
+                    anchors.fill: parent
+                    anchors.margins: 3
+                    font {
+                        pointSize: 11
+                        family: "Sans"
+                    }
+                    text: ""
+                    readOnly: !findBar.visible
+                    function doFind() {
+                        if (!findBar.visible) {
+                            return;
+                        }
+                        if (findTextInput.text == "") {
+                            failedOverlay.visible = false
+                        }
+                        findBar.find(findTextInput.text)
+                    }
+                    onTextChanged: {
+                        doFind()
+                    }
+                    Keys.onReturnPressed:{
+                        doFind()
+                    }
+                }
+            }
+            Rectangle {
+                id: prevButton
+                height: inputArea.height
+                width: height
+                anchors.right: nextButton.left
+                anchors.verticalCenter: parent.verticalCenter
+                color: "#efefef"
+                radius: 6
+
+                Image {
+                    anchors.centerIn: parent
+                    source: "../icons/previous.png"
+                }
+
+                Rectangle {
+                    anchors.fill: parent
+                    color: parent.color
+                    radius: parent.radius
+                    opacity: 0.8
+                    visible: !parent.enabled
+                }
+
+                MouseArea {
+                    anchors.fill: parent
+                    onPressed: { if (parent.enabled) parent.color = "#cfcfcf" }
+                    onReleased: { parent.color = "#efefef" }
+                    onClicked: {
+                        findBar.find(findTextInput.text, WebViewExperimental.FindBackward)
+                    }
+                }
+            }
+            Rectangle {
+                id: nextButton
+                height: inputArea.height
+                width: height
+                anchors.right: parent.right
+                anchors.verticalCenter: parent.verticalCenter
+                color: "#efefef"
+                radius: 6
+
+                Image {
+                    anchors.centerIn: parent
+                    source: "../icons/next.png"
+                }
+
+                Rectangle {
+                    anchors.fill: parent
+                    color: parent.color
+                    radius: parent.radius
+                    opacity: 0.8
+                    visible: !parent.enabled
+                }
+
+                MouseArea {
+                    anchors.fill: parent
+                    onPressed: { if (parent.enabled) parent.color = "#cfcfcf" }
+                    onReleased: { parent.color = "#efefef" }
+                    onClicked: {
+                        findBar.find(findTextInput.text, 0)
+                    }
+                }
+            }
+        }
+    }
     Rectangle {
         id: navigationBar
         color: "#efefef"
@@ -213,6 +370,27 @@ Rectangle {
             }
 
             Rectangle {
+                id: findButton
+                height: parent.height
+                width: height
+                color: "#efefef"
+                radius: 6
+
+                Image {
+                    anchors.centerIn: parent
+                    opacity: 0.6
+                    source: "../icons/find.png"
+                }
+
+                MouseArea {
+                    anchors.fill: parent
+                    onClicked: {
+                        findBar.toggle()
+                    }
+                }
+            }
+
+            Rectangle {
                 id: touchEventsButton
                 height: parent.height
                 width: height
@@ -335,7 +513,7 @@ Rectangle {
         clip: false
 
         anchors {
-            top: navigationBar.bottom
+            top: findBar.bottom
             left: parent.left
             right: parent.right
             bottom: parent.bottom