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:
parent
59b323260f
commit
020a7e96d4
@ -59,12 +59,6 @@ QWasmInputContext::QWasmInputContext()
|
|||||||
emscripten::val(quintptr(reinterpret_cast<void *>(this))));
|
emscripten::val(quintptr(reinterpret_cast<void *>(this))));
|
||||||
emscripten::val body = document["body"];
|
emscripten::val body = document["body"];
|
||||||
body.call<void>("appendChild", m_inputElement);
|
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) {
|
if (platform() == Platform::MacOS || platform() == Platform::iOS) {
|
||||||
@ -163,19 +157,5 @@ void QWasmInputContext::inputStringChanged(QString &inputString, int eventType,
|
|||||||
eventType == EMSCRIPTEN_EVENT_KEYDOWN ? inputString : QStringLiteral(""));
|
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
|
QT_END_NAMESPACE
|
||||||
|
@ -30,6 +30,7 @@ public:
|
|||||||
|
|
||||||
void focusWindowChanged(QWindow *focusWindow);
|
void focusWindowChanged(QWindow *focusWindow);
|
||||||
void inputStringChanged(QString &, int eventType, QWasmInputContext *context);
|
void inputStringChanged(QString &, int eventType, QWasmInputContext *context);
|
||||||
|
emscripten::val m_inputElement = emscripten::val::null();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
emscripten::val inputHandlerElementForFocusedWindow();
|
emscripten::val inputHandlerElementForFocusedWindow();
|
||||||
@ -37,11 +38,8 @@ private:
|
|||||||
bool m_inputPanelVisible = false;
|
bool m_inputPanelVisible = false;
|
||||||
|
|
||||||
QPointer<QWindow> m_focusWindow;
|
QPointer<QWindow> m_focusWindow;
|
||||||
emscripten::val m_inputElement = emscripten::val::null();
|
|
||||||
std::unique_ptr<qstdweb::EventCallback> m_blurEventHandler;
|
std::unique_ptr<qstdweb::EventCallback> m_blurEventHandler;
|
||||||
std::unique_ptr<qstdweb::EventCallback> m_inputEventHandler;
|
std::unique_ptr<qstdweb::EventCallback> m_inputEventHandler;
|
||||||
static int inputMethodKeyboardCallback(int eventType,
|
|
||||||
const EmscriptenKeyboardEvent *keyEvent, void *userData);
|
|
||||||
bool inputPanelIsOpen = false;
|
bool inputPanelIsOpen = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -127,9 +127,20 @@ QWasmWindow::QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport,
|
|||||||
event.call<void>("stopPropagation");
|
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 =
|
m_keyDownCallback =
|
||||||
std::make_unique<qstdweb::EventCallback>(m_qtWindow, "keydown", keyCallback);
|
std::make_unique<qstdweb::EventCallback>(keyFocusWindow, "keydown", keyCallback);
|
||||||
m_keyUpCallback = std::make_unique<qstdweb::EventCallback>(m_qtWindow, "keyup", keyCallback);
|
m_keyUpCallback = std::make_unique<qstdweb::EventCallback>(keyFocusWindow, "keyup", keyCallback);
|
||||||
|
|
||||||
setParent(parent());
|
setParent(parent());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user