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/. */
10 #include "LocalAccessible.h"
11 #include "nsCocoaUtils.h"
12 #include "mozilla/a11y/PDocAccessible.h"
18 // convert an array of Gecko accessibles to an NSArray of native accessibles
19 NSArray<mozAccessible*>* ConvertToNSArray(nsTArray<LocalAccessible*>& aArray) {
20 NSMutableArray* nativeArray = [[[NSMutableArray alloc] init] autorelease];
22 // iterate through the list, and get each native accessible.
23 size_t totalCount = aArray.Length();
24 for (size_t i = 0; i < totalCount; i++) {
25 LocalAccessible* curAccessible = aArray.ElementAt(i);
26 mozAccessible* curNative = GetNativeFromGeckoAccessible(curAccessible);
28 [nativeArray addObject:GetObjectOrRepresentedView(curNative)];
34 // convert an array of Gecko proxy accessibles to an NSArray of native
36 NSArray<mozAccessible*>* ConvertToNSArray(nsTArray<RemoteAccessible*>& aArray) {
37 NSMutableArray* nativeArray = [[[NSMutableArray alloc] init] autorelease];
39 // iterate through the list, and get each native accessible.
40 size_t totalCount = aArray.Length();
41 for (size_t i = 0; i < totalCount; i++) {
42 RemoteAccessible* curAccessible = aArray.ElementAt(i);
43 mozAccessible* curNative = GetNativeFromGeckoAccessible(curAccessible);
45 [nativeArray addObject:GetObjectOrRepresentedView(curNative)];
52 * Get a localized string from the a11y string bundle.
53 * Return nil if not found.
55 NSString* LocalizedString(const nsString& aString) {
58 LocalAccessible::TranslateString(aString, text);
60 return text.IsEmpty() ? nil : nsCocoaUtils::ToNSString(text);
63 NSString* GetAccAttr(mozAccessible* aNativeAccessible, nsAtom* aAttrName) {
65 RefPtr<AccAttributes> attributes;
66 if (LocalAccessible* acc = [aNativeAccessible geckoAccessible]->AsLocal()) {
67 attributes = acc->Attributes();
68 } else if (RemoteAccessible* proxy =
69 [aNativeAccessible geckoAccessible]->AsRemote()) {
70 proxy->Attributes(&attributes);
73 attributes->GetAttribute(aAttrName, result);
75 if (!result.IsEmpty()) {
76 return nsCocoaUtils::ToNSString(result);