macOS accessibility: Implement NSAccessibilityElement

Modern macOS accessibility is based on protocols.
By implementing NSAccessibilityElement we get warnings
for missing functions for the most basic accessibility
functionality.

Change-Id: I0595ea5b9927c5bfb4bbeff3fc9322cb1f232b9f
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
This commit is contained in:
Frederik Gladhorn 2018-11-21 16:40:55 +01:00
parent cd816d4b6a
commit 9ce6742790
2 changed files with 13 additions and 4 deletions

View File

@ -52,7 +52,7 @@
@class QT_MANGLE_NAMESPACE(QMacAccessibilityElement);
@interface QT_MANGLE_NAMESPACE(QMacAccessibilityElement) : NSObject
@interface QT_MANGLE_NAMESPACE(QMacAccessibilityElement) : NSObject <NSAccessibilityElement>
- (instancetype)initWithId:(QAccessible::Id)anId;
+ (instancetype)elementWithId:(QAccessible::Id)anId;

View File

@ -174,6 +174,17 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of
// accessibility protocol
//
- (BOOL)isAccessibilityFocused
{
QAccessibleInterface *iface = QAccessible::accessibleInterface(axid);
if (!iface || !iface->isValid()) {
return false;
}
// Just check if the app thinks we're focused.
id focusedElement = NSApp.accessibilityApplicationFocusedUIElement;
return [focusedElement isEqual:self];
}
// attributes
+ (id) lineNumberForIndex: (int)index forText:(const QString &)text
@ -300,9 +311,7 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of
} else if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
return QCocoaAccessible::unignoredChildren(iface);
} else if ([attribute isEqualToString:NSAccessibilityFocusedAttribute]) {
// Just check if the app thinks we're focused.
id focusedElement = [NSApp accessibilityAttributeValue:NSAccessibilityFocusedUIElementAttribute];
return @([focusedElement isEqual:self]);
return @(self.isAccessibilityFocused);
} else if ([attribute isEqualToString:NSAccessibilityParentAttribute]) {
return self.accessibilityParent;
} else if ([attribute isEqualToString:NSAccessibilityWindowAttribute]) {