diff options
author | Mikolaj Boc <[email protected]> | 2023-02-22 09:50:54 +0100 |
---|---|---|
committer | Mikolaj Boc <[email protected]> | 2023-06-09 14:05:06 +0200 |
commit | a1704ee6aa07e8bca7a1c4cf965f40a8255ffbc8 (patch) | |
tree | d91d4decfef49233d4e24a4a00e96bf558a26501 /tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp | |
parent | 5d12d9846a9436b4ef4e1f8ac42d081d60568ecf (diff) |
Correctly focus WASM windows on show
Since first requestActivate may happen before the window div is
actually displayed on-screen, we need to sync Qt's activation state
with DOM as soon as DOM element becomes visible. Focusing an
invisible element is impossible.
Fixes: QTBUG-79934
Change-Id: I04cf9b4ead006c9b8b135b3b6967d7938c581833
Reviewed-by: Morten Johan Sørvig <[email protected]>
Diffstat (limited to 'tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp')
-rw-r--r-- | tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp b/tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp index 3a8f0693dfd..eda557e195f 100644 --- a/tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp +++ b/tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include <QtCore/QEvent> + +#include <QtGui/qevent.h> #include <QtCore/qobject.h> #include <QtCore/qregularexpression.h> #include <QtGui/qscreen.h> @@ -26,6 +28,26 @@ private: Q_UNUSED(ev); delete this; } + + void keyPressEvent(QKeyEvent *event) final + { + auto data = emscripten::val::object(); + data.set("type", emscripten::val("keyPress")); + data.set("windowId", emscripten::val(winId())); + data.set("windowTitle", emscripten::val(title().toStdString())); + data.set("key", emscripten::val(event->text().toStdString())); + emscripten::val::global("window")["testSupport"].call<void>("reportEvent", std::move(data)); + } + + void keyReleaseEvent(QKeyEvent *event) final + { + auto data = emscripten::val::object(); + data.set("type", emscripten::val("keyRelease")); + data.set("windowId", emscripten::val(winId())); + data.set("windowTitle", emscripten::val(title().toStdString())); + data.set("key", emscripten::val(event->text().toStdString())); + emscripten::val::global("window")["testSupport"].call<void>("reportEvent", std::move(data)); + } }; using namespace emscripten; @@ -128,7 +150,19 @@ void createWindow(int x, int y, int w, int h, std::string screenId, std::string window->setTitle(QString::fromLatin1(title)); window->setGeometry(x, y, w, h); window->setScreen(*screen_it); - window->showNormal(); +} + +void setWindowVisible(int windowId, bool visible) { + auto windows = qGuiApp->allWindows(); + auto window_it = std::find_if(windows.begin(), windows.end(), [windowId](QWindow *window) { + return window->winId() == WId(windowId); + }); + if (window_it == windows.end()) { + qWarning() << "No such window: " << windowId; + return; + } + + (*window_it)->setVisible(visible); } EMSCRIPTEN_BINDINGS(qwasmwindow) @@ -136,6 +170,7 @@ EMSCRIPTEN_BINDINGS(qwasmwindow) emscripten::function("screenInformation", &screenInformation); emscripten::function("windowInformation", &windowInformation); emscripten::function("createWindow", &createWindow); + emscripten::function("setWindowVisible", &setWindowVisible); } int main(int argc, char **argv) |