diff options
author | Even Oscar Andersen <[email protected]> | 2025-05-12 11:59:20 +0200 |
---|---|---|
committer | Even Oscar Andersen <[email protected]> | 2025-05-14 17:40:08 +0200 |
commit | 83916851850bf41d9840a88d12112a20937da5f1 (patch) | |
tree | 87357d9b6c4eb7a790fb0c2a31e094b3165052d1 | |
parent | 3db537ee8e86fc355234794cecfba9627ea580ae (diff) |
wasm: set focus to m_canvas instead of m_window
Setting focus and contentEditable on m_window causes
innerHTML to build up with characters.
This does not happen when using the m_canvas
The downside is that m_canvas is aria-hidden, but this
should, in principle, not be a problem since
m_canvas should not be focused when a11y is in
effect.
Later aria-hidden might be set only if a11y is in
effect.
This is a candidate for manual cherry-picking to
6.9 6.9.1
Task-number: QTBUG-136687
Change-Id: I08a9db2c39f9b0b0038c75fd06d3504b736ea031
Reviewed-by: Morten Johan Sørvig <[email protected]>
-rw-r--r-- | src/plugins/platforms/wasm/qwasmclipboard.cpp | 14 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmclipboard.h | 2 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmwindow.cpp | 34 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmwindow.h | 3 |
4 files changed, 17 insertions, 36 deletions
diff --git a/src/plugins/platforms/wasm/qwasmclipboard.cpp b/src/plugins/platforms/wasm/qwasmclipboard.cpp index ff681398315..e5392f33cd7 100644 --- a/src/plugins/platforms/wasm/qwasmclipboard.cpp +++ b/src/plugins/platforms/wasm/qwasmclipboard.cpp @@ -86,20 +86,6 @@ void QWasmClipboard::paste(val event) QWasmIntegration::get()->getWasmClipboard()->sendClipboardData(event); } -void QWasmClipboard::beforeInput(emscripten::val event) -{ - event.call<void>("preventDefault"); - event.call<void>("stopPropagation"); -} - -void QWasmClipboard::input(emscripten::val event) -{ - event.call<void>("preventDefault"); - event.call<void>("stopPropagation"); - event["target"].set("innerHTML", std::string()); - event["target"].set("value", std::string()); -} - QWasmClipboard::QWasmClipboard() { val clipboard = val::global("navigator")["clipboard"]; diff --git a/src/plugins/platforms/wasm/qwasmclipboard.h b/src/plugins/platforms/wasm/qwasmclipboard.h index 9b221ded10c..3f24e64ceb5 100644 --- a/src/plugins/platforms/wasm/qwasmclipboard.h +++ b/src/plugins/platforms/wasm/qwasmclipboard.h @@ -43,8 +43,6 @@ public: static void cut(emscripten::val event); static void copy(emscripten::val event); static void paste(emscripten::val event); - static void beforeInput(emscripten::val event); - static void input(emscripten::val event); private: void initClipboardPermissions(); diff --git a/src/plugins/platforms/wasm/qwasmwindow.cpp b/src/plugins/platforms/wasm/qwasmwindow.cpp index 4e8399b6fcd..05ff67ced6f 100644 --- a/src/plugins/platforms/wasm/qwasmwindow.cpp +++ b/src/plugins/platforms/wasm/qwasmwindow.cpp @@ -59,7 +59,6 @@ QWasmWindow::QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport, m_document(dom::document()), m_decoratedWindow(m_document.call<emscripten::val>("createElement", emscripten::val("div"))), m_window(m_document.call<emscripten::val>("createElement", emscripten::val("div"))), - m_windowInput(m_document.call<emscripten::val>("createElement", emscripten::val("div"))), m_a11yContainer(m_document.call<emscripten::val>("createElement", emscripten::val("div"))), m_canvas(m_document.call<emscripten::val>("createElement", emscripten::val("canvas"))) { @@ -88,29 +87,30 @@ QWasmWindow::QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport, m_window.set("className", "qt-window"); m_decoratedWindow.call<void>("appendChild", m_window); - m_window.call<void>("appendChild", m_windowInput); m_canvas["classList"].call<void>("add", emscripten::val("qt-window-canvas")); + // Set contentEditable for two reasons; + // 1) so that the window gets clipboard events, + // 2) For applications who will handle keyboard events, but without having inputMethodAccepted() + // + // Set inputMode to none to avoid keyboard popping up on push buttons + // This is a tradeoff, we are not able to separate between a push button and + // a widget that reads keyboard events. + m_canvas.call<void>("setAttribute", std::string("inputmode"), std::string("none")); + m_canvas.call<void>("setAttribute", std::string("contenteditable"), std::string("true")); + m_canvas["style"].set("outline", std::string("none")); + #if QT_CONFIG(clipboard) if (QWasmClipboard::shouldInstallWindowEventHandlers()) { - // Set contentEditable so that the window gets clipboard events, - // then hide the resulting focus frame. - m_windowInput.set("contentEditable", std::string("true")); - m_windowInput["style"].set("outline", std::string("none")); - - m_cutCallback = QWasmEventHandler(m_windowInput, "cut", QWasmClipboard::cut); - m_copyCallback = QWasmEventHandler(m_windowInput, "copy", QWasmClipboard::copy); - m_pasteCallback = QWasmEventHandler(m_windowInput, "paste", QWasmClipboard::paste); - m_beforeInputCallback = - QWasmEventHandler(m_windowInput, "beforeinput", QWasmClipboard::beforeInput); - m_inputCallback = QWasmEventHandler(m_windowInput, "input", QWasmClipboard::input); + m_cutCallback = QWasmEventHandler(m_canvas, "cut", QWasmClipboard::cut); + m_copyCallback = QWasmEventHandler(m_canvas, "copy", QWasmClipboard::copy); + m_pasteCallback = QWasmEventHandler(m_canvas, "paste", QWasmClipboard::paste); } #endif // Set inputMode to none to stop the mobile keyboard from opening // when the user clicks on the window. m_window.set("inputMode", std::string("none")); - m_windowInput.set("inputMode", std::string("none")); // Hide the canvas from screen readers. m_canvas.call<void>("setAttribute", std::string("aria-hidden"), std::string("true")); @@ -202,9 +202,9 @@ void QWasmWindow::registerEventHandlers() [this](emscripten::val event) { this->handleKeyForInputContextEvent(EventType::KeyUp, event); }); } - m_keyDownCallback = QWasmEventHandler(m_window, "keydown", + m_keyDownCallback = QWasmEventHandler(m_canvas, "keydown", [this](emscripten::val event) { this->handleKeyEvent(KeyEvent(EventType::KeyDown, event, m_deadKeySupport)); }); - m_keyUpCallback =QWasmEventHandler(m_window, "keyup", + m_keyUpCallback =QWasmEventHandler(m_canvas, "keyup", [this](emscripten::val event) {this->handleKeyEvent(KeyEvent(EventType::KeyUp, event, m_deadKeySupport)); }); } @@ -951,7 +951,7 @@ void QWasmWindow::requestActivateWindow() void QWasmWindow::focus() { - m_windowInput.call<void>("focus"); + m_canvas.call<void>("focus"); } bool QWasmWindow::setMouseGrabEnabled(bool grab) diff --git a/src/plugins/platforms/wasm/qwasmwindow.h b/src/plugins/platforms/wasm/qwasmwindow.h index cd7d81aeb38..67a3e8ea293 100644 --- a/src/plugins/platforms/wasm/qwasmwindow.h +++ b/src/plugins/platforms/wasm/qwasmwindow.h @@ -143,7 +143,6 @@ private: emscripten::val m_document = emscripten::val::undefined(); emscripten::val m_decoratedWindow = emscripten::val::undefined(); emscripten::val m_window = emscripten::val::undefined(); - emscripten::val m_windowInput = emscripten::val::undefined(); emscripten::val m_a11yContainer = emscripten::val::undefined(); emscripten::val m_canvas = emscripten::val::undefined(); emscripten::val m_context2d = emscripten::val::undefined(); @@ -177,8 +176,6 @@ private: QWasmEventHandler m_cutCallback; QWasmEventHandler m_copyCallback; QWasmEventHandler m_pasteCallback; - QWasmEventHandler m_beforeInputCallback; - QWasmEventHandler m_inputCallback; Qt::WindowStates m_state = Qt::WindowNoState; Qt::WindowStates m_previousWindowState = Qt::WindowNoState; |