Title: [102553] trunk/Source/WebCore
Revision
102553
Author
commit-qu...@webkit.org
Date
2011-12-11 19:12:06 -0800 (Sun, 11 Dec 2011)

Log Message

Asynchronous path synchronous path of SpellChecker should share the code to mark misspellings.
https://bugs.webkit.org/show_bug.cgi?id=73616

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

Asynchronous spellchecking path should call the same method for the synchronous spellchecking path
to mark misspellings.

No new tests. Covered by existing tests.

* editing/Editor.cpp:
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
(WebCore::Editor::markAndReplaceFor):
  Takes SpellCheckRequest object.
* editing/Editor.h:
* editing/SpellChecker.cpp:
(WebCore::SpellChecker::didCheck):
  Calls the same method of synchronous spellchecking path.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (102552 => 102553)


--- trunk/Source/WebCore/ChangeLog	2011-12-12 02:24:28 UTC (rev 102552)
+++ trunk/Source/WebCore/ChangeLog	2011-12-12 03:12:06 UTC (rev 102553)
@@ -1,3 +1,24 @@
+2011-12-11  Shinya Kawanaka  <shin...@google.com>
+
+        Asynchronous path synchronous path of SpellChecker should share the code to mark misspellings.
+        https://bugs.webkit.org/show_bug.cgi?id=73616
+
+        Reviewed by Hajime Morita.
+
+        Asynchronous spellchecking path should call the same method for the synchronous spellchecking path
+        to mark misspellings.
+
+        No new tests. Covered by existing tests.
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
+        (WebCore::Editor::markAndReplaceFor):
+          Takes SpellCheckRequest object.
+        * editing/Editor.h:
+        * editing/SpellChecker.cpp:
+        (WebCore::SpellChecker::didCheck):
+          Calls the same method of synchronous spellchecking path.
+
 2011-12-11  Luke Macpherson   <macpher...@chromium.org>
 
         Implement CSS display property in CSSStyleApplyProperty.

Modified: trunk/Source/WebCore/editing/Editor.cpp (102552 => 102553)


--- trunk/Source/WebCore/editing/Editor.cpp	2011-12-12 02:24:28 UTC (rev 102552)
+++ trunk/Source/WebCore/editing/Editor.cpp	2011-12-12 03:12:06 UTC (rev 102553)
@@ -2015,25 +2015,31 @@
     TextCheckingParagraph paragraphToCheck(rangeToCheck);
     if (paragraphToCheck.isRangeEmpty() || paragraphToCheck.isEmpty())
         return;
+    RefPtr<Range> paragraphRange = paragraphToCheck.paragraphRange();
 
     bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->asynchronousSpellCheckingEnabled() && !shouldShowCorrectionPanel;
+
+    // In asynchronous mode, we intentionally check paragraph-wide sentence.
+    RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), asynchronous ? paragraphRange : rangeToCheck, paragraphRange);
+
     if (asynchronous) {
-        // In asynchronous mode, we intentionally check paragraph-wide sentence.
-        RefPtr<Range> paragraphRange = paragraphToCheck.paragraphRange();
-        m_spellChecker->requestCheckingFor(SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), paragraphRange, paragraphRange));
+        m_spellChecker->requestCheckingFor(request);
         return;
     }
 
     Vector<TextCheckingResult> results;
     checkTextOfParagraph(textChecker(), paragraphToCheck.textCharacters(), paragraphToCheck.textLength(),
         resolveTextCheckingTypeMask(textCheckingOptions), results);
-    markAndReplaceFor(textCheckingOptions, results, rangeToCheck, paragraphToCheck.paragraphRange());
+    markAndReplaceFor(request, results);
 }
 
-void Editor::markAndReplaceFor(TextCheckingTypeMask textCheckingOptions, const Vector<TextCheckingResult>& results, PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange)
+void Editor::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vector<TextCheckingResult>& results)
 {
-    TextCheckingParagraph paragraph(checkingRange, paragraphRange);
+    ASSERT(request);
 
+    TextCheckingTypeMask textCheckingOptions = request->mask();
+    TextCheckingParagraph paragraph(request->checkingRange(), request->paragraphRange());
+
     bool shouldMarkSpelling = textCheckingOptions & TextCheckingTypeSpelling;
     bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar;
     bool shouldPerformReplacement = textCheckingOptions & TextCheckingTypeReplacement;

Modified: trunk/Source/WebCore/editing/Editor.h (102552 => 102553)


--- trunk/Source/WebCore/editing/Editor.h	2011-12-12 02:24:28 UTC (rev 102552)
+++ trunk/Source/WebCore/editing/Editor.h	2011-12-12 03:12:06 UTC (rev 102553)
@@ -61,6 +61,7 @@
 class Pasteboard;
 class SimpleFontData;
 class SpellChecker;
+class SpellCheckRequest;
 class SpellingCorrectionController;
 class Text;
 class TextCheckerClient;
@@ -223,7 +224,7 @@
     void markMisspellings(const VisibleSelection&, RefPtr<Range>& firstMisspellingRange);
     void markBadGrammar(const VisibleSelection&);
     void markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection);
-    void markAndReplaceFor(TextCheckingTypeMask, const Vector<TextCheckingResult>&, PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange);
+    void markAndReplaceFor(PassRefPtr<SpellCheckRequest>, const Vector<TextCheckingResult>&);
 
 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
     void uppercaseWord();

Modified: trunk/Source/WebCore/editing/SpellChecker.cpp (102552 => 102553)


--- trunk/Source/WebCore/editing/SpellChecker.cpp	2011-12-12 02:24:28 UTC (rev 102552)
+++ trunk/Source/WebCore/editing/SpellChecker.cpp	2011-12-12 03:12:06 UTC (rev 102553)
@@ -163,37 +163,6 @@
     m_requestQueue.append(request);
 }
 
-static bool forwardIterator(PositionIterator& iterator, int distance)
-{
-    int remaining = distance;
-    while (!iterator.atEnd()) {
-        if (iterator.node()->isCharacterDataNode()) {
-            int length = lastOffsetForEditing(iterator.node());
-            int last = length - iterator.offsetInLeafNode();
-            if (remaining < last) {
-                iterator.setOffsetInLeafNode(iterator.offsetInLeafNode() + remaining);
-                return true;
-            }
-
-            remaining -= last;
-            iterator.setOffsetInLeafNode(iterator.offsetInLeafNode() + last);
-        }
-
-        iterator.increment();
-    }
-
-    return false;    
-}
-
-static DocumentMarker::MarkerType toMarkerType(TextCheckingType type)
-{
-    if (type == TextCheckingTypeSpelling)
-        return DocumentMarker::Spelling;
-    ASSERT(type == TextCheckingTypeGrammar);
-    return DocumentMarker::Grammar;
-}
-
-// Currenntly ignoring TextCheckingResult::details but should be handled. See Bug 56368.
 void SpellChecker::didCheck(int sequence, const Vector<TextCheckingResult>& results)
 {
     ASSERT(m_processingRequest);
@@ -203,35 +172,8 @@
         return;
     }
 
-    int startOffset = 0;
-    PositionIterator start = m_processingRequest->checkingRange()->startPosition();
-    for (size_t i = 0; i < results.size(); ++i) {
-        if (results[i].type != TextCheckingTypeSpelling && results[i].type != TextCheckingTypeGrammar)
-            continue;
+    m_frame->editor()->markAndReplaceFor(m_processingRequest, results);
 
-        // To avoid moving the position backward, we assume the given results are sorted with
-        // startOffset as the ones returned by [NSSpellChecker requestCheckingOfString:].
-        ASSERT(startOffset <= results[i].location);
-        if (!forwardIterator(start, results[i].location - startOffset))
-            break;
-        PositionIterator end = start;
-        if (!forwardIterator(end, results[i].length))
-            break;
-
-        // Users or _javascript_ applications may change text while a spell-checker checks its
-        // spellings in the background. To avoid adding markers to the words modified by users or
-        // _javascript_ applications, retrieve the words in the specified region and compare them with
-        // the original ones.
-        RefPtr<Range> range = Range::create(m_processingRequest->checkingRange()->ownerDocument(), start, end);
-        // FIXME: Use textContent() compatible string conversion.
-        String destination = range->text();
-        String source = m_processingRequest->text().substring(results[i].location, results[i].length);
-        if (destination == source)
-            m_processingRequest->checkingRange()->ownerDocument()->markers()->addMarker(range.get(), toMarkerType(results[i].type));
-
-        startOffset = results[i].location;
-    }
-
     if (m_lastProcessedSequence < sequence)
         m_lastProcessedSequence = sequence;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to