summaryrefslogtreecommitdiffstats
path: root/accessible/mac/mozDocAccessible.mm
blob: 4bae81f01c8e1044d816d00841c537ea80c28652 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "RootAccessibleWrap.h"

#import "mozDocAccessible.h"

#import "mozView.h"

// This must be included last:
#include "nsObjCExceptions.h"

using namespace mozilla::a11y;

static id <mozAccessible, mozView>
getNativeViewFromRootAccessible(Accessible* aAccessible)
{
  RootAccessibleWrap* root =
    static_cast<RootAccessibleWrap*>(aAccessible->AsRoot());
  id <mozAccessible, mozView> nativeView = nil;
  root->GetNativeWidget ((void**)&nativeView);
  return nativeView;
}

#pragma mark -

@implementation mozRootAccessible

- (NSArray*)accessibilityAttributeNames
{
  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;

  // if we're expired, we don't support any attributes.
  if (![self getGeckoAccessible])
    return [NSArray array];

  // standard attributes that are shared and supported by root accessible (AXMain) elements.
  static NSMutableArray* attributes = nil;

  if (!attributes) {
    attributes = [[super accessibilityAttributeNames] mutableCopy];
    [attributes addObject:NSAccessibilityMainAttribute];
    [attributes addObject:NSAccessibilityMinimizedAttribute];
  }

  return attributes;

  NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}

- (id)accessibilityAttributeValue:(NSString *)attribute
{
  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;

  if ([attribute isEqualToString:NSAccessibilityMainAttribute])
    return [NSNumber numberWithBool:[[self window] isMainWindow]];
  if ([attribute isEqualToString:NSAccessibilityMinimizedAttribute])
    return [NSNumber numberWithBool:[[self window] isMiniaturized]];

  return [super accessibilityAttributeValue:attribute];

  NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}


// return the AXParent that our parallell NSView tells us about.
- (id)parent
{
  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;

  if (!mParallelView)
    mParallelView = (id<mozView, mozAccessible>)[self representedView];

  if (mParallelView)
    return [mParallelView accessibilityAttributeValue:NSAccessibilityParentAttribute];

  NSAssert(mParallelView, @"we're a root accessible w/o native view?");
  return [super parent];

  NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}

- (BOOL)hasRepresentedView
{
  return YES;
}

// this will return our parallell NSView. see mozDocAccessible.h
- (id)representedView
{
  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;

  if (mParallelView)
    return (id)mParallelView;

  mParallelView = getNativeViewFromRootAccessible ([self getGeckoAccessible]);

  NSAssert(mParallelView, @"can't return root accessible's native parallel view.");
  return mParallelView;

  NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}

- (BOOL)isRoot
{
  return YES;
}

@end