AX: doAXRangeForLine does not work
authorcfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Oct 2010 21:03:21 +0000 (21:03 +0000)
committercfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Oct 2010 21:03:21 +0000 (21:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=47101

Reviewed by Beth Dakin.

WebCore:

Asking for NSAccessibilityRangeForLine was returning a null range for any line number > 0.
The code was using a SelectionController to extend to the next line. Rather than change the implementation
of that core functionality, it is cleaner to use endOfLine to find the end of the line.

Test: platform/mac/accessibility/range-for-line-textarea.html

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::doAXRangeForLine):

WebKitTools:

DRT support to handle NSAccessibilityRangeForLineParameterizedAttribute.

* DumpRenderTree/AccessibilityUIElement.cpp:
(rangeForLineCallback):
(AccessibilityUIElement::rangeForLine):
(AccessibilityUIElement::getJSClass):
* DumpRenderTree/AccessibilityUIElement.h:
* DumpRenderTree/mac/AccessibilityUIElementMac.mm:
(AccessibilityUIElement::rangeForLine):

LayoutTests:

* platform/mac/accessibility/range-for-line-textarea-expected.txt: Added.
* platform/mac/accessibility/range-for-line-textarea.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/platform/mac/accessibility/range-for-line-textarea-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/accessibility/range-for-line-textarea.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/accessibility/AccessibilityRenderObject.cpp
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/AccessibilityUIElement.cpp
WebKitTools/DumpRenderTree/AccessibilityUIElement.h
WebKitTools/DumpRenderTree/mac/AccessibilityUIElementMac.mm

index 6272438..094ea35 100644 (file)
@@ -1,3 +1,13 @@
+2010-10-04  Chris Fleizach  <cfleizach@apple.com>
+
+        Reviewed by Beth Dakin.
+
+        AX: doAXRangeForLine does not work
+        https://bugs.webkit.org/show_bug.cgi?id=47101
+
+        * platform/mac/accessibility/range-for-line-textarea-expected.txt: Added.
+        * platform/mac/accessibility/range-for-line-textarea.html: Added.
+
 2010-10-04  Alexey Proskuryakov  <ap@apple.com>
 
         Reviewed by Adam Barth.
diff --git a/LayoutTests/platform/mac/accessibility/range-for-line-textarea-expected.txt b/LayoutTests/platform/mac/accessibility/range-for-line-textarea-expected.txt
new file mode 100644 (file)
index 0000000..4ee2664
--- /dev/null
@@ -0,0 +1,22 @@
+
+This tests that a popup button will return the text under the element for its title.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS axElement.rangeForLine(0) is '{0, 14}'
+PASS axElement.rangeForLine(1) is '{14, 14}'
+PASS axElement.rangeForLine(2) is '{28, 16}'
+PASS axElement.rangeForLine(3) is '{44, 14}'
+PASS axElement.rangeForLine(4) is '{58, 14}'
+PASS axElement.rangeForLine(6) is '{84, 14}'
+PASS axElement.rangeForLine(7) is '{98, 16}'
+PASS axElement.rangeForLine(8) is '{114, 14}'
+PASS axElement.rangeForLine(9) is '{128, 12}'
+PASS axElement.rangeForLine(10) is '{140, 14}'
+PASS axElement.rangeForLine(100) is '{0, 0}'
+PASS axElement.rangeForLine(-1) is '{0, 0}'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/platform/mac/accessibility/range-for-line-textarea.html b/LayoutTests/platform/mac/accessibility/range-for-line-textarea.html
new file mode 100644 (file)
index 0000000..623dd82
--- /dev/null
@@ -0,0 +1,49 @@
+<!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">
+
+
+<textarea tabindex="0" id="text" cols=10 rows=50>A lot of text repeated many times. A lot of text repeated many times. A lot of text repeated many times. A lot of text repeated many times.
+A lot of text repeated many times. A lot of text repeated many times. A lot of text repeated many times. A lot of text repeated many times. A lot of text repeated many times.
+</textarea>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+
+    description("This tests that a popup button will return the text under the element for its title.");
+
+    if (window.accessibilityController) {
+        var textElement = document.getElementById("text");
+        textElement.focus();
+        var axElement = accessibilityController.focusedElement;
+
+        shouldBe("axElement.rangeForLine(0)", "'{0, 14}'");
+        shouldBe("axElement.rangeForLine(1)", "'{14, 14}'");
+        shouldBe("axElement.rangeForLine(2)", "'{28, 16}'");
+        shouldBe("axElement.rangeForLine(3)", "'{44, 14}'");
+        shouldBe("axElement.rangeForLine(4)", "'{58, 14}'");
+        shouldBe("axElement.rangeForLine(6)", "'{84, 14}'");
+        shouldBe("axElement.rangeForLine(7)", "'{98, 16}'");
+        shouldBe("axElement.rangeForLine(8)", "'{114, 14}'");
+        shouldBe("axElement.rangeForLine(9)", "'{128, 12}'");
+        shouldBe("axElement.rangeForLine(10)", "'{140, 14}'");
+
+        shouldBe("axElement.rangeForLine(100)", "'{0, 0}'");
+        shouldBe("axElement.rangeForLine(-1)", "'{0, 0}'");
+    }
+
+    successfullyParsed = true;
+</script>
+
+<script src="../../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
index 3ed1a6d..5ad3029 100644 (file)
@@ -1,3 +1,19 @@
+2010-10-04  Chris Fleizach  <cfleizach@apple.com>
+
+        Reviewed by Beth Dakin.
+
+        AX: doAXRangeForLine does not work
+        https://bugs.webkit.org/show_bug.cgi?id=47101
+
+        Asking for NSAccessibilityRangeForLine was returning a null range for any line number > 0.
+        The code was using a SelectionController to extend to the next line. Rather than change the implementation
+        of that core functionality, it is cleaner to use endOfLine to find the end of the line.
+
+        Test: platform/mac/accessibility/range-for-line-textarea.html
+
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::doAXRangeForLine):
+
 2010-10-04  Brent Fulgham  <bfulgham@webkit.org>
 
         Unreviewed, build fix for r68951.
index d6bec4f..b2cb9c1 100644 (file)
@@ -2646,20 +2646,11 @@ PlainTextRange AccessibilityRenderObject::doAXRangeForLine(unsigned lineNumber)
         if (visiblePos.isNull() || visiblePos == savedVisiblePos)
             return PlainTextRange();
     }
-    
-    // make a caret selection for the marker position, then extend it to the line
-    // NOTE: ignores results of selection.modify because it returns false when
-    // starting at an empty line.  The resulting selection in that case
-    // will be a caret at visiblePos.
-    SelectionController selection;
-    selection.setSelection(VisibleSelection(visiblePos));
-    selection.modify(SelectionController::AlterationExtend, SelectionController::DirectionLeft, LineBoundary);
-    selection.modify(SelectionController::AlterationExtend, SelectionController::DirectionRight, LineBoundary);
-    
-    // calculate the indices for the selection start and end
-    VisiblePosition startPosition = selection.selection().visibleStart();
-    VisiblePosition endPosition = selection.selection().visibleEnd();
-    int index1 = indexForVisiblePosition(startPosition);
+
+    // Get the end of the line based on the starting position.
+    VisiblePosition endPosition = endOfLine(visiblePos);
+
+    int index1 = indexForVisiblePosition(visiblePos);
     int index2 = indexForVisiblePosition(endPosition);
     
     // add one to the end index for a line break not caused by soft line wrap (to match AppKit)
index 8b458c2..dd4ea32 100644 (file)
@@ -1,3 +1,20 @@
+2010-10-04  Chris Fleizach  <cfleizach@apple.com>
+
+        Reviewed by Beth Dakin.
+
+        AX: doAXRangeForLine does not work
+        https://bugs.webkit.org/show_bug.cgi?id=47101
+
+        DRT support to handle NSAccessibilityRangeForLineParameterizedAttribute.
+
+        * DumpRenderTree/AccessibilityUIElement.cpp:
+        (rangeForLineCallback):
+        (AccessibilityUIElement::rangeForLine):
+        (AccessibilityUIElement::getJSClass):
+        * DumpRenderTree/AccessibilityUIElement.h:
+        * DumpRenderTree/mac/AccessibilityUIElementMac.mm:
+        (AccessibilityUIElement::rangeForLine):
+
 2010-10-04  Andrey Kosyakov  <caseq@chromium.org>
 
         Unreviewed. Adding myself to the committers list.
index 31488e5..52d238d 100644 (file)
@@ -128,6 +128,16 @@ static JSValueRef lineForIndexCallback(JSContextRef context, JSObjectRef functio
     return JSValueMakeNumber(context, toAXElement(thisObject)->lineForIndex(indexNumber));
 }
 
+static JSValueRef rangeForLineCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    int indexNumber = -1;
+    if (argumentCount == 1)
+        indexNumber = JSValueToNumber(context, arguments[0], exception);
+    
+    JSRetainPtr<JSStringRef> rangeLine(Adopt, toAXElement(thisObject)->rangeForLine(indexNumber));
+    return JSValueMakeString(context, rangeLine.get());
+}
+
 static JSValueRef boundsForRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     unsigned location = UINT_MAX, length = 0;
@@ -746,6 +756,7 @@ static JSValueRef removeNotificationListenerCallback(JSContextRef context, JSObj
 // Unsupported methods on various platforms.
 #if !PLATFORM(MAC)
 JSStringRef AccessibilityUIElement::speak() { return 0; }
+JSStringRef AccessibilityUIElement::rangeForLine(int line) { return 0; }
 #endif
 
 #if !SUPPORTS_AX_TEXTMARKERS
@@ -859,6 +870,7 @@ JSClassRef AccessibilityUIElement::getJSClass()
         { "attributesOfChildren", attributesOfChildrenCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "parameterizedAttributeNames", parameterizedAttributeNamesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "lineForIndex", lineForIndexCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "rangeForLine", rangeForLineCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "boundsForRange", boundsForRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "stringForRange", stringForRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "attributedStringForRange", attributedStringForRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
index aec6d61..9311dfd 100644 (file)
@@ -179,6 +179,7 @@ public:
     
     // Parameterized attributes
     int lineForIndex(int);
+    JSStringRef rangeForLine(int);
     JSStringRef boundsForRange(unsigned location, unsigned length);
     void setSelectedTextRange(unsigned location, unsigned length);
     JSStringRef stringForRange(unsigned location, unsigned length);
index 13c9fa1..2ca5755 100644 (file)
@@ -835,6 +835,18 @@ int AccessibilityUIElement::lineForIndex(int index)
     return -1;
 }
 
+JSStringRef AccessibilityUIElement::rangeForLine(int line)
+{
+    BEGIN_AX_OBJC_EXCEPTIONS
+    id value = [m_element accessibilityAttributeValue:NSAccessibilityRangeForLineParameterizedAttribute forParameter:[NSNumber numberWithInt:line]];
+    if ([value isKindOfClass:[NSValue class]]) {
+        return [NSStringFromRange([value rangeValue]) createJSStringRef];
+    }
+    END_AX_OBJC_EXCEPTIONS
+    
+    return 0;
+}
+
 JSStringRef AccessibilityUIElement::boundsForRange(unsigned location, unsigned length)
 {
     NSRange range = NSMakeRange(location, length);