From 92993bc16ed81e0407e11a12781f3f1e0c4fd96a Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Mon, 10 Apr 2017 13:37:45 +0200 Subject: Handle QInputMethodQueryEvent forwarded by RWHVQDW Task-number: QTBUG-58362 Change-Id: I6c80c8063ccad97aa80aff8ee44aa10a899c5ff5 Reviewed-by: Allan Sandfeld Jensen --- src/core/render_widget_host_view_qt.cpp | 16 +++++ src/core/render_widget_host_view_qt.h | 1 + .../widgets/qwebengineview/tst_qwebengineview.cpp | 80 ++++++++++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 619577d93..ab9fb66fb 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -917,6 +917,9 @@ bool RenderWidgetHostViewQt::forwardEvent(QEvent *event) case QEvent::InputMethod: handleInputMethodEvent(static_cast(event)); break; + case QEvent::InputMethodQuery: + handleInputMethodQueryEvent(static_cast(event)); + break; default: return false; } @@ -1258,6 +1261,19 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev) } } +void RenderWidgetHostViewQt::handleInputMethodQueryEvent(QInputMethodQueryEvent *ev) +{ + Qt::InputMethodQueries queries = ev->queries(); + for (uint i = 0; i < 32; ++i) { + Qt::InputMethodQuery query = (Qt::InputMethodQuery)(int)(queries & (1<setValue(query, v); + } + } + ev->accept(); +} + #ifndef QT_NO_ACCESSIBILITY void RenderWidgetHostViewQt::accessibilityActiveChanged(bool active) { diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h index 78b946a60..304fa0e1a 100644 --- a/src/core/render_widget_host_view_qt.h +++ b/src/core/render_widget_host_view_qt.h @@ -192,6 +192,7 @@ public: void handleHoverEvent(QHoverEvent*); void handleFocusEvent(QFocusEvent*); void handleInputMethodEvent(QInputMethodEvent*); + void handleInputMethodQueryEvent(QInputMethodQueryEvent*); #if defined(OS_MACOSX) virtual void SetActive(bool active) Q_DECL_OVERRIDE { QT_NOT_YET_IMPLEMENTED } diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index 82e50409d..75795c170 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -102,6 +102,8 @@ private Q_SLOTS: void hiddenText(); void emptyInputMethodEvent(); void imeComposition(); + void imeCompositionQueryEvent_data(); + void imeCompositionQueryEvent(); void newlineInTextarea(); }; @@ -1935,5 +1937,83 @@ void tst_QWebEngineView::newlineInTextarea() QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QString("\n\nthird line")); } +void tst_QWebEngineView::imeCompositionQueryEvent_data() +{ + QTest::addColumn("receiverObjectName"); + QTest::newRow("focusObject") << QString("focusObject"); + QTest::newRow("focusProxy") << QString("focusProxy"); + QTest::newRow("focusWidget") << QString("focusWidget"); +} + +void tst_QWebEngineView::imeCompositionQueryEvent() +{ + QWebEngineView view; + view.show(); + + QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool))); + view.setHtml("" + " " + ""); + QVERIFY(loadFinishedSpy.wait()); + + evaluateJavaScriptSync(view.page(), "document.getElementById('input1').focus()"); + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.activeElement.id").toString(), QStringLiteral("input1")); + + QObject *input = nullptr; + + QFETCH(QString, receiverObjectName); + if (receiverObjectName == "focusObject") + input = qApp->focusObject(); + else if (receiverObjectName == "focusProxy") + input = view.focusProxy(); + else if (receiverObjectName == "focusWidget") + input = view.focusWidget(); + + QVERIFY(input); + + QInputMethodQueryEvent srrndTextQuery(Qt::ImSurroundingText); + QInputMethodQueryEvent cursorPosQuery(Qt::ImCursorPosition); + QInputMethodQueryEvent anchorPosQuery(Qt::ImAnchorPosition); + + // Set composition + { + QList attributes; + QInputMethodEvent event("composition", attributes); + QApplication::sendEvent(input, &event); + qApp->processEvents(); + } + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QString("composition")); + QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImCursorPosition).toInt(), 11); + + QApplication::sendEvent(input, &srrndTextQuery); + QApplication::sendEvent(input, &cursorPosQuery); + QApplication::sendEvent(input, &anchorPosQuery); + qApp->processEvents(); + + QTRY_COMPARE(srrndTextQuery.value(Qt::ImSurroundingText).toString(), QString("")); + QTRY_COMPARE(cursorPosQuery.value(Qt::ImCursorPosition).toInt(), 11); + QTRY_COMPARE(anchorPosQuery.value(Qt::ImAnchorPosition).toInt(), 11); + + // Send commit + { + QList attributes; + QInputMethodEvent event("", attributes); + event.setCommitString("composition"); + QApplication::sendEvent(input, &event); + qApp->processEvents(); + } + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QString("composition")); + QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QString("composition")); + + QApplication::sendEvent(input, &srrndTextQuery); + QApplication::sendEvent(input, &cursorPosQuery); + QApplication::sendEvent(input, &anchorPosQuery); + qApp->processEvents(); + + QTRY_COMPARE(srrndTextQuery.value(Qt::ImSurroundingText).toString(), QString("composition")); + QTRY_COMPARE(cursorPosQuery.value(Qt::ImCursorPosition).toInt(), 11); + QTRY_COMPARE(anchorPosQuery.value(Qt::ImAnchorPosition).toInt(), 11); +} + QTEST_MAIN(tst_QWebEngineView) #include "tst_qwebengineview.moc" -- cgit v1.2.3