Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: AXManualAccessibility showing failure #38147

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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