Bug 1442196 - Expose an XML role of 'form' on a form element if it has an accessible name, r?surkov
MozReview-Commit-ID: 8vhHcWyg2
--- a/accessible/generic/HyperTextAccessible.cpp
+++ b/accessible/generic/HyperTextAccessible.cpp
@@ -1149,16 +1149,23 @@ HyperTextAccessible::LandmarkRole() cons
// Only return xml-roles "region" if the section has an accessible name.
if (mContent->IsHTMLElement(nsGkAtoms::section)) {
nsAutoString name;
const_cast<HyperTextAccessible*>(this)->Name(name);
return name.IsEmpty() ? nullptr : nsGkAtoms::region;
}
+ // Only return xml-roles "form" if the form has an accessible name.
+ if (mContent->IsHTMLElement(nsGkAtoms::form)) {
+ nsAutoString name;
+ const_cast<HyperTextAccessible*>(this)->Name(name);
+ return name.IsEmpty() ? nullptr : nsGkAtoms::form;
+ }
+
return nullptr;
}
int32_t
HyperTextAccessible::OffsetAtPoint(int32_t aX, int32_t aY, uint32_t aCoordType)
{
nsIFrame* hyperFrame = GetFrame();
if (!hyperFrame)
--- a/accessible/tests/mochitest/elm/test_HTMLSpec.html
+++ b/accessible/tests/mochitest/elm/test_HTMLSpec.html
@@ -538,20 +538,29 @@
testElm("footer_in_fieldset", obj);
testElm("footer_in_figure", obj);
testElm("footer_in_td", obj);
// ////////////////////////////////////////////////////////////////////////
// HTML:form
obj = {
- role: ROLE_FORM
+ role: ROLE_FORM,
+ absentAttributes: { "xml-roles": "form" }
};
testElm("form", obj);
+ // HTML:form with an accessible name
+
+ obj = {
+ role: ROLE_FORM,
+ attributes: { "xml-roles": "form" }
+ };
+ testElm("named_form", obj);
+
// ////////////////////////////////////////////////////////////////////////
// // HTML:frameset, HTML:frame and HTML:iframe
obj = {
INTERNAL_FRAME: [ { // HTML:iframe
DOCUMENT: [ {
INTERNAL_FRAME: [ { // HTML:frame
DOCUMENT: [ { role: ROLE_TEXT_LEAF} ]
@@ -1544,16 +1553,17 @@
<figure>
<footer id="footer_in_figure">Some copyright info</footer>
</figure>
<table><tr><td>
<footer id="footer_in_td">Some copyright info</footer>
</td></tr></table>
<form id="form"></form>
+ <form id="named_form" aria-label="New form"></form>
<iframe id="frameset_container"
src="data:text/html,<html><frameset><frame src='data:text/html,hi'></frame></frameset></html>">
</iframe>
<h1 id="h1">heading1</h1>
<h2 id="h2">heading2</h2>
<h3 id="h3">heading3</h3>