AX: isWordEndMatch should allow for multiple word selections
authorcfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Aug 2014 21:56:08 +0000 (21:56 +0000)
committercfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Aug 2014 21:56:08 +0000 (21:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=135573

Reviewed by Mario Sanchez Prada.

Source/WebCore:
isWordEndMatch was searching from the beginning of the selected range, which meant
that if the result was multiple words, we'd reject the result.
Instead, we should search from the end of the range, so that we encompass all words.

Modified existing test: platform/mac/accessibility/select-text-should-match-whole-words.html

* editing/TextIterator.cpp:
(WebCore::SearchBuffer::isWordEndMatch):

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

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

LayoutTests/ChangeLog
LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words-expected.txt
LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words.html
Source/WebCore/ChangeLog
Source/WebCore/editing/TextIterator.cpp

index 37de427..791ab06 100644 (file)
@@ -1,5 +1,15 @@
 2014-08-04  Chris Fleizach  <cfleizach@apple.com>
 
+        AX: isWordEndMatch should allow for multiple word selections
+        https://bugs.webkit.org/show_bug.cgi?id=135573
+
+        Reviewed by Mario Sanchez Prada.
+
+        * platform/mac/accessibility/select-text-should-match-whole-words-expected.txt:
+        * platform/mac/accessibility/select-text-should-match-whole-words.html:
+
+2014-08-04  Chris Fleizach  <cfleizach@apple.com>
+
         AX: Secure text fields need to support Search parameterized attributes
         https://bugs.webkit.org/show_bug.cgi?id=135568
 
index 918f0ef..98506db 100644 (file)
@@ -1,4 +1,4 @@
-The man jumped high.
+The man jumped higher.
 
 This tests that selection matches whole words, rather than partial matches.
 
@@ -11,6 +11,12 @@ 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 result is 'jumped higher'
+PASS windowSelection.getRangeAt(0).startOffset is 8
+PASS windowSelection.getRangeAt(0).endOffset is 21
+PASS result is ''
+PASS windowSelection.getRangeAt(0).startOffset is 0
+PASS windowSelection.getRangeAt(0).endOffset is 0
 PASS successfullyParsed is true
 
 TEST COMPLETE
index f174c4f..cf1379c 100644 (file)
@@ -6,7 +6,7 @@
 </head>
 <body>
 
-<p contenteditable="true" id="text">The man jumped high.</p>
+<p contenteditable="true" id="text">The man jumped higher.</p>
 
 <p id="description"></p>
 <div id="console"></div>
@@ -17,7 +17,6 @@
     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();
@@ -26,6 +25,7 @@
         var range = document.createRange();
         range.setStart(document.getElementById("text").firstChild, 0);
         range.setEnd(document.getElementById("text").firstChild, 0);
+        windowSelection.removeAllRanges();
         windowSelection.addRange(range);
       
         // Try to select a partial word, it should fail.
         shouldBe("result", "'jumped'");
         shouldBe("windowSelection.getRangeAt(0).startOffset", "8");
         shouldBe("windowSelection.getRangeAt(0).endOffset", "14");
+        windowSelection.removeAllRanges();
+        windowSelection.addRange(range);
 
+        // Select multiple whole word, it should succeed.
+        result = text.selectTextWithCriteria("AXSelectTextAmbiguityResolutionClosestToSelection", "jumped higher");
+        shouldBe("result", "'jumped higher'");
+        shouldBe("windowSelection.getRangeAt(0).startOffset", "8");
+        shouldBe("windowSelection.getRangeAt(0).endOffset", "21");
+        windowSelection.removeAllRanges();
+        windowSelection.addRange(range);
+
+        // Select multiple words, where one is not a whole word, it should fail.
+        result = text.selectTextWithCriteria("AXSelectTextAmbiguityResolutionClosestToSelection", "jumped high");
+        shouldBe("result", "''");
+        shouldBe("windowSelection.getRangeAt(0).startOffset", "0");
+        shouldBe("windowSelection.getRangeAt(0).endOffset", "0");
     }
 </script>
 
index e03d892..d31465e 100644 (file)
@@ -1,5 +1,21 @@
 2014-08-04  Chris Fleizach  <cfleizach@apple.com>
 
+        AX: isWordEndMatch should allow for multiple word selections
+        https://bugs.webkit.org/show_bug.cgi?id=135573
+
+        Reviewed by Mario Sanchez Prada.
+
+        isWordEndMatch was searching from the beginning of the selected range, which meant
+        that if the result was multiple words, we'd reject the result. 
+        Instead, we should search from the end of the range, so that we encompass all words.
+
+        Modified existing test: platform/mac/accessibility/select-text-should-match-whole-words.html
+
+        * editing/TextIterator.cpp:
+        (WebCore::SearchBuffer::isWordEndMatch):
+
+2014-08-04  Chris Fleizach  <cfleizach@apple.com>
+
         AX: Secure text fields need to support Search parameterized attributes
         https://bugs.webkit.org/show_bug.cgi?id=135568
 
index a300161..f422148 100644 (file)
@@ -2121,10 +2121,12 @@ inline bool SearchBuffer::isBadMatch(const UChar* match, size_t matchLength) con
     
 inline bool SearchBuffer::isWordEndMatch(size_t start, size_t length) const
 {
+    ASSERT(length);
     ASSERT(m_options & AtWordEnds);
 
     int endWord;
-    findEndWordBoundary(StringView(m_buffer.data(), m_buffer.size()), start, &endWord);
+    // Start searching at the end of matched search, so that multiple word matches succeed.
+    findEndWordBoundary(StringView(m_buffer.data(), m_buffer.size()), start + length - 1, &endWord);
     return static_cast<size_t>(endWord) == (start + length);
 }