Title: [101002] trunk
Revision
101002
Author
commit-qu...@webkit.org
Date
2011-11-22 07:39:57 -0800 (Tue, 22 Nov 2011)

Log Message

Source/WebCore: Spellcheck should be able to run asynchronously.
https://bugs.webkit.org/show_bug.cgi?id=71991

Patch by Shinya Kawanaka <shin...@google.com> on 2011-11-22
Reviewed by Hajime Morita.

Run asynchronous spell checker if both asynchronous flag and unified text checker flag are ON.

When multiple asynchronous spellchecking are requested, only the first request will be processed.

Test: editing/spelling/spellcheck-async.html

* editing/Editor.cpp:
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
  Uses asynchronous spell checker if asynchronous flag is ON.

LayoutTests: Spellcheck should be able to run asynchronously
https://bugs.webkit.org/show_bug.cgi?id=71991

Patch by Shinya Kawanaka <shin...@google.com> on 2011-11-22
Reviewed by Hajime Morita.

Added asynchronouse spell checking tests.
Fixed tests that fails tearing down.

* editing/spelling/script-tests/spellcheck-paste.js: Fixed tearing down.
* editing/spelling/spellcheck-async-expected.txt: Added.
* editing/spelling/spellcheck-async.html: Added.
* editing/spelling/spelling-unified-emulation.html: Fixed tearing down.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (101001 => 101002)


--- trunk/LayoutTests/ChangeLog	2011-11-22 15:18:02 UTC (rev 101001)
+++ trunk/LayoutTests/ChangeLog	2011-11-22 15:39:57 UTC (rev 101002)
@@ -1,3 +1,18 @@
+2011-11-22  Shinya Kawanaka  <shin...@google.com>
+
+        Spellcheck should be able to run asynchronously
+        https://bugs.webkit.org/show_bug.cgi?id=71991
+
+        Reviewed by Hajime Morita.
+
+        Added asynchronouse spell checking tests.
+        Fixed tests that fails tearing down.
+
+        * editing/spelling/script-tests/spellcheck-paste.js: Fixed tearing down.
+        * editing/spelling/spellcheck-async-expected.txt: Added.
+        * editing/spelling/spellcheck-async.html: Added.
+        * editing/spelling/spelling-unified-emulation.html: Fixed tearing down.
+
 2011-11-22  Vsevolod Vlasov  <vse...@chromium.org>
 
         Web Inspector: Extract SplitView from Panel.createSidebar() method and reuse in Elements and Scripts panels.

Modified: trunk/LayoutTests/editing/spelling/script-tests/spellcheck-paste.js (101001 => 101002)


--- trunk/LayoutTests/editing/spelling/script-tests/spellcheck-paste.js	2011-11-22 15:18:02 UTC (rev 101001)
+++ trunk/LayoutTests/editing/spelling/script-tests/spellcheck-paste.js	2011-11-22 15:39:57 UTC (rev 101002)
@@ -39,6 +39,8 @@
     if (next)
         return window.setTimeout(next, 0);
     testRoot.style.display = "none";
+
+    layoutTestController.setAsynchronousSpellCheckingEnabled(false);
     layoutTestController.notifyDone();
 }
 

Added: trunk/LayoutTests/editing/spelling/spellcheck-async-expected.txt (0 => 101002)


--- trunk/LayoutTests/editing/spelling/spellcheck-async-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/spelling/spellcheck-async-expected.txt	2011-11-22 15:39:57 UTC (rev 101002)
@@ -0,0 +1,18 @@
+Test for Unified Spell Checker & Async Spell Checker.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS text : "zz" has markers: [zz]
+PASS text : "apple,zz,orange" has markers: [zz]
+PASS text : "zz,zz" has markers: [zz,zz]
+PASS text : "zz zz zz" has markers: [zz,zz,zz]
+PASS text : " zz zz zz " has markers: [zz,zz,zz]
+PASS text : "zz apple orange" has markers: [zz]
+PASS text : "apple zz orange" has markers: [zz]
+PASS text : "apple orange zz" has markers: [zz]
+PASS text : "zzz" has markers: []
+PASS text : "I would like to sleep, zzz" has markers: []
+

Added: trunk/LayoutTests/editing/spelling/spellcheck-async.html (0 => 101002)


--- trunk/LayoutTests/editing/spelling/spellcheck-async.html	                        (rev 0)
+++ trunk/LayoutTests/editing/spelling/spellcheck-async.html	2011-11-22 15:39:57 UTC (rev 101002)
@@ -0,0 +1,136 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+<script src=""
+<style>
+.editing {
+    border: 2px solid red;
+    padding: 6px;
+    font-size: 18px;
+}
+</style>
+</head>
+<body>
+<pre id="description"></pre>
+<pre id="console"></pre>
+<div id="container"></div>
+
+<script>
+description("Test for Unified Spell Checker & Async Spell Checker.");
+
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.setAsynchronousSpellCheckingEnabled(true);
+    layoutTestController.waitUntilDone();
+}
+
+if (window.internals)
+    internals.setUnifiedTextCheckingEnabled(document, true);
+
+var container = document.getElementById('container');
+function removeChildren(node) {
+    while (node.firstChild)
+        node.removeChild(node.firstChild);
+}
+
+var testData = [
+    { text: 'zz', marked: ['zz'] },
+    { text: 'apple,zz,orange', marked: ['zz'] },
+    { text: 'zz,zz', marked: ['zz','zz'] },
+    { text: 'zz zz zz', marked: ['zz', 'zz', 'zz'] },
+    { text: ' zz zz zz ', marked: ['zz', 'zz', 'zz'] },
+    { text: 'zz apple orange', marked: ['zz'] },
+    { text: 'apple zz orange', marked: ['zz'] },
+    { text: 'apple orange zz', marked: ['zz'] },
+    { text: 'zzz', marked: [] },
+    { text: 'I would like to sleep, zzz', marked: [] }
+];
+
+var testNo = 0;
+function doTestIfAny() {
+    var next = testData.shift();
+    if (next)
+        return window.setTimeout(function(){ doTest(++testNo, next.text, next.marked); }, 0);
+
+    // No more tests.
+    removeChildren(container);
+    if (window.internals)
+        internals.setUnifiedTextCheckingEnabled(document, false);
+
+    if (window.layoutTestController) {
+        layoutTestController.setAsynchronousSpellCheckingEnabled(false);
+        layoutTestController.notifyDone();
+    }
+}
+
+function createEditableElement(id) {
+    var e = document.createElement('div');
+    e.setAttribute("contentEditable", "true");
+    e.className = 'editing';
+    e.id = id;
+
+    return e;
+}
+
+function typeText(e, text) {
+    e.focus();
+    for (var i = 0; i < text.length; ++i) {
+        typeCharacterCommand(text[i]);
+    }
+    typeCharacterCommand('.');
+}
+
+function doTest(testNo, text, marked) {
+    removeChildren(container);
+    var id = "spelling" + testNo;
+    var e = createEditableElement(id);
+    container.appendChild(e);
+
+    typeText(e, text);
+
+    if (!window.internals)
+        return;
+
+    tryVerify(10, id, text, marked, 1);
+}
+
+function tryVerify(restTry, id, text, marked, nsleep) {
+    // No more try.
+    if (restTry <= 0) {
+        testFailed('text : "' + text + '" should have markers: [' + marked + ']');
+        setTimeout(doTestIfAny, 0);
+        return;
+    }
+
+    var success = true;
+    var e = document.getElementById(id);
+    var numMarked = internals.markerCountForNode(e.firstChild, "spelling");
+    var success = numMarked == marked.length;
+
+    if (success) {
+        for (var i = 0; i < numMarked; ++i) {
+            var range = internals.markerRangeForNode(e.firstChild, "spelling", i);
+            if (range.toString() != marked[i])
+                success = false;
+        }
+    }
+
+    if (success) {
+        testPassed('text : "' + text + '" has markers: [' + marked + ']');
+        setTimeout(doTestIfAny, 0);
+    } else {
+        // Type '.' to invoke asynchronouse spell checking again.
+        typeCharacterCommand('.');
+        setTimeout(function() { tryVerify(restTry - 1, id, text, marked, nsleep * 2); }, nsleep);
+    }
+}
+
+doTestIfAny();
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/editing/spelling/spelling-unified-emulation.html (101001 => 101002)


--- trunk/LayoutTests/editing/spelling/spelling-unified-emulation.html	2011-11-22 15:18:02 UTC (rev 101001)
+++ trunk/LayoutTests/editing/spelling/spelling-unified-emulation.html	2011-11-22 15:39:57 UTC (rev 101002)
@@ -84,6 +84,9 @@
     performTest('test', testData[i]);
 }
 
+if (window.internals)
+    internals.setUnifiedTextCheckingEnabled(document, false);
+
 var successfullyParsed = true;
 </script>
 <script src=""

Modified: trunk/Source/WebCore/ChangeLog (101001 => 101002)


--- trunk/Source/WebCore/ChangeLog	2011-11-22 15:18:02 UTC (rev 101001)
+++ trunk/Source/WebCore/ChangeLog	2011-11-22 15:39:57 UTC (rev 101002)
@@ -1,3 +1,20 @@
+2011-11-22  Shinya Kawanaka  <shin...@google.com>
+
+        Spellcheck should be able to run asynchronously.
+        https://bugs.webkit.org/show_bug.cgi?id=71991
+
+        Reviewed by Hajime Morita.
+
+        Run asynchronous spell checker if both asynchronous flag and unified text checker flag are ON.
+
+        When multiple asynchronous spellchecking are requested, only the first request will be processed.
+
+        Test: editing/spelling/spellcheck-async.html
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
+          Uses asynchronous spell checker if asynchronous flag is ON.
+
 2011-11-22  Alexander Pavlov  <apav...@chromium.org>
 
         Web Inspector: [SuggestBox] Grayed prompt displayed with non-collapsed selection in place

Modified: trunk/Source/WebCore/editing/Editor.cpp (101001 => 101002)


--- trunk/Source/WebCore/editing/Editor.cpp	2011-11-22 15:18:02 UTC (rev 101001)
+++ trunk/Source/WebCore/editing/Editor.cpp	2011-11-22 15:39:57 UTC (rev 101002)
@@ -2042,6 +2042,16 @@
         }
     }
 
+
+    bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->asynchronousSpellCheckingEnabled() && !shouldShowCorrectionPanel;
+    if (asynchronous) {
+        if (shouldMarkGrammar)
+            m_spellChecker->requestCheckingFor(resolveTextCheckingTypeMask(textCheckingOptions), grammarParagraph.paragraphRange());
+        else
+            m_spellChecker->requestCheckingFor(resolveTextCheckingTypeMask(textCheckingOptions), spellingParagraph.paragraphRange());
+        return;
+    }
+
     Vector<TextCheckingResult> results;
     if (shouldMarkGrammar)
         checkTextOfParagraph(textChecker(), grammarParagraph.textCharacters(), grammarParagraph.textLength(), 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to