summaryrefslogtreecommitdiffstats
path: root/src/core/render_widget_host_view_qt.cpp
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2015-01-29 12:06:28 +0100
committerAndras Becsi <andras.becsi@theqtcompany.com>2015-02-05 13:10:41 +0000
commitfaec509a21b4700dbf271c4dcbb3a993f1c4042f (patch)
treedd16a33ab7070ab52e34843f666f1e6c87fdc5bf /src/core/render_widget_host_view_qt.cpp
parent0622e02b9da5b93c6824367732970af0214601fb (diff)
Propagate unhandled key events to the QtWebEngine view's parent
This allows applications to receive unhandled key events from the page by setting an event handler on the view's parent widget/item, like it was possible with QtWebKit. This is different in that events first have to asynchronously go through the QtWebEngineProcess. If the WebEngine view has the keyboard focus, the events will be consumed inconditionally by the RenderWidgetHostViewQtDelegates, and a copy will be resent to the view's parent if it wasn't consumed. This sends it to the parent instead of the QWebEngineView directly since those are only unhandled events, unlike with other widgets where you can first intercept events. It is done that way also in cases where the QWebEngineView would be be the focus widget directly in the future, instead of the RWHV. If applications want to intercept key events before they reach the page, they need to use an event filter on the QWebEngineView's children or globally on the application. Change-Id: I3b48f5212d3f238a1c0497cec1db6ae3badbad26 Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'src/core/render_widget_host_view_qt.cpp')
-rw-r--r--src/core/render_widget_host_view_qt.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
index bf4d5bf37..3741d8876 100644
--- a/src/core/render_widget_host_view_qt.cpp
+++ b/src/core/render_widget_host_view_qt.cpp
@@ -880,10 +880,17 @@ void RenderWidgetHostViewQt::handleKeyEvent(QKeyEvent *ev)
UnlockMouse();
content::NativeWebKeyboardEvent webEvent = WebEventFactory::toWebKeyboardEvent(ev);
- m_host->ForwardKeyboardEvent(webEvent);
if (webEvent.type == blink::WebInputEvent::RawKeyDown && !ev->text().isEmpty()) {
+ // Blink won't consume the RawKeyDown, but rather the Char event in this case.
+ // Make sure to skip the former on the way back. The same os_event will be set on both of them.
+ webEvent.skip_in_browser = true;
+ m_host->ForwardKeyboardEvent(webEvent);
+
+ webEvent.skip_in_browser = false;
webEvent.type = blink::WebInputEvent::Char;
m_host->ForwardKeyboardEvent(webEvent);
+ } else {
+ m_host->ForwardKeyboardEvent(webEvent);
}
}