macOS a11y: clean up ignore-logic

Replace an if-chain with a switch statement, and remove the duplicate
test for QAccessible::Client - we already ignore all such elements,
no matter their special role name.

Compare an object's className as a QByteArrayView, no need to expand to
a UTF16 QString just to compare with a Latin1 literal.

Pick-to: 6.8
Change-Id: I79f52277e4177f2a688216b7f5ef7469cfe0534c
Reviewed-by: Albert Astals Cid <aacid@kde.org>
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
(cherry picked from commit e88940941f8ffe8236d281d5e0e46205f5c405ee)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2025-03-31 17:03:45 +02:00 committed by Qt Cherry-pick Bot
parent 65768082fe
commit 56218773ce

View File

@ -213,41 +213,36 @@ bool shouldBeIgnored(QAccessibleInterface *interface)
// Cocoa accessibility does not have an attribute that corresponds to the Invisible/Offscreen
// state. Ignore interfaces with those flags set.
const QAccessible::State state = interface->state();
if (state.invisible ||
state.offscreen ||
state.invalid)
if (state.invisible || state.offscreen || state.invalid)
return true;
// Some roles are not interesting. In particular, container roles should be
// ignored in order to flatten the accessibility tree as seen by the user.
const QAccessible::Role role = interface->role();
if (role == QAccessible::Border || // QFrame
role == QAccessible::Application || // We use the system-provided application element.
role == QAccessible::ToolBar || // Access the tool buttons directly.
role == QAccessible::Pane || // Scroll areas.
role == QAccessible::Client || // The default for QWidget.
role == QAccessible::PopupMenu) // Access the menu items directly
switch (interface->role()) {
case QAccessible::Border: // QFrame
case QAccessible::Application: // We use the system-provided application element.
case QAccessible::ToolBar: // Access the tool buttons directly.
case QAccessible::Pane: // Scroll areas.
case QAccessible::Client: // The default for QWidget.
case QAccessible::PopupMenu: // Access the menu items directly
return true;
default:
break;
}
NSString *mac_role = macRole(interface);
if (mac_role == NSAccessibilityWindowRole || // We use the system-provided window elements.
mac_role == NSAccessibilityUnknownRole)
mac_role == NSAccessibilityUnknownRole) {
return true;
}
// Client is a generic role returned by plain QWidgets or other
// widgets that does not have separate QAccessible interface, such
// as the TabWidget. Return false unless macRole gives the interface
// a special role.
if (role == QAccessible::Client && mac_role == NSAccessibilityUnknownRole)
return true;
if (QObject * const object = interface->object()) {
const QString className = QLatin1StringView(object->metaObject()->className());
if (const QObject *object = interface->object()) {
const QByteArrayView className = object->metaObject()->className();
// VoiceOver focusing on tool tips can be confusing. The contents of the
// tool tip is available through the description attribute anyway, so
// we disable accessibility for tool tips.
if (className == "QTipLabel"_L1)
if (className == "QTipLabel"_ba)
return true;
}