wasm: move keyboard input handling for touchscreens

It's better served where all keys are handled,
and fixes bug with modifier keys

Fixes: QTBUG-118503
Pick-to: 6.6
Change-Id: Ic53d1b332bd918dbc4fdd27ea4e43ad1e1ecce82
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
(cherry picked from commit 75ac9adeda41194e1733c69b3176fc2a368a369e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Lorn Potter 2023-11-27 11:37:24 +10:00 committed by Qt Cherry-pick Bot
parent 59b323260f
commit 020a7e96d4
3 changed files with 14 additions and 25 deletions

View File

@ -59,12 +59,6 @@ QWasmInputContext::QWasmInputContext()
emscripten::val(quintptr(reinterpret_cast<void *>(this))));
emscripten::val body = document["body"];
body.call<void>("appendChild", m_inputElement);
// Enter is sent through target window, let's just handle this here
emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, (void *)this, 1,
&inputMethodKeyboardCallback);
emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, (void *)this, 1,
&inputMethodKeyboardCallback);
}
if (platform() == Platform::MacOS || platform() == Platform::iOS) {
@ -163,19 +157,5 @@ void QWasmInputContext::inputStringChanged(QString &inputString, int eventType,
eventType == EMSCRIPTEN_EVENT_KEYDOWN ? inputString : QStringLiteral(""));
}
int QWasmInputContext::inputMethodKeyboardCallback(int eventType,
const EmscriptenKeyboardEvent *keyEvent,
void *userData)
{
// we get Enter, Backspace and function keys via emscripten on target window
QString strKey(keyEvent->key);
if (strKey == "Unidentified" || strKey == "Process")
return false;
QWasmInputContext *wasmInput = reinterpret_cast<QWasmInputContext*>(userData);
wasmInput->inputStringChanged(strKey, eventType, wasmInput);
return true;
}
QT_END_NAMESPACE

View File

@ -30,6 +30,7 @@ public:
void focusWindowChanged(QWindow *focusWindow);
void inputStringChanged(QString &, int eventType, QWasmInputContext *context);
emscripten::val m_inputElement = emscripten::val::null();
private:
emscripten::val inputHandlerElementForFocusedWindow();
@ -37,11 +38,8 @@ private:
bool m_inputPanelVisible = false;
QPointer<QWindow> m_focusWindow;
emscripten::val m_inputElement = emscripten::val::null();
std::unique_ptr<qstdweb::EventCallback> m_blurEventHandler;
std::unique_ptr<qstdweb::EventCallback> m_inputEventHandler;
static int inputMethodKeyboardCallback(int eventType,
const EmscriptenKeyboardEvent *keyEvent, void *userData);
bool inputPanelIsOpen = false;
};

View File

@ -127,9 +127,20 @@ QWasmWindow::QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport,
event.call<void>("stopPropagation");
});
emscripten::val keyFocusWindow;
if (QWasmIntegration::get()->inputContext()) {
QWasmInputContext *wasmContext =
static_cast<QWasmInputContext *>(QWasmIntegration::get()->inputContext());
// if there is an touchscreen input context,
// use that window for key input
keyFocusWindow = wasmContext->m_inputElement;
} else {
keyFocusWindow = m_qtWindow;
}
m_keyDownCallback =
std::make_unique<qstdweb::EventCallback>(m_qtWindow, "keydown", keyCallback);
m_keyUpCallback = std::make_unique<qstdweb::EventCallback>(m_qtWindow, "keyup", keyCallback);
std::make_unique<qstdweb::EventCallback>(keyFocusWindow, "keydown", keyCallback);
m_keyUpCallback = std::make_unique<qstdweb::EventCallback>(keyFocusWindow, "keyup", keyCallback);
setParent(parent());
}