From e88940941f8ffe8236d281d5e0e46205f5c405ee Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 31 Mar 2025 17:03:45 +0200 Subject: [PATCH] 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.9 6.8 Change-Id: I79f52277e4177f2a688216b7f5ef7469cfe0534c Reviewed-by: Albert Astals Cid Reviewed-by: Michael Weghorn --- .../platforms/cocoa/qcocoaaccessibility.mm | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibility.mm b/src/plugins/platforms/cocoa/qcocoaaccessibility.mm index 448c5415555..4aace8838e9 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibility.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibility.mm @@ -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; }