Bug 1568360 - Don't calculate the accessible names for table or grid rows unless they have an explicit ARIA role, r=Jamie

Previously, we would always calculate the name for tr elements from their descendants unconditionally. Assistive technologies aren't using this information, moreover, it causes problems if the name gets too long, for example in layout tables.

We now only calculate the name if the tr element has an explicit ARIA role.

Differential Revision: https://phabricator.services.mozilla.com/D39314

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Marco Zehe 2019-07-26 09:14:55 +00:00
parent e17d60cbf4
commit b999f08200
5 changed files with 57 additions and 0 deletions

View File

@ -472,6 +472,19 @@ GroupPos ARIARowAccessible::GroupPosition() {
return AccessibleWrap::GroupPosition(); return AccessibleWrap::GroupPosition();
} }
// Accessible protected
ENameValueFlag ARIARowAccessible::NativeName(nsString& aName) const {
// We want to calculate the name from content only if an ARIA role is
// present. ARIARowAccessible might also be used by tables with
// display:block; styling, in which case we do not want the name from
// content.
if (HasStrongARIARole()) {
return AccessibleWrap::NativeName(aName);
}
return eNameOK;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// ARIAGridCellAccessible // ARIAGridCellAccessible
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -81,6 +81,9 @@ class ARIARowAccessible : public HyperTextAccessibleWrap {
protected: protected:
virtual ~ARIARowAccessible() {} virtual ~ARIARowAccessible() {}
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) const override;
}; };
/** /**

View File

@ -328,6 +328,17 @@ GroupPos HTMLTableRowAccessible::GroupPosition() {
return AccessibleWrap::GroupPosition(); return AccessibleWrap::GroupPosition();
} }
// Accessible protected
ENameValueFlag HTMLTableRowAccessible::NativeName(nsString& aName) const {
// For table row accessibles, we only want to calculate the name from the
// sub tree if an ARIA role is present.
if (HasStrongARIARole()) {
return AccessibleWrap::NativeName(aName);
}
return eNameOK;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// HTMLTableAccessible // HTMLTableAccessible
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -99,6 +99,9 @@ class HTMLTableRowAccessible : public HyperTextAccessibleWrap {
protected: protected:
virtual ~HTMLTableRowAccessible() {} virtual ~HTMLTableRowAccessible() {}
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) const override;
}; };
/** /**

View File

@ -221,6 +221,19 @@
testName("test_note", null); testName("test_note", null);
// //////////////////////////////////////////////////////////////////////
// Tests for name from sub tree of tr element.
// By default, we want no name.
testName("NoNameForTR", null);
testName("NoNameForNonStandardTR", null);
// But we want it if the tr has an ARIA role.
testName("NameForTRBecauseStrongARIA", "a b");
// But not if it is a weak (landmark) ARIA role
testName("NoNameForTRBecauseWeakARIA", null);
SimpleTest.finish(); SimpleTest.finish();
} }
@ -631,5 +644,19 @@
<!-- duplicate announcement --> <!-- duplicate announcement -->
<div id="test_note" role="note">subtree</div> <div id="test_note" role="note">subtree</div>
<!-- No name for tr from its sub tree -->
<table><tr id="NoNameForTR"><th>a</th><td>b</td></tr></table>
<table style="display: block;">
<tr id="NoNameForNonStandardTR" style="display:block;">
<th>a</th><td>b</td>
</tr>
</table>
<!-- Name from sub tree of tr, because it has a strong ARIA role -->
<table><tr id="NameForTRBecauseStrongARIA" role="row"><th>a</th><td>b</td></tr></table>
<!-- No name for tr because of weak (landmark) role -->
<table><tr id="NoNameForTRBecauseWeakARIA" role="main"><th>a</th><td>b</td></tr></table>
</body> </body>
</html> </html>