a11y macOS: Support titleUIElement property

In the macOS accessibility bridge, bridge the QAccessible::Label
relation to the corresponding titleUIElement NSAccessibility property [1]:

> An element that represents another element’s static text title (id)

In case there are multiple targets for the QAccessible::Label relation,
just report the first one.

With this in place, Accessibility Inspector on macOS now e.g. shows
"Locale (text) [QMacAccessibilityElement]" as the "Title UIElement"
of the corresponding combobox it labels in the calendarwidgets example
as expected and VoiceOver now says e.g. "English/Germany Locale General
Options, menu button" instead of just the current combobox value and
role "English/Germany, menu button", so the context and semantics of
the combobox becomes clearer to the user.

[1] https://developer.apple.com/documentation/appkit/nsaccessibility-swift.struct/attribute/titleuielement

Change-Id: I814658628c481fe71f17853f71dc5690971507b1
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
This commit is contained in:
Michael Weghorn 2024-11-27 16:18:30 +01:00 committed by Tor Arne Vestbø
parent 738c180c4f
commit 1df6a48a89

View File

@ -539,6 +539,26 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of
return nil; return nil;
} }
- (id) accessibilityTitleUIElement {
QAccessibleInterface *iface = self.qtInterface;
if (!iface)
return nil;
const auto labelRelations = iface->relations(QAccessible::Label);
if (labelRelations.empty())
return nil;
QAccessibleInterface *label = labelRelations.first().first;
if (!label)
return nil;
QMacAccessibilityElement *accessibleElement = [QMacAccessibilityElement elementWithInterface:label];
if (!accessibleElement)
return nil;
return NSAccessibilityUnignoredAncestor(accessibleElement);
}
- (NSString*) accessibilityIdentifier { - (NSString*) accessibilityIdentifier {
if (QAccessibleInterface *iface = self.qtInterface) if (QAccessibleInterface *iface = self.qtInterface)
return QAccessibleBridgeUtils::accessibleId(iface).toNSString(); return QAccessibleBridgeUtils::accessibleId(iface).toNSString();