From 5317ff74fd2ff31e4bfb8e7e6c4a6e06a16fffc8 Mon Sep 17 00:00:00 2001 From: Harald Sitter Date: Tue, 24 Jan 2023 13:02:28 +0100 Subject: [PATCH] a11y: even checkable buttons are pressable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit otherwise there is no way to synthesize a "click" through the a11y API. toggleAction only leads to a toggled() signal but the user may be more discerning and only listen to clicked() (or QAction::triggered) to react to **user** events not all toggle events. as such pressAction is always superior to toggleAction when user input is meant to be synthesized through a11y tooling. Change-Id: I7f024d57087b545d3cfd1805026ea538b0b3e166 Reviewed-by: Qt CI Bot Reviewed-by: Mårten Nordheim Reviewed-by: Jan Arve Sæther --- src/widgets/accessible/simplewidgets.cpp | 6 ++---- .../other/qaccessibility/tst_qaccessibility.cpp | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/widgets/accessible/simplewidgets.cpp b/src/widgets/accessible/simplewidgets.cpp index da4566bfff..fbbbab857d 100644 --- a/src/widgets/accessible/simplewidgets.cpp +++ b/src/widgets/accessible/simplewidgets.cpp @@ -216,11 +216,9 @@ QStringList QAccessibleButton::actionNames() const names << toggleAction(); break; default: - if (button()->isCheckable()) { + if (button()->isCheckable()) names << toggleAction(); - } else { - names << pressAction(); - } + names << pressAction(); break; } } diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 76d50b93e3..8c51022416 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -1118,7 +1118,10 @@ void tst_QAccessibility::buttonTest() interface = QAccessible::queryAccessibleInterface(&toggleButton); actionInterface = interface->actionInterface(); QCOMPARE(interface->role(), QAccessible::CheckBox); - QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::toggleAction() << QAccessibleActionInterface::setFocusAction()); + QCOMPARE(actionInterface->actionNames(), + QStringList() << QAccessibleActionInterface::toggleAction() + << QAccessibleActionInterface::pressAction() + << QAccessibleActionInterface::setFocusAction()); QCOMPARE(actionInterface->localizedActionDescription(QAccessibleActionInterface::toggleAction()), QString("Toggles the state")); QVERIFY(!toggleButton.isChecked()); QVERIFY(!interface->state().checked); @@ -1154,12 +1157,18 @@ void tst_QAccessibility::buttonTest() interface = QAccessible::queryAccessibleInterface(&checkBox); actionInterface = interface->actionInterface(); QCOMPARE(interface->role(), QAccessible::CheckBox); - QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::toggleAction() << QAccessibleActionInterface::setFocusAction()); + QCOMPARE(actionInterface->actionNames(), + QStringList() << QAccessibleActionInterface::toggleAction() + << QAccessibleActionInterface::pressAction() + << QAccessibleActionInterface::setFocusAction()); QVERIFY(!interface->state().checked); actionInterface->doAction(QAccessibleActionInterface::toggleAction()); QTest::qWait(500); - QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::toggleAction() << QAccessibleActionInterface::setFocusAction()); + QCOMPARE(actionInterface->actionNames(), + QStringList() << QAccessibleActionInterface::toggleAction() + << QAccessibleActionInterface::pressAction() + << QAccessibleActionInterface::setFocusAction()); QVERIFY(interface->state().checked); QVERIFY(checkBox.isChecked()); QAccessible::State st;