AX: <svg> elements with labels and no accessible contents are exposed as empty AXGroups
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Apr 2019 18:09:33 +0000 (18:09 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Apr 2019 18:09:33 +0000 (18:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=156774

Patch by Eric Liang <ericliang@apple.com> on 2019-04-08
Reviewed by Chris Fleizach.

Source/WebCore:

Labelled SVGs without accessible descendants are exposed as AXImage rather than groups.

Unlabelled equivalents are not exposed. Otherwise, SVGs with accessible descendants are exposed as AXGroup.
Also added back functionalities from last patch of determining whether a SVG element should be ignored.

Test: accessibility/svg-shape-labelled.html

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::updateRoleAfterChildrenCreation):
* accessibility/AccessibilitySVGElement.cpp:
(WebCore::AccessibilitySVGElement::computeAccessibilityIsIgnored const):

LayoutTests:

Added tests that verify svgs shapes that are labelled are exposed as images.
* accessibility/resources/apple-logo.svg: Added.
* accessibility/svg-shape-labelled-expected.txt: Added.
* accessibility/svg-shape-labelled.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/accessibility/resources/apple-logo.svg [new file with mode: 0644]
LayoutTests/accessibility/svg-shape-labelled-expected.txt [new file with mode: 0644]
LayoutTests/accessibility/svg-shape-labelled.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/accessibility/AccessibilitySVGElement.cpp

index 4604463..970f7da 100644 (file)
@@ -1,3 +1,15 @@
+2019-04-08  Eric Liang  <ericliang@apple.com>
+
+        AX: <svg> elements with labels and no accessible contents are exposed as empty AXGroups
+        https://bugs.webkit.org/show_bug.cgi?id=156774
+
+        Reviewed by Chris Fleizach.
+
+        Added tests that verify svgs shapes that are labelled are exposed as images.
+        * accessibility/resources/apple-logo.svg: Added.
+        * accessibility/svg-shape-labelled-expected.txt: Added.
+        * accessibility/svg-shape-labelled.html: Added.
+
 2019-04-08  Shawn Roberts  <sroberts@apple.com>
 
         Layout tests imported/w3c/IndexedDB-private-browsing/idbobjectstore_createIndex7-event_order.html
diff --git a/LayoutTests/accessibility/resources/apple-logo.svg b/LayoutTests/accessibility/resources/apple-logo.svg
new file mode 100644 (file)
index 0000000..1366fe9
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 19.2.1, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<svg version="1.1" id="GLYPHS" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+        width="20px" height="44px" viewBox="0 0 20 44" style="enable-background:new 0 0 20 44;" xml:space="preserve">
+<g id="Mac">
+       <g id="Apple_2_">
+               <path style="fill:#FFFFFF;" d="M18.1,24.23c-0.11,0.31-0.22,0.6-0.33,0.88c-0.29,0.66-0.63,1.27-1.02,1.84
+                       c-0.54,0.77-0.98,1.3-1.32,1.59c-0.52,0.48-1.09,0.73-1.69,0.74c-0.43,0-0.95-0.12-1.56-0.37c-0.61-0.25-1.17-0.37-1.68-0.37
+                       c-0.54,0-1.11,0.12-1.73,0.37c-0.62,0.25-1.11,0.38-1.49,0.39c-0.58,0.02-1.15-0.23-1.73-0.76c-0.37-0.32-0.83-0.87-1.38-1.65
+                       C3.58,26.06,3.09,25.1,2.71,24C2.3,22.81,2.1,21.66,2.1,20.55c0-1.27,0.28-2.37,0.83-3.29c0.43-0.74,1.01-1.32,1.73-1.75
+                       c0.72-0.43,1.5-0.65,2.34-0.66c0.46,0,1.06,0.14,1.81,0.42c0.75,0.28,1.23,0.42,1.44,0.42c0.16,0,0.69-0.17,1.59-0.5
+                       c0.85-0.31,1.57-0.43,2.16-0.38c1.6,0.13,2.8,0.76,3.6,1.89c-1.43,0.87-2.14,2.08-2.12,3.64c0.01,1.21,0.45,2.22,1.32,3.02
+                       C17.18,23.74,17.61,24.02,18.1,24.23z M14.08,10.31c0.01,0.13,0.02,0.25,0.02,0.38c0,0.95-0.35,1.84-1.04,2.66
+                       c-0.84,0.98-1.85,1.54-2.94,1.45c-0.01-0.11-0.02-0.23-0.02-0.36c0-0.91,0.4-1.89,1.1-2.69c0.35-0.4,0.8-0.74,1.34-1.01
+                       C13.09,10.48,13.6,10.33,14.08,10.31z"/>
+       </g>
+       <g>
+               <rect style="fill:none;" width="20" height="44"/>
+       </g>
+</g>
+</svg>
diff --git a/LayoutTests/accessibility/svg-shape-labelled-expected.txt b/LayoutTests/accessibility/svg-shape-labelled-expected.txt
new file mode 100644 (file)
index 0000000..bee4f41
--- /dev/null
@@ -0,0 +1,16 @@
+        
+This tests that SVG shapes are exposed to ax tree as images if there are labels describing them.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+circle1: AXRole: AXImage
+circle2: AXRole: AXImage
+circle3: Element not exposed
+PASS !image1 is true
+PASS image2.role is 'AXRole: AXImage'
+PASS image3.role is 'AXRole: AXImage'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/accessibility/svg-shape-labelled.html b/LayoutTests/accessibility/svg-shape-labelled.html
new file mode 100644 (file)
index 0000000..afb2e4c
--- /dev/null
@@ -0,0 +1,59 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<style>img {background-color: #000;}</style>
+<script src="../resources/js-test-pre.js"></script>
+<script src="../resources/accessibility-helper.js"></script>
+</head>
+<body id="body">
+
+<svg aria-label="Bar" height="100" width="100">
+    <circle id="circle1" cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
+</svg>
+
+<svg height="100" width="100">
+    <circle id="circle2" aria-label="Bar" cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
+</svg>
+
+<svg height="100" width="100">
+    <circle id="circle3" cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
+</svg>
+
+<img id="test1" src="resources/apple-logo.svg"/>
+
+<img id="test2" src="resources/apple-logo.svg" alt="hello" />
+
+<img id="test3" alt="Apple logo" src="resources/apple-logo.svg" />
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+
+    description("This tests that SVG shapes are exposed to ax tree as images if there are labels describing them.");
+
+    if (window.accessibilityController) {
+        var circle1 = accessibilityController.accessibleElementById("circle1");
+        debug("circle1: " + (circle1 ? circle1.role : "Element not exposed"));
+
+        var circle2 = accessibilityController.accessibleElementById("circle2");
+        debug("circle2: " + (circle2 ? circle2.role : "Element not exposed"));
+
+        var circle3 = accessibilityController.accessibleElementById("circle3");
+        debug("circle3: " + (circle3 ? circle3.role : "Element not exposed"));
+
+        var image1 = accessibilityController.accessibleElementById("test1");
+        shouldBeTrue("!image1");
+
+        var image2 = accessibilityController.accessibleElementById("test2");
+        shouldBe("image2.role", "'AXRole: AXImage'");
+
+        var image3 = accessibilityController.accessibleElementById("test3");
+        shouldBe("image3.role", "'AXRole: AXImage'");
+    }
+
+</script>
+
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
index 0aae5e6..84461ae 100644 (file)
@@ -1,3 +1,22 @@
+2019-04-08  Eric Liang  <ericliang@apple.com>
+
+        AX: <svg> elements with labels and no accessible contents are exposed as empty AXGroups
+        https://bugs.webkit.org/show_bug.cgi?id=156774
+
+        Reviewed by Chris Fleizach.
+
+        Labelled SVGs without accessible descendants are exposed as AXImage rather than groups.
+
+        Unlabelled equivalents are not exposed. Otherwise, SVGs with accessible descendants are exposed as AXGroup. 
+        Also added back functionalities from last patch of determining whether a SVG element should be ignored.
+        
+        Test: accessibility/svg-shape-labelled.html
+
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::updateRoleAfterChildrenCreation):
+        * accessibility/AccessibilitySVGElement.cpp:
+        (WebCore::AccessibilitySVGElement::computeAccessibilityIsIgnored const):
+
 2019-04-08  Youenn Fablet  <youenn@apple.com>
 
         Make sure UniqueIDBDatabaseConnection unregisters itself even if its database is gone
index b044703..b599ed3 100644 (file)
@@ -3263,7 +3263,8 @@ void AccessibilityRenderObject::addHiddenChildren()
 void AccessibilityRenderObject::updateRoleAfterChildrenCreation()
 {
     // If a menu does not have valid menuitem children, it should not be exposed as a menu.
-    if (roleValue() == AccessibilityRole::Menu) {
+    auto role = roleValue();
+    if (role == AccessibilityRole::Menu) {
         // Elements marked as menus must have at least one menu item child.
         size_t menuItemCount = 0;
         for (const auto& child : children()) {
@@ -3276,6 +3277,8 @@ void AccessibilityRenderObject::updateRoleAfterChildrenCreation()
         if (!menuItemCount)
             m_role = AccessibilityRole::Group;
     }
+    if (role == AccessibilityRole::SVGRoot && !hasChildren())
+        m_role = AccessibilityRole::Image;
 }
     
 void AccessibilityRenderObject::addChildren()
index 745fefc..9eb4e92 100644 (file)
@@ -245,8 +245,15 @@ bool AccessibilitySVGElement::computeAccessibilityIsIgnored() const
 
     // SVG shapes should not be included unless there's a concrete reason for inclusion.
     // https://rawgit.com/w3c/aria/master/svg-aam/svg-aam.html#exclude_elements
-    if (m_renderer->isSVGShape())
-        return !(hasAttributesRequiredForInclusion() || canSetFocusAttribute() || element()->hasEventListeners());
+    if (m_renderer->isSVGShape()) {
+        if (canSetFocusAttribute() || element()->hasEventListeners())
+            return false;
+        if (auto svgParent = AccessibilityObject::matchedParent(*this, true, [] (const AccessibilityObject& object) {
+            return object.hasAttributesRequiredForInclusion() || object.isAccessibilitySVGRoot();
+        }))
+            return !svgParent->hasAttributesRequiredForInclusion();
+        return true;
+    }
 
     return AccessibilityRenderObject::computeAccessibilityIsIgnored();
 }