Bug 1838502 - Don't expose a title for labels. r=morgan

THis is what VO expects, we apparently knew that but decided it wasn't worth fixing in the past

Differential Revision: https://phabricator.services.mozilla.com/D244050
This commit is contained in:
Eitan Isaacson
2025-04-22 22:07:02 +00:00
parent a39c7220f6
commit 5e15843b04
5 changed files with 29 additions and 14 deletions

View File

@@ -307,6 +307,9 @@ Class a11y::GetTypeFromRole(roles::Role aRole) {
case roles::OUTLINEITEM:
return [mozOutlineRowAccessible class];
case roles::LABEL:
return [MOXLabelAccessible class];
default:
return [mozAccessible class];
}

View File

@@ -887,22 +887,19 @@ struct RoleDescrComparator {
: nullptr;
if (maybeRoot && maybeRoot->IsRoot() &&
[[self moxDOMIdentifier] isEqualToString:@"a11y-announcement"]) {
// Our actual announcement should be stored as a child of the alert,
// so we verify a child exists, and then query that child below.
NSArray* children = [self moxChildren];
MOZ_ASSERT([children count] == 1 && children[0],
"A11yUtil event received, but no announcement found?");
mozAccessible* announcement = children[0];
NSString* key;
if ([announcement providesLabelNotTitle]) {
key = [announcement moxLabel];
nsAutoString name;
// Our actual announcement should be stored as a child of the alert.
if (Accessible* announcement = mGeckoAccessible->FirstChild()) {
announcement->Name(name);
} else {
key = [announcement moxTitle];
MOZ_ASSERT_UNREACHABLE(
"A11yUtil event received, but no announcement found?");
}
NSDictionary* info = @{
NSAccessibilityAnnouncementKey : key ? key : @(""),
NSAccessibilityAnnouncementKey : name.IsEmpty()
? @("")
: nsCocoaUtils::ToNSString(name),
// High priority means VO will stop what it is currently speaking
// to speak our announcement.
NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh)

View File

@@ -42,3 +42,10 @@
- (NSString*)moxTitle;
@end
@interface MOXLabelAccessible : mozAccessible
// override
- (NSString*)moxTitle;
@end

View File

@@ -81,3 +81,11 @@ using namespace mozilla::a11y;
}
@end
@implementation MOXLabelAccessible
- (NSString*)moxTitle {
return @"";
}
@end

View File

@@ -22,8 +22,8 @@ addAccessibleTask(
let n1 = getNativeInterface(accDoc, "n1");
let n1Label = n1.getAttributeValue("AXTitleUIElement");
// XXX: In Safari the label is an AXText with an AXValue,
// here it is an AXGroup witth an AXTitle
is(n1Label.getAttributeValue("AXTitle"), "Label");
// we emulate that so VoiceOver does not speak the label twice.
is(n1Label.getAttributeValue("AXTitle"), "");
let n2 = getNativeInterface(accDoc, "n2");
is(n2.getAttributeValue("AXDescription"), "Two Labels");