Browse Source

Announce changes to live regions on macOS (#21045)

* Announce changes to live regions on macOS

It is necessary to manually request announcement of the new name of a live
region, alongside posting the general kAXLiveRegionChangedNotification.

* Refactor -raisePropertyChanged: to use switch statement

* Fix warning about switch not covering all cases

---------

Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
release/12.0.1
Adam Demasi 6 months ago
committed by Julien Lebosquain
parent
commit
bc7eb02db7
  1. 32
      native/Avalonia.Native/src/OSX/automation.mm

32
native/Avalonia.Native/src/OSX/automation.mm

@ -130,7 +130,7 @@
case AutomationExpander: return NSAccessibilityDisclosureTriangleRole; case AutomationExpander: return NSAccessibilityDisclosureTriangleRole;
// Treat unknown roles as generic group container items. Returning // Treat unknown roles as generic group container items. Returning
// NSAccessibilityUnknownRole is also possible but makes the screen // NSAccessibilityUnknownRole is also possible but makes the screen
// reader focus on the item instead of passing focus to child items. // reader focus on the item instead of passing focus to child items.
default: return NSAccessibilityGroupRole; default: return NSAccessibilityGroupRole;
} }
} }
@ -191,6 +191,7 @@
{ {
switch (_peer->GetLiveSetting()) switch (_peer->GetLiveSetting())
{ {
case LiveSettingOff: return nil;
case LiveSettingPolite: return @"polite"; case LiveSettingPolite: return @"polite";
case LiveSettingAssertive: return @"assertive"; case LiveSettingAssertive: return @"assertive";
} }
@ -519,6 +520,35 @@
- (void)raiseLiveRegionChanged - (void)raiseLiveRegionChanged
{ {
NSAccessibilityPostNotification(self, @"AXLiveRegionChanged" /* kAXLiveRegionChangedNotification */); NSAccessibilityPostNotification(self, @"AXLiveRegionChanged" /* kAXLiveRegionChangedNotification */);
// Announce the new string
auto name = _peer->GetName();
if (name != nullptr)
{
NSAccessibilityPriorityLevel priority = NSAccessibilityPriorityLow;
switch (_peer->GetLiveSetting())
{
case LiveSettingOff:
return;
case LiveSettingPolite:
priority = NSAccessibilityPriorityMedium;
break;
case LiveSettingAssertive:
priority = NSAccessibilityPriorityHigh;
break;
}
NSDictionary <NSString *, id> *userInfo = @{
NSAccessibilityAnnouncementKey: GetNSStringAndRelease(name),
NSAccessibilityPriorityKey: @(priority)
};
id topLevel = [self accessibilityTopLevelUIElement];
if ([topLevel isKindOfClass:[AvnWindow class]])
{
NSAccessibilityPostNotificationWithUserInfo(topLevel, NSAccessibilityAnnouncementRequestedNotification, userInfo);
}
}
} }
- (void)setAccessibilityFocused:(BOOL)accessibilityFocused - (void)setAccessibilityFocused:(BOOL)accessibilityFocused

Loading…
Cancel
Save