AX: AXSelectTextWithCriteriaParameterizedAttribute incorrectly selects the beginning...
authorcfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Aug 2014 17:32:21 +0000 (17:32 +0000)
committercfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Aug 2014 17:32:21 +0000 (17:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=135547

Reviewed by Mario Sanchez Prada.

Source/WebCore:
Allow text search to specify that it wants to match end of words as well as start of words.
This allows select text criteria to match on whole words only.

Test: platform/mac/accessibility/select-text-should-match-whole-words.html

* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::rangeOfStringClosestToRangeInDirection):
* editing/FindOptions.h:
* editing/TextIterator.cpp:
(WebCore::SearchBuffer::isWordEndMatch):
(WebCore::SearchBuffer::search):

LayoutTests:
* platform/mac/accessibility/select-text-should-match-whole-words-expected.txt: Added.
* platform/mac/accessibility/select-text-should-match-whole-words.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityObject.cpp
Source/WebCore/editing/FindOptions.h
Source/WebCore/editing/TextIterator.cpp

index 74fff3b..b166ddd 100644 (file)
@@ -1,5 +1,15 @@
 2014-08-04  Chris Fleizach  <cfleizach@apple.com>
 
+        AX: AXSelectTextWithCriteriaParameterizedAttribute incorrectly selects the beginning letters of a word
+        https://bugs.webkit.org/show_bug.cgi?id=135547
+
+        Reviewed by Mario Sanchez Prada.
+
+        * platform/mac/accessibility/select-text-should-match-whole-words-expected.txt: Added.
+        * platform/mac/accessibility/select-text-should-match-whole-words.html: Added.
+
+2014-08-04  Chris Fleizach  <cfleizach@apple.com>
+
         AX: The Dictation command "Replace <phrase> with <phrase>" always capitalizes the replacement string
         https://bugs.webkit.org/show_bug.cgi?id=135557
 
diff --git a/LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words-expected.txt b/LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words-expected.txt
new file mode 100644 (file)
index 0000000..918f0ef
--- /dev/null
@@ -0,0 +1,17 @@
+The man jumped high.
+
+This tests that selection matches whole words, rather than partial matches.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS result is ''
+PASS windowSelection.getRangeAt(0).startOffset is 0
+PASS windowSelection.getRangeAt(0).endOffset is 0
+PASS result is 'jumped'
+PASS windowSelection.getRangeAt(0).startOffset is 8
+PASS windowSelection.getRangeAt(0).endOffset is 14
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words.html b/LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words.html
new file mode 100644 (file)
index 0000000..f174c4f
--- /dev/null
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../../resources/js-test-pre.js"></script>
+<title>Select Text</title>
+</head>
+<body>
+
+<p contenteditable="true" id="text">The man jumped high.</p>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+    description("This tests that selection matches whole words, rather than partial matches.");
+    
+    if (window.accessibilityController) {
+        var text = accessibilityController.accessibleElementById("text");
+        var windowSelection = window.getSelection();
+        windowSelection.removeAllRanges();
+
+        // A matching range before the selection should be selected when searching for closest match.
+        document.getElementById("text").focus();
+
+        // First find the range before the current selection.
+        var range = document.createRange();
+        range.setStart(document.getElementById("text").firstChild, 0);
+        range.setEnd(document.getElementById("text").firstChild, 0);
+        windowSelection.addRange(range);
+      
+        // Try to select a partial word, it should fail.
+        result = text.selectTextWithCriteria("AXSelectTextAmbiguityResolutionClosestToSelection", "jump");
+        shouldBe("result", "''");
+        shouldBe("windowSelection.getRangeAt(0).startOffset", "0");
+        shouldBe("windowSelection.getRangeAt(0).endOffset", "0");
+
+        // Select the whole word, it should succeed.
+        result = text.selectTextWithCriteria("AXSelectTextAmbiguityResolutionClosestToSelection", "jumped");
+        shouldBe("result", "'jumped'");
+        shouldBe("windowSelection.getRangeAt(0).startOffset", "8");
+        shouldBe("windowSelection.getRangeAt(0).endOffset", "14");
+
+    }
+</script>
+
+<script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
index 39b828b..fd11b6c 100644 (file)
@@ -1,3 +1,22 @@
+2014-08-04  Chris Fleizach  <cfleizach@apple.com>
+
+        AX: AXSelectTextWithCriteriaParameterizedAttribute incorrectly selects the beginning letters of a word
+        https://bugs.webkit.org/show_bug.cgi?id=135547
+
+        Reviewed by Mario Sanchez Prada.
+
+        Allow text search to specify that it wants to match end of words as well as start of words.
+        This allows select text criteria to match on whole words only.
+
+        Test: platform/mac/accessibility/select-text-should-match-whole-words.html
+
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::rangeOfStringClosestToRangeInDirection):
+        * editing/FindOptions.h:
+        * editing/TextIterator.cpp:
+        (WebCore::SearchBuffer::isWordEndMatch):
+        (WebCore::SearchBuffer::search):
+
 2014-08-04  Jer Noble  <jer.noble@apple.com>
 
         [MSE] Re-enqueing due to overlapping appended samples can cause stuttering playback
index 1901a73..ce81fed 100644 (file)
@@ -557,7 +557,7 @@ PassRefPtr<Range> AccessibilityObject::rangeOfStringClosestToRangeInDirection(Ra
         return nullptr;
     
     bool isBackwardSearch = searchDirection == SearchDirectionPrevious;
-    FindOptions findOptions = AtWordStarts | CaseInsensitive | StartInSelection;
+    FindOptions findOptions = AtWordStarts | AtWordEnds | CaseInsensitive | StartInSelection;
     if (isBackwardSearch)
         findOptions |= Backwards;
     
index 7291475..a79a562 100644 (file)
@@ -37,7 +37,8 @@ enum FindOptionFlag {
     Backwards = 1 << 3,
     WrapAround = 1 << 4,
     StartInSelection = 1 << 5,
-    DoNotRevealSelection = 1 << 6
+    DoNotRevealSelection = 1 << 6,
+    AtWordEnds = 1 << 7
 };
 
 typedef unsigned char FindOptions;
index 66f34e6..a300161 100644 (file)
@@ -92,6 +92,7 @@ public:
 private:
     bool isBadMatch(const UChar*, size_t length) const;
     bool isWordStartMatch(size_t start, size_t length) const;
+    bool isWordEndMatch(size_t start, size_t length) const;
 
     const String m_target;
     const StringView::UpconvertedCharacters m_targetCharacters;
@@ -2117,6 +2118,15 @@ inline bool SearchBuffer::isBadMatch(const UChar* match, size_t matchLength) con
         }
     }
 }
+    
+inline bool SearchBuffer::isWordEndMatch(size_t start, size_t length) const
+{
+    ASSERT(m_options & AtWordEnds);
+
+    int endWord;
+    findEndWordBoundary(StringView(m_buffer.data(), m_buffer.size()), start, &endWord);
+    return static_cast<size_t>(endWord) == (start + length);
+}
 
 inline bool SearchBuffer::isWordStartMatch(size_t start, size_t length) const
 {
@@ -2225,7 +2235,9 @@ nextMatch:
     ASSERT_WITH_SECURITY_IMPLICATION(matchStart + matchedLength <= size);
 
     // If this match is "bad", move on to the next match.
-    if (isBadMatch(m_buffer.data() + matchStart, matchedLength) || ((m_options & AtWordStarts) && !isWordStartMatch(matchStart, matchedLength))) {
+    if (isBadMatch(m_buffer.data() + matchStart, matchedLength)
+        || ((m_options & AtWordStarts) && !isWordStartMatch(matchStart, matchedLength))
+        || ((m_options & AtWordEnds) && !isWordEndMatch(matchStart, matchedLength))) {
         matchStart = usearch_next(searcher, &status);
         ASSERT(status == U_ZERO_ERROR);
         goto nextMatch;