From 77a825a96aebc1952adfb359ac6e128fd45f881a Mon Sep 17 00:00:00 2001 From: "caio.oliveira@openbossa.org" Date: Tue, 27 Sep 2011 14:09:00 +0000 Subject: [PATCH] [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: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96105 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebKit2/ChangeLog | 34 ++++++++++ .../WebKit2/UIProcess/API/qt/qdesktopwebview.cpp | 9 +++ Source/WebKit2/UIProcess/API/qt/qdesktopwebview.h | 1 + .../WebKit2/UIProcess/API/qt/qdesktopwebview_p.h | 5 ++ .../qmltests/DesktopWebView/tst_linkHovered.qml | 74 ++++++++++++++++++++++ .../API/qt/tests/qmltests/common/test2.html | 2 +- .../UIProcess/API/qt/tests/qmltests/qmltests.pro | 1 + Source/WebKit2/UIProcess/qt/ClientImpl.cpp | 8 +++ Source/WebKit2/UIProcess/qt/ClientImpl.h | 1 + Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp | 1 + Source/WebKit2/UIProcess/qt/TouchViewInterface.h | 2 + Source/WebKit2/UIProcess/qt/ViewInterface.h | 2 + Tools/ChangeLog | 15 +++++ Tools/MiniBrowser/qt/BrowserWindow.cpp | 9 ++- Tools/MiniBrowser/qt/BrowserWindow.h | 1 + 15 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_linkHovered.qml diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog index c3decec..6d76463 100644 --- a/Source/WebKit2/ChangeLog +++ b/Source/WebKit2/ChangeLog @@ -1,3 +1,37 @@ +2011-09-26 Caio Marcelo de Oliveira Filho + + [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 [Qt][WK2] API fixes for QML, the signal parameters needs to be named. diff --git a/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.cpp b/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.cpp index 9df8a0f..380214c 100644 --- a/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.cpp +++ b/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.cpp @@ -431,6 +431,15 @@ void QDesktopWebViewPrivate::onOpenPanelFinished(int result) 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) { diff --git a/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.h b/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.h index 80262e1..c1fb59f 100644 --- a/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.h +++ b/Source/WebKit2/UIProcess/API/qt/qdesktopwebview.h @@ -88,6 +88,7 @@ Q_SIGNALS: 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*); diff --git a/Source/WebKit2/UIProcess/API/qt/qdesktopwebview_p.h b/Source/WebKit2/UIProcess/API/qt/qdesktopwebview_p.h index 43b7dd2..054a9a6 100644 --- a/Source/WebKit2/UIProcess/API/qt/qdesktopwebview_p.h +++ b/Source/WebKit2/UIProcess/API/qt/qdesktopwebview_p.h @@ -84,6 +84,8 @@ private: 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 @@ private: QFileDialog* fileDialog; WKOpenPanelResultListenerRef openPanelResultListener; + + QUrl lastHoveredURL; + QString lastHoveredTitle; }; #endif /* qdesktopwebview_p_h */ diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_linkHovered.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_linkHovered.qml new file mode 100644 index 0000000..46e9868 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopWebView/tst_linkHovered.qml @@ -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, "") + } + } +} diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/test2.html b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/test2.html index 0a3c39d..629c2a0 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/test2.html +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/test2.html @@ -1,6 +1,6 @@ Test page with huge link area - + diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro index e812694..ab16177 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/qmltests.pro @@ -13,6 +13,7 @@ OTHER_FILES += \ 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 \ diff --git a/Source/WebKit2/UIProcess/qt/ClientImpl.cpp b/Source/WebKit2/UIProcess/qt/ClientImpl.cpp index 7191e4f..8359a02 100644 --- a/Source/WebKit2/UIProcess/qt/ClientImpl.cpp +++ b/Source/WebKit2/UIProcess/qt/ClientImpl.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -163,6 +164,13 @@ void qt_wk_runOpenPanel(WKPageRef, WKFrameRef, WKOpenPanelParametersRef paramete 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) { diff --git a/Source/WebKit2/UIProcess/qt/ClientImpl.h b/Source/WebKit2/UIProcess/qt/ClientImpl.h index c64d784..de46760 100644 --- a/Source/WebKit2/UIProcess/qt/ClientImpl.h +++ b/Source/WebKit2/UIProcess/qt/ClientImpl.h @@ -41,6 +41,7 @@ void qt_wk_didSameDocumentNavigationForFrame(WKPageRef, WKFrameRef, WKSameDocume // 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); diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp b/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp index 143f1c4..f3d5a00 100644 --- a/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp +++ b/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp @@ -143,6 +143,7 @@ void QtWebPageProxy::init() 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) { diff --git a/Source/WebKit2/UIProcess/qt/TouchViewInterface.h b/Source/WebKit2/UIProcess/qt/TouchViewInterface.h index f6397f4..d15e86de 100644 --- a/Source/WebKit2/UIProcess/qt/TouchViewInterface.h +++ b/Source/WebKit2/UIProcess/qt/TouchViewInterface.h @@ -79,6 +79,8 @@ private: virtual void chooseFiles(WKOpenPanelResultListenerRef, const QStringList&, FileChooserType) { } + virtual void didMouseMoveOverElement(const QUrl&, const QString&) { } + private: QTouchWebView* const m_viewportView; QTouchWebPage* const m_pageView; diff --git a/Source/WebKit2/UIProcess/qt/ViewInterface.h b/Source/WebKit2/UIProcess/qt/ViewInterface.h index 24c7932..47e6919 100644 --- a/Source/WebKit2/UIProcess/qt/ViewInterface.h +++ b/Source/WebKit2/UIProcess/qt/ViewInterface.h @@ -88,6 +88,8 @@ public: virtual QJSEngine* engine() = 0; virtual void chooseFiles(WKOpenPanelResultListenerRef, const QStringList& selectedFileNames, FileChooserType) = 0; + + virtual void didMouseMoveOverElement(const QUrl&, const QString&) = 0; }; } diff --git a/Tools/ChangeLog b/Tools/ChangeLog index 1c2184e..5dcc810 100644 --- a/Tools/ChangeLog +++ b/Tools/ChangeLog @@ -1,3 +1,18 @@ +2011-09-26 Caio Marcelo de Oliveira Filho + + [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 garden-o-matic's commit data on summary page should not crowd itself or twitch when hovered over. diff --git a/Tools/MiniBrowser/qt/BrowserWindow.cpp b/Tools/MiniBrowser/qt/BrowserWindow.cpp index 439f65a..bf506a7 100644 --- a/Tools/MiniBrowser/qt/BrowserWindow.cpp +++ b/Tools/MiniBrowser/qt/BrowserWindow.cpp @@ -64,8 +64,10 @@ BrowserWindow::BrowserWindow(WindowOptions* options) 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 @@ void BrowserWindow::printURL(const QUrl& url) output << "Loaded: " << url.toString() << endl; } +void BrowserWindow::onLinkHovered(const QUrl& url, const QString&) +{ + statusBar()->showMessage(url.toString()); +} + void BrowserWindow::updateUserAgentList() { #if 0 diff --git a/Tools/MiniBrowser/qt/BrowserWindow.h b/Tools/MiniBrowser/qt/BrowserWindow.h index 939bf19..d69f513 100644 --- a/Tools/MiniBrowser/qt/BrowserWindow.h +++ b/Tools/MiniBrowser/qt/BrowserWindow.h @@ -69,6 +69,7 @@ protected slots: void loadURLListFromFile(); void printURL(const QUrl&); + void onLinkHovered(const QUrl&, const QString&); private: void updateUserAgentList(); -- 2.7.4