0

I have a NSWebView and when I use VoiceOver on Mac OS X it announces the NSWebView selection as "HTML content" This is most likely going to confuse the end user as I am using it for a custom control and I have handled all the other accessibility aspects of the NSWebView correctly.

How can I override what VoiceOver announces for the NSWebView? I have tried the following however it doesn't make any difference:

[webView accessibilitySetOverrideValue:@"Map View" forAttribute:NSAccessibilityDescriptionAttribute];

I have also tried NSAccessibilityRoleDescriptionAttribute and NSAccessibilityTitleAttribute for the attributes.

Mutawe
  • 6,464
  • 3
  • 47
  • 90
Luke
  • 6,195
  • 11
  • 57
  • 85

1 Answers1

0

You may need to subclass NSWebView and override NSAccessibilityRoleDescriptionAttribute in the - (id)accessibilityAttributeValue:(NSString *)attribute method:

- (id)accessibilityAttributeValue:(NSString *)attribute
{
    id value = nil;

    if ( [attribute isEqualToString:NSAccessibilityRoleDescriptionAttribute] )
    {
        value = @"Map View";
    }
    // all your other ifs here
    else
    {
        value = [super accessibilityAttributeValue:attribute];
    }

    return value;
}

Be sure that you're telling NSAccessibility what you're providing (specifically the NSAccessibilityRoleDescriptionAttribute part):

- (NSArray *)accessibilityAttributeNames
{
    static NSMutableArray *attributes = nil;

    if ( attributes == nil )
    {
        attributes = [[super accessibilityAttributeNames] mutableCopy];

        NSArray *additionalAttributes = @[NSAccessibilityDescriptionAttribute, NSAccessibilityRoleAttribute, NSAccessibilityChildrenAttribute, NSAccessibilityTitleUIElementAttribute, NSAccessibilityRoleDescriptionAttribute];

        for ( NSString *attribute in additionalAttributes )
        {
            if ( ![attributes containsObject:attribute] )
            {
                [attributes addObject:attribute];
            }
        }
    }

    return attributes;
}
Jesse Bunch
  • 6,651
  • 4
  • 36
  • 59
  • I tried this and if I break point on the if statement the attribute is only ever set to AXParent or AXChildren. Any ideas? – Luke May 31 '13 at 05:43
  • See my edit. You might need to tell the protocol that you're providing `NSAccessibilityRoleDescriptionAttribute`. – Jesse Bunch Jun 03 '13 at 01:31
  • I just tried doing that and when I breakpoint [attributes addObject:attribute]; on breaks twice for AXDescription and AXTitleUIElement but not for the others. Also when using the Accesibility Inspector the AXRoleDescription is still showing 'HTML Content' Is seems that AXRoleDescription is already part of [super accessibilityAttributeNames]. Any other ideas? – Luke Jun 03 '13 at 02:37