1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/mac/mozHTMLAccessible.mm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,120 @@ 1.4 +/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:expandtab:shiftwidth=2:tabstop=2: 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#import "mozHTMLAccessible.h" 1.12 + 1.13 +#import "Accessible-inl.h" 1.14 +#import "HyperTextAccessible.h" 1.15 + 1.16 +#import "nsCocoaUtils.h" 1.17 + 1.18 +@implementation mozHeadingAccessible 1.19 + 1.20 +- (NSString*)title 1.21 +{ 1.22 + nsAutoString title; 1.23 + // XXX use the flattening API when there are available 1.24 + // see bug 768298 1.25 + mGeckoAccessible->GetContent()->GetTextContent(title); 1.26 + 1.27 + return nsCocoaUtils::ToNSString(title); 1.28 +} 1.29 + 1.30 +- (id)value 1.31 +{ 1.32 + if (!mGeckoAccessible || !mGeckoAccessible->IsHyperText()) 1.33 + return nil; 1.34 + 1.35 + uint32_t level = mGeckoAccessible->AsHyperText()->GetLevelInternal(); 1.36 + return [NSNumber numberWithInt:level]; 1.37 +} 1.38 + 1.39 +@end 1.40 + 1.41 +@interface mozLinkAccessible () 1.42 +-(NSURL*)url; 1.43 +@end 1.44 + 1.45 +@implementation mozLinkAccessible 1.46 + 1.47 +- (NSArray*)accessibilityAttributeNames 1.48 +{ 1.49 + // if we're expired, we don't support any attributes. 1.50 + if (!mGeckoAccessible) 1.51 + return [NSArray array]; 1.52 + 1.53 + static NSMutableArray* attributes = nil; 1.54 + 1.55 + if (!attributes) { 1.56 + attributes = [[super accessibilityAttributeNames] mutableCopy]; 1.57 + [attributes addObject:NSAccessibilityURLAttribute]; 1.58 + } 1.59 + 1.60 + return attributes; 1.61 +} 1.62 + 1.63 +- (id)accessibilityAttributeValue:(NSString *)attribute 1.64 +{ 1.65 + if ([attribute isEqualToString:NSAccessibilityURLAttribute]) 1.66 + return [self url]; 1.67 + 1.68 + return [super accessibilityAttributeValue:attribute]; 1.69 +} 1.70 + 1.71 +- (NSArray*)accessibilityActionNames 1.72 +{ 1.73 + // if we're expired, we don't support any attributes. 1.74 + if (!mGeckoAccessible) 1.75 + return [NSArray array]; 1.76 + 1.77 + static NSArray* actionNames = nil; 1.78 + 1.79 + if (!actionNames) { 1.80 + actionNames = [[NSArray alloc] initWithObjects:NSAccessibilityPressAction, 1.81 + nil]; 1.82 + } 1.83 + 1.84 + return actionNames; 1.85 +} 1.86 + 1.87 +- (void)accessibilityPerformAction:(NSString*)action 1.88 +{ 1.89 + if (!mGeckoAccessible) 1.90 + return; 1.91 + 1.92 + if ([action isEqualToString:NSAccessibilityPressAction]) 1.93 + mGeckoAccessible->DoAction(0); 1.94 + else 1.95 + [super accessibilityPerformAction:action]; 1.96 +} 1.97 + 1.98 +- (NSString*)customDescription 1.99 +{ 1.100 + return @""; 1.101 +} 1.102 + 1.103 +- (NSString*)value 1.104 +{ 1.105 + return @""; 1.106 +} 1.107 + 1.108 +- (NSURL*)url 1.109 +{ 1.110 + if (!mGeckoAccessible || mGeckoAccessible->IsDefunct()) 1.111 + return nil; 1.112 + 1.113 + nsAutoString value; 1.114 + mGeckoAccessible->Value(value); 1.115 + 1.116 + NSString* urlString = value.IsEmpty() ? nil : nsCocoaUtils::ToNSString(value); 1.117 + if (!urlString) 1.118 + return nil; 1.119 + 1.120 + return [NSURL URLWithString:urlString]; 1.121 +} 1.122 + 1.123 +@end