accessible/src/mac/mozDocAccessible.mm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/mac/mozDocAccessible.mm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "RootAccessibleWrap.h"
    1.10 +
    1.11 +#import "mozDocAccessible.h"
    1.12 +
    1.13 +#import "mozView.h"
    1.14 +
    1.15 +// This must be included last:
    1.16 +#include "nsObjCExceptions.h"
    1.17 +
    1.18 +using namespace mozilla::a11y;
    1.19 +
    1.20 +static id <mozAccessible, mozView> 
    1.21 +getNativeViewFromRootAccessible(Accessible* aAccessible)
    1.22 +{
    1.23 +  RootAccessibleWrap* root =
    1.24 +    static_cast<RootAccessibleWrap*>(aAccessible->AsRoot());
    1.25 +  id <mozAccessible, mozView> nativeView = nil;
    1.26 +  root->GetNativeWidget ((void**)&nativeView);
    1.27 +  return nativeView;
    1.28 +}
    1.29 +
    1.30 +#pragma mark -
    1.31 +
    1.32 +@implementation mozRootAccessible
    1.33 +
    1.34 +- (NSArray*)accessibilityAttributeNames
    1.35 +{
    1.36 +  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
    1.37 +  
    1.38 +  // if we're expired, we don't support any attributes.
    1.39 +  if (!mGeckoAccessible)
    1.40 +    return [NSArray array];
    1.41 +  
    1.42 +  // standard attributes that are shared and supported by root accessible (AXMain) elements.
    1.43 +  static NSMutableArray* attributes = nil;
    1.44 +  
    1.45 +  if (!attributes) {
    1.46 +    attributes = [[super accessibilityAttributeNames] mutableCopy];
    1.47 +    [attributes addObject:NSAccessibilityMainAttribute];
    1.48 +    [attributes addObject:NSAccessibilityMinimizedAttribute];
    1.49 +  }
    1.50 +
    1.51 +  return attributes;
    1.52 +
    1.53 +  NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
    1.54 +}
    1.55 +
    1.56 +- (id)accessibilityAttributeValue:(NSString *)attribute
    1.57 +{
    1.58 +  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
    1.59 +  
    1.60 +  if ([attribute isEqualToString:NSAccessibilityMainAttribute])
    1.61 +    return [NSNumber numberWithBool:[[self window] isMainWindow]];
    1.62 +  if ([attribute isEqualToString:NSAccessibilityMinimizedAttribute])
    1.63 +    return [NSNumber numberWithBool:[[self window] isMiniaturized]];
    1.64 +
    1.65 +  return [super accessibilityAttributeValue:attribute];
    1.66 +  
    1.67 +  NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
    1.68 +}
    1.69 +
    1.70 +
    1.71 +// return the AXParent that our parallell NSView tells us about.
    1.72 +- (id)parent
    1.73 +{
    1.74 +  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
    1.75 +
    1.76 +  if (!mParallelView)
    1.77 +    mParallelView = (id<mozView, mozAccessible>)[self representedView];
    1.78 +  
    1.79 +  if (mParallelView)
    1.80 +    return [mParallelView accessibilityAttributeValue:NSAccessibilityParentAttribute];
    1.81 +  
    1.82 +  NSAssert(mParallelView, @"we're a root accessible w/o native view?");
    1.83 +  return [super parent];
    1.84 +
    1.85 +  NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
    1.86 +}
    1.87 +
    1.88 +- (BOOL)hasRepresentedView
    1.89 +{
    1.90 +  return YES;
    1.91 +}
    1.92 +
    1.93 +// this will return our parallell NSView. see mozDocAccessible.h
    1.94 +- (id)representedView
    1.95 +{
    1.96 +  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
    1.97 +
    1.98 +  if (mParallelView)
    1.99 +    return (id)mParallelView;
   1.100 +  
   1.101 +  mParallelView = getNativeViewFromRootAccessible (mGeckoAccessible);
   1.102 +  
   1.103 +  NSAssert(mParallelView, @"can't return root accessible's native parallel view.");
   1.104 +  return mParallelView;
   1.105 +
   1.106 +  NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
   1.107 +}
   1.108 +
   1.109 +- (BOOL)isRoot
   1.110 +{
   1.111 +  return YES;
   1.112 +}
   1.113 +
   1.114 +@end

mercurial