Bug 1832284 - Fix rooting hazard in JSObject::swap r=sfink
[gecko.git] / accessible / mac / MacUtils.h
blob33ee5d0a19b8eb616015c2478dfed4991fd00427
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/. */
8 #ifndef _MacUtils_H_
9 #define _MacUtils_H_
11 #include "nsStringFwd.h"
12 #include "mozAccessible.h"
13 #include "MOXAccessibleBase.h"
15 @class NSString;
16 @class mozAccessible;
18 namespace mozilla {
19 namespace a11y {
20 namespace utils {
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];
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)];
34 return nativeArray;
37 /**
38 * Get a localized string from the string bundle.
39 * Return nil if not found.
41 NSString* LocalizedString(const nsString& aString);
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.
48 NSString* GetAccAttr(mozAccessible* aNativeAccessible, nsAtom* aAttrName);
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.
54 bool DocumentExists(Accessible* aDoc, uintptr_t aDocPtr);
56 NSDictionary* StringAttributesFromAccAttributes(AccAttributes* aAttributes,
57 Accessible* aContainer);
58 } // namespace utils
59 } // namespace a11y
60 } // namespace mozilla
62 #endif