Skip to content

Commit

Permalink
AX: Expose suggestion, insertion, deletion roles and attributes
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=242401

Reviewed by Andres Gonzalez.

At present, screenreaders on iOS and macOS do not convey information related to elements
with an insertion, deletion, or suggestion role (or, alternatively, `<ins>` and `<del>`) besides their content.

To appropriately convey the proper annotation information and purpose, insertions, deletions,
and suggestions are now exposed via new attributes and with new methods on the Web Accessibility
 Wrapper for iOS. This allows screenreaders to appropriately label the start and end positions
 of these elements.

* LayoutTests/accessibility/ios-simulator/suggestion-insertion-deletion-attributes-expected.txt: Added.
* LayoutTests/accessibility/ios-simulator/suggestion-insertion-deletion-attributes.html: Added.
* LayoutTests/accessibility/mac/attributed-string-includes-insertion-deletion-expected.txt: Added.
* LayoutTests/accessibility/mac/attributed-string-includes-insertion-deletion.html: Added.
* LayoutTests/accessibility/mac/suggestion-subrole-and-roledescription-expected.txt: Added.
* LayoutTests/accessibility/mac/suggestion-subrole-and-roledescription.html: Added.

Tests to check for the correct subrole and attributes.

* Source/WebCore/accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::text const):

Exposes inner content of static text methods.

* Source/WebCore/accessibility/AccessibilityObject.cpp:
(WebCore::initializeRoleMap):
(WebCore::AccessibilityObject::roleDescription const):
* Source/WebCore/accessibility/AccessibilityObjectInterface.h:
(WebCore::accessibilityRoleToString):
* Source/WebCore/accessibility/mac/AccessibilityObjectMac.mm:
(WebCore::AccessibilityObject::subrolePlatformString const):
(WebCore::Accessibility::createPlatformRoleMap):

Adds new mappings for "suggestion" role so they are recognized as roles.

* Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
(-[WebAccessibilityObjectWrapper determineIsAccessibilityElement]):
(-[WebAccessibilityObjectWrapper accessibilityIsInsertion]):
(-[WebAccessibilityObjectWrapper accessibilityIsDeletion]):

New methods that check for an ancestor that is an insertion or deletion, respectively, to convey if
we are inside an element with one of those roles.

(-[WebAccessibilityObjectWrapper accessibilityIsFirstItemInSuggestion]):
(-[WebAccessibilityObjectWrapper accessibilityIsLastItemInSuggestion]):

New methods that look for an ancestor that is a suggestion in addition to checking whether a
subelement in a suggestion is the first or last item, so that screenreaders can convey the start and end points for a suggestion.

* Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(AXAttributeStringSetStyle):

Applies the right attributes for insertions, deletions, and suggestions based on traversing the ancestors.

(AXAttributedStringAppendText):

Fixes an issue when appending text where the appended string inherits the attributes of the root string.

(-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):

* Source/WebCore/en.lproj/Localizable.strings:
* Source/WebCore/platform/LocalizedStrings.cpp:
(WebCore::AXSuggestionRoleDescriptionText):
* Source/WebCore/platform/LocalizedStrings.h:

* Tools/DumpRenderTree/AccessibilityUIElement.cpp:
(getIsInsertionCallback):
(getIsDeletionCallback):
(getIsFirstItemInSuggestionCallback):
(getIsLastItemInSuggestionCallback):
(AccessibilityUIElement::getJSClass):
* Tools/DumpRenderTree/AccessibilityUIElement.h:
* Tools/DumpRenderTree/ios/AccessibilityUIElementIOS.mm:
(AccessibilityUIElement::isInsertion):
(AccessibilityUIElement::isDeletion):
(AccessibilityUIElement::isFirstItemInSuggestion):
(AccessibilityUIElement::isLastItemInSuggestion):
* Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
* Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
* Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
(WTR::AccessibilityUIElement::isInsertion const):
(WTR::AccessibilityUIElement::isDeletion const):
(WTR::AccessibilityUIElement::isFirstItemInSuggestion const):
(WTR::AccessibilityUIElement::isLastItemInSuggestion const):
* Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
(WTR::AccessibilityUIElement::isInsertion const):
(WTR::AccessibilityUIElement::isDeletion const):
(WTR::AccessibilityUIElement::isFirstItemInSuggestion const):
(WTR::AccessibilityUIElement::isLastItemInSuggestion const):

Exposes the new methods for use in testing.

Canonical link: https://commits.webkit.org/252516@main
  • Loading branch information
hoffmanjoshua authored and AndresGonzalezApple committed Jul 15, 2022
1 parent 86cccca commit 3395d79
Show file tree
Hide file tree
Showing 24 changed files with 420 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This test makes sure that suggestions, insertions, and deletions expose the right attributes.
PASS: ins1.isInsertion === true
PASS: ins1.isFirstItemInSuggestion === true
PASS: ins1.isLastItemInSuggestion === false
PASS: del1.isDeletion === true
PASS: del1.isLastItemInSuggestion === true
PASS: del1.isFirstItemInSuggestion === false
PASS: ins2.isInsertion === true
PASS: ins2.isFirstItemInSuggestion === true
PASS: ins3.isInsertion === true
PASS: ins2.isLastItemInSuggestion === false
PASS: del2.isLastItemInSuggestion === true
PASS: ins3.isFirstItemInSuggestion === false

PASS successfullyParsed is true

TEST COMPLETE
inserted textdeleted text
inserted textdeleted text
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="../../resources/accessibility-helper.js"></script>
</head>
<body>

<div id="sug1" role="suggestion"><span id="ins1" role="insertion">inserted text</span><span id="del1" role="deletion">deleted text</span></div>

<div id="sug2" role="suggestion"><span id="ins2" role="insertion"><b>inserted</b> text</span><span id="del2" role="deletion">deleted text</span></div>


<script>

if (window.accessibilityController) {

let output = "This test makes sure that suggestions, insertions, and deletions expose the right attributes.\n";

var ins1 = accessibilityController.accessibleElementById("ins1").childAtIndex(0);
output += expect("ins1.isInsertion", "true");
output += expect("ins1.isFirstItemInSuggestion", "true");
output += expect("ins1.isLastItemInSuggestion", "false");

var del1 = accessibilityController.accessibleElementById("del1").childAtIndex(0);
output += expect("del1.isDeletion", "true");
output += expect("del1.isLastItemInSuggestion", "true");
output += expect("del1.isFirstItemInSuggestion", "false");

var ins2 = accessibilityController.accessibleElementById("ins2").childAtIndex(0);
var ins3 = accessibilityController.accessibleElementById("ins2").childAtIndex(1);
var del2 = accessibilityController.accessibleElementById("del2").childAtIndex(0);
output += expect("ins2.isInsertion", "true");
output += expect("ins2.isFirstItemInSuggestion", "true");
output += expect("ins3.isInsertion", "true");
output += expect("ins2.isLastItemInSuggestion", "false");
output += expect("del2.isLastItemInSuggestion", "true");
output += expect("ins3.isFirstItemInSuggestion", "false");

debug(output);
}

</script>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This verifies that using the insertion and deletion roles adds the attribute to the attributed string.
PASS: item1.attributedStringForTextMarkerRangeContainsAttribute('AXIsSuggestedInsertion', markerRange) === true
PASS: item2.attributedStringForTextMarkerRangeContainsAttribute('AXIsSuggestedDeletion', markerRange) === true
PASS: item3.attributedStringForTextMarkerRangeContainsAttribute('AXIsSuggestion', markerRange) === true

PASS successfullyParsed is true

TEST COMPLETE
inserted text
deleted text
hellohi
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="../../resources/accessibility-helper.js"></script>
</head>
<body id="body" role="group">

<div id="item1"><span role="insertion">inserted text</span></div>
<div id="item2"><span role="deletion">deleted text</span></div>
<div id="item3"><span role="suggestion"><span role="insertion">hello</span><span role="deletion">hi</span></span></div>

<script>
if (window.accessibilityController) {
let output = "This verifies that using the insertion and deletion roles adds the attribute to the attributed string.\n";

var item1 = accessibilityController.accessibleElementById("item1");
var markerRange = item1.textMarkerRangeForElement(item1);
output += expect("item1.attributedStringForTextMarkerRangeContainsAttribute('AXIsSuggestedInsertion', markerRange)", "true");

var item2 = accessibilityController.accessibleElementById("item2");
var markerRange = item2.textMarkerRangeForElement(item2);
output += expect("item2.attributedStringForTextMarkerRangeContainsAttribute('AXIsSuggestedDeletion', markerRange)", "true");

var item3 = accessibilityController.accessibleElementById("item3");
var markerRange = item3.textMarkerRangeForElement(item3);
output += expect("item3.attributedStringForTextMarkerRangeContainsAttribute('AXIsSuggestion', markerRange)", "true");

debug(output);
}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
This tests that suggestion, insertion, and deletion elements have the right subroles.
PASS: suggestion1.role === 'AXRole: AXGroup'
PASS: suggestion1.subrole === 'AXSubrole: AXSuggestion'
PASS: suggestion1.roleDescription === 'AXRoleDescription: suggestion'
PASS: ins1.subrole === 'AXSubrole: AXInsertStyleGroup'
PASS: ins2.subrole === 'AXSubrole: AXInsertStyleGroup'
PASS: del1.subrole === 'AXSubrole: AXDeleteStyleGroup'
PASS: del2.subrole === 'AXSubrole: AXDeleteStyleGroup'

PASS successfullyParsed is true

TEST COMPLETE
This is some test to insert and delete
this is inserted text.
This is also inserted text
This is deleted text
this is also deleted text
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="../../resources/accessibility-helper.js"></script>
</head>
<body id="body">

<div id="suggestion1" role="suggestion">This is some test to <span role="insertion">insert</span> and <span role="deletion">delete</span></div>

<div id="ins1" role="insertion">this is inserted text.</div>
<ins id="ins2">This is also inserted text</ins>

<div id="del1" role="deletion">This is deleted text</div>
<del id="del2">this is also deleted text</div>

<script>
if (window.accessibilityController) {
let output = "This tests that suggestion, insertion, and deletion elements have the right subroles.\n";

var suggestion1 = accessibilityController.accessibleElementById("suggestion1");
var ins1 = accessibilityController.accessibleElementById("ins1");
var ins2 = accessibilityController.accessibleElementById("ins2");
var del1 = accessibilityController.accessibleElementById("del1");
var del2 = accessibilityController.accessibleElementById("del2");

output += expect("suggestion1.role", "'AXRole: AXGroup'");
output += expect("suggestion1.subrole", "'AXSubrole: AXSuggestion'");
output += expect("suggestion1.roleDescription", "'AXRoleDescription: suggestion'");

output += expect("ins1.subrole", "'AXSubrole: AXInsertStyleGroup'");
output += expect("ins2.subrole", "'AXSubrole: AXInsertStyleGroup'");

output += expect("del1.subrole", "'AXSubrole: AXDeleteStyleGroup'");
output += expect("del2.subrole", "'AXSubrole: AXDeleteStyleGroup'");

debug(output);
}

</script>

</body>
</html>
3 changes: 3 additions & 0 deletions Source/WebCore/accessibility/AccessibilityNodeObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,9 @@ String AccessibilityNodeObject::text() const
return textOrder[0].text;
}

if (isStaticText())
return textUnderElement();

if (!isTextControl())
return String();

Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/accessibility/AccessibilityObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,7 @@ static void initializeRoleMap()
{ "spinbutton"_s, AccessibilityRole::SpinButton },
{ "status"_s, AccessibilityRole::ApplicationStatus },
{ "subscript"_s, AccessibilityRole::Subscript },
{ "suggestion"_s, AccessibilityRole::Suggestion },
{ "superscript"_s, AccessibilityRole::Superscript },
{ "switch"_s, AccessibilityRole::Switch },
{ "tab"_s, AccessibilityRole::Tab },
Expand Down Expand Up @@ -2733,6 +2734,9 @@ String AccessibilityObject::roleDescription() const

if (roleValue() == AccessibilityRole::Figure)
return AXFigureText();

if (roleValue() == AccessibilityRole::Suggestion)
return AXSuggestionRoleDescriptionText();

return roleDescription;
}
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/accessibility/AccessibilityObjectInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ enum class AccessibilityRole {
Splitter,
StaticText,
Subscript,
Suggestion,
Summary,
Superscript,
Switch,
Expand Down Expand Up @@ -503,6 +504,8 @@ ALWAYS_INLINE String accessibilityRoleToString(AccessibilityRole role)
return "StaticText"_s;
case AccessibilityRole::Subscript:
return "Subscript"_s;
case AccessibilityRole::Suggestion:
return "Suggestion"_s;
case AccessibilityRole::Summary:
return "Summary"_s;
case AccessibilityRole::Superscript:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,7 @@ - (BOOL)determineIsAccessibilityElement
case AccessibilityRole::SplitGroup:
case AccessibilityRole::Splitter:
case AccessibilityRole::Subscript:
case AccessibilityRole::Suggestion:
case AccessibilityRole::Superscript:
case AccessibilityRole::Summary:
case AccessibilityRole::SystemWide:
Expand Down Expand Up @@ -2770,6 +2771,64 @@ - (NSString *)accessibilityIdentifier
return self.axBackingObject->identifierAttribute();
}

- (BOOL)accessibilityIsInsertion
{
if (![self _prepareAccessibilityCall])
return NO;

return Accessibility::findAncestor(*self.axBackingObject, false, [] (const auto& object) {
return object.roleValue() == AccessibilityRole::Insertion;
});
}

- (BOOL)accessibilityIsDeletion
{
if (![self _prepareAccessibilityCall])
return NO;

return Accessibility::findAncestor(*self.axBackingObject, false, [] (const auto& object) {
return object.roleValue() == AccessibilityRole::Deletion;
});
}

- (BOOL)accessibilityIsFirstItemInSuggestion
{
if (![self _prepareAccessibilityCall])
return NO;

auto* object = self.axBackingObject;
auto* parent = object->parentObjectUnignored();

while (parent) {
if (!parent->children().size() || parent->children()[0] != object)
return NO;
if (parent->roleValue() == AccessibilityRole::Suggestion)
return YES;
object = parent;
parent = object->parentObjectUnignored();
}
return NO;
}

- (BOOL)accessibilityIsLastItemInSuggestion
{
if (![self _prepareAccessibilityCall])
return NO;

auto* object = self.axBackingObject;
auto* parent = object->parentObjectUnignored();

while (parent) {
if (!parent->children().size() || parent->children()[parent->children().size() - 1] != object)
return NO;
if (parent->roleValue() == AccessibilityRole::Suggestion)
return YES;
object = parent;
parent = object->parentObjectUnignored();
}
return NO;
}

- (NSArray<NSString *> *)accessibilitySpeechHint
{
if (![self _prepareAccessibilityCall])
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/accessibility/mac/AccessibilityObjectMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ static bool shouldIgnoreGroup(const AccessibilityObject& axObject)
return "AXDescription"_s;
case AccessibilityRole::WebApplication:
return "AXWebApplication"_s;
case AccessibilityRole::Suggestion:
return "AXSuggestion"_s;
// Default doesn't return anything, so roles defined below can be chosen.
default:
break;
Expand Down Expand Up @@ -686,6 +688,7 @@ PlatformRoleMap createPlatformRoleMap()
{ AccessibilityRole::Subscript, NSAccessibilityGroupRole },
{ AccessibilityRole::Superscript, NSAccessibilityGroupRole },
{ AccessibilityRole::Model, NSAccessibilityGroupRole },
{ AccessibilityRole::Suggestion, NSAccessibilityGroupRole },
};
PlatformRoleMap roleMap;
for (auto& role : roles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#import "ContextMenuController.h"
#import "Editing.h"
#import "Editor.h"
#import "ElementInlines.h"
#import "Font.h"
#import "FontCascade.h"
#import "Frame.h"
Expand Down Expand Up @@ -860,6 +861,15 @@ static void AXAttributeStringSetStyle(NSMutableAttributedString* attrString, Ren
for (Node* node = renderer->node(); node; node = node->parentNode()) {
if (node->hasTagName(HTMLNames::markTag))
AXAttributeStringSetNumber(attrString, @"AXHighlight", @YES, range);
if (auto* element = dynamicDowncast<Element>(*node)) {
auto& roleValue = element->attributeWithoutSynchronization(HTMLNames::roleAttr);
if (equalLettersIgnoringASCIICase(roleValue, "insertion"_s))
AXAttributeStringSetNumber(attrString, @"AXIsSuggestedInsertion", @YES, range);
else if (equalLettersIgnoringASCIICase(roleValue, "deletion"_s))
AXAttributeStringSetNumber(attrString, @"AXIsSuggestedDeletion", @YES, range);
else if (equalLettersIgnoringASCIICase(roleValue, "suggestion"_s))
AXAttributeStringSetNumber(attrString, @"AXIsSuggestion", @YES, range);
}
}
}

Expand Down Expand Up @@ -993,7 +1003,8 @@ static void AXAttributedStringAppendText(NSMutableAttributedString* attrString,
NSRange attrStringRange = NSMakeRange([attrString length], text.length());

// append the string from this node
[[attrString mutableString] appendString:text.createNSStringWithoutCopying().get()];
NSAttributedString *stringToAppend = adoptNS([[NSAttributedString alloc] initWithString:text.createNSStringWithoutCopying().get()]).autorelease();
[attrString appendAttributedString:stringToAppend];

// add new attributes and remove irrelevant inherited ones
// NOTE: color attributes are handled specially because -[NSMutableAttributedString addAttribute: value: range:] does not merge
Expand Down Expand Up @@ -4025,6 +4036,11 @@ - (id)accessibilityAttributeValue:(NSString*)attribute forParameter:(id)paramete
}
}

if (backingObject->isTextControl() || backingObject->isStaticText()) {
if ([attribute isEqualToString:(NSString *)kAXAttributedStringForRangeParameterizedAttribute])
return rangeSet ? [self doAXAttributedStringForRange:range] : nil;
}

if (backingObject->isTextControl()) {
if ([attribute isEqualToString: (NSString *)kAXLineForIndexParameterizedAttribute]) {
int lineNumber = backingObject->doAXLineForIndex([number intValue]);
Expand Down Expand Up @@ -4068,9 +4084,6 @@ - (id)accessibilityAttributeValue:(NSString*)attribute forParameter:(id)paramete
if ([attribute isEqualToString: (NSString*)kAXRTFForRangeParameterizedAttribute])
return rangeSet ? [self doAXRTFForRange:range] : nil;

if ([attribute isEqualToString: (NSString*)kAXAttributedStringForRangeParameterizedAttribute])
return rangeSet ? [self doAXAttributedStringForRange:range] : nil;

if ([attribute isEqualToString: (NSString*)kAXStyleRangeForIndexParameterizedAttribute]) {
PlainTextRange textRange = backingObject->doAXStyleRangeForIndex([number intValue]);
return [NSValue valueWithRange: NSMakeRange(textRange.start, textRange.length)];
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,9 @@
/* accessibility role description for a footer */
"footer" = "footer";

/* Suggestion role description for a suggestion group */
"suggestion" = "suggestion";

/* HTTP result code string */
"forbidden" = "forbidden";

Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/platform/LocalizedStrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,11 @@ String AXFooterRoleDescriptionText()
return WEB_UI_STRING("footer", "accessibility role description for a footer");
}

String AXSuggestionRoleDescriptionText()
{
return WEB_UI_STRING("suggestion", "accessibility role description for a suggestion element");
}

String AXFileUploadButtonText()
{
return WEB_UI_STRING("file upload button", "accessibility role description for a file upload button");
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/platform/LocalizedStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ namespace WebCore {
String AXDescriptionListTermText();
String AXDescriptionListDetailText();
String AXFooterRoleDescriptionText();
String AXSuggestionRoleDescriptionText();
String AXFileUploadButtonText();
String AXOutputText();
String AXSearchFieldCancelButtonText();
Expand Down
Loading

0 comments on commit 3395d79

Please sign in to comment.