Title: [96105] trunk
Revision
96105
Author
[email protected]
Date
2011-09-27 07:09:00 -0700 (Tue, 27 Sep 2011)

Log Message

[Qt][WK2] Add support for hover API in Qt WebKit2
https://bugs.webkit.org/show_bug.cgi?id=68369

Reviewed by Andreas Kling.

Source/WebKit2:

Based on the patch from Igor Oliveira in the same bug.

Expose a linkHovered() signal in QDesktopWebView, that passes the QUrl and the
QString corresponding to the link title. I left textContent out because was
unsure of its use case.

In QDesktopWebView we store the last URL and title emitted to make sure we send
the signal only if either value changes. Tests were added to the QML element to
check: if values are correctly emitted and if we don't emit more signals than
necessary.

* UIProcess/API/qt/qdesktopwebview.cpp:
(QDesktopWebViewPrivate::didMouseMoveOverElement):
* UIProcess/API/qt/qdesktopwebview.h:
* UIProcess/API/qt/qdesktopwebview_p.h:
* UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_linkHovered.qml: Added.
* UIProcess/API/qt/tests/qmltests/common/test2.html:
* UIProcess/API/qt/tests/qmltests/qmltests.pro:
* UIProcess/qt/ClientImpl.cpp:
(qt_wk_mouseDidMoveOverElement):
* UIProcess/qt/ClientImpl.h:
* UIProcess/qt/QtWebPageProxy.cpp:
(QtWebPageProxy::init):
* UIProcess/qt/TouchViewInterface.h:
(WebKit::TouchViewInterface::didMouseMoveOverElement):
* UIProcess/qt/ViewInterface.h:

Tools:

Change the statusbar to show the link URL when hovering links in
MiniBrowser using QDesktopWebView.

* MiniBrowser/qt/BrowserWindow.cpp:
(BrowserWindow::BrowserWindow):
(BrowserWindow::onLinkHovered):
* MiniBrowser/qt/BrowserWindow.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (96104 => 96105)


--- trunk/Source/WebKit2/ChangeLog	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Source/WebKit2/ChangeLog	2011-09-27 14:09:00 UTC (rev 96105)
@@ -1,3 +1,37 @@
+2011-09-26  Caio Marcelo de Oliveira Filho  <[email protected]>
+
+        [Qt][WK2] Add support for hover API in Qt WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=68369
+
+        Reviewed by Andreas Kling.
+
+        Based on the patch from Igor Oliveira in the same bug.
+
+        Expose a linkHovered() signal in QDesktopWebView, that passes the QUrl and the
+        QString corresponding to the link title. I left textContent out because was
+        unsure of its use case.
+
+        In QDesktopWebView we store the last URL and title emitted to make sure we send
+        the signal only if either value changes. Tests were added to the QML element to
+        check: if values are correctly emitted and if we don't emit more signals than
+        necessary.
+
+        * UIProcess/API/qt/qdesktopwebview.cpp:
+        (QDesktopWebViewPrivate::didMouseMoveOverElement):
+        * UIProcess/API/qt/qdesktopwebview.h:
+        * UIProcess/API/qt/qdesktopwebview_p.h:
+        * UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_linkHovered.qml: Added.
+        * UIProcess/API/qt/tests/qmltests/common/test2.html:
+        * UIProcess/API/qt/tests/qmltests/qmltests.pro:
+        * UIProcess/qt/ClientImpl.cpp:
+        (qt_wk_mouseDidMoveOverElement):
+        * UIProcess/qt/ClientImpl.h:
+        * UIProcess/qt/QtWebPageProxy.cpp:
+        (QtWebPageProxy::init):
+        * UIProcess/qt/TouchViewInterface.h:
+        (WebKit::TouchViewInterface::didMouseMoveOverElement):
+        * UIProcess/qt/ViewInterface.h:
+
 2011-09-27  Alexis Menard  <[email protected]>
 
         [Qt][WK2] API fixes for QML, the signal parameters needs to be named.

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.cpp (96104 => 96105)


--- trunk/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.cpp	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.cpp	2011-09-27 14:09:00 UTC (rev 96105)
@@ -431,6 +431,15 @@
     fileDialog = 0;
 }
 
+void QDesktopWebViewPrivate::didMouseMoveOverElement(const QUrl& linkURL, const QString& linkTitle)
+{
+    if (linkURL == lastHoveredURL && linkTitle == lastHoveredTitle)
+        return;
+    lastHoveredURL = linkURL;
+    lastHoveredTitle = linkTitle;
+    emit q->linkHovered(lastHoveredURL, lastHoveredTitle);
+}
+
 static PolicyInterface::PolicyAction toPolicyAction(QDesktopWebView::NavigationPolicy policy)
 {
     switch (policy) {

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.h (96104 => 96105)


--- trunk/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.h	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.h	2011-09-27 14:09:00 UTC (rev 96105)
@@ -88,6 +88,7 @@
     void loadFailed(QDesktopWebView::ErrorType errorType, int errorCode, const QUrl& url);
     void loadProgressChanged(int progress);
     void urlChanged(const QUrl& url);
+    void linkHovered(const QUrl& url, const QString& title);
 
 protected:
     virtual void keyPressEvent(QKeyEvent*);

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qdesktopwebview_p.h (96104 => 96105)


--- trunk/Source/WebKit2/UIProcess/API/qt/qdesktopwebview_p.h	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qdesktopwebview_p.h	2011-09-27 14:09:00 UTC (rev 96105)
@@ -84,6 +84,8 @@
 
     virtual void chooseFiles(WKOpenPanelResultListenerRef, const QStringList& selectedFileNames, ViewInterface::FileChooserType);
 
+    virtual void didMouseMoveOverElement(const QUrl&, const QString&);
+
     // PolicyInterface.
     virtual PolicyInterface::PolicyAction navigationPolicyForURL(const QUrl&, Qt::MouseButton, Qt::KeyboardModifiers);
 
@@ -91,6 +93,9 @@
 
     QFileDialog* fileDialog;
     WKOpenPanelResultListenerRef openPanelResultListener;
+
+    QUrl lastHoveredURL;
+    QString lastHoveredTitle;
 };
 
 #endif /* qdesktopwebview_p_h */

Added: trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_linkHovered.qml (0 => 96105)


--- trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_linkHovered.qml	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_linkHovered.qml	2011-09-27 14:09:00 UTC (rev 96105)
@@ -0,0 +1,74 @@
+import QtQuick 2.0
+import QtTest 1.0
+import QtWebKit.experimental 5.0
+
+DesktopWebView {
+    id: webView
+    width: 200
+    height: 400
+
+    property string lastUrl
+    property string lastTitle
+
+    SignalSpy {
+        id: spy
+        target: webView
+        signalName: "linkHovered"
+    }
+
+    SignalSpy {
+        id: loadSpy
+        target: webView
+        signalName: "loadSucceeded"
+    }
+
+    onLinkHovered: {
+        webView.lastUrl = url
+        webView.lastTitle = title
+    }
+
+    TestCase {
+        name: "DesktopWebViewLinkHovered"
+        when: windowShown
+
+        function init() {
+            webView.lastUrl = ""
+            webView.lastTitle = ""
+            spy.clear()
+        }
+
+        function test_linkHovered() {
+            compare(spy.count, 0)
+            webView.load(Qt.resolvedUrl("../common/test2.html"))
+            loadSpy.wait()
+            mouseMove(webView, 100, 100)
+            spy.wait()
+            compare(spy.count, 1)
+            compare(webView.lastUrl, Qt.resolvedUrl("../common/test1.html"))
+            compare(webView.lastTitle, "A title")
+            mouseMove(webView, 100, 300)
+            spy.wait()
+            compare(spy.count, 2)
+            compare(webView.lastUrl, "")
+            compare(webView.lastTitle, "")
+        }
+
+        function test_linkHoveredDoesntEmitRepeated() {
+            compare(spy.count, 0)
+            webView.load(Qt.resolvedUrl("../common/test2.html"))
+            loadSpy.wait()
+
+            for (var i = 0; i < 100; i += 10)
+                mouseMove(webView, 100, 100 + i)
+
+            tryCompare(spy.count, 1)
+
+            for (var i = 0; i < 100; i += 10)
+                mouseMove(webView, 100, 300 + i)
+
+            spy.wait()
+            tryCompare(spy.count, 2)
+            compare(webView.lastUrl, "")
+        }
+    }
+}

Modified: trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/test2.html (96104 => 96105)


--- trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/test2.html	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/test2.html	2011-09-27 14:09:00 UTC (rev 96105)
@@ -1,6 +1,6 @@
 <html>
 <head><title>Test page with huge link area</title></head>
 <body>
-<a href="" width=200 height=200></a>
+<a title="A title" href="" width=200 height=200></a>
 </body>
 </html>

Modified: trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro (96104 => 96105)


--- trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro	2011-09-27 14:09:00 UTC (rev 96105)
@@ -13,6 +13,7 @@
     DesktopWebView/tst_navigationPolicyForUrl.qml \
     DesktopWebView/tst_loadProgress.qml \
     DesktopWebView/tst_loadProgressSignal.qml \
+    DesktopWebView/tst_linkHovered.qml \
     TouchWebView/tst_properties.qml \
     TouchWebView/tst_load.qml \
     TouchWebView/tst_loadZeroSizeView.qml \

Modified: trunk/Source/WebKit2/UIProcess/qt/ClientImpl.cpp (96104 => 96105)


--- trunk/Source/WebKit2/UIProcess/qt/ClientImpl.cpp	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Source/WebKit2/UIProcess/qt/ClientImpl.cpp	2011-09-27 14:09:00 UTC (rev 96105)
@@ -32,6 +32,7 @@
 #include <WKArray.h>
 #include <WKFrame.h>
 #include <WKFramePolicyListener.h>
+#include <WKHitTestResult.h>
 #include <WKOpenPanelParameters.h>
 #include <WKOpenPanelResultListener.h>
 #include <WKType.h>
@@ -163,6 +164,13 @@
     toViewInterface(clientInfo)->chooseFiles(listener, selectedFileNames, allowMultipleFiles);
 }
 
+void qt_wk_mouseDidMoveOverElement(WKPageRef page, WKHitTestResultRef hitTestResult, WKEventModifiers modifiers, WKTypeRef userData, const void* clientInfo)
+{
+    const QUrl absoluteLinkUrl = WKURLCopyQUrl(WKHitTestResultCopyAbsoluteLinkURL(hitTestResult));
+    const QString linkTitle = WKStringCopyQString(WKHitTestResultCopyLinkTitle(hitTestResult));
+    toViewInterface(clientInfo)->didMouseMoveOverElement(absoluteLinkUrl, linkTitle);
+}
+
 static Qt::MouseButton toQtMouseButton(WKEventMouseButton button)
 {
     switch (button) {

Modified: trunk/Source/WebKit2/UIProcess/qt/ClientImpl.h (96104 => 96105)


--- trunk/Source/WebKit2/UIProcess/qt/ClientImpl.h	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Source/WebKit2/UIProcess/qt/ClientImpl.h	2011-09-27 14:09:00 UTC (rev 96105)
@@ -41,6 +41,7 @@
 // ui client
 void qt_wk_setStatusText(WKPageRef page, WKStringRef text, const void *clientInfo);
 void qt_wk_runOpenPanel(WKPageRef, WKFrameRef, WKOpenPanelParametersRef, WKOpenPanelResultListenerRef, const void* clientInfo);
+void qt_wk_mouseDidMoveOverElement(WKPageRef, WKHitTestResultRef, WKEventModifiers, WKTypeRef, const void* clientInfo);
 
 // Policy client.
 void qt_wk_decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef userData, const void* clientInfo);

Modified: trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp (96104 => 96105)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp	2011-09-27 14:09:00 UTC (rev 96105)
@@ -143,6 +143,7 @@
     uiClient.clientInfo = m_viewInterface;
     uiClient.setStatusText = qt_wk_setStatusText;
     uiClient.runOpenPanel = qt_wk_runOpenPanel;
+    uiClient.mouseDidMoveOverElement = qt_wk_mouseDidMoveOverElement;
     WKPageSetPageUIClient(toAPI(m_webPageProxy.get()), &uiClient);
 
     if (m_policyInterface) {

Modified: trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.h (96104 => 96105)


--- trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.h	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.h	2011-09-27 14:09:00 UTC (rev 96105)
@@ -79,6 +79,8 @@
 
     virtual void chooseFiles(WKOpenPanelResultListenerRef, const QStringList&, FileChooserType) { }
 
+    virtual void didMouseMoveOverElement(const QUrl&, const QString&) { }
+
 private:
     QTouchWebView* const m_viewportView;
     QTouchWebPage* const m_pageView;

Modified: trunk/Source/WebKit2/UIProcess/qt/ViewInterface.h (96104 => 96105)


--- trunk/Source/WebKit2/UIProcess/qt/ViewInterface.h	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Source/WebKit2/UIProcess/qt/ViewInterface.h	2011-09-27 14:09:00 UTC (rev 96105)
@@ -88,6 +88,8 @@
     virtual QJSEngine* engine() = 0;
 
     virtual void chooseFiles(WKOpenPanelResultListenerRef, const QStringList& selectedFileNames, FileChooserType) = 0;
+
+    virtual void didMouseMoveOverElement(const QUrl&, const QString&) = 0;
 };
 
 }

Modified: trunk/Tools/ChangeLog (96104 => 96105)


--- trunk/Tools/ChangeLog	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Tools/ChangeLog	2011-09-27 14:09:00 UTC (rev 96105)
@@ -1,3 +1,18 @@
+2011-09-26  Caio Marcelo de Oliveira Filho  <[email protected]>
+
+        [Qt][WK2] Add support for hover API in Qt WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=68369
+
+        Reviewed by Andreas Kling.
+
+        Change the statusbar to show the link URL when hovering links in
+        MiniBrowser using QDesktopWebView.
+
+        * MiniBrowser/qt/BrowserWindow.cpp:
+        (BrowserWindow::BrowserWindow):
+        (BrowserWindow::onLinkHovered):
+        * MiniBrowser/qt/BrowserWindow.h:
+
 2011-09-26  Dimitri Glazkov  <[email protected]>
 
         garden-o-matic's commit data on summary page should not crowd itself or twitch when hovered over.

Modified: trunk/Tools/MiniBrowser/qt/BrowserWindow.cpp (96104 => 96105)


--- trunk/Tools/MiniBrowser/qt/BrowserWindow.cpp	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Tools/MiniBrowser/qt/BrowserWindow.cpp	2011-09-27 14:09:00 UTC (rev 96105)
@@ -64,8 +64,10 @@
     if (m_windowOptions.printLoadedUrls)
         connect(webView(), SIGNAL(urlChanged(QUrl)), this, SLOT(printURL(QUrl)));
 
-    if (QDesktopWebView* const desktopWebView = m_browser->desktopWebView())
+    if (QDesktopWebView* const desktopWebView = m_browser->desktopWebView()) {
         connect(desktopWebView, SIGNAL(statusBarMessageChanged(QString)), statusBar(), SLOT(showMessage(QString)));
+        connect(desktopWebView, SIGNAL(linkHovered(QUrl, QString)), this, SLOT(onLinkHovered(QUrl, QString)));
+    }
 
     this->setCentralWidget(m_browser);
     m_browser->setFocus(Qt::OtherFocusReason);
@@ -287,6 +289,11 @@
     output << "Loaded: " << url.toString() << endl;
 }
 
+void BrowserWindow::onLinkHovered(const QUrl& url, const QString&)
+{
+    statusBar()->showMessage(url.toString());
+}
+
 void BrowserWindow::updateUserAgentList()
 {
 #if 0

Modified: trunk/Tools/MiniBrowser/qt/BrowserWindow.h (96104 => 96105)


--- trunk/Tools/MiniBrowser/qt/BrowserWindow.h	2011-09-27 13:23:49 UTC (rev 96104)
+++ trunk/Tools/MiniBrowser/qt/BrowserWindow.h	2011-09-27 14:09:00 UTC (rev 96105)
@@ -69,6 +69,7 @@
     void loadURLListFromFile();
 
     void printURL(const QUrl&);
+    void onLinkHovered(const QUrl&, const QString&);
 
 private:
     void updateUserAgentList();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to