From 79a11470f3c4c61951906223f97001a77ce36500 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 15 Jun 2022 12:32:23 +0200 Subject: Accessibility: don't emit focus change when reason is window activation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a window becomes active, then the accessibility system gets informed about that already. Qt puts focus on the focus child of the activated window afterwards, and if this emits another accessibility event, then accessibility clients like Windows Narrator will stop reading the activated window, and instead read about the focused widget. This makes dialogs like message boxes poorly accessible. Accessibility clients already know that a window became active, and can query Qt about the focused child within that window. Amend test case. Fixes: QTBUG-101585 Pick-to: 6.4 6.3 6.2 Change-Id: I2d6bff7c415a6f29c4a4f7f4e4be38079fb976ca Reviewed-by: Jan Arve Sæther --- tests/auto/other/qaccessibility/tst_qaccessibility.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/auto/other/qaccessibility/tst_qaccessibility.cpp') diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index de0942ba08..fa9f2a5866 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -4288,10 +4288,20 @@ void tst_QAccessibility::messageBoxTest() if (!boxPrivate->canBeNativeDialog()) { // platforms that use a native message box will not emit accessibility events box.show(); + QVERIFY(QTest::qWaitForWindowActive(&box)); QAccessibleEvent showEvent(&box, QAccessible::DialogStart); QVERIFY(QTestAccessibility::containsEvent(&showEvent)); + // on some platforms, like macOS, not all widgets get key board focus; we + // only care about a push button getting focus + if (QTest::qWaitFor([&box]{ return qobject_cast(box.focusWidget()); }, 1000)) { + // a widget that gets focus through window activation should not emit an accessibility + // notification + QAccessibleEvent focusEvent(box.focusWidget(), QAccessible::Focus); + QVERIFY(!QTestAccessibility::containsEvent(&focusEvent)); + } + box.hide(); QAccessibleEvent hideEvent(&box, QAccessible::DialogEnd); -- cgit v1.2.3