michael@0: /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "RootAccessibleWrap.h" michael@0: michael@0: #import "mozDocAccessible.h" michael@0: michael@0: #import "mozView.h" michael@0: michael@0: // This must be included last: michael@0: #include "nsObjCExceptions.h" michael@0: michael@0: using namespace mozilla::a11y; michael@0: michael@0: static id michael@0: getNativeViewFromRootAccessible(Accessible* aAccessible) michael@0: { michael@0: RootAccessibleWrap* root = michael@0: static_cast(aAccessible->AsRoot()); michael@0: id nativeView = nil; michael@0: root->GetNativeWidget ((void**)&nativeView); michael@0: return nativeView; michael@0: } michael@0: michael@0: #pragma mark - michael@0: michael@0: @implementation mozRootAccessible michael@0: michael@0: - (NSArray*)accessibilityAttributeNames michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; michael@0: michael@0: // if we're expired, we don't support any attributes. michael@0: if (!mGeckoAccessible) michael@0: return [NSArray array]; michael@0: michael@0: // standard attributes that are shared and supported by root accessible (AXMain) elements. michael@0: static NSMutableArray* attributes = nil; michael@0: michael@0: if (!attributes) { michael@0: attributes = [[super accessibilityAttributeNames] mutableCopy]; michael@0: [attributes addObject:NSAccessibilityMainAttribute]; michael@0: [attributes addObject:NSAccessibilityMinimizedAttribute]; michael@0: } michael@0: michael@0: return attributes; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NIL; michael@0: } michael@0: michael@0: - (id)accessibilityAttributeValue:(NSString *)attribute michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; michael@0: michael@0: if ([attribute isEqualToString:NSAccessibilityMainAttribute]) michael@0: return [NSNumber numberWithBool:[[self window] isMainWindow]]; michael@0: if ([attribute isEqualToString:NSAccessibilityMinimizedAttribute]) michael@0: return [NSNumber numberWithBool:[[self window] isMiniaturized]]; michael@0: michael@0: return [super accessibilityAttributeValue:attribute]; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NIL; michael@0: } michael@0: michael@0: michael@0: // return the AXParent that our parallell NSView tells us about. michael@0: - (id)parent michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; michael@0: michael@0: if (!mParallelView) michael@0: mParallelView = (id)[self representedView]; michael@0: michael@0: if (mParallelView) michael@0: return [mParallelView accessibilityAttributeValue:NSAccessibilityParentAttribute]; michael@0: michael@0: NSAssert(mParallelView, @"we're a root accessible w/o native view?"); michael@0: return [super parent]; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NIL; michael@0: } michael@0: michael@0: - (BOOL)hasRepresentedView michael@0: { michael@0: return YES; michael@0: } michael@0: michael@0: // this will return our parallell NSView. see mozDocAccessible.h michael@0: - (id)representedView michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; michael@0: michael@0: if (mParallelView) michael@0: return (id)mParallelView; michael@0: michael@0: mParallelView = getNativeViewFromRootAccessible (mGeckoAccessible); michael@0: michael@0: NSAssert(mParallelView, @"can't return root accessible's native parallel view."); michael@0: return mParallelView; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NIL; michael@0: } michael@0: michael@0: - (BOOL)isRoot michael@0: { michael@0: return YES; michael@0: } michael@0: michael@0: @end