From b0324c5e020b98cbc0caf8176bbdfc5cd80b545e Mon Sep 17 00:00:00 2001 From: Viktor Engelmann Date: Mon, 13 Mar 2017 14:30:02 +0100 Subject: Handle ViewHostMsg_Focus message from chromium MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Joerg Bornemann --- src/webengine/plugin/plugins.qmltypes | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/webengine/plugin/plugins.qmltypes') diff --git a/src/webengine/plugin/plugins.qmltypes b/src/webengine/plugin/plugins.qmltypes index 81ff25a63..0cfa2d25b 100644 --- a/src/webengine/plugin/plugins.qmltypes +++ b/src/webengine/plugin/plugins.qmltypes @@ -4,7 +4,7 @@ import QtQuick.tooling 1.2 // It is used for QML tooling purposes only. // // This file was auto-generated by: -// 'qmlplugindump -defaultplatform -dependencies dependencies.json -nonrelocatable QtWebEngine 1.5' +// 'qmlplugindump -defaultplatform -dependencies dependencies.json -nonrelocatable QtWebEngine 1.6' Module { dependencies: ["QtQuick 2.6"] @@ -509,10 +509,11 @@ Module { "QtWebEngine/WebEngineSettings 1.2", "QtWebEngine/WebEngineSettings 1.3", "QtWebEngine/WebEngineSettings 1.4", - "QtWebEngine/WebEngineSettings 1.5" + "QtWebEngine/WebEngineSettings 1.5", + "QtWebEngine/WebEngineSettings 1.6" ] isCreatable: false - exportMetaObjectRevisions: [0, 1, 2, 3, 4] + exportMetaObjectRevisions: [0, 1, 2, 3, 4, 5] Property { name: "autoLoadImages"; type: "bool" } Property { name: "javascriptEnabled"; type: "bool" } Property { name: "javascriptCanOpenWindows"; type: "bool" } @@ -536,6 +537,7 @@ Module { Property { name: "printElementBackgrounds"; revision: 3; type: "bool" } Property { name: "allowRunningInsecureContent"; revision: 3; type: "bool" } Property { name: "allowGeolocationOnInsecureOrigins"; revision: 4; type: "bool" } + Property { name: "allowWindowActivationFromJavaScript"; revision: 5; type: "bool" } Signal { name: "fullScreenSupportEnabledChanged"; revision: 1 } Signal { name: "screenCaptureEnabledChanged"; revision: 2 } Signal { name: "webGLEnabledChanged"; revision: 2 } @@ -546,6 +548,7 @@ Module { Signal { name: "printElementBackgroundsChanged"; revision: 3 } Signal { name: "allowRunningInsecureContentChanged"; revision: 3 } Signal { name: "allowGeolocationOnInsecureOriginsChanged"; revision: 4 } + Signal { name: "allowWindowActivationFromJavaScriptChanged"; revision: 5 } } Component { name: "QQuickWebEngineSingleton" -- cgit v1.2.3