accessible/src/mac/mozHTMLAccessible.mm

branch
TOR_BUG_9701
changeset 3
141e0f1194b1
equal deleted inserted replaced
-1:000000000000 0:2602ab6168d3
1 /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
8 #import "mozHTMLAccessible.h"
9
10 #import "Accessible-inl.h"
11 #import "HyperTextAccessible.h"
12
13 #import "nsCocoaUtils.h"
14
15 @implementation mozHeadingAccessible
16
17 - (NSString*)title
18 {
19 nsAutoString title;
20 // XXX use the flattening API when there are available
21 // see bug 768298
22 mGeckoAccessible->GetContent()->GetTextContent(title);
23
24 return nsCocoaUtils::ToNSString(title);
25 }
26
27 - (id)value
28 {
29 if (!mGeckoAccessible || !mGeckoAccessible->IsHyperText())
30 return nil;
31
32 uint32_t level = mGeckoAccessible->AsHyperText()->GetLevelInternal();
33 return [NSNumber numberWithInt:level];
34 }
35
36 @end
37
38 @interface mozLinkAccessible ()
39 -(NSURL*)url;
40 @end
41
42 @implementation mozLinkAccessible
43
44 - (NSArray*)accessibilityAttributeNames
45 {
46 // if we're expired, we don't support any attributes.
47 if (!mGeckoAccessible)
48 return [NSArray array];
49
50 static NSMutableArray* attributes = nil;
51
52 if (!attributes) {
53 attributes = [[super accessibilityAttributeNames] mutableCopy];
54 [attributes addObject:NSAccessibilityURLAttribute];
55 }
56
57 return attributes;
58 }
59
60 - (id)accessibilityAttributeValue:(NSString *)attribute
61 {
62 if ([attribute isEqualToString:NSAccessibilityURLAttribute])
63 return [self url];
64
65 return [super accessibilityAttributeValue:attribute];
66 }
67
68 - (NSArray*)accessibilityActionNames
69 {
70 // if we're expired, we don't support any attributes.
71 if (!mGeckoAccessible)
72 return [NSArray array];
73
74 static NSArray* actionNames = nil;
75
76 if (!actionNames) {
77 actionNames = [[NSArray alloc] initWithObjects:NSAccessibilityPressAction,
78 nil];
79 }
80
81 return actionNames;
82 }
83
84 - (void)accessibilityPerformAction:(NSString*)action
85 {
86 if (!mGeckoAccessible)
87 return;
88
89 if ([action isEqualToString:NSAccessibilityPressAction])
90 mGeckoAccessible->DoAction(0);
91 else
92 [super accessibilityPerformAction:action];
93 }
94
95 - (NSString*)customDescription
96 {
97 return @"";
98 }
99
100 - (NSString*)value
101 {
102 return @"";
103 }
104
105 - (NSURL*)url
106 {
107 if (!mGeckoAccessible || mGeckoAccessible->IsDefunct())
108 return nil;
109
110 nsAutoString value;
111 mGeckoAccessible->Value(value);
112
113 NSString* urlString = value.IsEmpty() ? nil : nsCocoaUtils::ToNSString(value);
114 if (!urlString)
115 return nil;
116
117 return [NSURL URLWithString:urlString];
118 }
119
120 @end

mercurial