Title: [184563] trunk
Revision
184563
Author
[email protected]
Date
2015-05-19 08:48:17 -0700 (Tue, 19 May 2015)

Log Message

AX: Select text mechanism returns results outside of text control regions
https://bugs.webkit.org/show_bug.cgi?id=145041

Reviewed by Mario Sanchez Prada.

Source/WebCore:

The behavior of the select text mechanism (inside accessibility) should make sure that results
returned stay within text control elements if the search was initiated inside a text control element.

Test: platform/mac/accessibility/select-text-stays-inside-text-controls.html

* accessibility/AccessibilityObject.cpp:
(WebCore::rangeClosestToRange):
(WebCore::AccessibilityObject::selectText):

LayoutTests:

* platform/mac/accessibility/select-text-stays-inside-text-controls-expected.txt: Added.
* platform/mac/accessibility/select-text-stays-inside-text-controls.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (184562 => 184563)


--- trunk/LayoutTests/ChangeLog	2015-05-19 15:10:40 UTC (rev 184562)
+++ trunk/LayoutTests/ChangeLog	2015-05-19 15:48:17 UTC (rev 184563)
@@ -1,3 +1,13 @@
+2015-05-14  Chris Fleizach  <[email protected]>
+
+        AX: Select text mechanism returns results outside of text control regions
+        https://bugs.webkit.org/show_bug.cgi?id=145041
+
+        Reviewed by Mario Sanchez Prada.
+
+        * platform/mac/accessibility/select-text-stays-inside-text-controls-expected.txt: Added.
+        * platform/mac/accessibility/select-text-stays-inside-text-controls.html: Added.
+
 2015-05-19  Marcos Chavarría Teijeiro  <[email protected]>
 
         [GTK] Gardening 19th May

Added: trunk/LayoutTests/platform/mac/accessibility/select-text-stays-inside-text-controls-expected.txt (0 => 184563)


--- trunk/LayoutTests/platform/mac/accessibility/select-text-stays-inside-text-controls-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/accessibility/select-text-stays-inside-text-controls-expected.txt	2015-05-19 15:48:17 UTC (rev 184563)
@@ -0,0 +1,23 @@
+ 
+ outside text
+This tests that the select text mechanism will not return results outside of a text input control.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS result is 'textfield'
+PASS document.getElementById('textfield').selectionStart is 0
+PASS document.getElementById('textfield').selectionEnd is 9
+PASS result is ''
+PASS document.getElementById('textfield').selectionStart is 0
+PASS document.getElementById('textfield').selectionEnd is 0
+PASS result is 'text area'
+PASS document.getElementById('textarea').selectionStart is 0
+PASS document.getElementById('textarea').selectionEnd is 9
+PASS result is ''
+PASS document.getElementById('textarea').selectionStart is 0
+PASS document.getElementById('textarea').selectionEnd is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/platform/mac/accessibility/select-text-stays-inside-text-controls.html (0 => 184563)


--- trunk/LayoutTests/platform/mac/accessibility/select-text-stays-inside-text-controls.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/accessibility/select-text-stays-inside-text-controls.html	2015-05-19 15:48:17 UTC (rev 184563)
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+
+<input type="text" id="textfield" value="textfield text">
+<br>
+<textarea id="textarea">text area text</textarea>
+outside text
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+    description("This tests that the select text mechanism will not return results outside of a text input control.");
+    
+    if (window.accessibilityController) {
+        var textfield = accessibilityController.accessibleElementById("textfield");
+        var windowSelection = window.getSelection();
+
+        document.getElementById("textfield").focus();
+        document.getElementById("textfield").setSelectionRange(0, 0);
+
+        // Try to select text inside the text field.
+        result = textfield.selectTextWithCriteria("AXSelectTextAmbiguityResolutionClosestToSelection", "textfield");
+        shouldBe("result", "'textfield'");
+        shouldBe("document.getElementById('textfield').selectionStart", "0");
+        shouldBe("document.getElementById('textfield').selectionEnd", "9");
+
+        document.getElementById("textfield").setSelectionRange(0, 0);
+
+        // Try to select text outside the focused text field. It should fail.
+        result = textfield.selectTextWithCriteria("AXSelectTextAmbiguityResolutionClosestToSelection", "outside");
+        shouldBe("result", "''");
+        shouldBe("document.getElementById('textfield').selectionStart", "0");
+        shouldBe("document.getElementById('textfield').selectionEnd", "0");
+
+        // Do the same for text area
+        document.getElementById("textarea").focus();
+        document.getElementById("textarea").setSelectionRange(0, 0);
+
+        var textarea = accessibilityController.accessibleElementById("textarea");
+
+        // Try to select text inside the text field.
+        result = textarea.selectTextWithCriteria("AXSelectTextAmbiguityResolutionClosestToSelection", "text area");
+        shouldBe("result", "'text area'");
+        shouldBe("document.getElementById('textarea').selectionStart", "0");
+        shouldBe("document.getElementById('textarea').selectionEnd", "9");
+
+        document.getElementById("textarea").setSelectionRange(0, 0);
+
+        // Try to select text outside the focused text field. It should fail.
+        result = textarea.selectTextWithCriteria("AXSelectTextAmbiguityResolutionClosestToSelection", "outside");
+        shouldBe("result", "''");
+        shouldBe("document.getElementById('textarea').selectionStart", "0");
+        shouldBe("document.getElementById('textarea').selectionEnd", "0");
+    }
+</script>
+
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (184562 => 184563)


--- trunk/Source/WebCore/ChangeLog	2015-05-19 15:10:40 UTC (rev 184562)
+++ trunk/Source/WebCore/ChangeLog	2015-05-19 15:48:17 UTC (rev 184563)
@@ -1,3 +1,19 @@
+2015-05-14  Chris Fleizach  <[email protected]>
+
+        AX: Select text mechanism returns results outside of text control regions
+        https://bugs.webkit.org/show_bug.cgi?id=145041
+
+        Reviewed by Mario Sanchez Prada.
+
+        The behavior of the select text mechanism (inside accessibility) should make sure that results
+        returned stay within text control elements if the search was initiated inside a text control element.
+
+        Test: platform/mac/accessibility/select-text-stays-inside-text-controls.html
+
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::rangeClosestToRange):
+        (WebCore::AccessibilityObject::selectText):
+
 2015-05-19  Chris Dumez  <[email protected]>
 
         Mark static variables as const when possible

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.cpp (184562 => 184563)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2015-05-19 15:10:40 UTC (rev 184562)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2015-05-19 15:48:17 UTC (rev 184563)
@@ -610,7 +610,15 @@
 static PassRefPtr<Range> rangeClosestToRange(Range* referenceRange, PassRefPtr<Range> afterRange, PassRefPtr<Range> beforeRange)
 {
     ASSERT(referenceRange);
+    
+    // The treeScope for shadow nodes may not be the same scope as another element in a document.
+    // Comparisons may fail in that case, which are expected behavior and should not assert.
+    if (afterRange && ((afterRange->startPosition().anchorNode()->compareDocumentPosition(referenceRange->endPosition().anchorNode()) & Node::DOCUMENT_POSITION_DISCONNECTED) == Node::DOCUMENT_POSITION_DISCONNECTED))
+        return nullptr;
     ASSERT(!afterRange || afterRange->startPosition() >= referenceRange->endPosition());
+    
+    if (beforeRange && ((beforeRange->endPosition().anchorNode()->compareDocumentPosition(referenceRange->startPosition().anchorNode()) & Node::DOCUMENT_POSITION_DISCONNECTED) == Node::DOCUMENT_POSITION_DISCONNECTED))
+        return nullptr;
     ASSERT(!beforeRange || beforeRange->endPosition() <= referenceRange->startPosition());
     
     if (!referenceRange || (!afterRange && !beforeRange))
@@ -710,6 +718,12 @@
     
     // Determine which candidate is closest to the selection and perform the activity.
     if (RefPtr<Range> closestStringRange = rangeClosestToRange(selectedStringRange.get(), closestAfterStringRange, closestBeforeStringRange)) {
+        // If the search started within a text control, ensure that the result is inside that element.
+        if (element() && element()->isTextFormControl()) {
+            if (!closestStringRange->startContainer()->isDescendantOrShadowDescendantOf(element()) || !closestStringRange->endContainer()->isDescendantOrShadowDescendantOf(element()))
+                return String();
+        }
+        
         String closestString = closestStringRange->text();
         bool replaceSelection = false;
         if (frame->selection().setSelectedRange(closestStringRange.get(), DOWNSTREAM, true)) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to