Bug 1777562 [wpt PR 34663] - [FedCM] Rename FederatedCredential to IdentityCredential...
[gecko.git] / accessible / mac / MacUtils.mm
blob7fbb0e9ba427ea9cdb7859dff93eab1b4b60afbf
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 #import "MacUtils.h"
10 #include "LocalAccessible.h"
11 #include "nsCocoaUtils.h"
12 #include "mozilla/a11y/PDocAccessible.h"
14 namespace mozilla {
15 namespace a11y {
16 namespace utils {
18 /**
19  * Get a localized string from the a11y string bundle.
20  * Return nil if not found.
21  */
22 NSString* LocalizedString(const nsString& aString) {
23   nsString text;
25   Accessible::TranslateString(aString, text);
27   return text.IsEmpty() ? nil : nsCocoaUtils::ToNSString(text);
30 NSString* GetAccAttr(mozAccessible* aNativeAccessible, nsAtom* aAttrName) {
31   nsAutoString result;
32   Accessible* acc = [aNativeAccessible geckoAccessible];
33   RefPtr<AccAttributes> attributes = acc->Attributes();
35   if (!attributes) {
36     return nil;
37   }
39   attributes->GetAttribute(aAttrName, result);
41   if (!result.IsEmpty()) {
42     return nsCocoaUtils::ToNSString(result);
43   }
45   return nil;