From 35ee29eb348b4629f47a6b700f9e2c356265aeba Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Wed, 21 Nov 2018 14:09:38 +0100 Subject: 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 --- src/core/render_widget_host_view_qt.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src/core/render_widget_host_view_qt.cpp') 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(); } -- cgit v1.2.3 From 43840350a1597d58116c36137c046ef595c57ed4 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Fri, 23 Nov 2018 09:22:38 +0100 Subject: Disable text prediction for input This is a workaround to avoid issues with QtVirtualKeyboard when used with QtWebEngine. Task-number: QTBUG-70158 Task-number: QTBUG-71995 Change-Id: I1e6fcd4dceb131dbe781dd7ab3856cb154ac6a18 Reviewed-by: Allan Sandfeld Jensen --- src/core/render_widget_host_view_qt.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/render_widget_host_view_qt.cpp') diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 2326dbdf7..99bda12d1 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -754,7 +754,7 @@ void RenderWidgetHostViewQt::OnUpdateTextInputStateCalled(content::TextInputMana } ui::TextInputType type = getTextInputType(); - m_delegate->setInputMethodHints(toQtInputMethodHints(getTextInputType())); + m_delegate->setInputMethodHints(toQtInputMethodHints(getTextInputType()) | Qt::ImhNoPredictiveText); m_surroundingText = QString::fromStdString(state->value); // Remove IME composition text from the surrounding text @@ -1112,7 +1112,7 @@ QVariant RenderWidgetHostViewQt::inputMethodQuery(Qt::InputMethodQuery query) // TODO: Implement this return QVariant(); // No limit. case Qt::ImHints: - return int(toQtInputMethodHints(getTextInputType())); + return int(toQtInputMethodHints(getTextInputType()) | Qt::ImhNoPredictiveText); default: return QVariant(); } -- cgit v1.2.3 From ec2337fd181e6dea02bf50c57400eaa6c5ec2871 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Wed, 28 Nov 2018 15:23:56 +0100 Subject: Disable external text handles and edit menu Chromium implements its own ones and we don't want to conflict with them. This disables the QtVirtualKeyboard's selection handle what is not functional with QtWebEngine. Task-number: QTBUG-59999 Change-Id: I6a615a04d5eac1ce2d0392d63ba0fc9039583914 Reviewed-by: Allan Sandfeld Jensen --- src/core/render_widget_host_view_qt.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/render_widget_host_view_qt.cpp') diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 99bda12d1..40ed75973 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -754,7 +754,7 @@ void RenderWidgetHostViewQt::OnUpdateTextInputStateCalled(content::TextInputMana } ui::TextInputType type = getTextInputType(); - m_delegate->setInputMethodHints(toQtInputMethodHints(getTextInputType()) | Qt::ImhNoPredictiveText); + m_delegate->setInputMethodHints(toQtInputMethodHints(getTextInputType()) | Qt::ImhNoPredictiveText | Qt::ImhNoTextHandles | Qt::ImhNoEditMenu); m_surroundingText = QString::fromStdString(state->value); // Remove IME composition text from the surrounding text @@ -1112,7 +1112,7 @@ QVariant RenderWidgetHostViewQt::inputMethodQuery(Qt::InputMethodQuery query) // TODO: Implement this return QVariant(); // No limit. case Qt::ImHints: - return int(toQtInputMethodHints(getTextInputType()) | Qt::ImhNoPredictiveText); + return int(toQtInputMethodHints(getTextInputType()) | Qt::ImhNoPredictiveText | Qt::ImhNoTextHandles | Qt::ImhNoEditMenu); default: return QVariant(); } -- cgit v1.2.3