tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mozRootAccessible.mm (2122B)


      1 /* clang-format off */
      2 /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      3 /* clang-format on */
      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/. */
      7 
      8 #include "RootAccessibleWrap.h"
      9 
     10 #import "mozRootAccessible.h"
     11 
     12 #import "mozView.h"
     13 
     14 #include "gfxPlatform.h"
     15 // This must be included last:
     16 #include "nsObjCExceptions.h"
     17 
     18 using namespace mozilla::a11y;
     19 
     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);
     26  return nativeView;
     27 }
     28 
     29 #pragma mark -
     30 
     31 @implementation mozRootAccessible
     32 
     33 - (id)initWithAccessible:(mozilla::a11y::Accessible*)aAcc {
     34  NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
     35 
     36  MOZ_ASSERT(!aAcc->IsRemote(), "mozRootAccessible is never a proxy");
     37 
     38  mParallelView = getNativeViewFromRootAccessible(aAcc->AsLocal());
     39 
     40  return [super initWithAccessible:aAcc];
     41 
     42  NS_OBJC_END_TRY_BLOCK_RETURN(nil);
     43 }
     44 
     45 - (NSNumber*)moxMain {
     46  return @([[self moxWindow] isMainWindow]);
     47 }
     48 
     49 - (NSNumber*)moxMinimized {
     50  return @([[self moxWindow] isMiniaturized]);
     51 }
     52 
     53 // return the AXParent that our parallell NSView tells us about.
     54 - (id)moxUnignoredParent {
     55  NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
     56 
     57  // If there is no represented view (eg. headless), this will return nil.
     58  return [[self representedView]
     59      accessibilityAttributeValue:NSAccessibilityParentAttribute];
     60 
     61  NS_OBJC_END_TRY_BLOCK_RETURN(nil);
     62 }
     63 
     64 - (BOOL)hasRepresentedView {
     65  return YES;
     66 }
     67 
     68 // this will return our parallell NSView. see mozDocAccessible.h
     69 - (id)representedView {
     70  NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
     71 
     72  MOZ_ASSERT(mParallelView || gfxPlatform::IsHeadless(),
     73             "root accessible does not have a native parallel view.");
     74 
     75  return mParallelView;
     76 
     77  NS_OBJC_END_TRY_BLOCK_RETURN(nil);
     78 }
     79 
     80 - (BOOL)isRoot {
     81  return YES;
     82 }
     83 
     84 @end