summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2023-01-03 12:08:13 +0100
committerMichael Weghorn <m.weghorn@posteo.de>2023-07-08 00:08:44 +0200
commit98e4e992fee5152912852fb686fa3a9e546853f2 (patch)
tree736956e1c2489832ea9b53e75279d58df04cc922
parent86ea40b47896878939d266e91e1728474c8d6228 (diff)
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 <volker.hilsheimer@qt.io>
-rw-r--r--src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm24
1 files changed, 24 insertions, 0 deletions
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<QAccessibleInterface *> selectedList = selection->selectedItems();
+ const qsizetype numSelected = selectedList.size();
+ NSMutableArray<QMacAccessibilityElement *> *selectedChildren =
+ [NSMutableArray<QMacAccessibilityElement *> 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];