summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets
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/webenginewidgets
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/webenginewidgets')
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp6
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h1
2 files changed, 7 insertions, 0 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 32c467c08..aceac91e3 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -271,6 +271,12 @@ void QWebEnginePagePrivate::focusContainer()
view->setFocus();
}
+void QWebEnginePagePrivate::unhandledKeyEvent(QKeyEvent *event)
+{
+ if (view && view->parentWidget())
+ QGuiApplication::sendEvent(view->parentWidget(), event);
+}
+
void QWebEnginePagePrivate::adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect &initialGeometry)
{
Q_Q(QWebEnginePage);
diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h
index 93b94bfa5..6c6520414 100644
--- a/src/webenginewidgets/api/qwebenginepage_p.h
+++ b/src/webenginewidgets/api/qwebenginepage_p.h
@@ -120,6 +120,7 @@ public:
virtual void loadVisuallyCommitted() Q_DECL_OVERRIDE { }
virtual void loadFinished(bool success, const QUrl &url, int errorCode = 0, const QString &errorDescription = QString()) Q_DECL_OVERRIDE;
virtual void focusContainer() Q_DECL_OVERRIDE;
+ virtual void unhandledKeyEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
virtual void adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect &initialGeometry) Q_DECL_OVERRIDE;
virtual void close() Q_DECL_OVERRIDE;
virtual bool contextMenuRequested(const WebEngineContextMenuData &data) Q_DECL_OVERRIDE;