Skip to content

Commit

Permalink
iOS: Iterate accessible interface to find window
Browse files Browse the repository at this point in the history
Many subclasses of QAccessibleInterface implement window(), but
some don't, and the documentation states that the backend (us)
will traverse ancestors until it finds one with a window.

We were not doing that for iOS, which caused a crash for
QAccessibleTabButton, which doesn't have a window.

In case we ever hit the code path where we can't find a
window we also skip adding the nil element to the array
in createAccessibleElement, as that causes an exception.

Amends 7a512d1

Pick-to: 6.8 6.5
Change-Id: I9b758423956e845a01b014022f4d3ab6306be94e
Reviewed-by: Doris Verria <[email protected]>
(cherry picked from commit 6689921)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
  • Loading branch information
torarnv authored and Qt Cherry-pick Bot committed Dec 11, 2024
1 parent 8a7ee8d commit b3c60bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/plugins/platforms/ios/quiaccessibilityelement.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,22 @@ + (instancetype)elementWithId:(QAccessible::Id)anId

QMacAccessibilityElement *element = cache->elementForId(anId);
if (!element) {
auto *a11yInterface = QAccessible::accessibleInterface(anId);
Q_ASSERT(a11yInterface);
auto *window = a11yInterface->window();
QWindow *window = nullptr;
auto *iface = QAccessible::accessibleInterface(anId);
while (iface) {
if ((window = iface->window()))
break;
iface = iface->parent();
}

if (window && window->handle()) {
auto *platformWindow = static_cast<QIOSWindow*>(window->handle());
element = [[self alloc] initWithId:anId withAccessibilityContainer:platformWindow->view()];
cache->insertElement(anId, element);
} else {
qWarning() << "Could not create a11y element for" << window
<< "with platform window" << (window ? window->handle() : nullptr);
qWarning() << "Could not create a11y element for" << iface
<< "with window" << window
<< "and platform window" << (window ? window->handle() : nullptr);
}
}
return element;
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/platforms/ios/quiview_accessibility.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ - (void)createAccessibleElement:(QAccessibleInterface *)iface
if (!iface || iface->state().invisible || (iface->text(QAccessible::Name).isEmpty() && iface->text(QAccessible::Value).isEmpty() && iface->text(QAccessible::Description).isEmpty()))
return;
QAccessible::Id accessibleId = QAccessible::uniqueId(iface);
UIAccessibilityElement *elem = [QT_MANGLE_NAMESPACE(QMacAccessibilityElement) elementWithId:accessibleId];
[m_accessibleElements addObject:elem];
if (UIAccessibilityElement *elem = [QT_MANGLE_NAMESPACE(QMacAccessibilityElement) elementWithId:accessibleId])
[m_accessibleElements addObject:elem];
}

- (void)createAccessibleContainer:(QAccessibleInterface *)iface
Expand Down

0 comments on commit b3c60bd

Please sign in to comment.