From 1df6a48a894f1d3c3cc9623454bf7fd326ca1207 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Wed, 27 Nov 2024 16:18:30 +0100 Subject: [PATCH] a11y macOS: Support titleUIElement property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø Reviewed-by: Jan Arve Sæther --- .../cocoa/qcocoaaccessibilityelement.mm | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm index a07c9fef3e2..7a05205c248 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm @@ -539,6 +539,26 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of 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 { if (QAccessibleInterface *iface = self.qtInterface) return QAccessibleBridgeUtils::accessibleId(iface).toNSString();