AX: Self-referencing aria-labelledby only uses contents.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Sep 2013 09:51:25 +0000 (09:51 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Sep 2013 09:51:25 +0000 (09:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=120814

Patch by Samuel White <samuel_white@apple.com> on 2013-09-12
Reviewed by Mario Sanchez Prada.

Source/WebCore:

Implemented additional 'Text Alternative Computation' steps documented at:
http://www.w3.org/WAI/PF/aria/complete#textalternativecomputation. This allows us to remove
our raw text node iteration that was previously forcing us to do our computation incorrectly.
Element content is now sourced using textUnderElement (step 2C of the computation).

Test: accessibility/self-referencing-aria-labelledby.html

* accessibility/AccessibilityNodeObject.cpp:
(WebCore::accessibleNameForNode):
(WebCore::AccessibilityNodeObject::accessibilityDescriptionForElements):

LayoutTests:

Test to verify that self-referencing aria-labelledby behavior works as expected.

* accessibility/self-referencing-aria-labelledby-expected.txt: Added.
* accessibility/self-referencing-aria-labelledby.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/accessibility/self-referencing-aria-labelledby-expected.txt [new file with mode: 0644]
LayoutTests/accessibility/self-referencing-aria-labelledby.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityNodeObject.cpp

index 9ca6c4c..4cf81de 100644 (file)
@@ -1,3 +1,15 @@
+2013-09-12  Samuel White  <samuel_white@apple.com>
+
+        AX: Self-referencing aria-labelledby only uses contents.
+        https://bugs.webkit.org/show_bug.cgi?id=120814
+
+        Reviewed by Mario Sanchez Prada.
+
+        Test to verify that self-referencing aria-labelledby behavior works as expected.
+
+        * accessibility/self-referencing-aria-labelledby-expected.txt: Added.
+        * accessibility/self-referencing-aria-labelledby.html: Added.
+
 2013-09-12  Denis Nomiyama  <d.nomiyama@samsung.com>
 
         REGRESSION(r154781): accessibility/notification-listeners.html is failing
diff --git a/LayoutTests/accessibility/self-referencing-aria-labelledby-expected.txt b/LayoutTests/accessibility/self-referencing-aria-labelledby-expected.txt
new file mode 100644 (file)
index 0000000..1652d40
--- /dev/null
@@ -0,0 +1,17 @@
+X ?          Y Z
+This tests that self-referencing aria-labelledby is exposed correctly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS test.description is 'AXDescription: X Y Z'
+PASS test.description is 'AXDescription: X Y Z'
+PASS test.description is 'AXDescription: X Y Z'
+PASS test.description is 'AXDescription: X Y Z'
+PASS test.description is 'AXDescription: X Y Z'
+PASS test.description is 'AXDescription: X Y Z'
+PASS test.description is 'AXDescription: X Y Z'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/accessibility/self-referencing-aria-labelledby.html b/LayoutTests/accessibility/self-referencing-aria-labelledby.html
new file mode 100644 (file)
index 0000000..3a3d105
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../resources/js-test-pre.js"></script>
+<title>Self-Referencing aria-labelledby</title>
+</head>
+<body>
+
+<!-- Self-referencing label should be the content text. -->
+<a aria-labelledby="t0 s0 s1" class="test" href="#" id="t0">X</a>
+
+<!-- Self-referencing label should be the aria-label text. -->
+<a aria-label="X" aria-labelledby="t1 s0 s1" class="test" href="#" id="t1">?</a>
+
+<!-- Self-referencing label should be the title text. -->
+<img alt="" aria-labelledby="t2 s0 s1" class="test" id="t2" src="resources/cake.png" title="X">
+
+<!-- Self-referencing label should be the alt text. -->
+<img alt="X" aria-labelledby="t3 s0 s1" class="test" id="t3" src="resources/cake.png" title="?">
+
+<!-- Self-referencing label should be the aria-label text. -->
+<img alt="?" aria-label="X" aria-labelledby="t4 s0 s1" class="test" id="t4" src="resources/cake.png" title="?">
+
+<!-- Self-referencing label should be the value text. -->
+<input aria-labelledby="t5 s0 s1" class="test" id="t5" type="text" value="X">
+
+<!-- Self-referencing label should be the aria-label text. -->
+<input aria-label="X" aria-labelledby="t6 s0 s1" class="test" id="t6" type="button" value="?">
+
+<span id="s0">Y</span>
+<span id="s1">Z</span>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+    description("This tests that self-referencing aria-labelledby is exposed correctly.");
+    
+    if (window.accessibilityController) {
+        testCount = document.getElementsByClassName("test").length;
+        for (var i = 0; i < testCount; ++i) {
+            var test = accessibilityController.accessibleElementById("t" + i);
+            shouldBe("test.description", "'AXDescription: X Y Z'");
+        }
+    }
+</script>
+
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
index 0908ff0..d77e2e2 100644 (file)
@@ -1,3 +1,21 @@
+2013-09-12  Samuel White  <samuel_white@apple.com>
+
+        AX: Self-referencing aria-labelledby only uses contents.
+        https://bugs.webkit.org/show_bug.cgi?id=120814
+
+        Reviewed by Mario Sanchez Prada.
+
+        Implemented additional 'Text Alternative Computation' steps documented at:
+        http://www.w3.org/WAI/PF/aria/complete#textalternativecomputation. This allows us to remove
+        our raw text node iteration that was previously forcing us to do our computation incorrectly.
+        Element content is now sourced using textUnderElement (step 2C of the computation).
+
+        Test: accessibility/self-referencing-aria-labelledby.html
+
+        * accessibility/AccessibilityNodeObject.cpp:
+        (WebCore::accessibleNameForNode):
+        (WebCore::AccessibilityNodeObject::accessibilityDescriptionForElements):
+
 2013-09-12  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r155597.
index 2d8487f..bf75f87 100644 (file)
@@ -1752,18 +1752,30 @@ void AccessibilityNodeObject::colorValue(int& r, int& g, int& b) const
 // ARIA Implementer's Guide.                                                                                            
 static String accessibleNameForNode(Node* node)
 {
-    if (node->isTextNode())
-        return toText(node)->data();
-
+    if (!node->isHTMLElement())
+        return String();
+    
+    HTMLElement* element = toHTMLElement(node);
+    
+    const AtomicString& ariaLabel = element->fastGetAttribute(aria_labelAttr);
+    if (!ariaLabel.isEmpty())
+        return ariaLabel;
+    
+    const AtomicString& alt = element->fastGetAttribute(altAttr);
+    if (!alt.isEmpty())
+        return alt;
+    
     if (isHTMLInputElement(node))
         return toHTMLInputElement(node)->value();
-
-    if (node->isHTMLElement()) {
-        const AtomicString& alt = toHTMLElement(node)->getAttribute(altAttr);
-        if (!alt.isEmpty())
-            return alt;
-    }
-
+    
+    String text = node->document().axObjectCache()->getOrCreate(node)->textUnderElement();
+    if (!text.isEmpty())
+        return text;
+    
+    const AtomicString& title = element->fastGetAttribute(titleAttr);
+    if (!title.isEmpty())
+        return title;
+    
     return String();
 }
 
@@ -1772,14 +1784,10 @@ String AccessibilityNodeObject::accessibilityDescriptionForElements(Vector<Eleme
     StringBuilder builder;
     unsigned size = elements.size();
     for (unsigned i = 0; i < size; ++i) {
-        Element* idElement = elements[i];
-
-        builder.append(accessibleNameForNode(idElement));
-        for (Node* n = idElement->firstChild(); n; n = NodeTraversal::next(n, idElement))
-            builder.append(accessibleNameForNode(n));
-
-        if (i != size - 1)
+        if (i)
             builder.append(' ');
+        
+        builder.append(accessibleNameForNode(elements[i]));
     }
     return builder.toString();
 }