Bug 1210630 - Section elements with accessible names should be mapped the same as ARIA role region, r=Jamie
authorMarco Zehe <mzehe@mozilla.com>
Wed, 24 Oct 2018 05:34:22 +0000
changeset 501930 be829221e462a24668b46f6d11b00402b9c01cf4
parent 501929 02d8210b89048b964a604d60b25b94d95b579cfb
child 501931 f266aa4cd4b04f7cec1fffeec4fccd1baafdf244
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamie
bugs1210630
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1210630 - Section elements with accessible names should be mapped the same as ARIA role region, r=Jamie Differential Revision: https://phabricator.services.mozilla.com/D9480
accessible/base/MarkupMap.h
accessible/generic/HyperTextAccessible.cpp
accessible/html/HTMLElementAccessibles.cpp
accessible/html/HTMLElementAccessibles.h
accessible/tests/mochitest/elm/test_HTMLSpec.html
--- a/accessible/base/MarkupMap.h
+++ b/accessible/base/MarkupMap.h
@@ -323,19 +323,23 @@ MARKUPMAP(p,
 MARKUPMAP(progress,
           New_HTMLProgress,
           0)
 
 MARKUPMAP(q,
           New_HyperText,
           0)
 
-MARKUPMAP(section,
-          New_HyperText,
-          roles::SECTION)
+MARKUPMAP(
+  section,
+  [](Element* aElement, Accessible* aContext) -> Accessible* {
+     return new HTMLSectionAccessible(aElement, aContext->Document());
+  },
+  0
+)
 
 MARKUPMAP(summary,
           New_HTMLSummary,
           roles::SUMMARY)
 
 MARKUPMAP(
   table,
   [](Element* aElement, Accessible* aContext) -> Accessible* {
--- a/accessible/generic/HyperTextAccessible.cpp
+++ b/accessible/generic/HyperTextAccessible.cpp
@@ -1137,23 +1137,16 @@ HyperTextAccessible::LandmarkRole() cons
   if (mContent->IsHTMLElement(nsGkAtoms::aside)) {
     return nsGkAtoms::complementary;
   }
 
   if (mContent->IsHTMLElement(nsGkAtoms::main)) {
     return nsGkAtoms::main;
   }
 
-  // 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;
--- a/accessible/html/HTMLElementAccessibles.cpp
+++ b/accessible/html/HTMLElementAccessibles.cpp
@@ -243,8 +243,34 @@ HTMLHeaderOrFooterAccessible::LandmarkRo
 
     if (mContent->IsHTMLElement(nsGkAtoms::footer)) {
       return nsGkAtoms::contentinfo;
     }
   }
 
   return nullptr;
 }
+
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLSectionAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+role
+HTMLSectionAccessible::NativeRole() const
+{
+  nsAutoString name;
+  const_cast<HTMLSectionAccessible*>(this)->Name(name);
+  return name.IsEmpty() ? roles::SECTION : roles::LANDMARK;
+}
+
+nsAtom*
+HTMLSectionAccessible::LandmarkRole() const
+{
+  if (!HasOwnContent()) {
+    return nullptr;
+  }
+
+  // Only return xml-roles "region" if the section has an accessible name.
+  nsAutoString name;
+  const_cast<HTMLSectionAccessible*>(this)->Name(name);
+  return name.IsEmpty() ? nullptr : nsGkAtoms::region;
+}
--- a/accessible/html/HTMLElementAccessibles.h
+++ b/accessible/html/HTMLElementAccessibles.h
@@ -132,12 +132,33 @@ public:
   // Accessible
   virtual nsAtom* LandmarkRole() const override;
   virtual a11y::role NativeRole() const override;
 
 protected:
   virtual ~HTMLHeaderOrFooterAccessible() {}
 };
 
+/**
+ * Used for HTML section element.
+ */
+class HTMLSectionAccessible : public HyperTextAccessibleWrap
+{
+public:
+
+  HTMLSectionAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+    HyperTextAccessibleWrap(aContent, aDoc) {}
+
+  NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLSectionAccessible,
+                                       HyperTextAccessibleWrap)
+
+  // Accessible
+  virtual nsAtom* LandmarkRole() const override;
+  virtual a11y::role NativeRole() const override;
+
+protected:
+  virtual ~HTMLSectionAccessible() = default;
+};
+
 } // namespace a11y
 } // namespace mozilla
 
 #endif
--- a/accessible/tests/mochitest/elm/test_HTMLSpec.html
+++ b/accessible/tests/mochitest/elm/test_HTMLSpec.html
@@ -1212,17 +1212,17 @@
         absentAttributes: { "xml-roles": "region" },
         interfaces: [ nsIAccessibleText, nsIAccessibleHyperText ],
       };
       testElm("section", obj);
 
       // HTML:section with an accessible name
 
       obj = {
-        role: ROLE_SECTION,
+        role: ROLE_LANDMARK,
         attributes: { "xml-roles": "region" },
         interfaces: [ nsIAccessibleText, nsIAccessibleHyperText ],
       };
       testElm("named_section", obj);
 
       // ////////////////////////////////////////////////////////////////////////
       // HTML:small contained by paragraph