MacUtils.h (2158B)
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 #ifndef _MacUtils_H_ 9 #define _MacUtils_H_ 10 11 #include "nsStringFwd.h" 12 #include "mozAccessible.h" 13 #include "MOXAccessibleBase.h" 14 15 @class NSString; 16 @class mozAccessible; 17 18 namespace mozilla { 19 namespace a11y { 20 namespace utils { 21 22 // convert an array of Gecko accessibles to an NSArray of native accessibles 23 template <typename AccArray> 24 NSArray<mozAccessible*>* ConvertToNSArray(AccArray& aArray) { 25 NSMutableArray* nativeArray = [[[NSMutableArray alloc] init] autorelease]; 26 27 // iterate through the list, and get each native accessible. 28 for (Accessible* curAccessible : aArray) { 29 mozAccessible* curNative = GetNativeFromGeckoAccessible(curAccessible); 30 if (curNative) 31 [nativeArray addObject:GetObjectOrRepresentedView(curNative)]; 32 } 33 34 return nativeArray; 35 } 36 37 /** 38 * Get a localized string from the string bundle. 39 * Return nil if not found. 40 */ 41 NSString* LocalizedString(const nsString& aString); 42 43 /** 44 * Gets an accessible atttribute from the mozAccessible's associated 45 * accessible wrapper or proxy, and returns the value as an NSString. 46 * nil if no attribute is found. 47 */ 48 NSString* GetAccAttr(mozAccessible* aNativeAccessible, nsAtom* aAttrName); 49 50 /** 51 * Return true if the passed raw pointer is a live document accessible. Uses 52 * the provided root doc accessible to check for current documents. 53 */ 54 bool DocumentExists(Accessible* aDoc, uintptr_t aDocPtr); 55 56 NSDictionary* StringAttributesFromAccAttributes(AccAttributes* aAttributes, 57 Accessible* aContainer); 58 59 /** 60 * Get the appropriate NSScreen for the given Accessible. 61 * This should mostly return the main screen, except for 62 * in the presence of multiple monitors. 63 */ 64 NSScreen* GetNSScreenForAcc(mozAccessible* aAcc); 65 } // namespace utils 66 } // namespace a11y 67 } // namespace mozilla 68 69 #endif