Bug 1420773 - Only return HTML captions as HTML table captions. r=morgan

Differential Revision: https://phabricator.services.mozilla.com/D106528
This commit is contained in:
Eitan Isaacson 2021-03-01 18:06:11 +00:00
parent aa458e10e9
commit 4f4b2106c4
2 changed files with 14 additions and 1 deletions

View File

@ -426,7 +426,16 @@ Relation HTMLTableAccessible::RelationByType(RelationType aType) const {
LocalAccessible* HTMLTableAccessible::Caption() const {
LocalAccessible* child = mChildren.SafeElementAt(0, nullptr);
return child && child->Role() == roles::CAPTION ? child : nullptr;
// Since this is an HTML table the caption needs to be a caption
// element with no ARIA role (except for a reduntant role='caption').
// If we did a full Role() calculation here we risk getting into an infinite
// loop where the parent role would depend on its name which would need to be
// calculated by retrieving the caption (bug 1420773.)
return child && child->NativeRole() == roles::CAPTION &&
(!child->HasStrongARIARole() ||
child->IsARIARole(nsGkAtoms::caption))
? child
: nullptr;
}
void HTMLTableAccessible::Summary(nsString& aSummary) {

View File

@ -74,6 +74,8 @@
testRole("aria_region_has_labelledby", ROLE_REGION);
testRole("aria_region_has_title", ROLE_REGION);
testRole("aria_region_empty_name", ROLE_TEXT);
testRole("aria_region_as_table_with_caption", ROLE_REGION);
testRole("aria_region_as_table_with_miscaption", ROLE_TABLE);
testRole("aria_row", ROLE_ROW);
testRole("aria_rowheader", ROLE_ROWHEADER);
testRole("aria_scrollbar", ROLE_SCROLLBAR);
@ -304,6 +306,8 @@
<span id="aria_region_has_labelledby" role="region" aria-labelledby="label"><span id="label" aria-label="label"></span>
<span id="aria_region_has_title" role="region" title="title"></span>
<span id="aria_region_empty_name" role="region" aria-label="" title="" aria-labelledby="empty"></span><span id="empty"></span>
<table id="aria_region_as_table_with_caption" role="region"><caption>hello</caption></table>
<table id="aria_region_as_table_with_miscaption" role="region"><caption role="option">hello</caption></table>
<span id="aria_row" role="row"></span>
<span id="aria_rowheader" role="rowheader"></span>
<span id="aria_scrollbar" role="scrollbar"></span>