AX: Need ability to get line range for text marker.
authorsamuel_white@apple.com <samuel_white@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 31 Mar 2014 18:02:51 +0000 (18:02 +0000)
committersamuel_white@apple.com <samuel_white@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 31 Mar 2014 18:02:51 +0000 (18:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=130906

Reviewed by Chris Fleizach.

LayoutTests:

Added test to ensure we can get the correct range of a line from a given marker.
Also updated existing bounds-for-range test to include new attribute.

* platform/mac/accessibility/bounds-for-range-expected.txt:
* platform/mac/accessibility/line-range-for-text-marker-expected.txt: Added.
* platform/mac/accessibility/line-range-for-text-marker.html: Added.

Source/WebCore:

Added ability to get line range from any marker on that line. This matches the functionality of existing
attributes such as AXParagraphTextMarkerRangeForTextMarker and AXSentenceTextMarkerRangeForTextMarker.

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

* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::visiblePositionRangeForRange):
(WebCore::AccessibilityObject::lineRangeForPosition):
* accessibility/AccessibilityObject.h:
* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper accessibilityParameterizedAttributeNames]):
(-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):

Tools:

Added a new function in DRT and TestRunner to test that AXLineTextMarkerRangeForTextMarker works as expected.

* DumpRenderTree/AccessibilityUIElement.cpp:
(lineTextMarkerRangeForTextMarkerCallback):
(AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
(AccessibilityUIElement::getJSClass):
* DumpRenderTree/AccessibilityUIElement.h:
* DumpRenderTree/mac/AccessibilityUIElementMac.mm:
(AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
* WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp:
(WTR::AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
* WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
* WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
* WebKitTestRunner/InjectedBundle/atk/AccessibilityUIElementAtk.cpp:
(WTR::AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
* WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
(WTR::AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
* WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
(WTR::AccessibilityUIElement::lineTextMarkerRangeForTextMarker):

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

18 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac/accessibility/bounds-for-range-expected.txt
LayoutTests/platform/mac/accessibility/line-range-for-text-marker-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/accessibility/line-range-for-text-marker.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityObject.cpp
Source/WebCore/accessibility/AccessibilityObject.h
Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
Tools/ChangeLog
Tools/DumpRenderTree/AccessibilityUIElement.cpp
Tools/DumpRenderTree/AccessibilityUIElement.h
Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm
Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp
Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h
Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl
Tools/WebKitTestRunner/InjectedBundle/atk/AccessibilityUIElementAtk.cpp
Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm
Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm

index 93cb907..3e1b09f 100644 (file)
@@ -1,3 +1,17 @@
+2014-03-31  Samuel White  <samuel_white@apple.com>
+
+        AX: Need ability to get line range for text marker.
+        https://bugs.webkit.org/show_bug.cgi?id=130906
+
+        Reviewed by Chris Fleizach.
+
+        Added test to ensure we can get the correct range of a line from a given marker.
+        Also updated existing bounds-for-range test to include new attribute.
+
+        * platform/mac/accessibility/bounds-for-range-expected.txt:
+        * platform/mac/accessibility/line-range-for-text-marker-expected.txt: Added.
+        * platform/mac/accessibility/line-range-for-text-marker.html: Added.
+
 2014-03-31  Alexey Proskuryakov  <ap@apple.com>
 
         transitions/3d/interrupted-transition.html is flaky
index 0f98c07..4c76b0d 100644 (file)
@@ -59,6 +59,7 @@ AXUIElementCountForSearchPredicate
 AXUIElementsForSearchPredicate
 AXEndTextMarkerForBounds
 AXStartTextMarkerForBounds
+AXLineTextMarkerRangeForTextMarker
 AXSelectTextWithCriteria
 
 ----------------------
diff --git a/LayoutTests/platform/mac/accessibility/line-range-for-text-marker-expected.txt b/LayoutTests/platform/mac/accessibility/line-range-for-text-marker-expected.txt
new file mode 100644 (file)
index 0000000..adc95ad
--- /dev/null
@@ -0,0 +1,12 @@
+This tests that line range is returned correctly for a given text marker.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS lineText is 'Line of text.'
+PASS lineText is 'Line of text.'
+PASS lineText is 'Line of text.'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/platform/mac/accessibility/line-range-for-text-marker.html b/LayoutTests/platform/mac/accessibility/line-range-for-text-marker.html
new file mode 100644 (file)
index 0000000..d58d8d7
--- /dev/null
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../../resources/js-test-pre.js"></script>
+<title>Line Range for Text Marker</title>
+</head>
+<body>
+
+<div id="container">
+<p>Before.</p>
+<p id="line">Line of text.</p>
+<p>After.</p>
+</div>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+    description("This tests that line range is returned correctly for a given text marker.");
+    
+    var lineText = 0;
+    
+    function lineTextForPoint(x, y) {
+        // Get the element for this point.
+        var element = accessibilityController.elementAtPoint(x, y);
+        // Get the text marker for this point.
+        var marker = element.textMarkerForPoint(x, y);
+        // Get the line text marker range for this text marker.
+        var range = element.lineTextMarkerRangeForTextMarker(marker);
+        // Return the text for this line text marker range.
+        return element.stringForTextMarkerRange(range);
+    }
+    
+    if (window.accessibilityController) {
+        var line = accessibilityController.accessibleElementById("line");
+        // Line text from first text marker (add one to make sure we get the first marker for THIS line).
+        lineText = lineTextForPoint(line.x + 1, line.y + 1);
+        shouldBe("lineText", "'Line of text.'");
+        // Line text from center text marker.
+        lineText = lineTextForPoint(line.x + line.width / 2, line.y + line.height / 2);
+        shouldBe("lineText", "'Line of text.'");
+        // Line text from last text marker (subtract one to make sure we get the last marker for THIS line).
+        lineText = lineTextForPoint(line.x + line.width - 1, line.y + line.height - 1);
+        shouldBe("lineText", "'Line of text.'");
+        
+        // Hide superfluous text.
+        document.getElementById("container").style.display = "none";
+    }
+</script>
+
+<script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
index 0d0afad..0a839b3 100644 (file)
@@ -1,3 +1,23 @@
+2014-03-31  Samuel White  <samuel_white@apple.com>
+
+        AX: Need ability to get line range for text marker.
+        https://bugs.webkit.org/show_bug.cgi?id=130906
+
+        Reviewed by Chris Fleizach.
+
+        Added ability to get line range from any marker on that line. This matches the functionality of existing
+        attributes such as AXParagraphTextMarkerRangeForTextMarker and AXSentenceTextMarkerRangeForTextMarker.
+
+        Test: platform/mac/accessibility/line-range-for-text-marker.html
+
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::visiblePositionRangeForRange):
+        (WebCore::AccessibilityObject::lineRangeForPosition):
+        * accessibility/AccessibilityObject.h:
+        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+        (-[WebAccessibilityObjectWrapper accessibilityParameterizedAttributeNames]):
+        (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
+
 2014-03-31  Anders Carlsson  <andersca@apple.com>
 
         Fix iOS build.
index 7cc9c18..c4c2e5d 100644 (file)
@@ -990,6 +990,13 @@ VisiblePositionRange AccessibilityObject::visiblePositionRangeForRange(const Pla
     return VisiblePositionRange(startPosition, endPosition);
 }
 
+VisiblePositionRange AccessibilityObject::lineRangeForPosition(const VisiblePosition& visiblePosition) const
+{
+    VisiblePosition startPosition = startOfLine(visiblePosition);
+    VisiblePosition endPosition = endOfLine(visiblePosition);
+    return VisiblePositionRange(startPosition, endPosition);
+}
+
 static bool replacedNodeNeedsCharacter(Node* replacedNode)
 {
     // we should always be given a rendered node and a replaced node, but be safe
index 5f08a8a..f8aace1 100644 (file)
@@ -776,6 +776,7 @@ public:
     VisiblePositionRange paragraphForPosition(const VisiblePosition&) const;
     VisiblePositionRange styleRangeForPosition(const VisiblePosition&) const;
     VisiblePositionRange visiblePositionRangeForRange(const PlainTextRange&) const;
+    VisiblePositionRange lineRangeForPosition(const VisiblePosition&) const;
 
     String stringForVisiblePositionRange(const VisiblePositionRange&) const;
     virtual IntRect boundsForVisiblePositionRange(const VisiblePositionRange&) const { return IntRect(); }
index 8a5ba51..0119018 100644 (file)
@@ -387,6 +387,10 @@ using namespace HTMLNames;
 #define NSAccessibilityStartTextMarkerForBoundsParameterizedAttribute @"AXStartTextMarkerForBounds"
 #endif
 
+#ifndef NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttribute
+#define NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttribute @"AXLineTextMarkerRangeForTextMarker"
+#endif
+
 // Text selection
 #ifndef NSAccessibilitySelectTextActivity
 #define NSAccessibilitySelectTextActivity @"AXSelectTextActivity"
@@ -3064,6 +3068,7 @@ static NSString* roleValueToNSString(AccessibilityRole value)
                       NSAccessibilityUIElementsForSearchPredicateParameterizedAttribute,
                       NSAccessibilityEndTextMarkerForBoundsParameterizedAttribute,
                       NSAccessibilityStartTextMarkerForBoundsParameterizedAttribute,
+                      NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttribute,
                       NSAccessibilitySelectTextWithCriteriaParameterizedAttribute,
                       nil];
     }
@@ -3479,6 +3484,12 @@ static RenderObject* rendererForView(NSView* view)
         return [self textMarkerForVisiblePosition:m_object->visiblePositionForBounds(webCoreRect, FirstVisiblePositionForBounds)];
     }
     
+    if ([attribute isEqualToString:NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttribute]) {
+        VisiblePosition visiblePosition = [self visiblePositionForTextMarker:textMarker];
+        VisiblePositionRange visiblePositionRange = m_object->lineRangeForPosition(visiblePosition);
+        return [self textMarkerRangeFromVisiblePositions:visiblePositionRange.start endPosition:visiblePositionRange.end];
+    }
+    
     if ([attribute isEqualToString:NSAccessibilityTextMarkerIsValidParameterizedAttribute]) {
         VisiblePosition pos = [self visiblePositionForTextMarker:textMarker];
         return [NSNumber numberWithBool:!pos.isNull()];
index 9d1a330..ff60799 100644 (file)
@@ -1,3 +1,30 @@
+2014-03-31  Samuel White  <samuel_white@apple.com>
+
+        AX: Need ability to get line range for text marker.
+        https://bugs.webkit.org/show_bug.cgi?id=130906
+
+        Reviewed by Chris Fleizach.
+
+        Added a new function in DRT and TestRunner to test that AXLineTextMarkerRangeForTextMarker works as expected.
+
+        * DumpRenderTree/AccessibilityUIElement.cpp:
+        (lineTextMarkerRangeForTextMarkerCallback):
+        (AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
+        (AccessibilityUIElement::getJSClass):
+        * DumpRenderTree/AccessibilityUIElement.h:
+        * DumpRenderTree/mac/AccessibilityUIElementMac.mm:
+        (AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
+        * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp:
+        (WTR::AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
+        * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
+        * WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
+        * WebKitTestRunner/InjectedBundle/atk/AccessibilityUIElementAtk.cpp:
+        (WTR::AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
+        * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
+        (WTR::AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
+        * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
+        (WTR::AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
+
 2014-03-31  Filip Pizlo  <fpizlo@apple.com>
 
         More validation for FTL inline caches
index 1b69510..c0d1dd9 100644 (file)
@@ -665,6 +665,14 @@ static JSValueRef removeSelectionCallback(JSContextRef context, JSObjectRef func
     return JSValueMakeUndefined(context);
 }
 
+static JSValueRef lineTextMarkerRangeForTextMarkerCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    AccessibilityTextMarker* textMarker = nullptr;
+    if (argumentCount == 1)
+        textMarker = toTextMarker(JSValueToObject(context, arguments[0], exception));
+    return AccessibilityTextMarkerRange::makeJSAccessibilityTextMarkerRange(context, toAXElement(thisObject)->lineTextMarkerRangeForTextMarker(textMarker));
+}
+
 static JSValueRef textMarkerRangeForElementCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     AccessibilityUIElement* uiElement = 0;
@@ -1338,6 +1346,11 @@ bool AccessibilityUIElement::isEqual(AccessibilityUIElement* otherElement)
 
 #if !SUPPORTS_AX_TEXTMARKERS
 
+AccessibilityTextMarkerRange AccessibilityUIElement::lineTextMarkerRangeForTextMarker(AccessibilityTextMarker*)
+{
+    return nullptr;
+}
+
 AccessibilityTextMarkerRange AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement*)
 {
     return 0;
@@ -1589,6 +1602,7 @@ JSClassRef AccessibilityUIElement::getJSClass()
         { "takeSelection", takeSelectionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "addSelection", addSelectionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "removeSelection", removeSelectionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "lineTextMarkerRangeForTextMarker", lineTextMarkerRangeForTextMarkerCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "textMarkerRangeForElement", textMarkerRangeForElementCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "attributedStringForTextMarkerRangeContainsAttribute", attributedStringForTextMarkerRangeContainsAttributeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "indexForTextMarker", indexForTextMarkerCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
index 71d1a72..aa781a6 100644 (file)
@@ -237,6 +237,7 @@ public:
     AccessibilityUIElement verticalScrollbar() const;
 
     // Text markers.
+    AccessibilityTextMarkerRange lineTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
     AccessibilityTextMarkerRange textMarkerRangeForElement(AccessibilityUIElement*);    
     AccessibilityTextMarkerRange textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker);
     AccessibilityTextMarker startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
index 9d52614..7ac6728 100644 (file)
@@ -1523,6 +1523,16 @@ void AccessibilityUIElement::removeSelection()
 #if SUPPORTS_AX_TEXTMARKERS
 
 // Text markers
+AccessibilityTextMarkerRange AccessibilityUIElement::lineTextMarkerRangeForTextMarker(AccessibilityTextMarker* textMarker)
+{
+    BEGIN_AX_OBJC_EXCEPTIONS
+    id textMarkerRange = [m_element accessibilityAttributeValue:@"AXLineTextMarkerRangeForTextMarker" forParameter:(id)textMarker->platformTextMarker()];
+    return AccessibilityTextMarkerRange(textMarkerRange);
+    END_AX_OBJC_EXCEPTIONS
+    
+    return nullptr;
+}
+
 AccessibilityTextMarkerRange AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
 {
     BEGIN_AX_OBJC_EXCEPTIONS
index 1e5b296..878074b 100644 (file)
@@ -184,6 +184,7 @@ PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::horizontalScrollbar()
 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::verticalScrollbar() const { return 0; }
 bool AccessibilityUIElement::addNotificationListener(JSValueRef) { return false; }
 bool AccessibilityUIElement::removeNotificationListener() { return false; }
+PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::lineTextMarkerRangeForTextMarker(AccessibilityTextMarker*) { return nullptr; }
 PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement*) { return 0; }
 int AccessibilityUIElement::textMarkerRangeLength(AccessibilityTextMarkerRange*) { return 0; }
 PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForMarkers(AccessibilityTextMarker*, AccessibilityTextMarker*) { return 0; }
index 4341923..7dfd844 100644 (file)
@@ -226,6 +226,7 @@ public:
     void scrollToMakeVisible();
     
     // Text markers.
+    PassRefPtr<AccessibilityTextMarkerRange> lineTextMarkerRangeForTextMarker(AccessibilityTextMarker*);
     PassRefPtr<AccessibilityTextMarkerRange> textMarkerRangeForElement(AccessibilityUIElement*);    
     PassRefPtr<AccessibilityTextMarkerRange> textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker);
     PassRefPtr<AccessibilityTextMarker> startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange*);
index ea8fd4a..1baed0a 100644 (file)
@@ -170,6 +170,7 @@ interface AccessibilityUIElement {
     void scrollToMakeVisible();
 
     // Text markers.
+    AccessibilityTextMarkerRange lineTextMarkerRangeForTextMarker(AccessibilityTextMarker textMarker);
     AccessibilityTextMarkerRange textMarkerRangeForElement(AccessibilityUIElement element);    
     AccessibilityTextMarkerRange textMarkerRangeForMarkers(AccessibilityTextMarker startMarker, AccessibilityTextMarker endMarker);
     AccessibilityTextMarker startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange range);
index 7193d0f..d9d4a65 100644 (file)
@@ -1770,6 +1770,12 @@ void AccessibilityUIElement::removeSelection()
 }
 
 // Text markers
+PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::lineTextMarkerRangeForTextMarker(AccessibilityTextMarker* textMarker)
+{
+    // FIXME: implement
+    return nullptr;
+}
+
 PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
 {
     // FIXME: implement
index 15a46ce..ca2c51b 100644 (file)
@@ -685,6 +685,11 @@ void AccessibilityUIElement::removeSelection()
 }
 
 // Text markers
+PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::lineTextMarkerRangeForTextMarker(AccessibilityTextMarker* textMarker)
+{
+    return nullptr;
+}
+
 PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
 {
     return 0;
index b23e528..a494dd3 100644 (file)
@@ -1540,6 +1540,16 @@ void AccessibilityUIElement::removeSelection()
 }
 
 // Text markers
+PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::lineTextMarkerRangeForTextMarker(AccessibilityTextMarker* textMarker)
+{
+    BEGIN_AX_OBJC_EXCEPTIONS
+    id textMarkerRange = [m_element accessibilityAttributeValue:@"AXLineTextMarkerRangeForTextMarker" forParameter:(id)textMarker->platformTextMarker()];
+    return AccessibilityTextMarkerRange::create(textMarkerRange);
+    END_AX_OBJC_EXCEPTIONS
+    
+    return nullptr;
+}
+
 PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
 {
     BEGIN_AX_OBJC_EXCEPTIONS