From 5faba47f95d0dd336f041b409de3130f637d7ffd Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 31 Oct 2022 12:44:48 +0100 Subject: [PATCH] Revert "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 This reverts commit 79a11470f3c4c61951906223f97001a77ce36500, which resulted in QTBUG-105735. The new behavior is worse and affects multiple screen readers, while the old issue is isolated to Windows Narrator and could be considered a narrator bug. Task-number: QTBUG-105735 Change-Id: Ic8be1dbd592a3fdf2c3219ec4c5524bc2c7f0f6a Reviewed-by: Jan Arve Sæther (cherry picked from commit d300a0fe765259d490c3510c9e2a8bac58e0aa15) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/kernel/qwidget.cpp | 14 +++++--------- .../other/qaccessibility/tst_qaccessibility.cpp | 10 ---------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 361e12887a6..a5ba895105e 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -6516,15 +6516,11 @@ void QWidget::setFocus(Qt::FocusReason reason) QApplicationPrivate::setFocusWidget(f, reason); #if QT_CONFIG(accessibility) - // If the widget gets focus because its window becomes active, then the accessibility - // subsystem is already informed about the window opening, and also knows which child - // within the window has focus. Don't interrupt it by emitting another focus event. - if (reason != Qt::ActiveWindowFocusReason) { - // menus update the focus manually and this would create bogus events - if (!(f->inherits("QMenuBar") || f->inherits("QMenu") || f->inherits("QMenuItem"))) { - QAccessibleEvent event(f, QAccessible::Focus); - QAccessible::updateAccessibility(&event); - } + // menus update the focus manually and this would create bogus events + if (!(f->inherits("QMenuBar") || f->inherits("QMenu") || f->inherits("QMenuItem"))) + { + QAccessibleEvent event(f, QAccessible::Focus); + QAccessible::updateAccessibility(&event); } #endif #if QT_CONFIG(graphicsview) diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 453f6b6fed2..a84c6dc0a0d 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -4336,20 +4336,10 @@ 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);