From bc1678c618342774be285f24c1e2995c0a0e1600 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Thu, 22 Nov 2018 13:22:34 +0100 Subject: macOS accessibility: fix crash for NSAccessibilityVisibleCharacterRangeAttribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VoiceOver or other tools may query this property even when there is no text interface. Make sure not to crash by verifying that the interface is supported. Found while using AccessibilityInspector to verify other changes. Change-Id: If7ee21b7616f091b71e86bab03a871ddbabe9200 Reviewed-by: Jan Arve Sæther --- src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm index 03dc895ffb..a1176da33f 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm @@ -345,8 +345,9 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of return [NSValue valueWithRange: NSMakeRange(0, 0)]; } else if ([attribute isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute]) { // FIXME This is not correct and may impact performance for big texts - return [NSValue valueWithRange: NSMakeRange(0, iface->textInterface()->characterCount())]; - + if (QAccessibleTextInterface *text = iface->textInterface()) + return [NSValue valueWithRange: NSMakeRange(0, text->characterCount())]; + return [NSValue valueWithRange: NSMakeRange(0, iface->text(QAccessible::Name).length())]; } else if ([attribute isEqualToString:NSAccessibilityInsertionPointLineNumberAttribute]) { if (QAccessibleTextInterface *text = iface->textInterface()) { int line = 0; // true for all single line edits -- cgit v1.2.3