From 7d0b534f272f7e98016633bfd92ce066dca2148b Mon Sep 17 00:00:00 2001 From: Morgan Reschenberg Date: Tue, 10 Mar 2020 21:50:54 +0000 Subject: [PATCH] Bug 1618716: Return the value associated with the aria-invalid attribute instead of relying on the state flag alone. r=eeejay Differential Revision: https://phabricator.services.mozilla.com/D66297 --HG-- extra : moz-landing-system : lando --- accessible/mac/mozTextAccessible.mm | 40 +++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/accessible/mac/mozTextAccessible.mm b/accessible/mac/mozTextAccessible.mm index 69e47712e63a..499243786cdc 100644 --- a/accessible/mac/mozTextAccessible.mm +++ b/accessible/mac/mozTextAccessible.mm @@ -108,7 +108,24 @@ inline NSString* ToNSString(id aValue) { } if ([attribute isEqualToString:@"AXInvalid"]) { - return [NSNumber numberWithBool:!!(accWrap->State() & states::INVALID)]; + if (accWrap->State() & states::INVALID) { + // If the attribute exists, it has one of four values: true, false, + // grammar, or spelling. We query the attribute value here in order + // to find the correct string to return. + nsAutoString invalidStr; + nsCOMPtr attributes = accWrap->Attributes(); + nsAccUtils::GetAccAttr(attributes, nsGkAtoms::invalid, invalidStr); + if (invalidStr.IsEmpty()) { + // if the attribute had no value, we should still respect the + // invalid state flag. + return @"true"; + } + return nsCocoaUtils::ToNSString(invalidStr); + } + // If the flag is not set, we return false. + return @"false"; + } else { + // if the attribute does not exist, we assume } } else if (ProxyAccessible* proxy = [self getProxyAccessible]) { if ([attribute isEqualToString:@"AXRequired"]) { @@ -116,7 +133,26 @@ inline NSString* ToNSString(id aValue) { } if ([attribute isEqualToString:@"AXInvalid"]) { - return [NSNumber numberWithBool:!!(proxy->State() & states::INVALID)]; + if (proxy->State() & states::INVALID) { + // Similar to the accWrap case above, we iterate through our attributes + // to find the value for `invalid`. + AutoTArray attrs; + proxy->DefaultTextAttributes(&attrs); + for (size_t i = 0; i < attrs.Length(); i++) { + if (attrs.ElementAt(i).Name() == "invalid") { + nsString invalidStr = attrs.ElementAt(i).Value(); + if (invalidStr.IsEmpty()) { + break; + } + return nsCocoaUtils::ToNSString(invalidStr); + } + } + // if we iterated through our attributes and didn't find `invalid`, + // or if the invalid attribute had no value, we should still respect + // the invalid flag and return true. + return @"true"; + } + return @"false"; } }