2 /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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/. */
8 #include "RootAccessibleWrap.h"
10 #import "mozRootAccessible.h"
14 #include "gfxPlatform.h"
15 // This must be included last:
16 #include "nsObjCExceptions.h"
18 using namespace mozilla::a11y;
20 static id<mozAccessible, mozView> getNativeViewFromRootAccessible(
21 LocalAccessible* aAccessible) {
22 RootAccessibleWrap* root =
23 static_cast<RootAccessibleWrap*>(aAccessible->AsRoot());
24 id<mozAccessible, mozView> nativeView = nil;
25 root->GetNativeWidget((void**)&nativeView);
31 @implementation mozRootAccessible
33 - (id)initWithAccessible:(mozilla::a11y::Accessible*)aAcc {
34 NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
36 MOZ_ASSERT(!aAcc->IsRemote(), "mozRootAccessible is never a proxy");
38 mParallelView = getNativeViewFromRootAccessible(aAcc->AsLocal());
40 return [super initWithAccessible:aAcc];
42 NS_OBJC_END_TRY_BLOCK_RETURN(nil);
45 - (NSNumber*)moxMain {
46 return @([[self moxWindow] isMainWindow]);
49 - (NSNumber*)moxMinimized {
50 return @([[self moxWindow] isMiniaturized]);
53 // return the AXParent that our parallell NSView tells us about.
54 - (id)moxUnignoredParent {
55 NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
57 // If there is no represented view (eg. headless), this will return nil.
58 return [[self representedView]
59 accessibilityAttributeValue:NSAccessibilityParentAttribute];
61 NS_OBJC_END_TRY_BLOCK_RETURN(nil);
64 - (BOOL)hasRepresentedView {
68 // this will return our parallell NSView. see mozDocAccessible.h
69 - (id)representedView {
70 NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
72 MOZ_ASSERT(mParallelView || gfxPlatform::IsHeadless(),
73 "root accessible does not have a native parallel view.");
77 NS_OBJC_END_TRY_BLOCK_RETURN(nil);