AX: WebKit seems to be running spell checker even on non-editable content text
authorcfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Mar 2018 03:53:41 +0000 (03:53 +0000)
committercfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Mar 2018 03:53:41 +0000 (03:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183456
<rdar://problem/38076042>

Reviewed by Joanmarie Diggs.

Source/WebCore:

Test: accessibility/mac/attributed-string/attributed-string-does-not-includes-misspelled-for-non-editable.html

Only apply misspelled attributes if it's for editable text. It's not useful or performant to do this for static text.

* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(AXAttributeStringSetSpelling):

LayoutTests:

* accessibility/mac/attributed-string/attributed-string-does-not-includes-misspelled-for-non-editable-expected.txt: Added.
* accessibility/mac/attributed-string/attributed-string-does-not-includes-misspelled-for-non-editable.html: Added.
* accessibility/mac/attributed-string/attributed-string-for-range-with-options.html:
* accessibility/mac/attributed-string/attributed-string-for-range.html:
     Update tests to reflect that only editable content returns misspelled attributes.

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

LayoutTests/ChangeLog
LayoutTests/accessibility/mac/attributed-string/attributed-string-does-not-includes-misspelled-for-non-editable-expected.txt [new file with mode: 0644]
LayoutTests/accessibility/mac/attributed-string/attributed-string-does-not-includes-misspelled-for-non-editable.html [new file with mode: 0644]
LayoutTests/accessibility/mac/attributed-string/attributed-string-for-range-with-options.html
LayoutTests/accessibility/mac/attributed-string/attributed-string-for-range.html
Source/WebCore/ChangeLog
Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm

index 97fad0e..2dbdae8 100644 (file)
@@ -1,3 +1,17 @@
+2018-03-09  Chris Fleizach  <cfleizach@apple.com>
+
+        AX: WebKit seems to be running spell checker even on non-editable content text
+        https://bugs.webkit.org/show_bug.cgi?id=183456
+        <rdar://problem/38076042>
+
+        Reviewed by Joanmarie Diggs.
+
+        * accessibility/mac/attributed-string/attributed-string-does-not-includes-misspelled-for-non-editable-expected.txt: Added.
+        * accessibility/mac/attributed-string/attributed-string-does-not-includes-misspelled-for-non-editable.html: Added.
+        * accessibility/mac/attributed-string/attributed-string-for-range-with-options.html:
+        * accessibility/mac/attributed-string/attributed-string-for-range.html:
+             Update tests to reflect that only editable content returns misspelled attributes.
+
 2018-03-09  Nan Wang  <n_wang@apple.com>
 
         AX: AOM: More accessibility events support
diff --git a/LayoutTests/accessibility/mac/attributed-string/attributed-string-does-not-includes-misspelled-for-non-editable-expected.txt b/LayoutTests/accessibility/mac/attributed-string/attributed-string-does-not-includes-misspelled-for-non-editable-expected.txt
new file mode 100644 (file)
index 0000000..9131a57
--- /dev/null
@@ -0,0 +1,17 @@
+
+
+test mispelled
+test mispelled
+This tests that spell checking is not run on non-editable elements.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS attrString.indexOf('AXMisspelled = 1') != -1 is true
+PASS attrString.indexOf('AXMisspelled = 1') != -1 is true
+PASS attrString.indexOf('AXMisspelled = 1') != -1 is true
+PASS staticText.attributedStringForTextMarkerRangeContainsAttribute('AXMisspelled', markerRange) is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/accessibility/mac/attributed-string/attributed-string-does-not-includes-misspelled-for-non-editable.html b/LayoutTests/accessibility/mac/attributed-string/attributed-string-does-not-includes-misspelled-for-non-editable.html
new file mode 100644 (file)
index 0000000..0d6689c
--- /dev/null
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+
+<input type="text" id="textfield" value="test mispelled"><br>
+<textarea id="textarea">test mispelled</textarea>
+<div id="contenteditable" contenteditable="true"><b>test mispelled</b></div>
+
+<div role="group" id="div">test mispelled</div>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+
+    description("This tests that spell checking is not run on non-editable elements.");
+
+    if (window.accessibilityController) {
+
+        var contentLength = document.getElementById("textfield").value.length;
+
+        // textfield
+        var attrString = accessibilityController.accessibleElementById("textfield").attributedStringForRange(0, contentLength);
+        shouldBeTrue("attrString.indexOf('AXMisspelled = 1') != -1");
+
+        // textarea
+        attrString = accessibilityController.accessibleElementById("textarea").attributedStringForRange(0, contentLength);
+        shouldBeTrue("attrString.indexOf('AXMisspelled = 1') != -1");
+
+        // contenteditable
+        attrString = accessibilityController.accessibleElementById("contenteditable").attributedStringForRange(0, contentLength);
+        shouldBeTrue("attrString.indexOf('AXMisspelled = 1') != -1");
+
+        // non-editable (the attributedStringForRange only works on text controls, so use attributedStringForTextMarkerRangeContainsAttribute).
+        var staticText = accessibilityController.accessibleElementById("div");
+        var markerRange = staticText.textMarkerRangeForElement(staticText);
+        shouldBeFalse("staticText.attributedStringForTextMarkerRangeContainsAttribute('AXMisspelled', markerRange)");
+    }
+
+</script>
+
+<script src="../../../resources/js-test-post.js"></script>
+
+</body>
+</html>
+
index d3895ae..8aecb02 100644 (file)
@@ -8,7 +8,7 @@
     </head>
     <body id="body">
 
-        <div id="content">
+        <div id="content" contenteditable>
             word mispelled word
         </div>
 
index 91ead32..29627a5 100644 (file)
@@ -8,7 +8,7 @@
     </head>
     <body id="body">
 
-        <div id="content">
+        <div id="content" contenteditable>
             word mispelled word
         </div>
 
index 255db2f..0a24f6a 100644 (file)
@@ -1,3 +1,18 @@
+2018-03-09  Chris Fleizach  <cfleizach@apple.com>
+
+        AX: WebKit seems to be running spell checker even on non-editable content text
+        https://bugs.webkit.org/show_bug.cgi?id=183456
+        <rdar://problem/38076042>
+
+        Reviewed by Joanmarie Diggs.
+
+        Test: accessibility/mac/attributed-string/attributed-string-does-not-includes-misspelled-for-non-editable.html
+
+        Only apply misspelled attributes if it's for editable text. It's not useful or performant to do this for static text.
+
+        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+        (AXAttributeStringSetSpelling):
+
 2018-03-09  Nan Wang  <n_wang@apple.com>
 
         AX: AOM: More accessibility events support
index cc64dc6..6bb557a 100644 (file)
@@ -922,6 +922,12 @@ static void AXAttributeStringSetBlockquoteLevel(NSMutableAttributedString* attrS
 
 static void AXAttributeStringSetSpelling(NSMutableAttributedString* attrString, Node* node, StringView text, NSRange range)
 {
+    ASSERT(node);
+    
+    // If this node is not inside editable content, do not run the spell checker on the text.
+    if (!node->document().axObjectCache()->rootAXEditableElement(node))
+        return;
+
     if (unifiedTextCheckerEnabled(node->document().frame())) {
         // Check the spelling directly since document->markersForNode() does not store the misspelled marking when the cursor is in a word.
         TextCheckerClient* checker = node->document().frame()->editor().textChecker();