2020-08-25 21:40:32 +00:00
|
|
|
/* clang-format off */
|
2012-01-27 06:14:09 +00:00
|
|
|
/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2020-08-25 21:40:32 +00:00
|
|
|
/* clang-format on */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-01-27 06:14:09 +00:00
|
|
|
|
|
|
|
#import "MacUtils.h"
|
|
|
|
|
2012-05-29 01:18:45 +00:00
|
|
|
#include "Accessible.h"
|
2012-01-27 06:14:09 +00:00
|
|
|
#include "nsCocoaUtils.h"
|
2020-03-16 22:15:57 +00:00
|
|
|
#include "mozilla/a11y/PDocAccessible.h"
|
|
|
|
#include "nsIPersistentProperties2.h"
|
2012-01-27 06:14:09 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
namespace utils {
|
|
|
|
|
2020-05-27 15:50:47 +00:00
|
|
|
// convert an array of Gecko accessibles to an NSArray of native accessibles
|
2020-08-14 19:31:50 +00:00
|
|
|
NSMutableArray* ConvertToNSArray(nsTArray<Accessible*>& aArray) {
|
2020-05-27 15:50:47 +00:00
|
|
|
NSMutableArray* nativeArray = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
// iterate through the list, and get each native accessible.
|
|
|
|
size_t totalCount = aArray.Length();
|
|
|
|
for (size_t i = 0; i < totalCount; i++) {
|
|
|
|
Accessible* curAccessible = aArray.ElementAt(i);
|
|
|
|
mozAccessible* curNative = GetNativeFromGeckoAccessible(curAccessible);
|
2020-08-25 21:40:32 +00:00
|
|
|
if (curNative)
|
|
|
|
[nativeArray addObject:GetObjectOrRepresentedView(curNative)];
|
2020-05-27 15:50:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nativeArray;
|
|
|
|
}
|
|
|
|
|
2020-08-25 21:40:32 +00:00
|
|
|
// convert an array of Gecko proxy accessibles to an NSArray of native
|
|
|
|
// accessibles
|
2020-08-14 19:31:50 +00:00
|
|
|
NSMutableArray* ConvertToNSArray(nsTArray<ProxyAccessible*>& aArray) {
|
2020-05-27 15:50:47 +00:00
|
|
|
NSMutableArray* nativeArray = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
// iterate through the list, and get each native accessible.
|
|
|
|
size_t totalCount = aArray.Length();
|
|
|
|
for (size_t i = 0; i < totalCount; i++) {
|
|
|
|
ProxyAccessible* curAccessible = aArray.ElementAt(i);
|
|
|
|
mozAccessible* curNative = GetNativeFromGeckoAccessible(curAccessible);
|
2020-08-25 21:40:32 +00:00
|
|
|
if (curNative)
|
|
|
|
[nativeArray addObject:GetObjectOrRepresentedView(curNative)];
|
2020-05-27 15:50:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nativeArray;
|
|
|
|
}
|
|
|
|
|
2012-01-27 06:14:09 +00:00
|
|
|
/**
|
|
|
|
* Get a localized string from the a11y string bundle.
|
|
|
|
* Return nil if not found.
|
|
|
|
*/
|
2019-01-21 17:18:16 +00:00
|
|
|
NSString* LocalizedString(const nsString& aString) {
|
2012-01-27 06:14:09 +00:00
|
|
|
nsString text;
|
2015-06-08 14:59:19 +00:00
|
|
|
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible::TranslateString(aString, text);
|
2015-06-08 14:59:19 +00:00
|
|
|
|
2012-01-27 06:14:09 +00:00
|
|
|
return text.IsEmpty() ? nil : nsCocoaUtils::ToNSString(text);
|
|
|
|
}
|
|
|
|
|
2020-03-16 22:15:57 +00:00
|
|
|
NSString* GetAccAttr(mozAccessible* aNativeAccessible, const char* aAttrName) {
|
|
|
|
nsAutoString result;
|
2020-05-27 15:50:47 +00:00
|
|
|
if (Accessible* acc = [aNativeAccessible geckoAccessible].AsAccessible()) {
|
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes = acc->Attributes();
|
2020-03-16 22:15:57 +00:00
|
|
|
attributes->GetStringProperty(nsCString(aAttrName), result);
|
2020-08-25 21:40:32 +00:00
|
|
|
} else if (ProxyAccessible* proxy =
|
|
|
|
[aNativeAccessible geckoAccessible].AsProxy()) {
|
2020-03-16 22:15:57 +00:00
|
|
|
AutoTArray<Attribute, 10> attrs;
|
|
|
|
proxy->Attributes(&attrs);
|
|
|
|
for (size_t i = 0; i < attrs.Length(); i++) {
|
|
|
|
if (attrs.ElementAt(i).Name() == aAttrName) {
|
|
|
|
result = attrs.ElementAt(i).Value();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result.IsEmpty()) {
|
|
|
|
return nsCocoaUtils::ToNSString(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
2012-01-27 06:14:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|