From ff5ae4a5785a12089910feda533e8230498ccfb7 Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Mon, 9 Jan 2012 14:37:33 +0100 Subject: Ignore uninteresting accessibile interfaces. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Certain interface roles should be ignored and not be a part of the user-visible accessibility interface tree. Change-Id: I264fef909052c528ee505875e3a211a33114d881 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoaaccessibility.h | 1 + src/plugins/platforms/cocoa/qcocoaaccessibility.mm | 49 ++++++++++++++++++++++ .../platforms/cocoa/qcocoaaccessibilityelement.mm | 2 +- .../platforms/cocoa/qnsviewaccessibility.mm | 4 +- 4 files changed, 54 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibility.h b/src/plugins/platforms/cocoa/qcocoaaccessibility.h index 4953be0e18..c3376ad5c5 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibility.h +++ b/src/plugins/platforms/cocoa/qcocoaaccessibility.h @@ -66,6 +66,7 @@ namespace QCocoaAccessible { */ NSString *macRole(QAccessible::Role); +bool shouldBeIgnrored(QAccessibleInterface *interface); NSString *getTranslatedAction(const QString &qtAction); NSMutableArray *createTranslatedActionsList(const QStringList &qtActions); QString translateAction(NSString *nsAction); diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibility.mm b/src/plugins/platforms/cocoa/qcocoaaccessibility.mm index 26ff9531a5..436d27eddf 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibility.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibility.mm @@ -113,6 +113,55 @@ NSString *macRole(QAccessible::Role qtRole) return NSAccessibilityUnknownRole; } +/* + Mac accessibility supports ignoring elements, which means that + the elements are still present in the accessibility tree but is + not used by the screen reader. +*/ +bool shouldBeIgnrored(QAccessibleInterface *interface) +{ + // Mac 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) + 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::MenuItem || // The system also provides the menu items. + role == QAccessible::ToolBar) // Access the tool buttons directly. + return true; + + NSString *mac_role = macRole(interface->role()); + if (mac_role == NSAccessibilityWindowRole || // We use the system-provided window elements. + mac_role == NSAccessibilityGroupRole || + 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 = QLatin1String(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 == QLatin1String("QTipLabel")) + return true; + } + + return false; +} + /* Translates a predefined QAccessibleActionInterface action to a Mac action constant. Returns 0 if the Qt Action has no mac equivalent. Ownership of the NSString is diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm index deacf518af..830e6860b7 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm @@ -216,7 +216,7 @@ static QAccessibleInterface *acast(void *ptr) // misc - (BOOL)accessibilityIsIgnored { - return NO; + return QCocoaAccessible::shouldBeIgnrored(acast(accessibleInterface)); } - (id)accessibilityHitTest:(NSPoint)point { diff --git a/src/plugins/platforms/cocoa/qnsviewaccessibility.mm b/src/plugins/platforms/cocoa/qnsviewaccessibility.mm index 8cb241ab8e..da6e4d0481 100644 --- a/src/plugins/platforms/cocoa/qnsviewaccessibility.mm +++ b/src/plugins/platforms/cocoa/qnsviewaccessibility.mm @@ -53,8 +53,10 @@ @implementation QNSView (QNSViewAccessibility) +// The QNSView is a container that the user does not interact directly with: +// Remove it from the user-visible accessibility tree. - (BOOL)accessibilityIsIgnored { - return NO; + return YES; } - (id)accessibilityAttributeValue:(NSString *)attribute { -- cgit v1.2.3