Skip to content

Commit

Permalink
fix: AXManualAccessibility showing failure (#38147)
Browse files Browse the repository at this point in the history
fix: AXManualAccessibility showing failure

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
  • Loading branch information
codebytere and trop[bot] committed May 3, 2023
1 parent 912aa52 commit a051ee5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
13 changes: 13 additions & 0 deletions docs/tutorial/accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ On macOS, third-party assistive technology can toggle accessibility features ins
Electron applications by setting the `AXManualAccessibility` attribute
programmatically:

Using Objective-C:

```objc
CFStringRef kAXManualAccessibility = CFSTR("AXManualAccessibility");

Expand All @@ -43,5 +45,16 @@ CFStringRef kAXManualAccessibility = CFSTR("AXManualAccessibility");
}
```

Using Swift:

```swift
import Cocoa
let name = CommandLine.arguments.count >= 2 ? CommandLine.arguments[1] : "Electron"
let pid = NSWorkspace.shared.runningApplications.first(where: {$0.localizedName == name})!.processIdentifier
let axApp = AXUIElementCreateApplication(pid)
let result = AXUIElementSetAttributeValue(axApp, "AXManualAccessibility" as CFString, true as CFTypeRef)
print("Setting 'AXManualAccessibility' \(error.rawValue == 0 ? "succeeded" : "failed")")
```

[a11y-docs]: https://www.chromium.org/developers/design-documents/accessibility#TOC-How-Chrome-detects-the-presence-of-Assistive-Technology
[setAccessibilitySupportEnabled]: ../api/app.md#appsetaccessibilitysupportenabledenabled-macos-windows
16 changes: 12 additions & 4 deletions shell/browser/mac/electron_application.mm
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,13 @@ - (void)handleURLEvent:(NSAppleEventDescriptor*)event
electron::Browser::Get()->OpenURL(base::SysNSStringToUTF8(url));
}

// AXEnhancedUserInterface is an undocumented attribute that screen reader
// related functionality sets when running, and AXManualAccessibility is an
// attribute Electron specifically allows third-party apps to use to enable
// a11y features in Electron.
- (void)accessibilitySetValue:(id)value forAttribute:(NSString*)attribute {
// Undocumented attribute that screen reader related functionality
// sets when running.
if ([attribute isEqualToString:@"AXEnhancedUserInterface"] ||
[attribute isEqualToString:@"AXManualAccessibility"]) {
bool is_manual_ax = [attribute isEqualToString:@"AXManualAccessibility"];
if ([attribute isEqualToString:@"AXEnhancedUserInterface"] || is_manual_ax) {
auto* ax_state = content::BrowserAccessibilityState::GetInstance();
if ([value boolValue]) {
ax_state->OnScreenReaderDetected();
Expand All @@ -188,6 +190,12 @@ - (void)accessibilitySetValue:(id)value forAttribute:(NSString*)attribute {
}

electron::Browser::Get()->OnAccessibilitySupportChanged();

// Don't call the superclass function for AXManualAccessibility,
// as it will log an AXError and make it appear as though the attribute
// failed to take effect.
if (is_manual_ax)
return;
}

return [super accessibilitySetValue:value forAttribute:attribute];
Expand Down

0 comments on commit a051ee5

Please sign in to comment.