diff options
author | Viktor Engelmann <Viktor.Engelmann@qt.io> | 2017-03-13 14:30:02 +0100 |
---|---|---|
committer | Viktor Engelmann <viktor.engelmann@qt.io> | 2017-05-24 08:03:01 +0000 |
commit | b0324c5e020b98cbc0caf8176bbdfc5cd80b545e (patch) | |
tree | 8227937e524c862e0f8d72a2a16924f6d906fd13 /src/webenginewidgets/api | |
parent | ac34e49473d731b068c7782674069cb9fcc95328 (diff) |
Handle ViewHostMsg_Focus message from chromium
Calling the method window.focus() in javascript causes chromium to send
a ViewHostMsg_Focus message, which is received by RenderViewHost,
which then calls RenderViewHost::OnFocus.
This calls WebContentsDelegate::ActivateContents, which does
nothing in the default implementation. We now override this method in
WebContentsDelegateQt::ActivateContents and call Focus() on
the WebContents object IF the new WebEngineSettings value
AllowWindowActivationFromJavaScript is true (by default, it is false).
This in turn calls QWebEnginePagePrivate::focusContainer.
The WebEnginePage now calls QWidget::activateWindow() in addition
to QWidget::setFocus, to make sure the window is also activated (which
it might not be, if multiple windows are open).
For the QML side, a new boolean Property
allowWindowActivationFromJavaScript was added.
Task-number: QTBUG-58800
Change-Id: Iabf5d4d15236c77838a3886de81e9dafcaf49f5d
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/webenginewidgets/api')
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 4 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginesettings.cpp | 2 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginesettings.h | 3 |
3 files changed, 7 insertions, 2 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 45b6af763..40180d9b8 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -379,8 +379,10 @@ void QWebEnginePagePrivate::didPrintPageToPdf(const QString &filePath, bool succ void QWebEnginePagePrivate::focusContainer() { - if (view) + if (view) { + view->activateWindow(); view->setFocus(); + } } void QWebEnginePagePrivate::unhandledKeyEvent(QKeyEvent *event) diff --git a/src/webenginewidgets/api/qwebenginesettings.cpp b/src/webenginewidgets/api/qwebenginesettings.cpp index 08d24376a..4c8c4be33 100644 --- a/src/webenginewidgets/api/qwebenginesettings.cpp +++ b/src/webenginewidgets/api/qwebenginesettings.cpp @@ -97,6 +97,8 @@ static WebEngineSettings::Attribute toWebEngineAttribute(QWebEngineSettings::Web return WebEngineSettings::AllowRunningInsecureContent; case QWebEngineSettings::AllowGeolocationOnInsecureOrigins: return WebEngineSettings::AllowGeolocationOnInsecureOrigins; + case QWebEngineSettings::AllowWindowActivationFromJavaScript: + return WebEngineSettings::AllowWindowActivationFromJavaScript; default: return WebEngineSettings::UnsupportedInCoreSettings; diff --git a/src/webenginewidgets/api/qwebenginesettings.h b/src/webenginewidgets/api/qwebenginesettings.h index 73995a457..4b997f0ac 100644 --- a/src/webenginewidgets/api/qwebenginesettings.h +++ b/src/webenginewidgets/api/qwebenginesettings.h @@ -89,7 +89,8 @@ public: FocusOnNavigationEnabled, PrintElementBackgrounds, AllowRunningInsecureContent, - AllowGeolocationOnInsecureOrigins + AllowGeolocationOnInsecureOrigins, + AllowWindowActivationFromJavaScript }; enum FontSize { |