From 98e4e992fee5152912852fb686fa3a9e546853f2 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Tue, 3 Jan 2023 12:08:13 +0100 Subject: a11y macOS: Report selection/Bridge QAccessibleSelectionInterface On macOS, support NSAccessibilityProtocol's accessibilitySelectedChildren method [1] by retrieving the selected children via the QAccessibleSelectionInterface introduced in commit 9d16d5e2245c26e5746fd7609300b84a2a983457. This e.g. makes a "selected children" attribute show up in "UI Browser" [2] for the item views in the "interview" example (examples/widgets/itemviews/interview/interview.app/Contents/MacOS/interview) and that one has an array containing the selected items as value. Sample scenario: 1) run the interview example (examples/widgets/itemviews/interview/interview.app) 2) select "Item 1:0", "Item 2:0" and "Item 3:0" by left-clicking on "Item 1:0" in the left view, then shift+clicking on "Item 3:0". 3) start UI Browser and navigate to the "group (group 1)" element and check that the value of its "selected children" attribute is an array containing the three selected items [1] https://developer.apple.com/documentation/appkit/nsaccessibilityprotocol/1524672-accessibilityselectedchildren [2] https://latenightsw.com/freeware/ui-browser/ Change-Id: Ic62f7fa82f2d01341a1dbc5ade2bd02c3ff99d9f Reviewed-by: Volker Hilsheimer --- .../platforms/cocoa/qcocoaaccessibilityelement.mm | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm index 27fd32f91f..7a1bab7351 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm @@ -434,6 +434,30 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of return QCocoaAccessible::unignoredChildren(iface); } +- (NSArray *) accessibilitySelectedChildren { + QAccessibleInterface *iface = QAccessible::accessibleInterface(axid); + if (!iface || !iface->isValid()) + return nil; + + QAccessibleSelectionInterface *selection = iface->selectionInterface(); + if (!selection) + return nil; + + const QList selectedList = selection->selectedItems(); + const qsizetype numSelected = selectedList.size(); + NSMutableArray *selectedChildren = + [NSMutableArray arrayWithCapacity:numSelected]; + for (QAccessibleInterface *selectedChild : selectedList) { + if (selectedChild && selectedChild->isValid()) { + QAccessible::Id id = QAccessible::uniqueId(selectedChild); + QMacAccessibilityElement *element = [QMacAccessibilityElement elementWithId:id]; + if (element) + [selectedChildren addObject:element]; + } + } + return NSAccessibilityUnignoredChildren(selectedChildren); +} + - (id) accessibilityWindow { // We're in the same window as our parent. return [self.accessibilityParent accessibilityWindow]; -- cgit v1.2.3