From 292f573f4e86d938a3bde80627637d245a949e56 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 9 May 2016 10:11:36 +0200 Subject: Fix event forwarding when activeFocusOnPress is false. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a QQuickWebEngineView does not have focus, and activeFocusOnPress is set to false, a user can still partially interact with the view. For instance hovering the mouse over a link would change the cursor, a link can be clicked to go to a different page. Clicking on a text input field would focus the text field, but entering characters will not be possible, because the view does not have QtQuick keyboard focus, and clicking does not give the focus (because activeFocusOnPress is set to false) and this leads to confusing behavior. Thus the fix is to make sure no mouse / keyboard events are forwarded to Chromium if the view has no focus, and activeFocusOnPress is set to false, in order to maintain a more user-friendly behavior. Manually forcing the focus via some user-provided method that calls forceActiveFocus() would allow further proper interaction. Change-Id: I72c3ff69438972b9a93ee2d415fa1d4b44b86cd9 Reviewed-by: Michael BrĂ¼ning --- .../render_widget_host_view_qt_delegate_quick.cpp | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/webengine/render_widget_host_view_qt_delegate_quick.cpp') 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 3ba3d117e..cd8fc54b9 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp @@ -219,18 +219,33 @@ void RenderWidgetHostViewQtDelegateQuick::focusOutEvent(QFocusEvent *event) void RenderWidgetHostViewQtDelegateQuick::mousePressEvent(QMouseEvent *event) { - if (!m_isPopup && (parentItem() && parentItem()->property("activeFocusOnPress").toBool())) + QQuickItem *parent = parentItem(); + if (!m_isPopup && (parent && parent->property("activeFocusOnPress").toBool())) forceActiveFocus(); + if (parent && !parent->property("activeFocusOnPress").toBool() && !parent->hasActiveFocus()) { + event->ignore(); + return; + } m_client->forwardEvent(event); } void RenderWidgetHostViewQtDelegateQuick::mouseMoveEvent(QMouseEvent *event) { + QQuickItem *parent = parentItem(); + if (parent && !parent->property("activeFocusOnPress").toBool() && !parent->hasActiveFocus()) { + event->ignore(); + return; + } m_client->forwardEvent(event); } void RenderWidgetHostViewQtDelegateQuick::mouseReleaseEvent(QMouseEvent *event) { + QQuickItem *parent = parentItem(); + if (parent && !parent->property("activeFocusOnPress").toBool() && !parent->hasActiveFocus()) { + event->ignore(); + return; + } m_client->forwardEvent(event); } @@ -251,14 +266,24 @@ void RenderWidgetHostViewQtDelegateQuick::wheelEvent(QWheelEvent *event) void RenderWidgetHostViewQtDelegateQuick::touchEvent(QTouchEvent *event) { + QQuickItem *parent = parentItem(); if (event->type() == QEvent::TouchBegin && !m_isPopup - && (parentItem() && parentItem()->property("activeFocusOnPress").toBool())) + && (parent && parent->property("activeFocusOnPress").toBool())) forceActiveFocus(); + if (parent && !parent->property("activeFocusOnPress").toBool() && !parent->hasActiveFocus()) { + event->ignore(); + return; + } m_client->forwardEvent(event); } void RenderWidgetHostViewQtDelegateQuick::hoverMoveEvent(QHoverEvent *event) { + QQuickItem *parent = parentItem(); + if (parent && !parent->property("activeFocusOnPress").toBool() && !parent->hasActiveFocus()) { + event->ignore(); + return; + } m_client->forwardEvent(event); } -- cgit v1.2.3