diff options
author | shinyak@chromium.org <shinyak@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-19 18:58:23 +0000 |
---|---|---|
committer | shinyak@chromium.org <shinyak@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-19 18:58:23 +0000 |
commit | acb38b0ab5acfa3327e57f2d2bed9d7626d0f2d0 (patch) | |
tree | 951b7f74260680369e9ec33d099de13488a4840b /chrome/renderer/spellchecker/spellcheck.h | |
parent | e4a1771c8d6de3e6eb60aa8ac159ad8e99403e06 (diff) | |
download | chromium_src-acb38b0ab5acfa3327e57f2d2bed9d7626d0f2d0.zip chromium_src-acb38b0ab5acfa3327e57f2d2bed9d7626d0f2d0.tar.gz chromium_src-acb38b0ab5acfa3327e57f2d2bed9d7626d0f2d0.tar.bz2 |
This patch implements asynchronous spellchecker on Windows and Linux.
Though Mac already has its own spellchecker, Linux and Windows don't have one. So we have implemented asynchronous spellchecker posting a task.
BUG=6424, 111593
TEST=SpellCheckTest.*
Review URL: http://codereview.chromium.org/9169082
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133029 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/spellchecker/spellcheck.h')
-rw-r--r-- | chrome/renderer/spellchecker/spellcheck.h | 62 |
1 files changed, 56 insertions, 6 deletions
diff --git a/chrome/renderer/spellchecker/spellcheck.h b/chrome/renderer/spellchecker/spellcheck.h index 8567163..5cf0ef4 100644 --- a/chrome/renderer/spellchecker/spellcheck.h +++ b/chrome/renderer/spellchecker/spellcheck.h @@ -7,16 +7,20 @@ #pragma once #include <string> +#include <queue> #include <vector> #include "base/gtest_prod_util.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" #include "base/platform_file.h" #include "base/string16.h" #include "base/time.h" #include "chrome/renderer/spellchecker/spellcheck_worditerator.h" #include "content/public/renderer/render_process_observer.h" #include "ipc/ipc_platform_file.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" #include "unicode/uscript.h" class Hunspell; @@ -26,9 +30,28 @@ namespace file_util { class MemoryMappedFile; } +namespace WebKit { +class WebTextCheckingCompletion; +struct WebTextCheckingResult; +} + +namespace spellcheck { +// Converts vector<SpellCheckResult> to WebVector<WebTextCheckingResult> +// for WebKit. +void ToWebResultList( + int offset, + const std::vector<SpellCheckResult>& results, + WebKit::WebVector<WebKit::WebTextCheckingResult>* web_results); + +WebKit::WebVector<WebKit::WebTextCheckingResult> ToWebResultList( + int offset, + const std::vector<SpellCheckResult>& results); +} + // TODO(morrita): Needs reorg with SpellCheckProvider. // See http://crbug.com/73699. -class SpellCheck : public content::RenderProcessObserver { +class SpellCheck : public content::RenderProcessObserver, + public base::SupportsWeakPtr<SpellCheck> { public: SpellCheck(); virtual ~SpellCheck(); @@ -57,10 +80,7 @@ class SpellCheck : public content::RenderProcessObserver { // SpellCheck a paragrpah. // Returns true if |text| is correctly spelled, false otherwise. // If the spellchecker failed to initialize, always returns true. - // The |tag| parameter should either be a unique identifier for the document, - // or 0. bool SpellCheckParagraph(const string16& text, - int tag, std::vector<SpellCheckResult>* results); // Find a possible correctly spelled word for a misspelled word. Computes an @@ -71,6 +91,12 @@ class SpellCheck : public content::RenderProcessObserver { // behind its command line flag. string16 GetAutoCorrectionWord(const string16& word, int tag); + // Requests to spellcheck the specified text in the background. This function + // posts a background task and calls SpellCheckParagraph() in the task. + void RequestTextChecking(const string16& text, + int offset, + WebKit::WebTextCheckingCompletion* completion); + // Returns true if the spellchecker delegate checking to a system-provided // checker on the browser process. bool is_using_platform_spelling_engine() const { @@ -79,6 +105,10 @@ class SpellCheck : public content::RenderProcessObserver { private: FRIEND_TEST_ALL_PREFIXES(SpellCheckTest, GetAutoCorrectionWord_EN_US); + FRIEND_TEST_ALL_PREFIXES(SpellCheckTest, + RequestSpellCheckMultipleTimesWithoutInitialization); + + class SpellCheckRequestParam; // RenderProcessObserver implementation: virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; @@ -107,6 +137,12 @@ class SpellCheck : public content::RenderProcessObserver { // backend, either hunspell or a platform-specific backend. bool CheckSpelling(const string16& word_to_check, int tag); + // Posts delayed spellcheck task and clear it if any. + void PostDelayedSpellCheckTask(); + + // Performs spell checking from the request queue. + void PerformSpellCheck(); + // When called, relays the request to fill the list with suggestions to // the proper backend, either hunspell or a platform-specific backend. void FillSuggestionList(const string16& wrong_word, @@ -147,12 +183,26 @@ class SpellCheck : public content::RenderProcessObserver { // and False if hunspell is being used. bool is_using_platform_spelling_engine_; - // This flags whether we have ever been initialized, or have asked the browser - // for a dictionary. The value indicates whether we should request a + // This flags is true if we have been intialized. + // The value indicates whether we should request a // dictionary from the browser when the render view asks us to check the // spelling of a word. bool initialized_; + // This flags is true if we have requested dictionary. + bool dictionary_requested_; + + // The parameters of a pending background-spellchecking request. When WebKit + // sends a background-spellchecking request before initializing hunspell, + // we save its parameters and start spellchecking after we finish initializing + // hunspell. (When WebKit sends two or more requests, we cancel the previous + // requests so we do not have to use vectors.) + scoped_refptr<SpellCheckRequestParam> pending_request_param_; + + // The set of params already requested. When finishing the request, the params + // should be removed from the set. + std::queue<scoped_refptr<SpellCheckRequestParam> > requested_params_; + DISALLOW_COPY_AND_ASSIGN(SpellCheck); }; |