Title: [137946] trunk
Revision
137946
Author
[email protected]
Date
2012-12-17 14:24:03 -0800 (Mon, 17 Dec 2012)

Log Message

AX: textUnderElement should consider alt text, but skip links and controls
https://bugs.webkit.org/show_bug.cgi?id=101650

Reviewed by Chris Fleizach.

Source/WebCore:

Getting inner text from an element now ignores focusable descendants
and containers, but uses alternative text.  The computation of
textUnderElement is now recursive and doesn't depend on text
iterators, which might not do the right thing for accessibility
anyways.

For GTK, the old behavior is retained so that support for
the object replacement character is still there. Filed a new
bug (105214) for GTK folks to look at this.

Test: accessibility/button-title-uses-inner-img-alt.html
Test: accessibility/focusable-div.html

* accessibility/AccessibilityNodeObject.cpp:
(WebCore):
(WebCore::shouldUseAccessiblityObjectInnerText):
(WebCore::AccessibilityNodeObject::textUnderElement):
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::textUnderElement):

LayoutTests:

Adds new tests to show that getting inner text from an element
now ignores focusable descendants and containers, but uses alternative
text.

Updates and rebaselines several tests to reflect the new logic.
Skips these tests on GTK until support for the object replacement
character can be added.

* accessibility/button-title-uses-inner-img-alt-expected.txt: Added.
* accessibility/button-title-uses-inner-img-alt.html: Added.
* accessibility/focusable-div-expected.txt: Extended with more test cases.
* accessibility/focusable-div.html: Extended with more test cases.
* platform/chromium/TestExpectations: Un-skip test that now passes.
* platform/chromium/accessibility/image-link-expected.txt: Rebaseline
* platform/mac/accessibility/image-link-expected.txt: Rebaseline
* platform/mac/accessibility/internal-link-anchors2-expected.txt: Rebaseline
* platform/mac/accessibility/static-text-role-uses-text-under-element-expected.txt: Rebaseline
* platform/mac/accessibility/static-text-role-uses-text-under-element.html: Fix
* platform/mac/accessibility/table-with-aria-role-expected.txt: Rebaseline
* platform/gtk/TestExpectations: Skip these tests until this feature is implemented for GTK.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (137945 => 137946)


--- trunk/LayoutTests/ChangeLog	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/LayoutTests/ChangeLog	2012-12-17 22:24:03 UTC (rev 137946)
@@ -1,3 +1,31 @@
+2012-12-17  Dominic Mazzoni  <[email protected]>
+
+        AX: textUnderElement should consider alt text, but skip links and controls
+        https://bugs.webkit.org/show_bug.cgi?id=101650
+
+        Reviewed by Chris Fleizach.
+
+        Adds new tests to show that getting inner text from an element
+        now ignores focusable descendants and containers, but uses alternative
+        text.
+
+        Updates and rebaselines several tests to reflect the new logic.
+        Skips these tests on GTK until support for the object replacement
+        character can be added.
+
+        * accessibility/button-title-uses-inner-img-alt-expected.txt: Added.
+        * accessibility/button-title-uses-inner-img-alt.html: Added.
+        * accessibility/focusable-div-expected.txt: Extended with more test cases.
+        * accessibility/focusable-div.html: Extended with more test cases.
+        * platform/chromium/TestExpectations: Un-skip test that now passes.
+        * platform/chromium/accessibility/image-link-expected.txt: Rebaseline
+        * platform/mac/accessibility/image-link-expected.txt: Rebaseline
+        * platform/mac/accessibility/internal-link-anchors2-expected.txt: Rebaseline
+        * platform/mac/accessibility/static-text-role-uses-text-under-element-expected.txt: Rebaseline
+        * platform/mac/accessibility/static-text-role-uses-text-under-element.html: Fix
+        * platform/mac/accessibility/table-with-aria-role-expected.txt: Rebaseline
+        * platform/gtk/TestExpectations: Skip these tests until this feature is implemented for GTK.
+
 2012-12-17  Levi Weintraub  <[email protected]>
 
         Convert sub-pixel iframe-copy-on-scroll tests to use Mock scrollbars

Added: trunk/LayoutTests/accessibility/button-title-uses-inner-img-alt-expected.txt (0 => 137946)


--- trunk/LayoutTests/accessibility/button-title-uses-inner-img-alt-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/accessibility/button-title-uses-inner-img-alt-expected.txt	2012-12-17 22:24:03 UTC (rev 137946)
@@ -0,0 +1,12 @@
+Button with image of 
+This test makes sure that a generic focusable div can get accessibility focus and gets its accessible text from contents..
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.activeElement == button is true
+PASS axButton.title.indexOf('Button with image of cake') >= 0 is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/accessibility/button-title-uses-inner-img-alt.html (0 => 137946)


--- trunk/LayoutTests/accessibility/button-title-uses-inner-img-alt.html	                        (rev 0)
+++ trunk/LayoutTests/accessibility/button-title-uses-inner-img-alt.html	2012-12-17 22:24:03 UTC (rev 137946)
@@ -0,0 +1,32 @@
+<!DOCTYPE HTML>
+<html>
+<body>
+<script src=""
+
+<style>
+button {
+  padding: 30px;
+}
+</style>
+
+<button id="cake">Button with image of <img alt="cake" src="" width="40px"></button>
+
+<div id="console"></div>
+<script>
+description("This test makes sure that a generic focusable div can get accessibility focus and gets its accessible text from contents..");
+
+if (window.testRunner && window.accessibilityController) {
+    window.testRunner.dumpAsText();
+
+    var button = document.getElementById('cake');
+    button.focus();
+    shouldBe("document.activeElement == button", "true");
+    window.axButton = accessibilityController.focusedElement;
+    shouldBe("axButton.title.indexOf('Button with image of cake') >= 0", "true");
+}
+
+</script>
+
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/accessibility/focusable-div-expected.txt (137945 => 137946)


--- trunk/LayoutTests/accessibility/focusable-div-expected.txt	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/LayoutTests/accessibility/focusable-div-expected.txt	2012-12-17 22:24:03 UTC (rev 137946)
@@ -1,7 +1,12 @@
 A
 B
 C
-This test makes sure that a generic focusable div can get accessibility focus.
+Link
+Initial text before linkLink
+List item
+Initial text before list
+List item
+This test makes sure that a generic focusable div can get accessibility focus and gets its accessible text from contents..
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
@@ -14,6 +19,16 @@
 PASS lastChar(axDiv2.title) is "C"
 PASS document.activeElement == div3 is true
 PASS lastChar(axDiv3.description) is "D"
+PASS document.activeElement == div4 is true
+PASS axDiv4.title.indexOf('Link') is -1
+PASS document.activeElement == div5 is true
+PASS axDiv5.title.indexOf('Link') is -1
+PASS axDiv5.title.indexOf('Initial text before link') >= 0 is true
+PASS document.activeElement == div6 is true
+PASS axDiv6.title.indexOf('List item') is -1
+PASS document.activeElement == div7 is true
+PASS axDiv7.title.indexOf('List item') is -1
+PASS axDiv7.title.indexOf('Initial text before list') >= 0 is true
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/accessibility/focusable-div.html (137945 => 137946)


--- trunk/LayoutTests/accessibility/focusable-div.html	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/LayoutTests/accessibility/focusable-div.html	2012-12-17 22:24:03 UTC (rev 137946)
@@ -3,14 +3,23 @@
 <body>
 <script src=""
 
+<!-- A link always gets its accessible text from contents. -->
 <a id="link" href=""
+
+<!-- A generic focusable div should also get its accessible text from contents. -->
 <div id="div" tabindex="0">B</div>
 <div id="div2" tabindex="0"><div></div>C</div>
 <div id="div3" tabindex="0" aria-label="D"></div>
 
+<!-- A generic focusable div should not get accessible text from children that are focusable or containers. -->
+<div id="div4" tabindex="0"><a href=""
+<div id="div5" tabindex="0">Initial text before link<a href=""
+<div id="div6" tabindex="0"><ul><li>List item</li></ul></div>
+<div id="div7" tabindex="0">Initial text before list<ul><li>List item</li></ul></div>
+
 <div id="console"></div>
 <script>
-description("This test makes sure that a generic focusable div can get accessibility focus.");
+description("This test makes sure that a generic focusable div can get accessibility focus and gets its accessible text from contents..");
 
 if (window.testRunner && window.accessibilityController) {
     window.testRunner.dumpAsText();
@@ -42,6 +51,32 @@
     shouldBe("document.activeElement == div3", "true");
     window.axDiv3 = accessibilityController.focusedElement;
     shouldBe("lastChar(axDiv3.description)", "\"D\"");
+
+    var div4 = document.getElementById('div4');
+    div4.focus();
+    shouldBe("document.activeElement == div4", "true");
+    window.axDiv4 = accessibilityController.focusedElement;
+    shouldBe("axDiv4.title.indexOf('Link')", "-1");
+
+    var div5 = document.getElementById('div5');
+    div5.focus();
+    shouldBe("document.activeElement == div5", "true");
+    window.axDiv5 = accessibilityController.focusedElement;
+    shouldBe("axDiv5.title.indexOf('Link')", "-1");
+    shouldBe("axDiv5.title.indexOf('Initial text before link') >= 0", "true");
+
+    var div6 = document.getElementById('div6');
+    div6.focus();
+    shouldBe("document.activeElement == div6", "true");
+    window.axDiv6 = accessibilityController.focusedElement;
+    shouldBe("axDiv6.title.indexOf('List item')", "-1");
+
+    var div7 = document.getElementById('div7');
+    div7.focus();
+    shouldBe("document.activeElement == div7", "true");
+    window.axDiv7 = accessibilityController.focusedElement;
+    shouldBe("axDiv7.title.indexOf('List item')", "-1");
+    shouldBe("axDiv7.title.indexOf('Initial text before list') >= 0", "true");
 }
 
 </script>

Modified: trunk/LayoutTests/platform/chromium/TestExpectations (137945 => 137946)


--- trunk/LayoutTests/platform/chromium/TestExpectations	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/LayoutTests/platform/chromium/TestExpectations	2012-12-17 22:24:03 UTC (rev 137946)
@@ -1398,7 +1398,6 @@
 crbug.com/10322 accessibility/deleting-iframe-destroys-axcache.html [ Skip ]
 crbug.com/10322 accessibility/document-attributes.html [ Skip ]
 crbug.com/10322 accessibility/iframe-bastardization.html [ Skip ]
-crbug.com/10322 accessibility/image-link.html [ Skip ]
 crbug.com/10322 accessibility/image-map-update-parent-crash.html [ Skip ]
 crbug.com/10322 accessibility/image-map2.html [ Skip ]
 crbug.com/10322 accessibility/internal-link-anchors2.html [ Skip ]

Modified: trunk/LayoutTests/platform/chromium/accessibility/image-link-expected.txt (137945 => 137946)


--- trunk/LayoutTests/platform/chromium/accessibility/image-link-expected.txt	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/LayoutTests/platform/chromium/accessibility/image-link-expected.txt	2012-12-17 22:24:03 UTC (rev 137946)
@@ -3,55 +3,13 @@
 This test checks that the right accessibility tree is generated for a link inside an image
 
 
+AXTitle: Delicious cake
 AXRole: AXLink
-AXSubrole: (null)
-AXRoleDescription: link
-AXChildren: <array of size 1>
-AXHelp: 
-AXParent: <AXLink>
-AXSize: NSSize: {280, 213}
-AXTitle: 
 AXDescription: 
-AXValue: 
-AXFocused: 1
-AXEnabled: 1
-AXWindow: <AXLink>
-AXSelectedTextMarkerRange: (null)
-AXStartTextMarker: <AXLink>
-AXEndTextMarker: <AXLink>
-AXVisited: 0
-AXLinkedUIElements: (null)
-AXSelected: 0
-AXBlockQuoteLevel: 0
-AXTopLevelUIElement: <AXLink>
-AXURL: http://www.wowhead.com/?item=33924
-AXAccessKey: (null)
 
-
 Child 0:
-AXRole: AXImage
-AXSubrole: (null)
-AXRoleDescription: image
-AXChildren: <array of size 0>
-AXHelp: 
-AXParent: <AXImage>
-AXSize: NSSize: {280, 209}
 AXTitle: 
+AXRole: AXImage
 AXDescription: Delicious cake
-AXValue: 
-AXFocused: 0
-AXEnabled: 1
-AXWindow: <AXImage>
-AXSelectedTextMarkerRange: (null)
-AXStartTextMarker: <AXImage>
-AXEndTextMarker: <AXImage>
-AXVisited: 0
-AXLinkedUIElements: (null)
-AXSelected: 0
-AXBlockQuoteLevel: 0
-AXTopLevelUIElement: <AXImage>
-AXURL: LayoutTests/accessibility/resources/cake.png
-AXAccessKey: (null)
 
 
-

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (137945 => 137946)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2012-12-17 22:24:03 UTC (rev 137946)
@@ -772,7 +772,9 @@
 webkit.org/b/98359 accessibility/aria-text-role.html [ Failure ]
 webkit.org/b/98360 accessibility/aria-used-on-image-maps.html [ Failure ]
 webkit.org/b/98361 accessibility/button-press-action.html [ Failure ]
+webkit.org/b/105214 accessibility/button-title-uses-inner-img-alt.html [ Failure ]
 webkit.org/b/98363 accessibility/canvas-fallback-content-2.html [ Failure ]
+webkit.org/b/105214 accessibility/focusable-div.html [ Failure ]
 webkit.org/b/98370 accessibility/loading-iframe-sends-notification.html [ Failure ]
 webkit.org/b/98371 accessibility/loading-iframe-updates-axtree.html [ Failure ]
 webkit.org/b/98372 accessibility/onclick-handlers.html [ Failure ]

Modified: trunk/LayoutTests/platform/mac/accessibility/image-link-expected.txt (137945 => 137946)


--- trunk/LayoutTests/platform/mac/accessibility/image-link-expected.txt	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/LayoutTests/platform/mac/accessibility/image-link-expected.txt	2012-12-17 22:24:03 UTC (rev 137946)
@@ -8,22 +8,22 @@
 AXRoleDescription: link
 AXChildren: <array of size 1>
 AXHelp: 
-AXParent: <AXLink>
+AXParent: <AXLink: 'Delicious cake'>
 AXSize: NSSize: {280, 213}
-AXTitle: 
+AXTitle: Delicious cake
 AXDescription: 
 AXValue: 
 AXFocused: 1
 AXEnabled: 1
-AXWindow: <AXLink>
+AXWindow: <AXLink: 'Delicious cake'>
 AXSelectedTextMarkerRange: (null)
-AXStartTextMarker: <AXLink>
-AXEndTextMarker: <AXLink>
+AXStartTextMarker: <AXLink: 'Delicious cake'>
+AXEndTextMarker: <AXLink: 'Delicious cake'>
 AXVisited: 0
 AXLinkedUIElements: (null)
 AXSelected: 0
 AXBlockQuoteLevel: 0
-AXTopLevelUIElement: <AXLink>
+AXTopLevelUIElement: <AXLink: 'Delicious cake'>
 AXURL: http://www.wowhead.com/?item=33924
 AXAccessKey: (null)
 AXARIABusy: 0

Modified: trunk/LayoutTests/platform/mac/accessibility/internal-link-anchors2-expected.txt (137945 => 137946)


--- trunk/LayoutTests/platform/mac/accessibility/internal-link-anchors2-expected.txt	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/LayoutTests/platform/mac/accessibility/internal-link-anchors2-expected.txt	2012-12-17 22:24:03 UTC (rev 137946)
@@ -5,22 +5,22 @@
 AXRoleDescription: heading
 AXChildren: <array of size 4>
 AXHelp: 
-AXParent: <AXHeading: '[edit] Tourette syndrome'>
+AXParent: <AXHeading: '[] Tourette syndrome'>
 AXSize: NSSize: {769, 22}
-AXTitle: [edit] Tourette syndrome
+AXTitle: [] Tourette syndrome
 AXDescription: 
 AXValue: 3
 AXFocused: 0
 AXEnabled: 1
-AXWindow: <AXHeading: '[edit] Tourette syndrome'>
+AXWindow: <AXHeading: '[] Tourette syndrome'>
 AXSelectedTextMarkerRange: (null)
-AXStartTextMarker: <AXHeading: '[edit] Tourette syndrome'>
-AXEndTextMarker: <AXHeading: '[edit] Tourette syndrome'>
+AXStartTextMarker: <AXHeading: '[] Tourette syndrome'>
+AXEndTextMarker: <AXHeading: '[] Tourette syndrome'>
 AXVisited: 0
 AXLinkedUIElements: (null)
 AXSelected: 0
 AXBlockQuoteLevel: 0
-AXTopLevelUIElement: <AXHeading: '[edit] Tourette syndrome'>
+AXTopLevelUIElement: <AXHeading: '[] Tourette syndrome'>
 AXARIABusy: 0
 
 ------------

Modified: trunk/LayoutTests/platform/mac/accessibility/static-text-role-uses-text-under-element-expected.txt (137945 => 137946)


--- trunk/LayoutTests/platform/mac/accessibility/static-text-role-uses-text-under-element-expected.txt	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/LayoutTests/platform/mac/accessibility/static-text-role-uses-text-under-element-expected.txt	2012-12-17 22:24:03 UTC (rev 137946)
@@ -4,7 +4,7 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS text.stringValue is 'AXValue: Text 1 Text 2 Text 3'
+PASS text.stringValue is 'AXValue:   Text 3'
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/platform/mac/accessibility/static-text-role-uses-text-under-element.html (137945 => 137946)


--- trunk/LayoutTests/platform/mac/accessibility/static-text-role-uses-text-under-element.html	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/LayoutTests/platform/mac/accessibility/static-text-role-uses-text-under-element.html	2012-12-17 22:24:03 UTC (rev 137946)
@@ -26,7 +26,7 @@
     if (window.accessibilityController) {
         document.getElementById("text1").focus();
         var text = accessibilityController.focusedElement;
-        shouldBe("text.stringValue", "'AXValue: Text 1 Text 2 Text 3'");
+        shouldBe("text.stringValue", "'AXValue:   Text 3'");
     }
 
 </script>

Modified: trunk/LayoutTests/platform/mac/accessibility/table-with-aria-role-expected.txt (137945 => 137946)


--- trunk/LayoutTests/platform/mac/accessibility/table-with-aria-role-expected.txt	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/LayoutTests/platform/mac/accessibility/table-with-aria-role-expected.txt	2012-12-17 22:24:03 UTC (rev 137946)
@@ -7,33 +7,21 @@
 AXRoleDescription: button
 AXChildren: <array of size 0>
 AXHelp: 
-AXParent: <AXButton: 'test	test	test
-test	test	test
-'>
+AXParent: <AXButton: 'testtesttesttesttesttest'>
 AXSize: NSSize: {85, 52}
-AXTitle: test	test	test
-test	test	test
-
+AXTitle: testtesttesttesttesttest
 AXDescription: 
 AXFocused: 0
 AXEnabled: 1
-AXWindow: <AXButton: 'test	test	test
-test	test	test
-'>
+AXWindow: <AXButton: 'testtesttesttesttesttest'>
 AXSelectedTextMarkerRange: (null)
-AXStartTextMarker: <AXButton: 'test	test	test
-test	test	test
-'>
-AXEndTextMarker: <AXButton: 'test	test	test
-test	test	test
-'>
+AXStartTextMarker: <AXButton: 'testtesttesttesttesttest'>
+AXEndTextMarker: <AXButton: 'testtesttesttesttesttest'>
 AXVisited: 0
 AXLinkedUIElements: (null)
 AXSelected: 0
 AXBlockQuoteLevel: 0
-AXTopLevelUIElement: <AXButton: 'test	test	test
-test	test	test
-'>
+AXTopLevelUIElement: <AXButton: 'testtesttesttesttesttest'>
 AXTitleUIElement: (null)
 AXAccessKey: (null)
 AXARIABusy: 0

Modified: trunk/Source/WebCore/ChangeLog (137945 => 137946)


--- trunk/Source/WebCore/ChangeLog	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/Source/WebCore/ChangeLog	2012-12-17 22:24:03 UTC (rev 137946)
@@ -1,3 +1,30 @@
+2012-12-17  Dominic Mazzoni  <[email protected]>
+
+        AX: textUnderElement should consider alt text, but skip links and controls
+        https://bugs.webkit.org/show_bug.cgi?id=101650
+
+        Reviewed by Chris Fleizach.
+
+        Getting inner text from an element now ignores focusable descendants
+        and containers, but uses alternative text.  The computation of
+        textUnderElement is now recursive and doesn't depend on text
+        iterators, which might not do the right thing for accessibility
+        anyways.
+
+        For GTK, the old behavior is retained so that support for
+        the object replacement character is still there. Filed a new
+        bug (105214) for GTK folks to look at this.
+
+        Test: accessibility/button-title-uses-inner-img-alt.html
+        Test: accessibility/focusable-div.html
+
+        * accessibility/AccessibilityNodeObject.cpp:
+        (WebCore):
+        (WebCore::shouldUseAccessiblityObjectInnerText):
+        (WebCore::AccessibilityNodeObject::textUnderElement):
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::textUnderElement):
+
 2012-12-17  Otto Derek Cheung  <[email protected]>
 
         [BlackBerry] Prevent CookieManager from blocking the WKT thread

Modified: trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp (137945 => 137946)


--- trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp	2012-12-17 22:24:03 UTC (rev 137946)
@@ -1434,20 +1434,62 @@
     return level;
 }
 
+// When building the textUnderElement for an object, determine whether or not
+// we should include the inner text of this given descendant object or skip it.
+static bool shouldUseAccessiblityObjectInnerText(AccessibilityObject* obj)
+{
+    // Consider this hypothetical example:
+    // <div tabindex=0>
+    //   <h2>
+    //     Table of contents
+    //   </h2>
+    //   <a href="" to start of book</a>
+    //   <ul>
+    //     <li><a href="" 1</a></li>
+    //     <li><a href="" 2</a></li>
+    //   </ul>
+    // </div>
+    //
+    // The goal is to return a reasonable title for the outer container div, because
+    // it's focusable - but without making its title be the full inner text, which is
+    // quite long. As a heuristic, skip links, controls, and elements that are usually
+    // containers with lots of children.
+
+    // Skip focusable children, so we don't include the text of links and controls.
+    if (obj->canSetFocusAttribute())
+        return false;
+
+    // Skip big container elements like lists, tables, etc.
+    if (obj->isList() || obj->isAccessibilityTable() || obj->isTree() || obj->isCanvas())
+        return false;
+
+    return true;
+}
+
 String AccessibilityNodeObject::textUnderElement() const
 {
     Node* node = this->node();
-    if (!node)
-        return String();
+    if (node && node->isTextNode())
+        return toText(node)->wholeText();
 
-    // Note: TextIterator doesn't return any text for nodes that don't have renderers.
-    // If this could be fixed, it'd be more accurate use TextIterator here.
-    if (node->isElementNode())
-        return toElement(node)->innerText();
-    else if (node->isTextNode())
-        return toText(node)->wholeText();
-    
-    return String();
+    String result;
+    for (AccessibilityObject* child = firstChild(); child; child = child->nextSibling()) {
+        if (!shouldUseAccessiblityObjectInnerText(child))
+            continue;
+
+        if (child->isAccessibilityNodeObject()) {
+            Vector<AccessibilityText> textOrder;
+            toAccessibilityNodeObject(child)->alternativeText(textOrder);
+            if (textOrder.size() > 0) {
+                result.append(textOrder[0].text);
+                continue;
+            }
+        }
+
+        result.append(child->textUnderElement());
+    }
+
+    return result;
 }
 
 String AccessibilityNodeObject::title() const

Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (137945 => 137946)


--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp	2012-12-17 22:17:42 UTC (rev 137945)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp	2012-12-17 22:24:03 UTC (rev 137946)
@@ -624,12 +624,10 @@
 {
     if (!m_renderer)
         return String();
-    
+
     if (m_renderer->isFileUploadControl())
         return toRenderFileUploadControl(m_renderer)->buttonValue();
     
-    Node* node = m_renderer->node();
-
 #if ENABLE(MATHML)
     // Math operators create RenderText nodes on the fly that are not tied into the DOM in a reasonable way,
     // so rangeOfContents does not work for them (nor does regular text selection).
@@ -640,8 +638,13 @@
         }
     }
 #endif
-    
-    if (node) {
+
+#if PLATFORM(GTK)
+    // On GTK, always use a text iterator in order to get embedded object characters.
+    // TODO: Add support for embedded object characters to the other codepaths that try
+    // to build the accessible text recursively, so this special case isn't needed.
+    // https://bugs.webkit.org/show_bug.cgi?id=105214
+    if (Node* node = this->node()) {
         if (Frame* frame = node->document()->frame()) {
             // catch stale WebCoreAXObject (see <rdar://problem/3960196>)
             if (frame->document() != node->document())
@@ -650,18 +653,29 @@
             return plainText(rangeOfContents(node).get(), textIteratorBehaviorForTextRange());
         }
     }
+#endif
+
+    if (m_renderer->isText()) {
+        // If possible, use a text iterator to get the text, so that whitespace
+        // is handled consistently.
+        if (Node* node = this->node()) {
+            if (Frame* frame = node->document()->frame()) {
+                // catch stale WebCoreAXObject (see <rdar://problem/3960196>)
+                if (frame->document() != node->document())
+                    return String();
+
+                return plainText(rangeOfContents(node).get(), textIteratorBehaviorForTextRange());
+            }
+        }
     
-    // Sometimes text fragments don't have Node's associated with them (like when
-    // CSS content is used to insert text).
-    if (m_renderer->isText()) {
+        // Sometimes text fragments don't have Nodes associated with them (like when
+        // CSS content is used to insert text).
         RenderText* renderTextObject = toRenderText(m_renderer);
         if (renderTextObject->isTextFragment())
             return String(static_cast<RenderTextFragment*>(m_renderer)->contentString());
     }
     
-    // return the null string for anonymous text because it is non-trivial to get
-    // the actual text and, so far, that is not needed
-    return String();
+    return AccessibilityNodeObject::textUnderElement();
 }
 
 Node* AccessibilityRenderObject::node() const
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to