Skip to content

Commit 4c21432

Browse files
Morten SørvigQt Cherry-pick Bot
authored andcommitted
wasm: simplify compose key handling
Use keyCode 229 to determine if the key event is a part of input method compose, as documented by MDN: developer.mozilla.org/en-US/docs/Web/API/Element/keydown_event#keydown_events_with_ime This restores correct key event behavior where KeyPress events are sent for key events which are not part of an input method compose. Task-number: QTBUG-141226 Change-Id: I681ec15cae70c00049c9be03f6ea98222498ba6a Reviewed-by: Lorn Potter <lorn.potter@qt.io> (cherry picked from commit 9af69e8) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
1 parent bd60840 commit 4c21432

File tree

3 files changed

+15
-44
lines changed

3 files changed

+15
-44
lines changed

src/plugins/platforms/wasm/qwasmevent.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ KeyEvent::KeyEvent(EventType type, emscripten::val event, QWasmDeadKeySupport *d
120120
autoRepeat = event["repeat"].as<bool>();
121121
modifiers = getKeyboardModifiers(event);
122122
key = webKeyToQtKey(code, webKey, deadKey, modifiers);
123+
isComposing = event["isComposing"].as<bool>();
124+
keyCode = event["keyCode"].as<int>();
123125

124126
text = QString::fromUtf8(webKey);
125127

src/plugins/platforms/wasm/qwasmevent.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ struct KeyEvent : public Event
7272
bool deadKey;
7373
QString text;
7474
bool autoRepeat;
75+
bool isComposing;
76+
int keyCode;
7577
};
7678

7779
struct MouseEvent : public Event

src/plugins/platforms/wasm/qwasmwindow.cpp

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -688,51 +688,18 @@ bool QWasmWindow::processKey(const KeyEvent &event)
688688

689689
void QWasmWindow::handleKeyForInputContextEvent(const KeyEvent &keyEvent)
690690
{
691-
//
692-
// Things to consider:
693-
//
694-
// (Alt + '̃~') + a -> compose('~', 'a')
695-
// (Compose) + '\'' + e -> compose('\'', 'e')
696-
// complex (i.e Chinese et al) input handling
697-
// Multiline text edit backspace at start of line
698-
//
691+
// Don't send Qt key events if the key event is a part of input composition,
692+
// let those be handled by by the input event key handler. Check for the
693+
// keyCode 229 as well as isComposing in order catch all cases (see mdn
694+
// docs for the keyDown event)
695+
if (keyEvent.isComposing || keyEvent.keyCode == 229)
696+
return;
697+
698+
qCDebug(qLcQpaWasmInputContext) << "processKey as KeyEvent";
699699
emscripten::val event = keyEvent.webEvent;
700-
bool useInputContext = [event]() -> bool {
701-
const QWasmInputContext *wasmInput = QWasmIntegration::get()->wasmInputContext();
702-
if (!wasmInput)
703-
return false;
704-
705-
const auto keyString = QString::fromStdString(event["key"].as<std::string>());
706-
qCDebug(qLcQpaWasmInputContext) << "Key callback" << keyString << keyString.size();
707-
708-
// Events with isComposing set are handled by the input context
709-
bool composing = event["isComposing"].as<bool>();
710-
711-
// Android makes a bunch of KeyEvents as "Unidentified",
712-
// make inputContext handle those.
713-
bool androidUnidentified = (keyString == "Unidentified");
714-
715-
// Not all platforms use 'isComposing' for '~' + 'a', in this
716-
// case send the key with state ('ctrl', 'alt', or 'meta') to
717-
// processKeyForInputContext
718-
bool hasModifiers = event["ctrlKey"].as<bool>()
719-
|| event["altKey"].as<bool>()
720-
|| event["metaKey"].as<bool>();
721-
722-
// This is like; 'Shift','ArrowRight','AltGraph', ...
723-
// send all of these to processKeyForInputContext
724-
bool hasNoncharacterKeyString = keyString.size() != 1;
725-
726-
bool overrideCompose = !hasModifiers && !hasNoncharacterKeyString && wasmInput->inputMethodAccepted();
727-
return composing || androidUnidentified || overrideCompose;
728-
}();
729-
730-
if (!useInputContext) {
731-
qCDebug(qLcQpaWasmInputContext) << "processKey as KeyEvent";
732-
if (processKeyForInputContext(keyEvent))
733-
event.call<void>("preventDefault");
734-
event.call<void>("stopImmediatePropagation");
735-
}
700+
if (processKeyForInputContext(keyEvent))
701+
event.call<void>("preventDefault");
702+
event.call<void>("stopImmediatePropagation");
736703
}
737704

738705
bool QWasmWindow::processKeyForInputContext(const KeyEvent &event)

0 commit comments

Comments
 (0)