Title: [102328] trunk/Source/WebCore
Revision
102328
Author
[email protected]
Date
2011-12-08 02:46:32 -0800 (Thu, 08 Dec 2011)

Log Message

Refactoring: Editor::requestCheckingFor should take SpellCheckRequest object.
https://bugs.webkit.org/show_bug.cgi?id=74033

Patch by Shinya Kawanaka <[email protected]> on 2011-12-08
Reviewed by Hajime Morita.

SpellChecker::requestCheckingFor takes SpellCheckRequest object in order to make it easy to
pass necessary information to requestCheckingFor.

No new tests. Covered by existing tests.

* editing/Editor.cpp:
(WebCore::Editor::replaceSelectionWithFragment):
  Uses the new interface.
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): ditto.
* editing/SpellChecker.cpp:
(WebCore::SpellCheckRequest::SpellCheckRequest):
(WebCore::SpellCheckRequest::~SpellCheckRequest):
(WebCore::SpellCheckRequest::create):
  Creates a new SpellCheckRequest object.
(WebCore::SpellChecker::requestCheckingFor):
  Uses the new interface.
(WebCore::SpellChecker::didCheck):
* editing/SpellChecker.h:
(WebCore::SpellCheckRequest::setSequence):
(WebCore::SpellCheckRequest::sequence):
(WebCore::SpellCheckRequest::checkingRange):
(WebCore::SpellCheckRequest::paragraphRange):
(WebCore::SpellCheckRequest::text):
(WebCore::SpellCheckRequest::mask):
(WebCore::SpellCheckRequest::rootEditableElement):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (102327 => 102328)


--- trunk/Source/WebCore/ChangeLog	2011-12-08 10:44:51 UTC (rev 102327)
+++ trunk/Source/WebCore/ChangeLog	2011-12-08 10:46:32 UTC (rev 102328)
@@ -1,3 +1,36 @@
+2011-12-08  Shinya Kawanaka  <[email protected]>
+
+        Refactoring: Editor::requestCheckingFor should take SpellCheckRequest object.
+        https://bugs.webkit.org/show_bug.cgi?id=74033
+
+        Reviewed by Hajime Morita.
+
+        SpellChecker::requestCheckingFor takes SpellCheckRequest object in order to make it easy to
+        pass necessary information to requestCheckingFor.
+
+        No new tests. Covered by existing tests.
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::replaceSelectionWithFragment):
+          Uses the new interface.
+        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): ditto.
+        * editing/SpellChecker.cpp:
+        (WebCore::SpellCheckRequest::SpellCheckRequest):
+        (WebCore::SpellCheckRequest::~SpellCheckRequest):
+        (WebCore::SpellCheckRequest::create):
+          Creates a new SpellCheckRequest object.
+        (WebCore::SpellChecker::requestCheckingFor):
+          Uses the new interface.
+        (WebCore::SpellChecker::didCheck):
+        * editing/SpellChecker.h:
+        (WebCore::SpellCheckRequest::setSequence):
+        (WebCore::SpellCheckRequest::sequence):
+        (WebCore::SpellCheckRequest::checkingRange):
+        (WebCore::SpellCheckRequest::paragraphRange):
+        (WebCore::SpellCheckRequest::text):
+        (WebCore::SpellCheckRequest::mask):
+        (WebCore::SpellCheckRequest::rootEditableElement):
+
 2011-12-08  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r102323.

Modified: trunk/Source/WebCore/editing/Editor.cpp (102327 => 102328)


--- trunk/Source/WebCore/editing/Editor.cpp	2011-12-08 10:44:51 UTC (rev 102327)
+++ trunk/Source/WebCore/editing/Editor.cpp	2011-12-08 10:46:32 UTC (rev 102328)
@@ -416,8 +416,8 @@
     if (!nodeToCheck)
         return;
 
-    m_spellChecker->requestCheckingFor(resolveTextCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar),
-        Range::create(m_frame->document(), firstPositionInNode(nodeToCheck), lastPositionInNode(nodeToCheck)));
+    RefPtr<Range> rangeToCheck = Range::create(m_frame->document(), firstPositionInNode(nodeToCheck), lastPositionInNode(nodeToCheck));
+    m_spellChecker->requestCheckingFor(SpellCheckRequest::create(resolveTextCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), rangeToCheck, rangeToCheck));
 }
 
 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement, bool smartReplace)
@@ -2017,7 +2017,9 @@
 
     bool asynchronous = m_frame && m_frame->settings() && m_frame->settings()->asynchronousSpellCheckingEnabled() && !shouldShowCorrectionPanel;
     if (asynchronous) {
-        m_spellChecker->requestCheckingFor(resolveTextCheckingTypeMask(textCheckingOptions), paragraphToCheck.paragraphRange());
+        // In asynchronous mode, we intentionally check paragraph-wide sentence.
+        RefPtr<Range> paragraphRange = paragraphToCheck.paragraphRange();
+        m_spellChecker->requestCheckingFor(SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), paragraphRange, paragraphRange));
         return;
     }
 

Modified: trunk/Source/WebCore/editing/SpellChecker.cpp (102327 => 102328)


--- trunk/Source/WebCore/editing/SpellChecker.cpp	2011-12-08 10:44:51 UTC (rev 102327)
+++ trunk/Source/WebCore/editing/SpellChecker.cpp	2011-12-08 10:46:32 UTC (rev 102328)
@@ -45,31 +45,37 @@
 
 namespace WebCore {
 
-class SpellChecker::SpellCheckRequest : public RefCounted<SpellChecker::SpellCheckRequest> {
-public:
-    SpellCheckRequest(int sequence, PassRefPtr<Range> range, const String& text, TextCheckingTypeMask mask)
-        : m_sequence(sequence)
-        , m_range(range)
-        , m_text(text)
-        , m_mask(mask)
-        , m_rootEditableElement(m_range->startContainer()->rootEditableElement())
-    {
-    }
+static const int unrequestedSequence = -1;
 
-    int sequence() const { return m_sequence; }
-    Range* range() const { return m_range.get(); }
-    const String& text() const { return m_text; }
-    TextCheckingTypeMask mask() const { return m_mask; }
-    Element* rootEditableElement() const { return m_rootEditableElement; }
+SpellCheckRequest::SpellCheckRequest(int sequence, PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange, const String& text, TextCheckingTypeMask mask)
+    : m_sequence(sequence)
+    , m_checkingRange(checkingRange)
+    , m_paragraphRange(paragraphRange)
+    , m_text(text)
+    , m_mask(mask)
+    , m_rootEditableElement(m_checkingRange->startContainer()->rootEditableElement())
+{
+}
 
-private:
-    int m_sequence;
-    RefPtr<Range> m_range;
-    String m_text;
-    TextCheckingTypeMask m_mask;
-    Element* m_rootEditableElement;
-};
+SpellCheckRequest::~SpellCheckRequest()
+{
+}
 
+// static
+PassRefPtr<SpellCheckRequest> SpellCheckRequest::create(TextCheckingTypeMask textCheckingOptions, PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange)
+{
+    ASSERT(checkingRange);
+    ASSERT(paragraphRange);
+
+    String text = checkingRange->text();
+    if (!text.length())
+        return PassRefPtr<SpellCheckRequest>();
+
+    return adoptRef(new SpellCheckRequest(unrequestedSequence, checkingRange, paragraphRange, text, textCheckingOptions));
+}
+
+
+
 SpellChecker::SpellChecker(Frame* frame)
     : m_frame(frame)
     , m_lastRequestSequence(0)
@@ -90,17 +96,6 @@
     return page->editorClient()->textChecker();
 }
 
-PassRefPtr<SpellChecker::SpellCheckRequest> SpellChecker::createRequest(TextCheckingTypeMask mask, PassRefPtr<Range> range)
-{
-    ASSERT(canCheckAsynchronously(range.get()));
-
-    String text = range->text();
-    if (!text.length())
-        return PassRefPtr<SpellCheckRequest>();
-
-    return adoptRef(new SpellCheckRequest(++m_lastRequestSequence, range, text, mask));
-}
-
 void SpellChecker::timerFiredToProcessQueuedRequest(Timer<SpellChecker>*)
 {
     ASSERT(!m_requestQueue.isEmpty());
@@ -125,21 +120,24 @@
     return range && range->firstNode() && range->firstNode()->renderer();
 }
 
-void SpellChecker::requestCheckingFor(TextCheckingTypeMask mask, PassRefPtr<Range> range)
+void SpellChecker::requestCheckingFor(PassRefPtr<SpellCheckRequest> request)
 {
-    if (!canCheckAsynchronously(range.get()))
+    if (!request || !canCheckAsynchronously(request->paragraphRange().get()))
         return;
 
-    RefPtr<SpellCheckRequest> request(createRequest(mask, range));
-    if (!request)
-        return;
+    ASSERT(request->sequence() == unrequestedSequence);
+    int sequence = ++m_lastRequestSequence;
+    if (sequence == unrequestedSequence)
+        sequence = ++m_lastRequestSequence;
 
+    request->setSequence(sequence);
+
     if (m_timerToProcessQueuedRequest.isActive() || m_processingRequest) {
-        enqueueRequest(request.release());
+        enqueueRequest(request);
         return;
     }
 
-    invokeRequest(request.release());
+    invokeRequest(request);
 }
 
 void SpellChecker::invokeRequest(PassRefPtr<SpellCheckRequest> request)
@@ -206,7 +204,7 @@
     }
 
     int startOffset = 0;
-    PositionIterator start = m_processingRequest->range()->startPosition();
+    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;
@@ -224,12 +222,12 @@
         // 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->range()->ownerDocument(), start, end);
+        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->range()->ownerDocument()->markers()->addMarker(range.get(), toMarkerType(results[i].type));
+            m_processingRequest->checkingRange()->ownerDocument()->markers()->addMarker(range.get(), toMarkerType(results[i].type));
 
         startOffset = results[i].location;
     }

Modified: trunk/Source/WebCore/editing/SpellChecker.h (102327 => 102328)


--- trunk/Source/WebCore/editing/SpellChecker.h	2011-12-08 10:44:51 UTC (rev 102327)
+++ trunk/Source/WebCore/editing/SpellChecker.h	2011-12-08 10:46:32 UTC (rev 102328)
@@ -26,10 +26,13 @@
 #ifndef SpellChecker_h
 #define SpellChecker_h
 
+#include "Element.h"
 #include "PlatformString.h"
+#include "Range.h"
 #include "TextChecking.h"
 #include "Timer.h"
 #include <wtf/Deque.h>
+#include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/Vector.h>
@@ -40,8 +43,31 @@
 class Node;
 class TextCheckerClient;
 struct TextCheckingResult;
-class Range;
 
+class SpellCheckRequest : public RefCounted<SpellCheckRequest> {
+public:
+    SpellCheckRequest(int sequence, PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange, const String&, TextCheckingTypeMask);
+    ~SpellCheckRequest();
+
+    static PassRefPtr<SpellCheckRequest> create(TextCheckingTypeMask, PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange);
+
+    void setSequence(int sequence) { m_sequence = sequence; }
+    int sequence() const { return m_sequence; }
+    PassRefPtr<Range> checkingRange() const { return m_checkingRange; }
+    PassRefPtr<Range> paragraphRange() const { return m_paragraphRange; }
+    const String& text() const { return m_text; }
+    TextCheckingTypeMask mask() const { return m_mask; }
+    PassRefPtr<Element> rootEditableElement() const { return m_rootEditableElement; }
+private:
+
+    int m_sequence;
+    RefPtr<Range> m_checkingRange;
+    RefPtr<Range> m_paragraphRange;
+    String m_text;
+    TextCheckingTypeMask m_mask;
+    RefPtr<Element> m_rootEditableElement;
+};
+
 class SpellChecker {
     WTF_MAKE_NONCOPYABLE(SpellChecker);
 public:
@@ -50,7 +76,8 @@
 
     bool isAsynchronousEnabled() const;
     bool isCheckable(Range*) const;
-    void requestCheckingFor(TextCheckingTypeMask, PassRefPtr<Range>);
+
+    void requestCheckingFor(PassRefPtr<SpellCheckRequest>);
     void didCheck(int sequence, const Vector<TextCheckingResult>&);
 
     int lastRequestSequence() const
@@ -64,11 +91,9 @@
     }
 
 private:
-    class SpellCheckRequest;
     typedef Deque<RefPtr<SpellCheckRequest> > RequestQueue;
 
     bool canCheckAsynchronously(Range*) const;
-    PassRefPtr<SpellCheckRequest> createRequest(TextCheckingTypeMask, PassRefPtr<Range>);
     TextCheckerClient* client() const;
     void timerFiredToProcessQueuedRequest(Timer<SpellChecker>*);
     void invokeRequest(PassRefPtr<SpellCheckRequest>);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to