|
1 /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "RootAccessibleWrap.h" |
|
7 |
|
8 #import "mozDocAccessible.h" |
|
9 |
|
10 #import "mozView.h" |
|
11 |
|
12 // This must be included last: |
|
13 #include "nsObjCExceptions.h" |
|
14 |
|
15 using namespace mozilla::a11y; |
|
16 |
|
17 static id <mozAccessible, mozView> |
|
18 getNativeViewFromRootAccessible(Accessible* aAccessible) |
|
19 { |
|
20 RootAccessibleWrap* root = |
|
21 static_cast<RootAccessibleWrap*>(aAccessible->AsRoot()); |
|
22 id <mozAccessible, mozView> nativeView = nil; |
|
23 root->GetNativeWidget ((void**)&nativeView); |
|
24 return nativeView; |
|
25 } |
|
26 |
|
27 #pragma mark - |
|
28 |
|
29 @implementation mozRootAccessible |
|
30 |
|
31 - (NSArray*)accessibilityAttributeNames |
|
32 { |
|
33 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; |
|
34 |
|
35 // if we're expired, we don't support any attributes. |
|
36 if (!mGeckoAccessible) |
|
37 return [NSArray array]; |
|
38 |
|
39 // standard attributes that are shared and supported by root accessible (AXMain) elements. |
|
40 static NSMutableArray* attributes = nil; |
|
41 |
|
42 if (!attributes) { |
|
43 attributes = [[super accessibilityAttributeNames] mutableCopy]; |
|
44 [attributes addObject:NSAccessibilityMainAttribute]; |
|
45 [attributes addObject:NSAccessibilityMinimizedAttribute]; |
|
46 } |
|
47 |
|
48 return attributes; |
|
49 |
|
50 NS_OBJC_END_TRY_ABORT_BLOCK_NIL; |
|
51 } |
|
52 |
|
53 - (id)accessibilityAttributeValue:(NSString *)attribute |
|
54 { |
|
55 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; |
|
56 |
|
57 if ([attribute isEqualToString:NSAccessibilityMainAttribute]) |
|
58 return [NSNumber numberWithBool:[[self window] isMainWindow]]; |
|
59 if ([attribute isEqualToString:NSAccessibilityMinimizedAttribute]) |
|
60 return [NSNumber numberWithBool:[[self window] isMiniaturized]]; |
|
61 |
|
62 return [super accessibilityAttributeValue:attribute]; |
|
63 |
|
64 NS_OBJC_END_TRY_ABORT_BLOCK_NIL; |
|
65 } |
|
66 |
|
67 |
|
68 // return the AXParent that our parallell NSView tells us about. |
|
69 - (id)parent |
|
70 { |
|
71 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; |
|
72 |
|
73 if (!mParallelView) |
|
74 mParallelView = (id<mozView, mozAccessible>)[self representedView]; |
|
75 |
|
76 if (mParallelView) |
|
77 return [mParallelView accessibilityAttributeValue:NSAccessibilityParentAttribute]; |
|
78 |
|
79 NSAssert(mParallelView, @"we're a root accessible w/o native view?"); |
|
80 return [super parent]; |
|
81 |
|
82 NS_OBJC_END_TRY_ABORT_BLOCK_NIL; |
|
83 } |
|
84 |
|
85 - (BOOL)hasRepresentedView |
|
86 { |
|
87 return YES; |
|
88 } |
|
89 |
|
90 // this will return our parallell NSView. see mozDocAccessible.h |
|
91 - (id)representedView |
|
92 { |
|
93 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; |
|
94 |
|
95 if (mParallelView) |
|
96 return (id)mParallelView; |
|
97 |
|
98 mParallelView = getNativeViewFromRootAccessible (mGeckoAccessible); |
|
99 |
|
100 NSAssert(mParallelView, @"can't return root accessible's native parallel view."); |
|
101 return mParallelView; |
|
102 |
|
103 NS_OBJC_END_TRY_ABORT_BLOCK_NIL; |
|
104 } |
|
105 |
|
106 - (BOOL)isRoot |
|
107 { |
|
108 return YES; |
|
109 } |
|
110 |
|
111 @end |