wasm: handle isComposing for platforms that support it

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 <morten.sorvig@qt.io>
(cherry picked from commit efa0d60fe465542c8233b1e6d9ed35806967c86c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Even Oscar Andersen 2024-11-21 12:33:31 +01:00 committed by Qt Cherry-pick Bot
parent d06cc87de4
commit f0c7c66b21

View File

@ -502,38 +502,38 @@ bool QWasmWindow::processKey(const KeyEvent &event)
void QWasmWindow::handleKeyForInputContextEvent(const emscripten::val &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) { if (wasmInput) {
const auto keyString = QString::fromStdString(event["key"].as<std::string>()); const auto keyString = QString::fromStdString(event["key"].as<std::string>());
qCDebug(qLcQpaWasmInputContext) << "Key callback" << keyString << keyString.size(); qCDebug(qLcQpaWasmInputContext) << "Key callback" << keyString << keyString.size();
if (keyString == "Unidentified") { if (keyString == "Unidentified") {
// Android makes a bunch of KeyEvents as "Unidentified" // Android makes a bunch of KeyEvents as "Unidentified"
// They will be processed just in InputContext. // They will be processed just in InputContext.
return; return;
} else if (event["isComposing"].as<bool>()) {
// Handled by the input context
return;
} else if (event["ctrlKey"].as<bool>() } else if (event["ctrlKey"].as<bool>()
|| event["altKey"].as<bool>() || event["altKey"].as<bool>()
|| event["metaKey"].as<bool>()) { || event["metaKey"].as<bool>()) {
if (processKeyForInputContext(*KeyEvent::fromWebWithDeadKeyTranslation(event, m_deadKeySupport))) // Not all platforms use 'isComposing' for '~' + 'a', in this
event.call<void>("preventDefault"); // case send the key with state ('ctrl', 'alt', or 'meta') to
event.call<void>("stopImmediatePropagation"); // processKeyForInputContext
return;
; // fallthrough
} else if (keyString.size() != 1) { } else if (keyString.size() != 1) {
if (!wasmInput->preeditString().isEmpty()) { // This is like; 'Shift','ArrowRight','AltGraph', ...
if (keyString == "Process" || keyString == "Backspace" || keyString == "Dead") { // send all of these to processKeyForInputContext
// processed by InputContext
// "Process" should be handled by InputContext but ; // fallthrough
// 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();
}
}
} else if (wasmInput->inputMethodAccepted()) { } else if (wasmInput->inputMethodAccepted()) {
// processed in inputContext with skipping processKey // processed in inputContext with skipping processKey
return; return;
@ -571,13 +571,6 @@ bool QWasmWindow::processKeyForInputContext(const KeyEvent &event)
void QWasmWindow::handlePointerEvent(const emscripten::val &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))) if (processPointer(*PointerEvent::fromWeb(event)))
event.call<void>("preventDefault"); event.call<void>("preventDefault");
} }