Skip to content

Commit

Permalink
wasm: handle isComposing for platforms that support it
Browse files Browse the repository at this point in the history
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
Pick-to: 6.8
Change-Id: I0d4641d89952e0b4117226994a91e40039ad8a03
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
  • Loading branch information
EvenOAndersen committed Nov 21, 2024
1 parent 3307d59 commit efa0d60
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions src/plugins/platforms/wasm/qwasmwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,38 +515,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<std::string>());
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<bool>()) {
// Handled by the input context
return;
} else if (event["ctrlKey"].as<bool>()
|| event["altKey"].as<bool>()
|| event["metaKey"].as<bool>()) {
if (processKeyForInputContext(*KeyEvent::fromWebWithDeadKeyTranslation(event, m_deadKeySupport)))
event.call<void>("preventDefault");
event.call<void>("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;
Expand Down Expand Up @@ -584,13 +584,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<void>("preventDefault");
}
Expand Down

0 comments on commit efa0d60

Please sign in to comment.