Bug 1442196 - Expose an XML role of 'form' on a form element if it has an accessible name, r?surkov draft
authorMarco Zehe <mzehe@mozilla.com>
Mon, 05 Mar 2018 12:37:35 +0100
changeset 763110 3f9f40c372c8b0e45eb4a5ea65f326eccbccd741
parent 763109 51200c0fdaddb2749549a82596da5323a4cbd499
push id101338
push userbmo:mzehe@mozilla.com
push dateMon, 05 Mar 2018 11:38:49 +0000
reviewerssurkov
bugs1442196
milestone60.0a1
Bug 1442196 - Expose an XML role of 'form' on a form element if it has an accessible name, r?surkov MozReview-Commit-ID: 8vhHcWyg2
accessible/generic/HyperTextAccessible.cpp
accessible/tests/mochitest/elm/test_HTMLSpec.html
--- 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>