AX: [IOS] Implement next/previous text marker functions using TextIterator
authorn_wang@apple.com <n_wang@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Jan 2016 08:35:10 +0000 (08:35 +0000)
committern_wang@apple.com <n_wang@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Jan 2016 08:35:10 +0000 (08:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=153292
<rdar://problem/24268243>

Reviewed by Chris Fleizach.

Source/WebCore:

Added support for the refactored next/previous text marker functions on iOS. And
made text marker tests working on iOS.
Also, fixed an issue in AXObjectCache where creating a range with a replaced node
at the start or end might exclude that node.

Tests: accessibility/text-marker/text-marker-previous-next.html
       accessibility/text-marker/text-marker-with-user-select-none.html

* accessibility/AXObjectCache.cpp:
(WebCore::characterOffsetsInOrder):
(WebCore::resetNodeAndOffsetForReplacedNode):
(WebCore::AXObjectCache::rangeForUnorderedCharacterOffsets):
* accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
(+[WebAccessibilityTextMarker textMarkerWithVisiblePosition:cache:]):
(+[WebAccessibilityTextMarker textMarkerWithCharacterOffset:cache:]):
(+[WebAccessibilityTextMarker startOrEndTextMarkerForRange:isStart:cache:]):
(-[WebAccessibilityTextMarker dataRepresentation]):
(-[WebAccessibilityTextMarker visiblePosition]):
(-[WebAccessibilityTextMarker characterOffset]):
(-[WebAccessibilityTextMarker isIgnored]):
(-[WebAccessibilityTextMarker accessibilityObject]):
(-[WebAccessibilityTextMarker description]):
(-[WebAccessibilityObjectWrapper stringForTextMarkers:]):
(blockquoteLevel):
(-[WebAccessibilityObjectWrapper textMarkerRange]):
(-[WebAccessibilityObjectWrapper accessibilityObjectForTextMarker:]):
(-[WebAccessibilityObjectWrapper nextMarkerForMarker:]):
(-[WebAccessibilityObjectWrapper previousMarkerForMarker:]):
(-[WebAccessibilityObjectWrapper textMarkerForPoint:]):
(-[WebAccessibilityObjectWrapper nextMarkerForCharacterOffset:]):
(-[WebAccessibilityObjectWrapper previousMarkerForCharacterOffset:]):
(-[WebAccessibilityObjectWrapper rangeForTextMarkers:]):
(-[WebAccessibilityObjectWrapper lengthForTextMarkers:]):
(-[WebAccessibilityObjectWrapper startOrEndTextMarkerForTextMarkers:isStart:]):
(-[WebAccessibilityObjectWrapper textMarkerRangeForMarkers:]):
(-[WebAccessibilityObjectWrapper accessibilityIdentifier]):

Tools:

Made text marker tests available on iOS.

* DumpRenderTree/AccessibilityTextMarker.h:
* DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
* DumpRenderTree/ios/AccessibilityTextMarkerIOS.mm: Added.
(AccessibilityTextMarker::AccessibilityTextMarker):
(AccessibilityTextMarker::~AccessibilityTextMarker):
(AccessibilityTextMarker::isEqual):
(AccessibilityTextMarker::platformTextMarker):
(AccessibilityTextMarkerRange::AccessibilityTextMarkerRange):
(AccessibilityTextMarkerRange::~AccessibilityTextMarkerRange):
(AccessibilityTextMarkerRange::isEqual):
(AccessibilityTextMarkerRange::platformTextMarkerRange):
* DumpRenderTree/ios/AccessibilityUIElementIOS.mm:
(AccessibilityUIElement::pathDescription):
(AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
(AccessibilityUIElement::textMarkerRangeForElement):
(AccessibilityUIElement::selectedTextMarkerRange):
(AccessibilityUIElement::resetSelectedTextMarkerRange):
(AccessibilityUIElement::textMarkerRangeLength):
(AccessibilityUIElement::textMarkerRangeForMarkers):
(AccessibilityUIElement::startTextMarkerForTextMarkerRange):
(AccessibilityUIElement::endTextMarkerForTextMarkerRange):
(AccessibilityUIElement::accessibilityElementForTextMarker):
(AccessibilityUIElement::endTextMarkerForBounds):
(AccessibilityUIElement::startTextMarkerForBounds):
(AccessibilityUIElement::textMarkerForPoint):
(AccessibilityUIElement::previousTextMarker):
(AccessibilityUIElement::nextTextMarker):
(AccessibilityUIElement::stringForTextMarkerRange):
(AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute):
(AccessibilityUIElement::indexForTextMarker):
(AccessibilityUIElement::isTextMarkerValid):
(AccessibilityUIElement::textMarkerForIndex):
(AccessibilityUIElement::startTextMarker):
(AccessibilityUIElement::endTextMarker):
(AccessibilityUIElement::setSelectedVisibleTextRange):
(AccessibilityUIElement::getLinkedUIElements):
* DumpRenderTree/mac/AccessibilityTextMarkerMac.mm:
(AccessibilityTextMarkerRange::platformTextMarkerRange):
* DumpRenderTree/mac/AccessibilityUIElementMac.mm:
(AccessibilityUIElement::removeSelection):
(AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
(AccessibilityUIElement::setSelectedVisibleTextRange):
(AccessibilityUIElement::supportedActions):
* WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
(WTR::AccessibilityUIElement::textMarkerRangeForElement):
(WTR::AccessibilityUIElement::textMarkerRangeLength):
(WTR::AccessibilityUIElement::previousTextMarker):
(WTR::AccessibilityUIElement::nextTextMarker):
(WTR::AccessibilityUIElement::stringForTextMarkerRange):
(WTR::AccessibilityUIElement::textMarkerRangeForMarkers):
(WTR::AccessibilityUIElement::startTextMarkerForTextMarkerRange):
(WTR::AccessibilityUIElement::endTextMarkerForTextMarkerRange):
(WTR::AccessibilityUIElement::endTextMarkerForBounds):
(WTR::AccessibilityUIElement::accessibilityElementForTextMarker):
(WTR::AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute):

LayoutTests:

* accessibility/mac/previous-next-text-marker-expected.txt: Removed.
* accessibility/mac/previous-next-text-marker.html: Removed.
* accessibility/mac/text-marker-with-user-select-none-expected.txt: Removed.
* accessibility/mac/text-marker-with-user-select-none.html: Removed.
* accessibility/text-marker: Added.
* accessibility/text-marker/text-marker-previous-next-expected.txt: Added.
* accessibility/text-marker/text-marker-previous-next.html: Added.
* accessibility/text-marker/text-marker-with-user-select-none-expected.txt: Added.
* accessibility/text-marker/text-marker-with-user-select-none.html: Added.
* platform/efl/TestExpectations:
* platform/gtk/TestExpectations:
* platform/ios-simulator/TestExpectations:
* platform/win/TestExpectations:

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

20 files changed:
LayoutTests/ChangeLog
LayoutTests/accessibility/text-marker/text-marker-previous-next-expected.txt [moved from LayoutTests/accessibility/mac/previous-next-text-marker-expected.txt with 73% similarity]
LayoutTests/accessibility/text-marker/text-marker-previous-next.html [moved from LayoutTests/accessibility/mac/previous-next-text-marker.html with 76% similarity]
LayoutTests/accessibility/text-marker/text-marker-with-user-select-none-expected.txt [moved from LayoutTests/accessibility/mac/text-marker-with-user-select-none-expected.txt with 100% similarity]
LayoutTests/accessibility/text-marker/text-marker-with-user-select-none.html [moved from LayoutTests/accessibility/mac/text-marker-with-user-select-none.html with 100% similarity]
LayoutTests/platform/efl/TestExpectations
LayoutTests/platform/gtk/TestExpectations
LayoutTests/platform/ios-simulator/TestExpectations
LayoutTests/platform/win/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AXObjectCache.cpp
Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm
Tools/ChangeLog
Tools/DumpRenderTree/AccessibilityTextMarker.h
Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj
Tools/DumpRenderTree/ios/AccessibilityTextMarkerIOS.mm [new file with mode: 0644]
Tools/DumpRenderTree/ios/AccessibilityUIElementIOS.mm
Tools/DumpRenderTree/mac/AccessibilityTextMarkerMac.mm
Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm
Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm

index d6d3d9f..4a81710 100644 (file)
@@ -1,3 +1,25 @@
+2016-01-21  Nan Wang  <n_wang@apple.com>
+
+        AX: [IOS] Implement next/previous text marker functions using TextIterator
+        https://bugs.webkit.org/show_bug.cgi?id=153292
+        <rdar://problem/24268243>
+
+        Reviewed by Chris Fleizach.
+
+        * accessibility/mac/previous-next-text-marker-expected.txt: Removed.
+        * accessibility/mac/previous-next-text-marker.html: Removed.
+        * accessibility/mac/text-marker-with-user-select-none-expected.txt: Removed.
+        * accessibility/mac/text-marker-with-user-select-none.html: Removed.
+        * accessibility/text-marker: Added.
+        * accessibility/text-marker/text-marker-previous-next-expected.txt: Added.
+        * accessibility/text-marker/text-marker-previous-next.html: Added.
+        * accessibility/text-marker/text-marker-with-user-select-none-expected.txt: Added.
+        * accessibility/text-marker/text-marker-with-user-select-none.html: Added.
+        * platform/efl/TestExpectations:
+        * platform/gtk/TestExpectations:
+        * platform/ios-simulator/TestExpectations:
+        * platform/win/TestExpectations:
+
 2016-01-20  Zalan Bujtas  <zalan@apple.com>
 
         http://victordarras.fr/cssgame/ doesn't work in Safari.
@@ -12,20 +12,14 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
 PASS text.textMarkerRangeLength(textMarkerRange) is 4
 PASS text.accessibilityElementForTextMarker(startMarker).isEqual(text) is true
 PASS text.accessibilityElementForTextMarker(endMarker).isEqual(text) is true
-PASS element.stringValue is 'AXValue: '
-PASS element.stringValue is 'AXValue: text1'
-PASS element.stringValue is 'AXValue: '
-PASS element.stringValue is 'AXValue: text'
+PASS text.stringForTextMarkerRange(markerRange) is ''
+PASS text.stringForTextMarkerRange(markerRange) is 't'
+PASS text.stringForTextMarkerRange(markerRange) is ''
+PASS text.stringForTextMarkerRange(markerRange) is 't'
 PASS text2.textMarkerRangeLength(textMarkerRange2) is 5
 Object string for range: c [ATTACHMENT] d
-AXValue: c 
-AXValue: c 
-AXValue: 
-AXValue:  d
-AXValue: 
-AXValue: c 
-AXValue: c 
-AXValue: text1
+PASS text2.stringForTextMarkerRange(markerRange) is 'd'
+PASS text2.stringForTextMarkerRange(markerRange) is '1'
 PASS text3.stringForTextMarkerRange(markerRange) is 'ect'
 PASS text3.stringForTextMarkerRange(markerRange) is 'sel'
 PASS !psw.accessibilityElementForTextMarker(start) is true
@@ -44,26 +44,31 @@ c <img src="#" aria-label="blah" style="background-color: #aaaaaa; width: 100px;
         
         // Check next text marker. (Advance 5 characters, it will land at <br>.)
         var currentMarker = startMarker;
+        var previousMarker, markerRange;
         for (var i = 0; i < 5; i++) {
+            previousMarker = currentMarker;
             currentMarker = text.nextTextMarker(currentMarker);
         }
-        var element = text.accessibilityElementForTextMarker(currentMarker);
-        shouldBe("element.stringValue", "'AXValue: '");
+        markerRange = text.textMarkerRangeForMarkers(previousMarker, currentMarker);
+        shouldBe("text.stringForTextMarkerRange(markerRange)", "''");
         
         // Advance one more character, it will lande at "t" in "text1".
+        previousMarker = currentMarker;
         currentMarker = text.nextTextMarker(currentMarker);
-        element = text.accessibilityElementForTextMarker(currentMarker);
-        shouldBe("element.stringValue", "'AXValue: text1'");
+        markerRange = text.textMarkerRangeForMarkers(previousMarker, currentMarker);
+        shouldBe("text.stringForTextMarkerRange(markerRange)", "'t'");
         
         // Check previous text marker. (Traverse backwards one character, it will land at <br>.)
+        previousMarker = text.previousTextMarker(previousMarker);
         currentMarker = text.previousTextMarker(currentMarker);
-        element = text.accessibilityElementForTextMarker(currentMarker);
-        shouldBe("element.stringValue", "'AXValue: '");
+        markerRange = text.textMarkerRangeForMarkers(previousMarker, currentMarker);
+        shouldBe("text.stringForTextMarkerRange(markerRange)", "''");
         
         // Traverse backwards one more character, it will land at the last character of "text".
+        previousMarker = text.previousTextMarker(previousMarker);
         currentMarker = text.previousTextMarker(currentMarker);
-        element = text.accessibilityElementForTextMarker(currentMarker);
-        shouldBe("element.stringValue", "'AXValue: text'");
+        markerRange = text.textMarkerRangeForMarkers(previousMarker, currentMarker);
+        shouldBe("text.stringForTextMarkerRange(markerRange)", "'t'");
         
         // Check the case with replaced node
         var text2 = accessibilityController.accessibleElementById("text2");
@@ -73,19 +78,21 @@ c <img src="#" aria-label="blah" style="background-color: #aaaaaa; width: 100px;
         debug("Object string for range: " + str);
         
         currentMarker = text2.startTextMarkerForTextMarkerRange(textMarkerRange2);
-        // Advance 4 characters, it will land at first character of " d".
-        for (var i = 0; i < 4; i++) {
+        // Advance 5 characters, it will land at "d".
+        for (var i = 0; i < 5; i++) {
+            previousMarker = currentMarker;
             currentMarker = text2.nextTextMarker(currentMarker);
-            element = text2.accessibilityElementForTextMarker(currentMarker);
-            debug(element.stringValue);
         }
+        markerRange = text2.textMarkerRangeForMarkers(previousMarker, currentMarker);
+        shouldBe("text2.stringForTextMarkerRange(markerRange)", "'d'");
         
-        // Traverse backwards 4 characters, it will land at the last character of "text1".
-        for (var i = 0; i < 4; i++) {
+        // Traverse backwards 5 characters, it will land at the last character of "text1".
+        for (var i = 0; i < 5; i++) {
+            previousMarker = text2.previousTextMarker(previousMarker);
             currentMarker = text2.previousTextMarker(currentMarker);
-            element = text2.accessibilityElementForTextMarker(currentMarker);
-            debug(element.stringValue);
         }
+        markerRange = text2.textMarkerRangeForMarkers(previousMarker, currentMarker);
+        shouldBe("text2.stringForTextMarkerRange(markerRange)", "'1'");
         
         // Check the case with user-select:none, nextTextMarker/previousTextMarker should still work.
         var text3 = accessibilityController.accessibleElementById("text3");
@@ -100,7 +107,7 @@ c <img src="#" aria-label="blah" style="background-color: #aaaaaa; width: 100px;
             }
         }
         marker2 = currentMarker;
-        var markerRange = text3.textMarkerRangeForMarkers(marker1, marker2);
+        markerRange = text3.textMarkerRangeForMarkers(marker1, marker2);
         shouldBe("text3.stringForTextMarkerRange(markerRange)", "'ect'");
         // Iterate backwards the second marker for 6 characters, the range should be "sel"
         for (var i = 0; i < 6; i++) {
index 5605625..3292259 100644 (file)
@@ -2346,6 +2346,9 @@ accessibility/content-editable-as-textarea.html [ Missing ]
 webkit.org/b/146887 accessibility/aria-roledescription.html [ Failure ]
 webkit.org/b/146887 accessibility/list-detection.html [ Failure ]
 
+# Text marker tests are not supported
+webkit.org/b/153292 accessibility/text-marker [ Skip ]
+
 # This test hardcodes the result of a platform-dependent font lookup algorithm.
 fast/text/fallback-language-han.html [ Skip ]
 fast/text/fallback-language-han-2.html [ Skip ]
index e85acd2..6525619 100644 (file)
@@ -609,6 +609,9 @@ webkit.org/b/149016 accessibility/aria-current.html [ Skip ]
 # ARIA 1.1 table related attributes are not supported
 webkit.org/b/148967 accessibility/aria-table-attributes.html [ Skip ]
 
+# Text marker tests are not supported
+webkit.org/b/153292 accessibility/text-marker [ Skip ]
+
 # WebKitGTK+ needs WOFF2 support.
 webkit.org/b/152616 fast/text/woff2.html [ ImageOnlyFailure ]
 
index b66aebb..573bec5 100644 (file)
@@ -2764,6 +2764,9 @@ webkit.org/b/149297 accessibility/aria-current.html [ Pass ]
 # Enable "aria-table-attributes" test for iOS
 webkit.org/b/150366 accessibility/aria-table-attributes.html [ Pass ]
 
+# Enable Text marker tests for iOS
+webkit.org/b/153292 accessibility/text-marker [ Pass ]
+
 # More flaky tests (Sept 18, 2015)
 
 fast/forms/select-element-focus-ring.html [ Failure Pass ]
index 1ad4992..0a5c452 100644 (file)
@@ -1718,6 +1718,9 @@ webkit.org/b/146903 accessibility/roles-table-and-cell.html [ Skip ]
 webkit.org/b/138566 accessibility/aria-modal.html [ Skip ]
 webkit.org/b/138566 accessibility/aria-modal-multiple-dialogs.html [ Skip ]
 
+# Text marker tests are not supported
+webkit.org/b/153292 accessibility/text-marker [ Skip ]
+
 ################################################################################
 #######################   End Accessibility Issues   ###########################
 ################################################################################
index 03374a7..8b2cf24 100644 (file)
@@ -1,3 +1,48 @@
+2016-01-21  Nan Wang  <n_wang@apple.com>
+
+        AX: [IOS] Implement next/previous text marker functions using TextIterator
+        https://bugs.webkit.org/show_bug.cgi?id=153292
+        <rdar://problem/24268243>
+
+        Reviewed by Chris Fleizach.
+
+        Added support for the refactored next/previous text marker functions on iOS. And 
+        made text marker tests working on iOS.
+        Also, fixed an issue in AXObjectCache where creating a range with a replaced node
+        at the start or end might exclude that node.
+
+        Tests: accessibility/text-marker/text-marker-previous-next.html
+               accessibility/text-marker/text-marker-with-user-select-none.html
+
+        * accessibility/AXObjectCache.cpp:
+        (WebCore::characterOffsetsInOrder):
+        (WebCore::resetNodeAndOffsetForReplacedNode):
+        (WebCore::AXObjectCache::rangeForUnorderedCharacterOffsets):
+        * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
+        (+[WebAccessibilityTextMarker textMarkerWithVisiblePosition:cache:]):
+        (+[WebAccessibilityTextMarker textMarkerWithCharacterOffset:cache:]):
+        (+[WebAccessibilityTextMarker startOrEndTextMarkerForRange:isStart:cache:]):
+        (-[WebAccessibilityTextMarker dataRepresentation]):
+        (-[WebAccessibilityTextMarker visiblePosition]):
+        (-[WebAccessibilityTextMarker characterOffset]):
+        (-[WebAccessibilityTextMarker isIgnored]):
+        (-[WebAccessibilityTextMarker accessibilityObject]):
+        (-[WebAccessibilityTextMarker description]):
+        (-[WebAccessibilityObjectWrapper stringForTextMarkers:]):
+        (blockquoteLevel):
+        (-[WebAccessibilityObjectWrapper textMarkerRange]):
+        (-[WebAccessibilityObjectWrapper accessibilityObjectForTextMarker:]):
+        (-[WebAccessibilityObjectWrapper nextMarkerForMarker:]):
+        (-[WebAccessibilityObjectWrapper previousMarkerForMarker:]):
+        (-[WebAccessibilityObjectWrapper textMarkerForPoint:]):
+        (-[WebAccessibilityObjectWrapper nextMarkerForCharacterOffset:]):
+        (-[WebAccessibilityObjectWrapper previousMarkerForCharacterOffset:]):
+        (-[WebAccessibilityObjectWrapper rangeForTextMarkers:]):
+        (-[WebAccessibilityObjectWrapper lengthForTextMarkers:]):
+        (-[WebAccessibilityObjectWrapper startOrEndTextMarkerForTextMarkers:isStart:]):
+        (-[WebAccessibilityObjectWrapper textMarkerRangeForMarkers:]):
+        (-[WebAccessibilityObjectWrapper accessibilityIdentifier]):
+
 2016-01-20  Zalan Bujtas  <zalan@apple.com>
 
         http://victordarras.fr/cssgame/ doesn't work in Safari.
index 19985fa..8afc8a6 100644 (file)
@@ -1545,6 +1545,23 @@ static bool characterOffsetsInOrder(const CharacterOffset& characterOffset1, con
     return range1->compareBoundaryPoints(Range::START_TO_START, range2.get(), IGNORE_EXCEPTION) <= 0;
 }
 
+static Node* resetNodeAndOffsetForReplacedNode(Node* replacedNode, int& offset, int characterCount)
+{
+    // Use this function to include the replaced node itself in the range we are creating.
+    if (!replacedNode)
+        return nullptr;
+    
+    RefPtr<Range> nodeRange = AXObjectCache::rangeForNodeContents(replacedNode);
+    int nodeLength = TextIterator::rangeLength(nodeRange.get());
+    offset = characterCount <= nodeLength ? replacedNode->computeNodeIndex() : replacedNode->computeNodeIndex() + 1;
+    return replacedNode->parentNode();
+}
+
+static bool isReplacedNodeOrBR(Node* node)
+{
+    return AccessibilityObject::replacedNodeNeedsCharacter(node) || node->hasTagName(brTag);
+}
+
 RefPtr<Range> AXObjectCache::rangeForUnorderedCharacterOffsets(const CharacterOffset& characterOffset1, const CharacterOffset& characterOffset2)
 {
     if (characterOffset1.isNull() || characterOffset2.isNull())
@@ -1554,30 +1571,33 @@ RefPtr<Range> AXObjectCache::rangeForUnorderedCharacterOffsets(const CharacterOf
     CharacterOffset startCharacterOffset = alreadyInOrder ? characterOffset1 : characterOffset2;
     CharacterOffset endCharacterOffset = alreadyInOrder ? characterOffset2 : characterOffset1;
     
-    int endOffset = endCharacterOffset.offset;
-    
-    // endOffset can be out of bounds sometimes if the node is a replaced node or has brTag.
-    if (startCharacterOffset.node == endCharacterOffset.node) {
-        RefPtr<Range> nodeRange = AXObjectCache::rangeForNodeContents(startCharacterOffset.node);
-        int nodeLength = TextIterator::rangeLength(nodeRange.get());
-        if (endOffset > nodeLength)
-            endOffset = nodeLength;
-    }
-    
     int startOffset = startCharacterOffset.startIndex + startCharacterOffset.offset;
-    endOffset = endCharacterOffset.startIndex + endOffset;
-    
-    // If start node is a replaced node and it has children, we want to include the replaced node itself in the range.
+    int endOffset = endCharacterOffset.startIndex + endCharacterOffset.offset;
     Node* startNode = startCharacterOffset.node;
-    if (AccessibilityObject::replacedNodeNeedsCharacter(startNode) && (startNode->hasChildNodes() || startNode != endCharacterOffset.node)) {
-        startOffset = startNode->computeNodeIndex();
-        startNode = startNode->parentNode();
+    Node* endNode = endCharacterOffset.node;
+    
+    // Consider the case when the replaced node is at the start/end of the range.
+    bool startNodeIsReplacedOrBR = isReplacedNodeOrBR(startNode);
+    bool endNodeIsReplacedOrBR = isReplacedNodeOrBR(endNode);
+    if (startNodeIsReplacedOrBR || endNodeIsReplacedOrBR) {
+        // endOffset can be out of bounds sometimes if the node is a replaced node or has brTag and it has no children.
+        if (startNode == endNode && !startNode->hasChildNodes()) {
+            RefPtr<Range> nodeRange = AXObjectCache::rangeForNodeContents(startNode);
+            int nodeLength = TextIterator::rangeLength(nodeRange.get());
+            if (endCharacterOffset.offset > nodeLength)
+                endOffset = endCharacterOffset.startIndex + nodeLength;
+        } else {
+            if (startNodeIsReplacedOrBR)
+                startNode = resetNodeAndOffsetForReplacedNode(startNode, startOffset, startCharacterOffset.offset);
+            if (endNodeIsReplacedOrBR)
+                endNode = resetNodeAndOffsetForReplacedNode(startNode, endOffset, startCharacterOffset.offset);
+        }
     }
     
     RefPtr<Range> result = Range::create(m_document);
     ExceptionCode ecStart = 0, ecEnd = 0;
     result->setStart(startNode, startOffset, ecStart);
-    result->setEnd(endCharacterOffset.node, endOffset, ecEnd);
+    result->setEnd(endNode, endOffset, ecEnd);
     if (ecStart || ecEnd)
         return nullptr;
     
index 21b6557..9c7fe29 100644 (file)
@@ -134,6 +134,8 @@ static AccessibilityObjectWrapper* AccessibilityUnignoredAncestor(AccessibilityO
 }
 
 + (WebAccessibilityTextMarker *)textMarkerWithVisiblePosition:(VisiblePosition&)visiblePos cache:(AXObjectCache*)cache;
++ (WebAccessibilityTextMarker *)textMarkerWithCharacterOffset:(CharacterOffset&)characterOffset cache:(AXObjectCache*)cache;
++ (WebAccessibilityTextMarker *)startOrEndTextMarkerForRange:(const RefPtr<Range>)range isStart:(BOOL)isStart cache:(AXObjectCache*)cache;
 
 @end
 
@@ -178,6 +180,33 @@ static AccessibilityObjectWrapper* AccessibilityUnignoredAncestor(AccessibilityO
     return [[[WebAccessibilityTextMarker alloc] initWithTextMarker:&textMarkerData cache:cache] autorelease];
 }
 
++ (WebAccessibilityTextMarker *)textMarkerWithCharacterOffset:(CharacterOffset&)characterOffset cache:(AXObjectCache*)cache
+{
+    if (!cache)
+        return nil;
+    
+    if (characterOffset.isNull())
+        return nil;
+    
+    TextMarkerData textMarkerData;
+    cache->textMarkerDataForCharacterOffset(textMarkerData, *characterOffset.node, characterOffset.offset, false);
+    if (!textMarkerData.axID && !textMarkerData.ignored)
+        return nil;
+    return [[[WebAccessibilityTextMarker alloc] initWithTextMarker:&textMarkerData cache:cache] autorelease];
+}
+
++ (WebAccessibilityTextMarker *)startOrEndTextMarkerForRange:(const RefPtr<Range>)range isStart:(BOOL)isStart cache:(AXObjectCache*)cache
+{
+    if (!cache)
+        return nil;
+    
+    TextMarkerData textMarkerData;
+    cache->startOrEndTextMarkerDataForRange(textMarkerData, range, isStart);
+    if (!textMarkerData.axID)
+        return nil;
+    return [[[WebAccessibilityTextMarker alloc] initWithTextMarker:&textMarkerData cache:cache] autorelease];
+}
+
 - (NSData *)dataRepresentation
 {
     return [NSData dataWithBytes:&_textMarkerData length:sizeof(TextMarkerData)];
@@ -188,6 +217,25 @@ static AccessibilityObjectWrapper* AccessibilityUnignoredAncestor(AccessibilityO
     return _cache->visiblePositionForTextMarkerData(_textMarkerData);
 }
 
+- (CharacterOffset)characterOffset
+{
+    if (_textMarkerData.ignored)
+        return CharacterOffset();
+    return CharacterOffset(_textMarkerData.node, _textMarkerData.characterStartIndex, _textMarkerData.characterOffset);
+}
+
+- (BOOL)isIgnored
+{
+    return _textMarkerData.ignored;
+}
+
+- (AccessibilityObject*)accessibilityObject
+{
+    if (_textMarkerData.ignored)
+        return nullptr;
+    return _cache->accessibilityObjectForTextMarkerData(_textMarkerData);
+}
+
 - (NSString *)description
 {
     return [NSString stringWithFormat:@"[AXTextMarker %p] = node: %p offset: %d", self, _textMarkerData.node, _textMarkerData.offset];
@@ -1831,25 +1879,11 @@ static RenderObject* rendererForView(WAKView* view)
     if (![self _prepareAccessibilityCall])
         return nil;
     
-    if ([markers count] != 2)
-        return nil;
-    
-    WebAccessibilityTextMarker* startMarker = [markers objectAtIndex:0];
-    WebAccessibilityTextMarker* endMarker = [markers objectAtIndex:1];
-    if (![startMarker isKindOfClass:[WebAccessibilityTextMarker class]] || ![endMarker isKindOfClass:[WebAccessibilityTextMarker class]])
-        return nil;
-    
-    // extract the start and end VisiblePosition
-    VisiblePosition startVisiblePosition = [startMarker visiblePosition];
-    if (startVisiblePosition.isNull())
+    RefPtr<Range> range = [self rangeForTextMarkers:markers];
+    if (!range)
         return nil;
     
-    VisiblePosition endVisiblePosition = [endMarker visiblePosition];
-    if (endVisiblePosition.isNull())
-        return nil;
-
-    VisiblePositionRange visiblePosRange = VisiblePositionRange(startVisiblePosition, endVisiblePosition);
-    return m_object->stringForVisiblePositionRange(visiblePosRange);
+    return m_object->stringForRange(range);
 }
 
 static int blockquoteLevel(RenderObject* renderer)
@@ -2124,13 +2158,8 @@ static void AXAttributedStringAppendText(NSMutableAttributedString* attrString,
     if (![self _prepareAccessibilityCall])
         return nil;
     
-    VisiblePositionRange range = m_object->visiblePositionRange();
-    VisiblePosition startPosition = range.start;
-    VisiblePosition endPosition = range.end;
-    WebAccessibilityTextMarker* start = [WebAccessibilityTextMarker textMarkerWithVisiblePosition:startPosition cache:m_object->axObjectCache()];
-    WebAccessibilityTextMarker* end = [WebAccessibilityTextMarker textMarkerWithVisiblePosition:endPosition cache:m_object->axObjectCache()];
-    
-    return [NSArray arrayWithObjects:start, end, nil];
+    RefPtr<Range> range = m_object->elementRange();
+    return [self textMarkersForRange:range];
 }
 
 // A method to get the normalized text cursor range of an element. Used in DumpRenderTree.
@@ -2160,8 +2189,7 @@ static void AXAttributedStringAppendText(NSMutableAttributedString* attrString,
     if (!marker)
         return nil;
     
-    VisiblePosition visiblePosition = [marker visiblePosition];
-    AccessibilityObject* obj = m_object->accessibilityObjectForPosition(visiblePosition);
+    AccessibilityObject* obj = [marker accessibilityObject];
     if (!obj)
         return nil;
     
@@ -2354,14 +2382,10 @@ static void AXAttributedStringAppendText(NSMutableAttributedString* attrString,
     if (!marker)
         return nil;
     
-    VisiblePosition start = [marker visiblePosition];
-    VisiblePosition nextMarker = m_object->nextVisiblePosition(start);
-    
-    return [WebAccessibilityTextMarker textMarkerWithVisiblePosition:nextMarker cache:m_object->axObjectCache()];
+    CharacterOffset start = [marker characterOffset];
+    return [self nextMarkerForCharacterOffset:start];
 }
 
-// This method is intended to return the marker at the start of the line starting at
-// the marker that is passed into the method.
 - (WebAccessibilityTextMarker *)previousMarkerForMarker:(WebAccessibilityTextMarker *)marker
 {
     if (![self _prepareAccessibilityCall])
@@ -2370,10 +2394,8 @@ static void AXAttributedStringAppendText(NSMutableAttributedString* attrString,
     if (!marker)
         return nil;
     
-    VisiblePosition start = [marker visiblePosition];
-    VisiblePosition previousMarker = m_object->previousVisiblePosition(start);
-    
-    return [WebAccessibilityTextMarker textMarkerWithVisiblePosition:previousMarker cache:m_object->axObjectCache()];
+    CharacterOffset start = [marker characterOffset];
+    return [self previousMarkerForCharacterOffset:start];
 }
 
 // This method is intended to return the bounds of a text marker range in screen coordinates.
@@ -2403,6 +2425,87 @@ static void AXAttributedStringAppendText(NSMutableAttributedString* attrString,
     return [WebAccessibilityTextMarker textMarkerWithVisiblePosition:pos cache:m_object->axObjectCache()];
 }
 
+- (WebAccessibilityTextMarker *)nextMarkerForCharacterOffset:(CharacterOffset&)characterOffset
+{
+    characterOffset.offset = characterOffset.offset + 1;
+    WebAccessibilityTextMarker *textMarker = [WebAccessibilityTextMarker textMarkerWithCharacterOffset:characterOffset cache:m_object->axObjectCache()];
+    if (textMarker && textMarker.isIgnored)
+        textMarker = [self nextMarkerForCharacterOffset:characterOffset];
+    return textMarker;
+}
+
+- (WebAccessibilityTextMarker *)previousMarkerForCharacterOffset:(CharacterOffset&)characterOffset
+{
+    characterOffset.offset = characterOffset.offset - 1;
+    WebAccessibilityTextMarker *textMarker = [WebAccessibilityTextMarker textMarkerWithCharacterOffset:characterOffset cache:m_object->axObjectCache()];
+    if (textMarker && textMarker.isIgnored)
+        textMarker = [self previousMarkerForCharacterOffset:characterOffset];
+    return textMarker;
+}
+
+- (RefPtr<Range>)rangeForTextMarkers:(NSArray *)textMarkers
+{
+    if ([textMarkers count] != 2)
+        return nullptr;
+    
+    WebAccessibilityTextMarker *startMarker = [textMarkers objectAtIndex:0];
+    WebAccessibilityTextMarker *endMarker = [textMarkers objectAtIndex:1];
+    
+    if (![startMarker isKindOfClass:[WebAccessibilityTextMarker class]] || ![endMarker isKindOfClass:[WebAccessibilityTextMarker class]])
+        return nullptr;
+    
+    AXObjectCache* cache = m_object->axObjectCache();
+    if (!cache)
+        return nullptr;
+    
+    CharacterOffset startCharacterOffset = [startMarker characterOffset];
+    CharacterOffset endCharacterOffset = [endMarker characterOffset];
+    return cache->rangeForUnorderedCharacterOffsets(startCharacterOffset, endCharacterOffset);
+}
+
+- (NSInteger)lengthForTextMarkers:(NSArray *)textMarkers
+{
+    if (![self _prepareAccessibilityCall])
+        return 0;
+    
+    RefPtr<Range> range = [self rangeForTextMarkers:textMarkers];
+    int length = AXObjectCache::lengthForRange(range.get());
+    return length < 0 ? 0 : length;
+}
+
+- (WebAccessibilityTextMarker *)startOrEndTextMarkerForTextMarkers:(NSArray *)textMarkers isStart:(BOOL)isStart
+{
+    if (![self _prepareAccessibilityCall])
+        return nil;
+    
+    RefPtr<Range> range = [self rangeForTextMarkers:textMarkers];
+    if (!range)
+        return nil;
+    
+    return [WebAccessibilityTextMarker startOrEndTextMarkerForRange:range isStart:isStart cache:m_object->axObjectCache()];
+}
+
+- (NSArray *)textMarkerRangeForMarkers:(NSArray *)textMarkers
+{
+    if (![self _prepareAccessibilityCall])
+        return nil;
+    
+    RefPtr<Range> range = [self rangeForTextMarkers:textMarkers];
+    return [self textMarkersForRange:range];
+}
+
+- (NSArray *)textMarkersForRange:(RefPtr<Range>)range
+{
+    if (!range)
+        return nil;
+    
+    WebAccessibilityTextMarker* start = [WebAccessibilityTextMarker startOrEndTextMarkerForRange:range isStart:YES cache:m_object->axObjectCache()];
+    WebAccessibilityTextMarker* end = [WebAccessibilityTextMarker startOrEndTextMarkerForRange:range isStart:NO cache:m_object->axObjectCache()];
+    if (!start || !end)
+        return nil;
+    return [NSArray arrayWithObjects:start, end, nil];
+}
+
 - (NSString *)accessibilityIdentifier
 {
     if (![self _prepareAccessibilityCall])
index d7fec4a..0ce01cc 100644 (file)
@@ -1,3 +1,69 @@
+2016-01-21  Nan Wang  <n_wang@apple.com>
+
+        AX: [IOS] Implement next/previous text marker functions using TextIterator
+        https://bugs.webkit.org/show_bug.cgi?id=153292
+        <rdar://problem/24268243>
+
+        Reviewed by Chris Fleizach.
+
+        Made text marker tests available on iOS.
+
+        * DumpRenderTree/AccessibilityTextMarker.h:
+        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
+        * DumpRenderTree/ios/AccessibilityTextMarkerIOS.mm: Added.
+        (AccessibilityTextMarker::AccessibilityTextMarker):
+        (AccessibilityTextMarker::~AccessibilityTextMarker):
+        (AccessibilityTextMarker::isEqual):
+        (AccessibilityTextMarker::platformTextMarker):
+        (AccessibilityTextMarkerRange::AccessibilityTextMarkerRange):
+        (AccessibilityTextMarkerRange::~AccessibilityTextMarkerRange):
+        (AccessibilityTextMarkerRange::isEqual):
+        (AccessibilityTextMarkerRange::platformTextMarkerRange):
+        * DumpRenderTree/ios/AccessibilityUIElementIOS.mm:
+        (AccessibilityUIElement::pathDescription):
+        (AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
+        (AccessibilityUIElement::textMarkerRangeForElement):
+        (AccessibilityUIElement::selectedTextMarkerRange):
+        (AccessibilityUIElement::resetSelectedTextMarkerRange):
+        (AccessibilityUIElement::textMarkerRangeLength):
+        (AccessibilityUIElement::textMarkerRangeForMarkers):
+        (AccessibilityUIElement::startTextMarkerForTextMarkerRange):
+        (AccessibilityUIElement::endTextMarkerForTextMarkerRange):
+        (AccessibilityUIElement::accessibilityElementForTextMarker):
+        (AccessibilityUIElement::endTextMarkerForBounds):
+        (AccessibilityUIElement::startTextMarkerForBounds):
+        (AccessibilityUIElement::textMarkerForPoint):
+        (AccessibilityUIElement::previousTextMarker):
+        (AccessibilityUIElement::nextTextMarker):
+        (AccessibilityUIElement::stringForTextMarkerRange):
+        (AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute):
+        (AccessibilityUIElement::indexForTextMarker):
+        (AccessibilityUIElement::isTextMarkerValid):
+        (AccessibilityUIElement::textMarkerForIndex):
+        (AccessibilityUIElement::startTextMarker):
+        (AccessibilityUIElement::endTextMarker):
+        (AccessibilityUIElement::setSelectedVisibleTextRange):
+        (AccessibilityUIElement::getLinkedUIElements):
+        * DumpRenderTree/mac/AccessibilityTextMarkerMac.mm:
+        (AccessibilityTextMarkerRange::platformTextMarkerRange):
+        * DumpRenderTree/mac/AccessibilityUIElementMac.mm:
+        (AccessibilityUIElement::removeSelection):
+        (AccessibilityUIElement::lineTextMarkerRangeForTextMarker):
+        (AccessibilityUIElement::setSelectedVisibleTextRange):
+        (AccessibilityUIElement::supportedActions):
+        * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:
+        (WTR::AccessibilityUIElement::textMarkerRangeForElement):
+        (WTR::AccessibilityUIElement::textMarkerRangeLength):
+        (WTR::AccessibilityUIElement::previousTextMarker):
+        (WTR::AccessibilityUIElement::nextTextMarker):
+        (WTR::AccessibilityUIElement::stringForTextMarkerRange):
+        (WTR::AccessibilityUIElement::textMarkerRangeForMarkers):
+        (WTR::AccessibilityUIElement::startTextMarkerForTextMarkerRange):
+        (WTR::AccessibilityUIElement::endTextMarkerForTextMarkerRange):
+        (WTR::AccessibilityUIElement::endTextMarkerForBounds):
+        (WTR::AccessibilityUIElement::accessibilityElementForTextMarker):
+        (WTR::AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute):
+
 2016-01-20  Filip Pizlo  <fpizlo@apple.com>
 
         Unreviewed, revert accidental unreviewed commit.
index 7e17b14..7809ea4 100644 (file)
@@ -28,7 +28,7 @@
 
 #include <JavaScriptCore/JSObjectRef.h>
 
-#if PLATFORM(MAC) && !PLATFORM(IOS)
+#if PLATFORM(MAC) || PLATFORM(IOS)
 #define SUPPORTS_AX_TEXTMARKERS 1
 #else
 #define SUPPORTS_AX_TEXTMARKERS 0
@@ -58,7 +58,7 @@ public:
     
 private:
     static JSClassRef getJSClass();
-#if SUPPORTS_AX_TEXTMARKERS
+#if SUPPORTS_AX_TEXTMARKERS && PLATFORM(MAC)
     RetainPtr<PlatformTextMarker> m_textMarker;
 #else
     PlatformTextMarker m_textMarker;
@@ -78,7 +78,7 @@ public:
     
 private:
     static JSClassRef getJSClass();
-#if SUPPORTS_AX_TEXTMARKERS
+#if SUPPORTS_AX_TEXTMARKERS && PLATFORM(MAC)
     RetainPtr<PlatformTextMarkerRange> m_textMarkerRange;
 #else
     PlatformTextMarkerRange m_textMarkerRange;
index 0a924d3..0a9ae82 100644 (file)
@@ -95,6 +95,7 @@
                A8B91ADC0CF3B32F008F91FF /* DumpRenderTreeWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = A8B91AD90CF3B32F008F91FF /* DumpRenderTreeWindow.mm */; };
                A8B91BFD0CF522B4008F91FF /* CheckedMalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8B91BF70CF522B4008F91FF /* CheckedMalloc.cpp */; };
                A8D79CEB0FC28B2C004AC8FE /* DumpRenderTreeFileDraggingSource.m in Sources */ = {isa = PBXBuildFile; fileRef = A8D79CE90FC28B2C004AC8FE /* DumpRenderTreeFileDraggingSource.m */; };
+               A9BB7C5C1C505278002C525B /* AccessibilityTextMarkerIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = A9BB7C5B1C505278002C525B /* AccessibilityTextMarkerIOS.mm */; };
                AA5A15EF16E15CD000F7C561 /* AccessibilityControllerIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = AA5A15ED16E15CD000F7C561 /* AccessibilityControllerIOS.mm */; };
                AA5A15F016E15CD000F7C561 /* AccessibilityUIElementIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = AA5A15EE16E15CD000F7C561 /* AccessibilityUIElementIOS.mm */; };
                BC0131DA0C9772010087317D /* TestRunner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC0131D80C9772010087317D /* TestRunner.cpp */; };
                A8B91BF90CF522B4008F91FF /* CheckedMalloc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CheckedMalloc.h; path = mac/CheckedMalloc.h; sourceTree = "<group>"; };
                A8D79CE80FC28B2C004AC8FE /* DumpRenderTreeFileDraggingSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DumpRenderTreeFileDraggingSource.h; sourceTree = "<group>"; };
                A8D79CE90FC28B2C004AC8FE /* DumpRenderTreeFileDraggingSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DumpRenderTreeFileDraggingSource.m; sourceTree = "<group>"; };
+               A9BB7C5B1C505278002C525B /* AccessibilityTextMarkerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AccessibilityTextMarkerIOS.mm; path = ios/AccessibilityTextMarkerIOS.mm; sourceTree = "<group>"; };
                AA5A15ED16E15CD000F7C561 /* AccessibilityControllerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AccessibilityControllerIOS.mm; path = ios/AccessibilityControllerIOS.mm; sourceTree = "<group>"; };
                AA5A15EE16E15CD000F7C561 /* AccessibilityUIElementIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AccessibilityUIElementIOS.mm; path = ios/AccessibilityUIElementIOS.mm; sourceTree = "<group>"; };
                AA7F10C20CB3C1030003BDC9 /* AHEM____.TTF */ = {isa = PBXFileReference; lastKnownFileType = file; name = "AHEM____.TTF"; path = "fonts/AHEM____.TTF"; sourceTree = "<group>"; };
                                80045AEC147718E7008290A8 /* AccessibilityNotificationHandler.mm */,
                                29CFBA0F122736E600BC30C0 /* AccessibilityTextMarker.cpp */,
                                29CFBA0E122736E600BC30C0 /* AccessibilityTextMarker.h */,
+                               A9BB7C5B1C505278002C525B /* AccessibilityTextMarkerIOS.mm */,
                                29CFBA2D12273A1000BC30C0 /* AccessibilityTextMarkerMac.mm */,
                                BC0E24DF0E2D9451001B6BC2 /* AccessibilityUIElement.cpp */,
                                BC0E24DE0E2D9451001B6BC2 /* AccessibilityUIElement.h */,
                                BCA18C470C9B5B9400114369 /* DumpRenderTree.mm in Sources */,
                                9830F31F15C81181005AB206 /* DumpRenderTreeCommon.cpp in Sources */,
                                BCA18B7B0C9B08F100114369 /* DumpRenderTreeDraggingInfo.mm in Sources */,
+                               A9BB7C5C1C505278002C525B /* AccessibilityTextMarkerIOS.mm in Sources */,
                                A8D79CEB0FC28B2C004AC8FE /* DumpRenderTreeFileDraggingSource.m in Sources */,
                                A8B91ADA0CF3B32F008F91FF /* DumpRenderTreePasteboard.m in Sources */,
                                A8B91ADC0CF3B32F008F91FF /* DumpRenderTreeWindow.mm in Sources */,
diff --git a/Tools/DumpRenderTree/ios/AccessibilityTextMarkerIOS.mm b/Tools/DumpRenderTree/ios/AccessibilityTextMarkerIOS.mm
new file mode 100644 (file)
index 0000000..6f6bb4b
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#import "config.h"
+#import "AccessibilityTextMarker.h"
+
+#import "DumpRenderTree.h"
+
+#if SUPPORTS_AX_TEXTMARKERS && PLATFORM(IOS)
+
+// MARK: AccessibilityTextMarker
+
+AccessibilityTextMarker::AccessibilityTextMarker(PlatformTextMarker marker)
+    : m_textMarker(marker)
+{
+}
+
+AccessibilityTextMarker::AccessibilityTextMarker(const AccessibilityTextMarker& marker)
+    : m_textMarker(marker.platformTextMarker())
+{
+}
+
+AccessibilityTextMarker::~AccessibilityTextMarker()
+{
+}
+
+bool AccessibilityTextMarker::isEqual(AccessibilityTextMarker* other)
+{
+    return [(id)platformTextMarker() isEqual:(id)other->platformTextMarker()];
+}
+
+PlatformTextMarker AccessibilityTextMarker::platformTextMarker() const 
+{ 
+    return m_textMarker;
+}
+
+// MARK: AccessibilityTextMarkerRange
+
+AccessibilityTextMarkerRange::AccessibilityTextMarkerRange(PlatformTextMarkerRange markerRange)
+    : m_textMarkerRange(markerRange)
+{
+}
+
+AccessibilityTextMarkerRange::AccessibilityTextMarkerRange(const AccessibilityTextMarkerRange& markerRange)
+    : m_textMarkerRange(markerRange.platformTextMarkerRange())
+{
+}
+
+AccessibilityTextMarkerRange::~AccessibilityTextMarkerRange()
+{
+}
+
+bool AccessibilityTextMarkerRange::isEqual(AccessibilityTextMarkerRange* other)
+{
+    return [(id)platformTextMarkerRange() isEqual:(id)other->platformTextMarkerRange()];
+}
+
+PlatformTextMarkerRange AccessibilityTextMarkerRange::platformTextMarkerRange() const
+{
+    return m_textMarkerRange;
+}
+
+#endif // SUPPORTS_AX_TEXTMARKERS && PLATFORM(IOS)
index 0bb5ca2..3a3f6a7 100644 (file)
@@ -94,6 +94,16 @@ AccessibilityUIElement::~AccessibilityUIElement()
 - (NSUInteger)accessibilityARIAColumnIndex;
 - (UIAccessibilityTraits)_axContainedByFieldsetTrait;
 - (id)_accessibilityFieldsetAncestor;
+
+// TextMarker related
+- (NSArray *)textMarkerRange;
+- (NSInteger)lengthForTextMarkers:(NSArray *)textMarkers;
+- (NSString *)stringForTextMarkers:(NSArray *)markers;
+- (id)startOrEndTextMarkerForTextMarkers:(NSArray*)textMarkers isStart:(BOOL)isStart;
+- (NSArray *)textMarkerRangeForMarkers:(NSArray *)textMarkers;
+- (id)nextMarkerForMarker:(id)marker;
+- (id)previousMarkerForMarker:(id)marker;
+- (id)accessibilityObjectForTextMarker:(id)marker;
 @end
 
 @interface NSObject (WebAccessibilityObjectWrapperPrivate)
@@ -411,6 +421,137 @@ JSStringRef AccessibilityUIElement::pathDescription() const
     return [result createJSStringRef];
 }
 
+#if SUPPORTS_AX_TEXTMARKERS && PLATFORM(IOS)
+
+// Text markers
+
+AccessibilityTextMarkerRange AccessibilityUIElement::lineTextMarkerRangeForTextMarker(AccessibilityTextMarker*)
+{
+    return nullptr;
+}
+
+AccessibilityTextMarkerRange AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
+{
+    id textMarkerRange = [element->platformUIElement() textMarkerRange];
+    return AccessibilityTextMarkerRange(textMarkerRange);
+}
+
+AccessibilityTextMarkerRange AccessibilityUIElement::selectedTextMarkerRange()
+{
+    return nullptr;
+}
+
+void AccessibilityUIElement::resetSelectedTextMarkerRange()
+{
+}
+
+int AccessibilityUIElement::textMarkerRangeLength(AccessibilityTextMarkerRange* range)
+{
+    id textMarkers = (id)range->platformTextMarkerRange();
+    return [m_element lengthForTextMarkers:textMarkers];
+}
+
+AccessibilityTextMarkerRange AccessibilityUIElement::textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker)
+{
+    NSArray *textMarkers = [NSArray arrayWithObjects:(id)startMarker->platformTextMarker(), (id)endMarker->platformTextMarker(), nil];
+    id textMarkerRange = [m_element textMarkerRangeForMarkers:textMarkers];
+    return AccessibilityTextMarkerRange(textMarkerRange);
+}
+
+AccessibilityTextMarker AccessibilityUIElement::startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange* range)
+{
+    id textMarkers = (id)range->platformTextMarkerRange();
+    id textMarker = [m_element startOrEndTextMarkerForTextMarkers:textMarkers isStart:YES];
+    return AccessibilityTextMarker(textMarker);
+}
+
+AccessibilityTextMarker AccessibilityUIElement::endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange* range)
+{
+    id textMarkers = (id)range->platformTextMarkerRange();
+    id textMarker = [m_element startOrEndTextMarkerForTextMarkers:textMarkers isStart:NO];
+    return AccessibilityTextMarker(textMarker);
+}
+
+AccessibilityUIElement AccessibilityUIElement::accessibilityElementForTextMarker(AccessibilityTextMarker* marker)
+{
+    id obj = [m_element accessibilityObjectForTextMarker:(id)marker->platformTextMarker()];
+    if (obj)
+        return AccessibilityUIElement(obj);
+    return nullptr;
+}
+
+AccessibilityTextMarker AccessibilityUIElement::endTextMarkerForBounds(int x, int y, int width, int height)
+{
+    return nullptr;
+}
+
+AccessibilityTextMarker AccessibilityUIElement::startTextMarkerForBounds(int x, int y, int width, int height)
+{
+    return nullptr;
+}
+
+AccessibilityTextMarker AccessibilityUIElement::textMarkerForPoint(int x, int y)
+{
+    return nullptr;
+}
+
+AccessibilityTextMarker AccessibilityUIElement::previousTextMarker(AccessibilityTextMarker* textMarker)
+{
+    id previousMarker = [m_element previousMarkerForMarker:(id)textMarker->platformTextMarker()];
+    return AccessibilityTextMarker(previousMarker);
+}
+
+AccessibilityTextMarker AccessibilityUIElement::nextTextMarker(AccessibilityTextMarker* textMarker)
+{
+    id nextMarker = [m_element nextMarkerForMarker:(id)textMarker->platformTextMarker()];
+    return AccessibilityTextMarker(nextMarker);
+}
+
+JSStringRef AccessibilityUIElement::stringForTextMarkerRange(AccessibilityTextMarkerRange* markerRange)
+{
+    id textMarkers = (id)markerRange->platformTextMarkerRange();
+    if (!textMarkers || ![textMarkers isKindOfClass:[NSArray class]])
+        return JSStringCreateWithCharacters(0, 0);
+    return [[m_element stringForTextMarkers:textMarkers] createJSStringRef];
+}
+
+bool AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute(JSStringRef, AccessibilityTextMarkerRange*)
+{
+    return false;
+}
+
+int AccessibilityUIElement::indexForTextMarker(AccessibilityTextMarker*)
+{
+    return -1;
+}
+
+bool AccessibilityUIElement::isTextMarkerValid(AccessibilityTextMarker*)
+{
+    return false;
+}
+
+AccessibilityTextMarker AccessibilityUIElement::textMarkerForIndex(int)
+{
+    return nullptr;
+}
+
+AccessibilityTextMarker AccessibilityUIElement::startTextMarker()
+{
+    return nullptr;
+}
+
+AccessibilityTextMarker AccessibilityUIElement::endTextMarker()
+{
+    return nullptr;
+}
+
+bool AccessibilityUIElement::setSelectedVisibleTextRange(AccessibilityTextMarkerRange*)
+{
+    return false;
+}
+
+#endif // SUPPORTS_AX_TEXTMARKERS && PLATFORM(IOS)
+
 #pragma mark Unused
 
 void AccessibilityUIElement::getLinkedUIElements(Vector<AccessibilityUIElement>& elementVector)
index 59faaa4..b4781e2 100644 (file)
@@ -28,7 +28,7 @@
 #import "AccessibilityTextMarker.h"
 #import "DumpRenderTree.h"
 
-#if SUPPORTS_AX_TEXTMARKERS
+#if SUPPORTS_AX_TEXTMARKERS && PLATFORM(MAC)
 
 // MARK: AccessibilityTextMarker
 
@@ -82,4 +82,4 @@ PlatformTextMarkerRange AccessibilityTextMarkerRange::platformTextMarkerRange()
     return m_textMarkerRange.get();
 }
 
-#endif // SUPPORTS_AX_TEXTMARKERS
+#endif // SUPPORTS_AX_TEXTMARKERS && PLATFORM(MAC)
index e1cd770..4b040a3 100644 (file)
@@ -1612,7 +1612,7 @@ void AccessibilityUIElement::removeSelection()
     // FIXME: implement
 }
 
-#if SUPPORTS_AX_TEXTMARKERS
+#if SUPPORTS_AX_TEXTMARKERS && PLATFORM(MAC)
 
 // Text markers
 AccessibilityTextMarkerRange AccessibilityUIElement::lineTextMarkerRangeForTextMarker(AccessibilityTextMarker* textMarker)
@@ -1846,7 +1846,7 @@ bool AccessibilityUIElement::setSelectedVisibleTextRange(AccessibilityTextMarker
     return true;
 }
 
-#endif // SUPPORTS_AX_TEXTMARKERS
+#endif // SUPPORTS_AX_TEXTMARKERS && PLATFORM(MAC)
 
 JSStringRef AccessibilityUIElement::supportedActions()
 {
index 3045ce6..44109c3 100644 (file)
@@ -71,6 +71,16 @@ typedef void (*AXPostedNotificationCallback)(id element, NSString* notification,
 - (NSUInteger)accessibilityARIAColumnIndex;
 - (UIAccessibilityTraits)_axContainedByFieldsetTrait;
 - (id)_accessibilityFieldsetAncestor;
+
+// TextMarker related
+- (NSArray *)textMarkerRange;
+- (NSInteger)lengthForTextMarkers:(NSArray *)textMarkers;
+- (NSString *)stringForTextMarkers:(NSArray *)markers;
+- (id)startOrEndTextMarkerForTextMarkers:(NSArray*)textMarkers isStart:(BOOL)isStart;
+- (NSArray *)textMarkerRangeForMarkers:(NSArray *)textMarkers;
+- (id)nextMarkerForMarker:(id)marker;
+- (id)previousMarkerForMarker:(id)marker;
+- (id)accessibilityObjectForTextMarker:(id)marker;
 @end
 
 @interface NSObject (WebAccessibilityObjectWrapperPrivate)
@@ -982,42 +992,55 @@ PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::lineTextMarkerR
 
 PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
 {
-    return 0;
+    id textMarkerRange = [element->platformUIElement() textMarkerRange];
+    return AccessibilityTextMarkerRange::create(textMarkerRange);
 }
 
 int AccessibilityUIElement::textMarkerRangeLength(AccessibilityTextMarkerRange* range)
 {
-    return 0;
+    id textMarkers = (id)range->platformTextMarkerRange();    
+    return [m_element lengthForTextMarkers:textMarkers];
 }
 
 PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::previousTextMarker(AccessibilityTextMarker* textMarker)
 {
-    return 0;
+    id previousMarker = [m_element previousMarkerForMarker:(id)textMarker->platformTextMarker()];
+    return AccessibilityTextMarker::create(previousMarker);
 }
 
 PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::nextTextMarker(AccessibilityTextMarker* textMarker)
 {
-    return 0;
+    id nextMarker = [m_element nextMarkerForMarker:(id)textMarker->platformTextMarker()];
+    return AccessibilityTextMarker::create(nextMarker);
 }
 
 JSRetainPtr<JSStringRef> AccessibilityUIElement::stringForTextMarkerRange(AccessibilityTextMarkerRange* markerRange)
 {
-    return 0;
+    id textMarkers = (id)markerRange->platformTextMarkerRange();
+    if (!textMarkers || ![textMarkers isKindOfClass:[NSArray class]])
+        return JSStringCreateWithCharacters(0, 0);
+    return [[m_element stringForTextMarkers:textMarkers] createJSStringRef];
 }
 
 PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker)
 {
-    return 0;
+    NSArray *textMarkers = [NSArray arrayWithObjects:(id)startMarker->platformTextMarker(), (id)endMarker->platformTextMarker(), nil];
+    id textMarkerRange = [m_element textMarkerRangeForMarkers:textMarkers];
+    return AccessibilityTextMarkerRange::create(textMarkerRange);
 }
 
 PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange* range)
 {
-    return 0;
+    id textMarkers = (id)range->platformTextMarkerRange();
+    id textMarker = [m_element startOrEndTextMarkerForTextMarkers:textMarkers isStart:YES];
+    return AccessibilityTextMarker::create(textMarker);
 }
 
 PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange* range)
 {
-    return 0;
+    id textMarkers = (id)range->platformTextMarkerRange();
+    id textMarker = [m_element startOrEndTextMarkerForTextMarkers:textMarkers isStart:NO];
+    return AccessibilityTextMarker::create(textMarker);
 }
 
 PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::endTextMarkerForBounds(int x, int y, int width, int height)
@@ -1037,7 +1060,10 @@ PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::textMarkerForPoint(i
 
 PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::accessibilityElementForTextMarker(AccessibilityTextMarker* marker)
 {
-    return 0;
+    id obj = [m_element accessibilityObjectForTextMarker:(id)marker->platformTextMarker()];
+    if (obj)
+        return AccessibilityUIElement::create(obj);
+    return nullptr;
 }
 
 bool AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute(JSStringRef attribute, AccessibilityTextMarkerRange* range)