summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/render_widget_host_view_qt.cpp4
-rw-r--r--src/core/web_event_factory.cpp18
-rw-r--r--src/core/web_event_factory.h2
-rw-r--r--src/webengine/render_widget_host_view_qt_delegate_quick.cpp5
-rw-r--r--src/webengine/render_widget_host_view_qt_delegate_quick.h1
-rw-r--r--tests/auto/quick/qmltests/data/tst_mouseMove.qml96
-rw-r--r--tests/auto/quick/qmltests/qmltests.pro1
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp53
8 files changed, 177 insertions, 3 deletions
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
index 980550620..0d78d6743 100644
--- a/src/core/render_widget_host_view_qt.cpp
+++ b/src/core/render_widget_host_view_qt.cpp
@@ -960,6 +960,10 @@ bool RenderWidgetHostViewQt::forwardEvent(QEvent *event)
case QEvent::InputMethodQuery:
handleInputMethodQueryEvent(static_cast<QInputMethodQueryEvent*>(event));
break;
+ case QEvent::HoverLeave:
+ case QEvent::Leave:
+ m_host->ForwardMouseEvent(WebEventFactory::toWebMouseEvent(event));
+ break;
default:
return false;
}
diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp
index f5264708d..0e46aced5 100644
--- a/src/core/web_event_factory.cpp
+++ b/src/core/web_event_factory.cpp
@@ -1019,12 +1019,14 @@ static ui::DomKey getDomKeyFromQKeyEvent(QKeyEvent *ev)
}
}
-static inline double currentTimeForEvent(const QInputEvent* event)
+static inline double currentTimeForEvent(const QEvent *event)
{
Q_ASSERT(event);
- if (event->timestamp())
- return static_cast<double>(event->timestamp()) / 1000;
+ if (const QInputEvent *inputEvent = static_cast<const QInputEvent *>(event)) {
+ if (inputEvent->timestamp())
+ return static_cast<double>(inputEvent->timestamp()) / 1000;
+ }
static QElapsedTimer timer;
if (!timer.isValid())
@@ -1211,6 +1213,16 @@ WebMouseEvent WebEventFactory::toWebMouseEvent(QHoverEvent *ev, double dpiScale)
return webKitEvent;
}
+WebMouseEvent WebEventFactory::toWebMouseEvent(QEvent *ev)
+{
+ Q_ASSERT(ev->type() == QEvent::Leave || ev->type() == QEvent::HoverLeave);
+
+ WebMouseEvent webKitEvent;
+ webKitEvent.timeStampSeconds = currentTimeForEvent(ev);
+ webKitEvent.type = WebInputEvent::MouseLeave;
+ return webKitEvent;
+}
+
#ifndef QT_NO_GESTURES
WebGestureEvent WebEventFactory::toWebGestureEvent(QNativeGestureEvent *ev, double dpiScale)
{
diff --git a/src/core/web_event_factory.h b/src/core/web_event_factory.h
index 859e97643..b28710d66 100644
--- a/src/core/web_event_factory.h
+++ b/src/core/web_event_factory.h
@@ -49,6 +49,7 @@
#include <QtGlobal>
QT_BEGIN_NAMESPACE
+class QEvent;
class QHoverEvent;
class QKeyEvent;
class QMouseEvent;
@@ -63,6 +64,7 @@ class WebEventFactory {
public:
static blink::WebMouseEvent toWebMouseEvent(QMouseEvent*, double dpiScale);
static blink::WebMouseEvent toWebMouseEvent(QHoverEvent*, double dpiScale);
+ static blink::WebMouseEvent toWebMouseEvent(QEvent *);
#ifndef QT_NO_GESTURES
static blink::WebGestureEvent toWebGestureEvent(QNativeGestureEvent *, double dpiScale);
#endif
diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp
index 5d8c4fa43..0d77a5040 100644
--- a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp
+++ b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp
@@ -332,6 +332,11 @@ void RenderWidgetHostViewQtDelegateQuick::hoverMoveEvent(QHoverEvent *event)
m_client->forwardEvent(event);
}
+void RenderWidgetHostViewQtDelegateQuick::hoverLeaveEvent(QHoverEvent *event)
+{
+ m_client->forwardEvent(event);
+}
+
QVariant RenderWidgetHostViewQtDelegateQuick::inputMethodQuery(Qt::InputMethodQuery query) const
{
return m_client->inputMethodQuery(query);
diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.h b/src/webengine/render_widget_host_view_qt_delegate_quick.h
index 7a08e915b..eeb7db9cb 100644
--- a/src/webengine/render_widget_host_view_qt_delegate_quick.h
+++ b/src/webengine/render_widget_host_view_qt_delegate_quick.h
@@ -90,6 +90,7 @@ protected:
virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
virtual void touchEvent(QTouchEvent *event) Q_DECL_OVERRIDE;
virtual void hoverMoveEvent(QHoverEvent *event) Q_DECL_OVERRIDE;
+ virtual void hoverLeaveEvent(QHoverEvent *event) Q_DECL_OVERRIDE;
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const Q_DECL_OVERRIDE;
virtual void inputMethodEvent(QInputMethodEvent *event) Q_DECL_OVERRIDE;
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
diff --git a/tests/auto/quick/qmltests/data/tst_mouseMove.qml b/tests/auto/quick/qmltests/data/tst_mouseMove.qml
new file mode 100644
index 000000000..adb937139
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/tst_mouseMove.qml
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtTest 1.0
+import QtWebEngine 1.4
+
+Rectangle {
+ id: root
+ width: 200
+ height: 200
+
+ Column {
+ anchors.fill: parent
+ Rectangle {
+ id: placeHolder
+ width: parent.width
+ height: 100
+ color: "red"
+ }
+
+ TestWebEngineView {
+ id: webEngineView
+ width: parent.width
+ height: 100
+
+ function getInnerText(element) {
+ var innerText;
+ runJavaScript("document.getElementById('" + element + "').innerText", function(result) {
+ innerText = result;
+ });
+ testCase.tryVerify(function() { return innerText != undefined; });
+ return innerText;
+ }
+ }
+ }
+
+ TestCase {
+ id: testCase
+ name: "WebEngineViewMouseMove"
+ when: windowShown
+
+ function test_mouseLeave() {
+ mouseMove(root, 0, 0);
+ webEngineView.loadHtml(
+ "<html>" +
+ "<head><script>" +
+ "function init() {" +
+ " var div = document.getElementById('testDiv');" +
+ " div.onmouseenter = function(e) { div.innerText = 'Mouse IN' };" +
+ " div.onmouseleave = function(e) { div.innerText = 'Mouse OUT' };" +
+ "}" +
+ "</script></head>" +
+ "<body onload='init()' style='margin: 0px; padding: 0px'>" +
+ " <div id='testDiv' style='width: 100%; height: 100%; background-color: green' />" +
+ "</body>" +
+ "</html>");
+ verify(webEngineView.waitForLoadSucceeded());
+ verify(!webEngineView.getInnerText("testDiv"));
+
+ for (var i = 90; i < 110; ++i)
+ mouseMove(root, 50, i);
+ tryVerify(function() { return webEngineView.getInnerText("testDiv") == "Mouse IN" });
+
+ for (var i = 110; i > 90; --i)
+ mouseMove(root, 50, i);
+ tryVerify(function() { return webEngineView.getInnerText("testDiv") == "Mouse OUT" });
+ }
+ }
+}
+
diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro
index e7c5ededc..f09e5f009 100644
--- a/tests/auto/quick/qmltests/qmltests.pro
+++ b/tests/auto/quick/qmltests/qmltests.pro
@@ -59,6 +59,7 @@ OTHER_FILES += \
$$PWD/data/tst_loadProgress.qml \
$$PWD/data/tst_loadRecursionCrash.qml \
$$PWD/data/tst_loadUrl.qml \
+ $$PWD/data/tst_mouseMove.qml \
$$PWD/data/tst_navigationHistory.qml \
$$PWD/data/tst_navigationRequested.qml \
$$PWD/data/tst_newViewRequest.qml \
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index 7f9e1cff5..04de4d951 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -34,6 +34,7 @@
#include <qstackedlayout.h>
#include <qtemporarydir.h>
#include <QCompleter>
+#include <QLabel>
#include <QLineEdit>
#include <QHBoxLayout>
#include <QQuickItem>
@@ -145,6 +146,8 @@ private Q_SLOTS:
void imeCompositionQueryEvent_data();
void imeCompositionQueryEvent();
void newlineInTextarea();
+
+ void mouseLeave();
};
// This will be called before the first test function is executed.
@@ -2207,5 +2210,55 @@ void tst_QWebEngineView::imeCompositionQueryEvent()
QTRY_COMPARE(anchorPosQuery.value(Qt::ImAnchorPosition).toInt(), 11);
}
+void tst_QWebEngineView::mouseLeave()
+{
+ QScopedPointer<QWidget> containerWidget(new QWidget);
+
+ QLabel *label = new QLabel(containerWidget.data());
+ label->setStyleSheet("background-color: red;");
+ label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
+ label->setMinimumHeight(100);
+
+ QWebEngineView *view = new QWebEngineView(containerWidget.data());
+ view->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
+ view->setMinimumHeight(100);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->setAlignment(Qt::AlignTop);
+ layout->setSpacing(0);
+ layout->setMargin(0);
+ layout->addWidget(label);
+ layout->addWidget(view);
+ containerWidget->setLayout(layout);
+ containerWidget->show();
+ QVERIFY(QTest::qWaitForWindowExposed(containerWidget.data()));
+ QTest::mouseMove(containerWidget->windowHandle(), QPoint(0, 0));
+
+ auto innerText = [view]() -> QString {
+ return evaluateJavaScriptSync(view->page(), "document.getElementById('testDiv').innerText").toString();
+ };
+
+ QSignalSpy loadFinishedSpy(view, SIGNAL(loadFinished(bool)));
+ view->setHtml("<html>"
+ "<head><script>"
+ "function init() {"
+ " var div = document.getElementById('testDiv');"
+ " div.onmouseenter = function(e) { div.innerText = 'Mouse IN' };"
+ " div.onmouseleave = function(e) { div.innerText = 'Mouse OUT' };"
+ "}"
+ "</script></head>"
+ "<body onload='init()' style='margin: 0px; padding: 0px'>"
+ " <div id='testDiv' style='width: 100%; height: 100%; background-color: green' />"
+ "</body>"
+ "</html>");
+ QVERIFY(loadFinishedSpy.wait());
+ QVERIFY(innerText().isEmpty());
+
+ QTest::mouseMove(containerWidget->windowHandle(), QPoint(50, 150));
+ QTRY_COMPARE(innerText(), QStringLiteral("Mouse IN"));
+ QTest::mouseMove(containerWidget->windowHandle(), QPoint(50, 50));
+ QTRY_COMPARE(innerText(), QStringLiteral("Mouse OUT"));
+}
+
QTEST_MAIN(tst_QWebEngineView)
#include "tst_qwebengineview.moc"