Bug 1476347: Fix accessibility for HTML dt/dd with a div as its parent. r?MarcoZ draft
authorJames Teh <jteh@mozilla.com>
Wed, 18 Jul 2018 20:13:01 +1000
changeset 820662 b5a0e93a0db5664af096185ae36e2d50135dc279
parent 819645 8dab948a10f073a46f13f55f94d1f6514c7360ac
push id116890
push userbmo:jteh@mozilla.com
push dateFri, 20 Jul 2018 01:27:21 +0000
reviewersMarcoZ
bugs1476347
milestone63.0a1
Bug 1476347: Fix accessibility for HTML dt/dd with a div as its parent. r?MarcoZ It is conforming in HTML to use a div to group dt/dd elements. Previously, we didn't create an accessible for dt/dd elements in this case. MozReview-Commit-ID: 8GDDxU3RbLd
accessible/base/MarkupMap.h
accessible/base/nsAccessibilityService.cpp
accessible/tests/mochitest/tree/test_list.html
--- a/accessible/base/MarkupMap.h
+++ b/accessible/base/MarkupMap.h
@@ -26,33 +26,33 @@ MARKUPMAP(aside,
           New_HyperText,
           roles::NOTE)
 
 MARKUPMAP(blockquote,
           New_HyperText,
           roles::BLOCKQUOTE)
 
 MARKUPMAP(dd,
-          New_HTMLDefinition,
+          New_HTMLDtOrDd<HyperTextAccessibleWrap>,
           roles::DEFINITION)
 
 MARKUPMAP(details,
           New_HyperText,
           roles::DETAILS)
 
 MARKUPMAP(div,
           nullptr,
           roles::SECTION)
 
 MARKUPMAP(dl,
           New_HTMLList,
           roles::DEFINITION_LIST)
 
 MARKUPMAP(dt,
-          New_HTMLListitem,
+          New_HTMLDtOrDd<HTMLLIAccessible>,
           roles::TERM)
 
 MARKUPMAP(figcaption,
           New_HTMLFigcaption,
           roles::CAPTION)
 
 MARKUPMAP(figure,
           New_HTMLFigure,
--- a/accessible/base/nsAccessibilityService.cpp
+++ b/accessible/base/nsAccessibilityService.cpp
@@ -214,21 +214,30 @@ New_HTMLListitem(Element* aElement, Acce
   // it unconditionally by tag name. nsBlockFrame creates the list item
   // accessible for other elements styled as list items.
   if (aContext->IsList() && aContext->GetContent() == aElement->GetParent())
     return new HTMLLIAccessible(aElement, aContext->Document());
 
   return nullptr;
 }
 
+template<typename AccClass>
 static Accessible*
-New_HTMLDefinition(Element* aElement, Accessible* aContext)
+New_HTMLDtOrDd(Element* aElement, Accessible* aContext)
 {
-  if (aContext->IsList())
-    return new HyperTextAccessibleWrap(aElement, aContext->Document());
+  nsIContent* parent = aContext->GetContent();
+  if (parent->IsHTMLElement(nsGkAtoms::div)) {
+    // It is conforming in HTML to use a div to group dt/dd elements.
+    parent = parent->GetParent();
+  }
+
+  if (parent && parent->IsHTMLElement(nsGkAtoms::dl)) {
+    return new AccClass(aElement, aContext->Document());
+  }
+
   return nullptr;
 }
 
 static Accessible* New_HTMLLabel(Element* aElement, Accessible* aContext)
   { return new HTMLLabelAccessible(aElement, aContext->Document()); }
 
 static Accessible* New_HTMLInput(Element* aElement, Accessible* aContext)
 {
--- a/accessible/tests/mochitest/tree/test_list.html
+++ b/accessible/tests/mochitest/tree/test_list.html
@@ -143,16 +143,39 @@
             { TEXT_LEAF: [] }
           ] }
         ] };
       testAccessibleTree("list8", tree);
 
       // span having display:list-item style
       testAccessibleTree("list9", discAccTree);
 
+      // dl with div grouping dt/dd
+      tree =
+        { DEFINITION_LIST: [ // dl
+          { SECTION: [ // div
+            { TERM: [ // dt
+              { TEXT_LEAF: [] },
+            ] },
+            { DEFINITION: [ // dd
+              { TEXT_LEAF: [] }
+            ] },
+          ] },
+          { SECTION: [ // div
+            { TERM: [ // dt
+              { TEXT_LEAF: [] }
+            ] },
+            { DEFINITION: [ // dd
+              { TEXT_LEAF: [] }
+            ] }
+          ] }
+        ] };
+
+      testAccessibleTree("list10", tree);
+
       SimpleTest.finish();
     }
 
     SimpleTest.waitForExplicitFinish();
     addA11yLoadEvent(doTest);
   </script>
 </head>
 <body>
@@ -236,10 +259,17 @@
   </ul>
 
   <!-- list-item display style -->
   <ul id="list9">
     <span id="l9_li1" style="display:list-item">Oranges</span>
     <span id="l9_li2" style="display:list-item">Apples</span>
     <span id="l9_li3" style="display:list-item">Bananas</span>
   </ul>
+
+  <!-- dl with div grouping dd/dt elements (bug 1476347) -->
+  <dl id="list10">
+    <div><dt>item1</dt><dd>description</dd></div>
+    <div><dt>item2</td><dd>description</dd></div>
+  </dl>
+
 </body>
 </html>