AX: support role mapping for HTML5 section elements
authorcfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Oct 2011 19:01:28 +0000 (19:01 +0000)
committercfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Oct 2011 19:01:28 +0000 (19:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=69150

Source/WebCore:

We need to map these HTML5 elements to appropriate ARIA roles. That mapping is:
  article -> Document article
  nav -> Landmark navigation
  aside -> Landmark complementary
  section -> Document region
  address -> Landmark content info
  header -> Landmark banner (unless it's in an article or section)
  footer -> Landmark content info (unless it's in an article or section)

Reviewed by Darin Adler.

Test: platform/mac/accessibility/html-section-elements.html

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::isDescendantOfElementType):
(WebCore::AccessibilityRenderObject::determineAccessibilityRole):
* accessibility/AccessibilityRenderObject.h:

LayoutTests:

Reviewed by Darin Adler.

* platform/mac/accessibility/html-section-elements-expected.txt: Added.
* platform/mac/accessibility/html-section-elements.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96524 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/mac/accessibility/html-section-elements-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/accessibility/html-section-elements.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/accessibility/AccessibilityRenderObject.h

index e7868e9..01d01b6 100644 (file)
@@ -1,5 +1,15 @@
 2011-10-03  Chris Fleizach  <cfleizach@apple.com>
 
+        AX: support role mapping for HTML5 section elements
+        https://bugs.webkit.org/show_bug.cgi?id=69150
+
+        Reviewed by Darin Adler.
+
+        * platform/mac/accessibility/html-section-elements-expected.txt: Added.
+        * platform/mac/accessibility/html-section-elements.html: Added.
+
+2011-10-03  Chris Fleizach  <cfleizach@apple.com>
+
         AX: click point for AXHeadings often returns point on empty space (results in wrong context menu)
         https://bugs.webkit.org/show_bug.cgi?id=69262
 
diff --git a/LayoutTests/platform/mac/accessibility/html-section-elements-expected.txt b/LayoutTests/platform/mac/accessibility/html-section-elements-expected.txt
new file mode 100644 (file)
index 0000000..51f6a59
--- /dev/null
@@ -0,0 +1,29 @@
+header
+footer
+section
+article
+nav
+aside
+Should be IGNORED because it's inside an article, so it should not be a landmark
+Should be IGNORED because it's inside an article, so it should not be a landmark
+Should be IGNORED because it's inside a section, so it should not be a landmark
+Should be IGNORED because it's inside a section, so it should not be a landmark
+This tests that the HTML5 section elements map to the correct AX roles.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS body.childAtIndex(0).subrole is 'AXSubrole: AXLandmarkBanner'
+PASS body.childAtIndex(1).subrole is 'AXSubrole: AXLandmarkContentInfo'
+PASS body.childAtIndex(2).subrole is 'AXSubrole: AXDocumentRegion'
+PASS body.childAtIndex(3).subrole is 'AXSubrole: AXDocumentArticle'
+PASS body.childAtIndex(4).subrole is 'AXSubrole: AXLandmarkNavigation'
+PASS body.childAtIndex(5).subrole is 'AXSubrole: AXLandmarkComplementary'
+PASS body.childAtIndex(6).childAtIndex(0).subrole is 'AXSubrole: '
+PASS body.childAtIndex(6).childAtIndex(1).subrole is 'AXSubrole: '
+PASS body.childAtIndex(7).childAtIndex(0).subrole is 'AXSubrole: '
+PASS body.childAtIndex(7).childAtIndex(1).subrole is 'AXSubrole: '
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/platform/mac/accessibility/html-section-elements.html b/LayoutTests/platform/mac/accessibility/html-section-elements.html
new file mode 100644 (file)
index 0000000..8a3fce5
--- /dev/null
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../fast/js/resources/js-test-style.css">
+<script>
+var successfullyParsed = false;
+</script>
+<script src="../../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body id="body">
+
+<header>header</header>
+<footer>footer</footer>
+<section>section</section>
+<article>article</article>
+<nav>nav</nav>
+<aside>aside</aside>
+
+<article>
+<header>Should be IGNORED because it's inside an article, so it should not be a landmark</header>
+<footer>Should be IGNORED because it's inside an article, so it should not be a landmark</footer>
+</article>
+
+<section>
+<header>Should be IGNORED because it's inside a section, so it should not be a landmark</header>
+<footer>Should be IGNORED because it's inside a section, so it should not be a landmark</footer>
+</section>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+
+    description("This tests that the HTML5 section elements map to the correct AX roles.");
+
+    if (window.accessibilityController) {
+
+          document.getElementById("body").focus();
+          var body = accessibilityController.focusedElement;
+          shouldBe("body.childAtIndex(0).subrole", "'AXSubrole: AXLandmarkBanner'");
+          shouldBe("body.childAtIndex(1).subrole", "'AXSubrole: AXLandmarkContentInfo'");
+          shouldBe("body.childAtIndex(2).subrole", "'AXSubrole: AXDocumentRegion'");
+          shouldBe("body.childAtIndex(3).subrole", "'AXSubrole: AXDocumentArticle'");
+          shouldBe("body.childAtIndex(4).subrole", "'AXSubrole: AXLandmarkNavigation'");
+          shouldBe("body.childAtIndex(5).subrole", "'AXSubrole: AXLandmarkComplementary'");
+
+          // When a header and footer are inside an article, they should not be landmarks.
+          shouldBe("body.childAtIndex(6).childAtIndex(0).subrole", "'AXSubrole: '");
+          shouldBe("body.childAtIndex(6).childAtIndex(1).subrole", "'AXSubrole: '");
+
+          // When a header and footer are inside a section, they should not be landmarks.
+          shouldBe("body.childAtIndex(7).childAtIndex(0).subrole", "'AXSubrole: '");
+          shouldBe("body.childAtIndex(7).childAtIndex(1).subrole", "'AXSubrole: '");
+    }
+
+    successfullyParsed = true;
+</script>
+
+<script src="../../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
index 7f3cb1d..9c5ea26 100644 (file)
@@ -1,5 +1,28 @@
 2011-10-03  Chris Fleizach  <cfleizach@apple.com>
 
+        AX: support role mapping for HTML5 section elements
+        https://bugs.webkit.org/show_bug.cgi?id=69150
+
+        We need to map these HTML5 elements to appropriate ARIA roles. That mapping is:
+          article -> Document article
+          nav -> Landmark navigation
+          aside -> Landmark complementary
+          section -> Document region
+          address -> Landmark content info
+          header -> Landmark banner (unless it's in an article or section)
+          footer -> Landmark content info (unless it's in an article or section)
+
+        Reviewed by Darin Adler.
+
+        Test: platform/mac/accessibility/html-section-elements.html
+
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::isDescendantOfElementType):
+        (WebCore::AccessibilityRenderObject::determineAccessibilityRole):
+        * accessibility/AccessibilityRenderObject.h:
+
+2011-10-03  Chris Fleizach  <cfleizach@apple.com>
+
         AX: click point for AXHeadings often returns point on empty space (results in wrong context menu)
         https://bugs.webkit.org/show_bug.cgi?id=69262
 
index 29232b0..024da7d 100644 (file)
@@ -3094,6 +3094,15 @@ void AccessibilityRenderObject::updateAccessibilityRole()
         childrenChanged();
 }
     
+bool AccessibilityRenderObject::isDescendantOfElementType(const QualifiedName& tagName) const
+{
+    for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
+        if (parent->node() && parent->node()->hasTagName(tagName))
+            return true;
+    }
+    return false;
+}
+    
 AccessibilityRole AccessibilityRenderObject::determineAccessibilityRole()
 {
     if (!m_renderer)
@@ -3210,6 +3219,28 @@ AccessibilityRole AccessibilityRenderObject::determineAccessibilityRole()
         return GroupRole;
 #endif
 
+    if (node && node->hasTagName(articleTag))
+        return DocumentArticleRole;
+
+    if (node && node->hasTagName(navTag))
+        return LandmarkNavigationRole;
+
+    if (node && node->hasTagName(asideTag))
+        return LandmarkComplementaryRole;
+
+    if (node && node->hasTagName(sectionTag))
+        return DocumentRegionRole;
+
+    if (node && node->hasTagName(addressTag))
+        return LandmarkContentInfoRole;
+
+    // There should only be one banner/contentInfo per page. If header/footer are being used within an article or section
+    // then it should not be exposed as whole page's banner/contentInfo
+    if (node && node->hasTagName(headerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
+        return LandmarkBannerRole;
+    if (node && node->hasTagName(footerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
+        return LandmarkContentInfoRole;
+
     if (m_renderer->isBlockFlow())
         return GroupRole;
     
index 6a20706..45e02f6 100644 (file)
@@ -299,6 +299,7 @@ private:
     AccessibilityObject* accessibilityParentForImageMap(HTMLMapElement*) const;
     bool renderObjectIsObservable(RenderObject*) const;
     RenderObject* renderParentObject() const;
+    bool isDescendantOfElementType(const QualifiedName& tagName) const;
     
     void ariaSelectedRows(AccessibilityChildrenVector&);