macOS: Activate Qt's platform a11y whenever the system queries us

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 <jan-arve.saether@qt.io>
(cherry picked from commit cf13e4c84c44b6f66f651035b3c3d012718b82dc)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2023-10-03 11:47:48 +02:00 committed by Qt Cherry-pick Bot
parent 6818d6915d
commit e58b1efcae

View File

@ -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];
}