summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/render_widget_host_view_qt.cpp11
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp42
2 files changed, 45 insertions, 8 deletions
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
index af7471759..267460bdc 100644
--- a/src/core/render_widget_host_view_qt.cpp
+++ b/src/core/render_widget_host_view_qt.cpp
@@ -1316,14 +1316,9 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev)
if (replacementLength > 0)
{
- int start = ev->replacementStart();
-
- if (start >= 0)
- replacementRange = gfx::Range(start, start + replacementLength);
- else if (m_surroundingText.length() + start >= 0) {
- start = m_surroundingText.length() + start;
- replacementRange = gfx::Range(start, start + replacementLength);
- }
+ int replacementStart = ev->replacementStart() < 0 ? m_cursorPosition + ev->replacementStart() : ev->replacementStart();
+ if (replacementStart >= 0 && replacementStart < m_surroundingText.length())
+ replacementRange = gfx::Range(replacementStart, replacementStart + replacementLength);
}
// There are so-far two known cases, when an empty QInputMethodEvent is received.
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index a0f8f11d2..a6487d19a 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -2292,6 +2292,48 @@ void tst_QWebEngineView::imeComposition()
QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImAnchorPosition).toInt(), 15);
QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImCurrentSelection).toString(), QString(""));
QCOMPARE(selectionChangedSpy.count(), 2);
+ selectionChangedSpy.clear();
+
+
+ // 5. Mimic behavior of QtVirtualKeyboard with enabled text prediction.
+ evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value='QtWebEngine';");
+ QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QString("QtWebEngine"));
+
+ // Move cursor into position.
+ QTest::keyClick(view.focusProxy(), Qt::Key_Home);
+ for (int j = 0; j < 2; ++j)
+ QTest::keyClick(view.focusProxy(), Qt::Key_Right);
+ QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImCursorPosition).toInt(), 2);
+
+ // Turn text into composition by using negative start position.
+ {
+ int replaceFrom = -1 * view.focusProxy()->inputMethodQuery(Qt::ImCursorPosition).toInt();
+ int replaceLength = view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString().size();
+
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("QtWebEngine", attributes);
+ event.setCommitString(QString(), replaceFrom, replaceLength);
+ QApplication::sendEvent(view.focusProxy(), &event);
+ }
+ QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QString(""));
+ QCOMPARE(view.focusProxy()->inputMethodQuery(Qt::ImCursorPosition).toInt(), 11);
+ QCOMPARE(view.focusProxy()->inputMethodQuery(Qt::ImAnchorPosition).toInt(), 11);
+ QCOMPARE(view.focusProxy()->inputMethodQuery(Qt::ImCurrentSelection).toString(), QString(""));
+ QCOMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QString("QtWebEngine"));
+
+ // Commit.
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event(QString(), attributes);
+ event.setCommitString("QtWebEngine", 0, 0);
+ QApplication::sendEvent(view.focusProxy(), &event);
+ }
+ QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QString("QtWebEngine"));
+ QCOMPARE(view.focusProxy()->inputMethodQuery(Qt::ImCursorPosition).toInt(), 11);
+ QCOMPARE(view.focusProxy()->inputMethodQuery(Qt::ImAnchorPosition).toInt(), 11);
+ QCOMPARE(view.focusProxy()->inputMethodQuery(Qt::ImCurrentSelection).toString(), QString(""));
+ QCOMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QString("QtWebEngine"));
+ QCOMPARE(selectionChangedSpy.count(), 0);
}
void tst_QWebEngineView::newlineInTextarea()