Cocoa accessibility: Make menu items accessible

To make menu items accessible in Cocoa we need to:
1- Tell the accessbility framework that the focused element is now the
popup menu
Since we don't give focus to the popup menu in Qt, we have to work-
around this in the cocoa accessibility framework by sending a
NSAccessibilityFocusedUIElementChangedNotification when the
QAccessible::PopupMenuStart event happens.
2- Ignore the PopupMenu role
In a native context menu in macOS, the expected accessible element
is not the menu itself, but the menu items. That is why we should
ignore the PopupMenu role and directly access the menu items.

Fixes: QTBUG-68465
Pick-to: 6.7 6.5
Change-Id: I6b45fa3c762734274b4288cddeb038018327a4fe
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
(cherry picked from commit b17a8a9b26368ea39d6cec36b39286ff1b307cd2)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Doris Verria 2024-06-27 14:21:54 +02:00 committed by Qt Cherry-pick Bot
parent b0bcb24bad
commit b792b40378

View File

@ -57,6 +57,9 @@ void QCocoaAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event)
NSAccessibilityPostNotification(element, NSAccessibilityFocusedUIElementChangedNotification);
break;
}
case QAccessible::PopupMenuStart:
NSAccessibilityPostNotification(element, NSAccessibilityFocusedUIElementChangedNotification);
break;
case QAccessible::StateChanged:
case QAccessible::ValueChanged:
case QAccessible::TextInserted:
@ -221,7 +224,8 @@ bool shouldBeIgnored(QAccessibleInterface *interface)
role == QAccessible::Application || // We use the system-provided application element.
role == QAccessible::ToolBar || // Access the tool buttons directly.
role == QAccessible::Pane || // Scroll areas.
role == QAccessible::Client) // The default for QWidget.
role == QAccessible::Client || // The default for QWidget.
role == QAccessible::PopupMenu) // Access the menu items directly
return true;
NSString *mac_role = macRole(interface);
@ -252,7 +256,6 @@ bool shouldBeIgnored(QAccessibleInterface *interface)
NSArray<QMacAccessibilityElement *> *unignoredChildren(QAccessibleInterface *interface)
{
int numKids = interface->childCount();
// qDebug() << "Children for: " << axid << iface << " are: " << numKids;
NSMutableArray<QMacAccessibilityElement *> *kids = [NSMutableArray<QMacAccessibilityElement *> arrayWithCapacity:numKids];
for (int i = 0; i < numKids; ++i) {
@ -261,7 +264,6 @@ NSArray<QMacAccessibilityElement *> *unignoredChildren(QAccessibleInterface *int
continue;
QAccessible::Id childId = QAccessible::uniqueId(child);
//qDebug() << " kid: " << childId << child;
QMacAccessibilityElement *element = [QMacAccessibilityElement elementWithId: childId];
if (element)