summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2017-04-10 13:37:45 +0200
committerPeter Varga <pvarga@inf.u-szeged.hu>2017-04-12 15:02:36 +0000
commit92993bc16ed81e0407e11a12781f3f1e0c4fd96a (patch)
tree540a8fec7b567016b3f9f09fba1b48e36ddb5009
parent78417958b7172ec4968088fc3a908a219ed848f6 (diff)
Handle QInputMethodQueryEvent forwarded by RWHVQDW
Task-number: QTBUG-58362 Change-Id: I6c80c8063ccad97aa80aff8ee44aa10a899c5ff5 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/core/render_widget_host_view_qt.cpp16
-rw-r--r--src/core/render_widget_host_view_qt.h1
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp80
3 files changed, 97 insertions, 0 deletions
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<QInputMethodEvent*>(event));
break;
+ case QEvent::InputMethodQuery:
+ handleInputMethodQueryEvent(static_cast<QInputMethodQueryEvent*>(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<<i));
+ if (query) {
+ QVariant v = inputMethodQuery(query);
+ ev->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<QString>("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("<html><body>"
+ " <input type='text' id='input1' />"
+ "</body></html>");
+ 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<QInputMethodEvent::Attribute> 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<QInputMethodEvent::Attribute> 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"