summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/web_event_factory.cpp7
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp40
2 files changed, 35 insertions, 12 deletions
diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp
index ba04806d5..f4940f305 100644
--- a/src/core/web_event_factory.cpp
+++ b/src/core/web_event_factory.cpp
@@ -157,8 +157,11 @@ static Qt::KeyboardModifiers qtModifiersForEvent(const QInputEvent *ev)
//
// On Linux, the Control modifier transformation is applied [1]. For example,
// pressing Ctrl+@ generates the text "\u0000". We would like "@" instead.
+// Windows also translates some control key combinations into ASCII control
+// characters [2].
//
// [1]: https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Control_Modifier
+// [2]: https://docs.microsoft.com/en-us/windows/win32/learnwin32/keyboard-input#character-messages
//
// On macOS, if the Control modifier is used, then no text is generated at all.
// We need some text.
@@ -171,8 +174,10 @@ static QString qtTextForKeyEvent(const QKeyEvent *ev, int qtKey, Qt::KeyboardMod
{
QString text = ev->text();
- if ((qtModifiers & Qt::ControlModifier) && keyboardDriver() == KeyboardDriver::Xkb)
+ if ((qtModifiers & Qt::ControlModifier) &&
+ (keyboardDriver() == KeyboardDriver::Xkb || keyboardDriver() == KeyboardDriver::Windows)) {
text.clear();
+ }
return text;
}
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index b5f038bba..2862be1dd 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -199,6 +199,7 @@ private Q_SLOTS:
void visibilityState();
void visibilityState2();
void visibilityState3();
+ void jsKeyboardEvent_data();
void jsKeyboardEvent();
void deletePage();
void closeOpenerTab();
@@ -3364,6 +3365,28 @@ void tst_QWebEngineView::visibilityState3()
QCOMPARE(evaluateJavaScriptSync(&page2, "document.visibilityState").toString(), QStringLiteral("visible"));
}
+void tst_QWebEngineView::jsKeyboardEvent_data()
+{
+ QTest::addColumn<char>("key");
+ QTest::addColumn<Qt::KeyboardModifiers>("modifiers");
+ QTest::addColumn<QString>("expected");
+
+#if defined(Q_OS_MACOS)
+ // See Qt::AA_MacDontSwapCtrlAndMeta
+ Qt::KeyboardModifiers controlModifier = Qt::MetaModifier;
+#else
+ Qt::KeyboardModifiers controlModifier = Qt::ControlModifier;
+#endif
+
+ QTest::newRow("Ctrl+Shift+A") << 'A' << (controlModifier | Qt::ShiftModifier) << QStringLiteral(
+ "16,ShiftLeft,Shift,false,true,false;"
+ "17,ControlLeft,Control,true,true,false;"
+ "65,KeyA,A,true,true,false;");
+ QTest::newRow("Ctrl+z") << 'z' << controlModifier << QStringLiteral(
+ "17,ControlLeft,Control,true,false,false;"
+ "90,KeyZ,z,true,false,false;");
+}
+
void tst_QWebEngineView::jsKeyboardEvent()
{
QWebEngineView view;
@@ -3373,18 +3396,13 @@ void tst_QWebEngineView::jsKeyboardEvent()
"addEventListener('keydown', (ev) => {"
" log += [ev.keyCode, ev.code, ev.key, ev.ctrlKey, ev.shiftKey, ev.altKey].join(',') + ';';"
"});");
+
+ QFETCH(char, key);
+ QFETCH(Qt::KeyboardModifiers, modifiers);
+ QFETCH(QString, expected);
+
// Note that this only tests the fallback code path where native scan codes are not used.
-#if defined(Q_OS_MACOS)
- // See Qt::AA_MacDontSwapCtrlAndMeta
- QTest::keyClick(view.focusProxy(), 'A', Qt::MetaModifier | Qt::ShiftModifier);
-#else
- QTest::keyClick(view.focusProxy(), 'A', Qt::ControlModifier | Qt::ShiftModifier);
-#endif
- QString expected = QStringLiteral(
- "16,ShiftLeft,Shift,false,true,false;"
- "17,ControlLeft,Control,true,true,false;"
- "65,KeyA,A,true,true,false;"
- );
+ QTest::keyClick(view.focusProxy(), key, modifiers);
QTRY_VERIFY(evaluateJavaScriptSync(view.page(), "log") != QVariant(QString()));
QCOMPARE(evaluateJavaScriptSync(view.page(), "log"), expected);
}