Title: [171996] trunk
Revision
171996
Author
[email protected]
Date
2014-08-04 10:32:21 -0700 (Mon, 04 Aug 2014)

Log Message

AX: AXSelectTextWithCriteriaParameterizedAttribute incorrectly selects the beginning letters of a word
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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (171995 => 171996)


--- trunk/LayoutTests/ChangeLog	2014-08-04 17:26:42 UTC (rev 171995)
+++ trunk/LayoutTests/ChangeLog	2014-08-04 17:32:21 UTC (rev 171996)
@@ -1,5 +1,15 @@
 2014-08-04  Chris Fleizach  <[email protected]>
 
+        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  <[email protected]>
+
         AX: The Dictation command "Replace <phrase> with <phrase>" always capitalizes the replacement string
         https://bugs.webkit.org/show_bug.cgi?id=135557
 

Added: trunk/LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words-expected.txt (0 => 171996)


--- trunk/LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words-expected.txt	2014-08-04 17:32:21 UTC (rev 171996)
@@ -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
+

Added: trunk/LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words.html (0 => 171996)


--- trunk/LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/accessibility/select-text-should-match-whole-words.html	2014-08-04 17:32:21 UTC (rev 171996)
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<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=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (171995 => 171996)


--- trunk/Source/WebCore/ChangeLog	2014-08-04 17:26:42 UTC (rev 171995)
+++ trunk/Source/WebCore/ChangeLog	2014-08-04 17:32:21 UTC (rev 171996)
@@ -1,3 +1,22 @@
+2014-08-04  Chris Fleizach  <[email protected]>
+
+        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  <[email protected]>
 
         [MSE] Re-enqueing due to overlapping appended samples can cause stuttering playback

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.cpp (171995 => 171996)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2014-08-04 17:26:42 UTC (rev 171995)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2014-08-04 17:32:21 UTC (rev 171996)
@@ -557,7 +557,7 @@
         return nullptr;
     
     bool isBackwardSearch = searchDirection == SearchDirectionPrevious;
-    FindOptions findOptions = AtWordStarts | CaseInsensitive | StartInSelection;
+    FindOptions findOptions = AtWordStarts | AtWordEnds | CaseInsensitive | StartInSelection;
     if (isBackwardSearch)
         findOptions |= Backwards;
     

Modified: trunk/Source/WebCore/editing/FindOptions.h (171995 => 171996)


--- trunk/Source/WebCore/editing/FindOptions.h	2014-08-04 17:26:42 UTC (rev 171995)
+++ trunk/Source/WebCore/editing/FindOptions.h	2014-08-04 17:32:21 UTC (rev 171996)
@@ -37,7 +37,8 @@
     Backwards = 1 << 3,
     WrapAround = 1 << 4,
     StartInSelection = 1 << 5,
-    DoNotRevealSelection = 1 << 6
+    DoNotRevealSelection = 1 << 6,
+    AtWordEnds = 1 << 7
 };
 
 typedef unsigned char FindOptions;

Modified: trunk/Source/WebCore/editing/TextIterator.cpp (171995 => 171996)


--- trunk/Source/WebCore/editing/TextIterator.cpp	2014-08-04 17:26:42 UTC (rev 171995)
+++ trunk/Source/WebCore/editing/TextIterator.cpp	2014-08-04 17:32:21 UTC (rev 171996)
@@ -92,6 +92,7 @@
 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,7 +2118,16 @@
         }
     }
 }
+    
+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
 {
     ASSERT(m_options & AtWordStarts);
@@ -2225,7 +2235,9 @@
     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;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to