From a89ac4b8816d61d56c7504afab9e99b55d0e4ff5 Mon Sep 17 00:00:00 2001 From: Even Oscar Andersen Date: Mon, 12 May 2025 12:02:04 +0200 Subject: [PATCH] wasm: handle changes in inputMethodAccepted() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The result of inputMethodAccepted() function might switch after setFocusObject()/showInputPanel() has been called. End result it was not picked up and not acted upon. It turns out update() is called after this flag is set, so check for changes in the update() function. Task-number: QTBUG-136687 Change-Id: I585cc82f2a177bb7708627102d3074a627d0f024 Reviewed-by: Morten Johan Sørvig --- .../platforms/wasm/qwasminputcontext.cpp | 23 +++++++++++-------- .../platforms/wasm/qwasminputcontext.h | 1 - 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/plugins/platforms/wasm/qwasminputcontext.cpp b/src/plugins/platforms/wasm/qwasminputcontext.cpp index 0957af45d89..27641195cae 100644 --- a/src/plugins/platforms/wasm/qwasminputcontext.cpp +++ b/src/plugins/platforms/wasm/qwasminputcontext.cpp @@ -283,28 +283,33 @@ void QWasmInputContext::update(Qt::InputMethodQueries queries) { qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << queries; + if ((queries & Qt::ImEnabled) && (inputMethodAccepted() != m_inputMethodAccepted)) { + if (m_focusObject && !m_preeditString.isEmpty()) + commitPreeditAndClear(); + updateInputElement(); + } QPlatformInputContext::update(queries); } void QWasmInputContext::showInputPanel() { qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO; - m_visibleInputPanel = true; + // Note: showInputPanel not necessarily called, we shall + // still accept input if we have a focus object and + // inputMethodAccepted(). updateInputElement(); } void QWasmInputContext::updateGeometry() { const QWindow *focusWindow = QGuiApplication::focusWindow(); - if (!m_focusObject || !focusWindow || !m_visibleInputPanel || !m_inputMethodAccepted) { + if (!m_focusObject || !focusWindow || !m_inputMethodAccepted) { m_inputElement["style"].set("left", "0px"); m_inputElement["style"].set("top", "0px"); - } - else { + } else { Q_ASSERT(focusWindow); Q_ASSERT(m_focusObject); - Q_ASSERT(m_visibleInputPanel); Q_ASSERT(m_inputMethodAccepted); // Set the geometry @@ -329,13 +334,15 @@ void QWasmInputContext::updateGeometry() void QWasmInputContext::updateInputElement() { + m_inputMethodAccepted = inputMethodAccepted(); + // Mobile devices can dismiss keyboard/IME and focus is still on input. // Successive clicks on the same input should open the keyboard/IME. updateGeometry(); // If there is no focus object, or no visible input panel, remove focus const QWindow *focusWindow = QGuiApplication::focusWindow(); - if (!m_focusObject || !focusWindow || !m_visibleInputPanel || !m_inputMethodAccepted) { + if (!m_focusObject || !focusWindow || !m_inputMethodAccepted) { m_inputElement.set("value", ""); if (QWasmWindow *wasmwindow = QWasmWindow::fromWindow(focusWindow)) @@ -349,7 +356,6 @@ void QWasmInputContext::updateInputElement() Q_ASSERT(focusWindow); Q_ASSERT(m_focusObject); - Q_ASSERT(m_visibleInputPanel); Q_ASSERT(m_inputMethodAccepted); qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << QRectF::fromDOMRect(m_inputElement.call("getBoundingClientRect")); @@ -381,8 +387,8 @@ void QWasmInputContext::setFocusObject(QObject *object) if (m_focusObject && !m_preeditString.isEmpty()) commitPreeditAndClear(); - m_inputMethodAccepted = (object && inputMethodAccepted()); m_focusObject = object; + updateInputElement(); QPlatformInputContext::setFocusObject(object); } @@ -390,7 +396,6 @@ void QWasmInputContext::setFocusObject(QObject *object) void QWasmInputContext::hideInputPanel() { qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO; - m_visibleInputPanel = false; // hide only if m_focusObject does not exist if (!m_focusObject) diff --git a/src/plugins/platforms/wasm/qwasminputcontext.h b/src/plugins/platforms/wasm/qwasminputcontext.h index 4c09f6c2b74..72476adfe1b 100644 --- a/src/plugins/platforms/wasm/qwasminputcontext.h +++ b/src/plugins/platforms/wasm/qwasminputcontext.h @@ -65,7 +65,6 @@ private: QString m_preeditString; int m_replaceSize = 0; - bool m_visibleInputPanel = false; bool m_inputMethodAccepted = false; QObject *m_focusObject = nullptr; };