diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2018-11-21 14:09:38 +0100 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2018-11-29 13:26:18 +0000 |
commit | 35ee29eb348b4629f47a6b700f9e2c356265aeba (patch) | |
tree | b33d72bf152b494f7c5b7017fdc218da1d975a07 /src | |
parent | ce7d46d6122c0af2c5820d51bbb804bc81cdefa7 (diff) |
Fix input method update
Do the update after the input properties are changed in
RenderWidgetHostViewQt. Moreover, always update on input
state changes, like cursor position, surrounding text and
text selection (see QInputMethod::update() docs).
Task-number: QTBUG-70158
Task-number: QTBUG-71995
Change-Id: I9d5c6e299826fbe66f5285b648013ef79aabed9b
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src')
5 files changed, 23 insertions, 26 deletions
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 267460bdc..2326dbdf7 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -746,25 +746,29 @@ void RenderWidgetHostViewQt::OnUpdateTextInputStateCalled(content::TextInputMana Q_UNUSED(updated_view); Q_UNUSED(did_update_state); - ui::TextInputType type = getTextInputType(); - m_delegate->inputMethodStateChanged(type != ui::TEXT_INPUT_TYPE_NONE, type == ui::TEXT_INPUT_TYPE_PASSWORD); - m_delegate->setInputMethodHints(toQtInputMethodHints(type)); - const content::TextInputState *state = text_input_manager_->GetTextInputState(); - if (!state) + if (!state) { + m_delegate->inputMethodStateChanged(false /*editorVisible*/, false /*passwordInput*/); + m_delegate->setInputMethodHints(Qt::ImhNone); return; + } - // At this point it is unknown whether the text input state has been updated due to a text selection. - // Keep the cursor position updated for cursor movements too. - if (GetSelectedText().empty()) - m_cursorPosition = state->selection_start; + ui::TextInputType type = getTextInputType(); + m_delegate->setInputMethodHints(toQtInputMethodHints(getTextInputType())); m_surroundingText = QString::fromStdString(state->value); - // Remove IME composition text from the surrounding text if (state->composition_start != -1 && state->composition_end != -1) m_surroundingText.remove(state->composition_start, state->composition_end - state->composition_start); + // In case of text selection, the update is expected in RenderWidgetHostViewQt::selectionChanged(). + if (GetSelectedText().empty()) { + // At this point it is unknown whether the text input state has been updated due to a text selection. + // Keep the cursor position updated for cursor movements too. + m_cursorPosition = state->selection_start; + m_delegate->inputMethodStateChanged(type != ui::TEXT_INPUT_TYPE_NONE, type == ui::TEXT_INPUT_TYPE_PASSWORD); + } + if (m_imState & ImStateFlags::TextInputStateUpdated) { m_imState = ImStateFlags::TextInputStateUpdated; return; @@ -821,9 +825,10 @@ void RenderWidgetHostViewQt::selectionChanged() { // Reset input manager state m_imState = 0; + ui::TextInputType type = getTextInputType(); // Handle text selection out of an input field - if (getTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { + if (type == ui::TEXT_INPUT_TYPE_NONE) { if (GetSelectedText().empty() && m_emptyPreviousSelection) return; @@ -843,12 +848,13 @@ void RenderWidgetHostViewQt::selectionChanged() // if the selection is cleared because TextInputState changes before the TextSelection change. Q_ASSERT(text_input_manager_->GetTextInputState()); m_cursorPosition = text_input_manager_->GetTextInputState()->selection_start; + m_delegate->inputMethodStateChanged(true /*editorVisible*/, type == ui::TEXT_INPUT_TYPE_PASSWORD); m_anchorPositionWithinSelection = m_cursorPosition; m_cursorPositionWithinSelection = m_cursorPosition; if (!m_emptyPreviousSelection) { - m_emptyPreviousSelection = GetSelectedText().empty(); + m_emptyPreviousSelection = true; m_adapterClient->selectionChanged(); } @@ -883,6 +889,7 @@ void RenderWidgetHostViewQt::selectionChanged() m_cursorPosition = newCursorPositionWithinSelection; m_emptyPreviousSelection = selection->selected_text().empty(); + m_delegate->inputMethodStateChanged(true /*editorVisible*/, type == ui::TEXT_INPUT_TYPE_PASSWORD); m_adapterClient->selectionChanged(); } diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp index 1176573fd..2f65db97a 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp @@ -54,7 +54,6 @@ namespace QtWebEngineCore { RenderWidgetHostViewQtDelegateQuick::RenderWidgetHostViewQtDelegateQuick(RenderWidgetHostViewQtDelegateClient *client, bool isPopup) : m_client(client) , m_isPopup(isPopup) - , m_isPasswordInput(false) { setFlag(ItemHasContents); setAcceptedMouseButtons(Qt::AllButtons); @@ -206,11 +205,9 @@ void RenderWidgetHostViewQtDelegateQuick::inputMethodStateChanged(bool editorVis if (parentItem()) parentItem()->setFlag(QQuickItem::ItemAcceptsInputMethod, editorVisible && !passwordInput); - if (qApp->inputMethod()->isVisible() != editorVisible || m_isPasswordInput != passwordInput) { - qApp->inputMethod()->update(Qt::ImQueryInput | Qt::ImEnabled | Qt::ImHints); + qApp->inputMethod()->update(Qt::ImQueryInput | Qt::ImEnabled | Qt::ImHints); + if (qApp->inputMethod()->isVisible() != editorVisible) qApp->inputMethod()->setVisible(editorVisible); - m_isPasswordInput = passwordInput; - } } bool RenderWidgetHostViewQtDelegateQuick::event(QEvent *event) diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.h b/src/webengine/render_widget_host_view_qt_delegate_quick.h index 6f6cd1509..d4d64804a 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.h +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.h @@ -113,7 +113,6 @@ private: RenderWidgetHostViewQtDelegateClient *m_client; QList<QMetaObject::Connection> m_windowConnections; bool m_isPopup; - bool m_isPasswordInput; QPointF m_lastGlobalPos; QQuickWebEngineView *m_view = nullptr; }; diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp index e34bca875..900ed3324 100644 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp +++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp @@ -107,7 +107,6 @@ RenderWidgetHostViewQtDelegateWidget::RenderWidgetHostViewQtDelegateWidget(Rende , m_client(client) , m_rootItem(new RenderWidgetHostViewQuickItem(client)) , m_isPopup(false) - , m_isPasswordInput(false) { setFocusPolicy(Qt::StrongFocus); @@ -341,14 +340,10 @@ void RenderWidgetHostViewQtDelegateWidget::move(const QPoint &screenPos) void RenderWidgetHostViewQtDelegateWidget::inputMethodStateChanged(bool editorVisible, bool passwordInput) { - if (qApp->inputMethod()->isVisible() == editorVisible && m_isPasswordInput == passwordInput) - return; - QQuickWidget::setAttribute(Qt::WA_InputMethodEnabled, editorVisible && !passwordInput); - m_isPasswordInput = passwordInput; - qApp->inputMethod()->update(Qt::ImQueryInput | Qt::ImEnabled | Qt::ImHints); - qApp->inputMethod()->setVisible(editorVisible); + if (qApp->inputMethod()->isVisible() != editorVisible) + qApp->inputMethod()->setVisible(editorVisible); } void RenderWidgetHostViewQtDelegateWidget::setInputMethodHints(Qt::InputMethodHints hints) diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h index e23f13d86..c1cd90093 100644 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h +++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h @@ -110,7 +110,6 @@ private: RenderWidgetHostViewQtDelegateClient *m_client; QScopedPointer<QQuickItem> m_rootItem; bool m_isPopup; - bool m_isPasswordInput; QColor m_clearColor; QPoint m_lastGlobalPos; QList<QMetaObject::Connection> m_windowConnections; |