From f0c7c66b2149d01732becc8dfc48d920b41b6309 Mon Sep 17 00:00:00 2001 From: Even Oscar Andersen Date: Thu, 21 Nov 2024 12:33:31 +0100 Subject: [PATCH] wasm: handle isComposing for platforms that support it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes (Alt + '~') + 'a' -> ã (Compose) + '\'' + e -> é A key change is to look at "isComposing" for events Related bugs: QTBUG-107139 QTBUG-124932 QTBUG-117096 Fixes: QTBUG-130887 Change-Id: I0d4641d89952e0b4117226994a91e40039ad8a03 Reviewed-by: Morten Johan Sørvig (cherry picked from commit efa0d60fe465542c8233b1e6d9ed35806967c86c) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/wasm/qwasmwindow.cpp | 49 ++++++++++------------ 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/plugins/platforms/wasm/qwasmwindow.cpp b/src/plugins/platforms/wasm/qwasmwindow.cpp index b8b76cafe12..8b01b9d33e7 100644 --- a/src/plugins/platforms/wasm/qwasmwindow.cpp +++ b/src/plugins/platforms/wasm/qwasmwindow.cpp @@ -502,38 +502,38 @@ bool QWasmWindow::processKey(const KeyEvent &event) void QWasmWindow::handleKeyForInputContextEvent(const emscripten::val &event) { - QWasmInputContext *wasmInput = QWasmIntegration::get()->wasmInputContext(); + // + // Things to consider: + // + // (Alt + '̃~') + a -> compose('~', 'a') + // (Compose) + '\'' + e -> compose('\'', 'e') + // complex (i.e Chinese et al) input handling + // Multiline text edit backspace at start of line + // + const QWasmInputContext *wasmInput = QWasmIntegration::get()->wasmInputContext(); if (wasmInput) { const auto keyString = QString::fromStdString(event["key"].as()); qCDebug(qLcQpaWasmInputContext) << "Key callback" << keyString << keyString.size(); - if (keyString == "Unidentified") { // Android makes a bunch of KeyEvents as "Unidentified" // They will be processed just in InputContext. return; + } else if (event["isComposing"].as()) { + // Handled by the input context + return; } else if (event["ctrlKey"].as() || event["altKey"].as() || event["metaKey"].as()) { - if (processKeyForInputContext(*KeyEvent::fromWebWithDeadKeyTranslation(event, m_deadKeySupport))) - event.call("preventDefault"); - event.call("stopImmediatePropagation"); - return; + // Not all platforms use 'isComposing' for '~' + 'a', in this + // case send the key with state ('ctrl', 'alt', or 'meta') to + // processKeyForInputContext + + ; // fallthrough } else if (keyString.size() != 1) { - if (!wasmInput->preeditString().isEmpty()) { - if (keyString == "Process" || keyString == "Backspace" || keyString == "Dead") { - // processed by InputContext - // "Process" should be handled by InputContext but - // QWasmInputContext's function is incomplete now - // so, there will be some exceptions here. - return; - } else if (keyString != "Shift" - && keyString != "Meta" - && keyString != "Alt" - && keyString != "Control" - && !keyString.startsWith("Arrow")) { - wasmInput->commitPreeditAndClear(); - } - } + // This is like; 'Shift','ArrowRight','AltGraph', ... + // send all of these to processKeyForInputContext + + ; // fallthrough } else if (wasmInput->inputMethodAccepted()) { // processed in inputContext with skipping processKey return; @@ -571,13 +571,6 @@ bool QWasmWindow::processKeyForInputContext(const KeyEvent &event) void QWasmWindow::handlePointerEvent(const emscripten::val &event) { - // Ideally it should not be happened but - // it takes place sometime with some reason - // without compositionend. - QWasmInputContext *wasmInput = QWasmIntegration::get()->wasmInputContext(); - if (wasmInput && !wasmInput->preeditString().isEmpty()) - wasmInput->commitPreeditAndClear(); - if (processPointer(*PointerEvent::fromWeb(event))) event.call("preventDefault"); }