diff options
author | Alexandru Croitor <alexandru.croitor@theqtcompany.com> | 2016-05-09 10:11:36 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@theqtcompany.com> | 2016-05-26 09:05:10 +0000 |
commit | 292f573f4e86d938a3bde80627637d245a949e56 (patch) | |
tree | db9a74bc68f9d23838498443310a0fa877cb626f /src/webengine/render_widget_host_view_qt_delegate_quick.cpp | |
parent | 4c305cba0bf7cc021fd355af574b431f0d5a057d (diff) |
Fix event forwarding when activeFocusOnPress is false.
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 <michael.bruning@theqtcompany.com>
Diffstat (limited to 'src/webengine/render_widget_host_view_qt_delegate_quick.cpp')
-rw-r--r-- | src/webengine/render_widget_host_view_qt_delegate_quick.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
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); } |