From e58b1efcae5c38fdb2fb0aebe61d51d97ba003ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 3 Oct 2023 11:47:48 +0200 Subject: [PATCH] macOS: Activate Qt's platform a11y whenever the system queries us MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise the cached information we store about e.g. table rows and columns will not be updated, as QAccessible::isActive() is false during QAbstractItemViewPrivate::rowsInserted(), and as a result we'll be operating on stale information when the system comes back later to query us about one of the cells. This was observed when running a Qt Widgets table app with the system's Keyboard Viewer open. Change-Id: I88efd46dbc3d35c8b1888d3e29ef3d001bb9eac7 Reviewed-by: Jan Arve Sæther (cherry picked from commit cf13e4c84c44b6f66f651035b3c3d012718b82dc) Reviewed-by: Qt Cherry-pick Bot --- .../platforms/cocoa/qnsview_accessibility.mm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/cocoa/qnsview_accessibility.mm b/src/plugins/platforms/cocoa/qnsview_accessibility.mm index 3f3898fd182..e781f21a6c9 100644 --- a/src/plugins/platforms/cocoa/qnsview_accessibility.mm +++ b/src/plugins/platforms/cocoa/qnsview_accessibility.mm @@ -13,6 +13,15 @@ @implementation QNSView (Accessibility) +- (void)activateQtAccessibility +{ + // Activate the Qt accessibility machinery for all entry points + // below that may be triggered by system accessibility queries, + // as otherwise Qt is not aware that the system needs to know + // about all accessibility state changes in Qt. + QCocoaIntegration::instance()->accessibility()->setActive(true); +} + - (id)childAccessibleElement { QCocoaWindow *platformWindow = self.platformWindow; @@ -32,8 +41,7 @@ - (id)accessibilityAttributeValue:(NSString *)attribute { - // activate accessibility updates - QCocoaIntegration::instance()->accessibility()->setActive(true); + [self activateQtAccessibility]; if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) return NSAccessibilityUnignoredChildrenForOnlyChild([self childAccessibleElement]); @@ -43,11 +51,13 @@ - (id)accessibilityHitTest:(NSPoint)point { + [self activateQtAccessibility]; return [[self childAccessibleElement] accessibilityHitTest:point]; } - (id)accessibilityFocusedUIElement { + [self activateQtAccessibility]; return [[self childAccessibleElement] accessibilityFocusedUIElement]; }