wasm: fix compositional input event handler leaks
Change-Id: Ia6d7b9972c126b926e1d7d458ef4e034edbc924a Reviewed-by: Even Oscar Andersen <even.oscar.andersen@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
0d0a151e0d
commit
13e9228319
@ -19,7 +19,7 @@ Q_LOGGING_CATEGORY(qLcQpaWasmInputContext, "qt.qpa.wasm.inputcontext")
|
|||||||
|
|
||||||
using namespace qstdweb;
|
using namespace qstdweb;
|
||||||
|
|
||||||
static void inputCallback(emscripten::val event)
|
void QWasmInputContext::inputCallback(emscripten::val event)
|
||||||
{
|
{
|
||||||
qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << "isComposing : " << event["isComposing"].as<bool>();
|
qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << "isComposing : " << event["isComposing"].as<bool>();
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ static void inputCallback(emscripten::val event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void compositionEndCallback(emscripten::val event)
|
void QWasmInputContext::compositionEndCallback(emscripten::val event)
|
||||||
{
|
{
|
||||||
const auto inputStr = QString::fromStdString(event["data"].as<std::string>());
|
const auto inputStr = QString::fromStdString(event["data"].as<std::string>());
|
||||||
qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << inputStr;
|
qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << inputStr;
|
||||||
@ -122,7 +122,7 @@ static void compositionEndCallback(emscripten::val event)
|
|||||||
wasmInput->commitPreeditAndClear();
|
wasmInput->commitPreeditAndClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void compositionStartCallback(emscripten::val event)
|
void QWasmInputContext::compositionStartCallback(emscripten::val event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO;
|
qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO;
|
||||||
@ -145,7 +145,7 @@ static void beforeInputCallback(emscripten::val event)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void compositionUpdateCallback(emscripten::val event)
|
void QWasmInputContext::compositionUpdateCallback(emscripten::val event)
|
||||||
{
|
{
|
||||||
const auto compositionStr = QString::fromStdString(event["data"].as<std::string>());
|
const auto compositionStr = QString::fromStdString(event["data"].as<std::string>());
|
||||||
qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << compositionStr;
|
qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << compositionStr;
|
||||||
@ -232,11 +232,6 @@ static void pasteCallback(emscripten::val event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
EMSCRIPTEN_BINDINGS(wasminputcontext_module) {
|
EMSCRIPTEN_BINDINGS(wasminputcontext_module) {
|
||||||
function("qtCompositionEndCallback", &compositionEndCallback);
|
|
||||||
function("qtCompositionStartCallback", &compositionStartCallback);
|
|
||||||
function("qtCompositionUpdateCallback", &compositionUpdateCallback);
|
|
||||||
function("qtInputCallback", &inputCallback);
|
|
||||||
//function("qtBeforeInputCallback", &beforeInputCallback);
|
|
||||||
|
|
||||||
function("qtCopyCallback", ©Callback);
|
function("qtCopyCallback", ©Callback);
|
||||||
function("qtCutCallback", &cutCallback);
|
function("qtCutCallback", &cutCallback);
|
||||||
@ -265,21 +260,10 @@ QWasmInputContext::QWasmInputContext()
|
|||||||
emscripten::val body = document["body"];
|
emscripten::val body = document["body"];
|
||||||
body.call<void>("appendChild", m_inputElement);
|
body.call<void>("appendChild", m_inputElement);
|
||||||
|
|
||||||
m_inputElement.call<void>("addEventListener", std::string("compositionstart"),
|
m_inputCallback = QWasmEventHandler(m_inputElement, "input", QWasmInputContext::inputCallback);
|
||||||
emscripten::val::module_property("qtCompositionStartCallback"),
|
m_compositionEndCallback = QWasmEventHandler(m_inputElement, "compositionend", QWasmInputContext::compositionEndCallback);
|
||||||
emscripten::val(false));
|
m_compositionStartCallback = QWasmEventHandler(m_inputElement, "compositionstart", QWasmInputContext::compositionStartCallback);
|
||||||
m_inputElement.call<void>("addEventListener", std::string("compositionupdate"),
|
m_compositionUpdateCallback = QWasmEventHandler(m_inputElement, "compositionupdate", QWasmInputContext::compositionUpdateCallback);
|
||||||
emscripten::val::module_property("qtCompositionUpdateCallback"),
|
|
||||||
emscripten::val(false));
|
|
||||||
m_inputElement.call<void>("addEventListener", std::string("compositionend"),
|
|
||||||
emscripten::val::module_property("qtCompositionEndCallback"),
|
|
||||||
emscripten::val(false));
|
|
||||||
m_inputElement.call<void>("addEventListener", std::string("input"),
|
|
||||||
emscripten::val::module_property("qtInputCallback"),
|
|
||||||
emscripten::val(false));
|
|
||||||
//m_inputElement.call<void>("addEventListener", std::string("beforeinput"),
|
|
||||||
// emscripten::val::module_property("qtBeforeInputCallback"),
|
|
||||||
// emscripten::val(false));
|
|
||||||
|
|
||||||
// Clipboard for InputContext
|
// Clipboard for InputContext
|
||||||
m_inputElement.call<void>("addEventListener", std::string("cut"),
|
m_inputElement.call<void>("addEventListener", std::string("cut"),
|
||||||
|
@ -39,9 +39,18 @@ public:
|
|||||||
|
|
||||||
void insertText(QString inputStr, bool replace = false);
|
void insertText(QString inputStr, bool replace = false);
|
||||||
|
|
||||||
|
QWasmEventHandler m_inputCallback;
|
||||||
|
QWasmEventHandler m_compositionEndCallback;
|
||||||
|
QWasmEventHandler m_compositionStartCallback;
|
||||||
|
QWasmEventHandler m_compositionUpdateCallback;
|
||||||
|
|
||||||
bool usingTextInput() const { return m_inputMethodAccepted; }
|
bool usingTextInput() const { return m_inputMethodAccepted; }
|
||||||
void setFocusObject(QObject *object) override;
|
void setFocusObject(QObject *object) override;
|
||||||
|
|
||||||
|
static void inputCallback(emscripten::val event);
|
||||||
|
static void compositionEndCallback(emscripten::val event);
|
||||||
|
static void compositionStartCallback(emscripten::val event);
|
||||||
|
static void compositionUpdateCallback(emscripten::val event);
|
||||||
private:
|
private:
|
||||||
void updateInputElement();
|
void updateInputElement();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user