Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: chrome/renderer/spellchecker/spellcheck.h

Issue 9169082: Asynchronous spellchecking on Win and Linux (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_ 5 #ifndef CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_
6 #define CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_ 6 #define CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/platform_file.h" 15 #include "base/platform_file.h"
15 #include "base/string16.h" 16 #include "base/string16.h"
16 #include "base/time.h" 17 #include "base/time.h"
17 #include "chrome/renderer/spellchecker/spellcheck_worditerator.h" 18 #include "chrome/renderer/spellchecker/spellcheck_worditerator.h"
18 #include "content/public/renderer/render_process_observer.h" 19 #include "content/public/renderer/render_process_observer.h"
19 #include "ipc/ipc_platform_file.h" 20 #include "ipc/ipc_platform_file.h"
20 #include "unicode/uscript.h" 21 #include "unicode/uscript.h"
21 22
22 class Hunspell; 23 class Hunspell;
23 24
24 namespace file_util { 25 namespace file_util {
25 class MemoryMappedFile; 26 class MemoryMappedFile;
26 } 27 }
27 28
28 namespace WebKit { 29 namespace WebKit {
30 class WebTextCheckingCompletion;
29 struct WebTextCheckingResult; 31 struct WebTextCheckingResult;
30 } 32 }
31 33
32 // TODO(morrita): Needs reorg with SpellCheckProvider. 34 // TODO(morrita): Needs reorg with SpellCheckProvider.
33 // See http://crbug.com/73699. 35 // See http://crbug.com/73699.
34 class SpellCheck : public content::RenderProcessObserver { 36 class SpellCheck : public content::RenderProcessObserver {
35 public: 37 public:
36 SpellCheck(); 38 SpellCheck();
37 virtual ~SpellCheck(); 39 virtual ~SpellCheck();
38 40
(...skipping 28 matching lines...) Expand all
67 std::vector<WebKit::WebTextCheckingResult>* results); 69 std::vector<WebKit::WebTextCheckingResult>* results);
68 70
69 // Find a possible correctly spelled word for a misspelled word. Computes an 71 // Find a possible correctly spelled word for a misspelled word. Computes an
70 // empty string if input misspelled word is too long, there is ambiguity, or 72 // empty string if input misspelled word is too long, there is ambiguity, or
71 // the correct spelling cannot be determined. 73 // the correct spelling cannot be determined.
72 // NOTE: If using the platform spellchecker, this will send a *lot* of sync 74 // NOTE: If using the platform spellchecker, this will send a *lot* of sync
73 // IPCs. We should probably refactor this if we ever plan to take it out from 75 // IPCs. We should probably refactor this if we ever plan to take it out from
74 // behind its command line flag. 76 // behind its command line flag.
75 string16 GetAutoCorrectionWord(const string16& word, int tag); 77 string16 GetAutoCorrectionWord(const string16& word, int tag);
76 78
79 // Requests to spellcheck the specified text in the background. This function
80 // posts a background task and calls SpellCheckParagraph() in the task.
81 void RequestTextChecking(const string16& text,
82 int document_tag,
83 WebKit::WebTextCheckingCompletion* completion);
84
77 // Returns true if the spellchecker delegate checking to a system-provided 85 // Returns true if the spellchecker delegate checking to a system-provided
78 // checker on the browser process. 86 // checker on the browser process.
79 bool is_using_platform_spelling_engine() const { 87 bool is_using_platform_spelling_engine() const {
80 return is_using_platform_spelling_engine_; 88 return is_using_platform_spelling_engine_;
81 } 89 }
82 90
83 private: 91 private:
84 FRIEND_TEST_ALL_PREFIXES(SpellCheckTest, GetAutoCorrectionWord_EN_US); 92 FRIEND_TEST_ALL_PREFIXES(SpellCheckTest, GetAutoCorrectionWord_EN_US);
93 FRIEND_TEST_ALL_PREFIXES(SpellCheckTest,
94 RequestSpellCheckMultipleTimesWithoutInitialization);
95
96 class SpellCheckRequest;
85 97
86 // RenderProcessObserver implementation: 98 // RenderProcessObserver implementation:
87 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; 99 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
88 100
89 // Message handlers. 101 // Message handlers.
90 void OnInit(IPC::PlatformFileForTransit bdict_file, 102 void OnInit(IPC::PlatformFileForTransit bdict_file,
91 const std::vector<std::string>& custom_words, 103 const std::vector<std::string>& custom_words,
92 const std::string& language, 104 const std::string& language,
93 bool auto_spell_correct); 105 bool auto_spell_correct);
94 void OnWordAdded(const std::string& word); 106 void OnWordAdded(const std::string& word);
95 void OnEnableAutoSpellCorrect(bool enable); 107 void OnEnableAutoSpellCorrect(bool enable);
96 108
97 // Initializes the Hunspell dictionary, or does nothing if |hunspell_| is 109 // Initializes the Hunspell dictionary, or does nothing if |hunspell_| is
98 // non-null. This blocks. 110 // non-null. This blocks.
99 void InitializeHunspell(); 111 void InitializeHunspell();
100 112
101 // If there is no dictionary file, then this requests one from the browser 113 // If there is no dictionary file, then this requests one from the browser
102 // and does not block. In this case it returns true. 114 // and does not block. In this case it returns true.
103 // If there is a dictionary file, but Hunspell has not been loaded, then 115 // If there is a dictionary file, but Hunspell has not been loaded, then
104 // this loads Hunspell. 116 // this loads Hunspell.
105 // If Hunspell is already loaded, this does nothing. In both the latter cases 117 // If Hunspell is already loaded, this does nothing. In both the latter cases
106 // it returns false, meaning that it is OK to continue spellchecking. 118 // it returns false, meaning that it is OK to continue spellchecking.
107 bool InitializeIfNeeded(); 119 bool InitializeIfNeeded();
108 120
109 // When called, relays the request to check the spelling to the proper 121 // When called, relays the request to check the spelling to the proper
110 // backend, either hunspell or a platform-specific backend. 122 // backend, either hunspell or a platform-specific backend.
111 bool CheckSpelling(const string16& word_to_check, int tag); 123 bool CheckSpelling(const string16& word_to_check, int tag);
112 124
125 // Posts delayed spellcheck task and clear it if any.
126 void PostDelayedSpellCheckTask();
127
113 // When called, relays the request to fill the list with suggestions to 128 // When called, relays the request to fill the list with suggestions to
114 // the proper backend, either hunspell or a platform-specific backend. 129 // the proper backend, either hunspell or a platform-specific backend.
115 void FillSuggestionList(const string16& wrong_word, 130 void FillSuggestionList(const string16& wrong_word,
116 std::vector<string16>* optional_suggestions); 131 std::vector<string16>* optional_suggestions);
117 132
118 // Returns whether or not the given word is a contraction of valid words 133 // Returns whether or not the given word is a contraction of valid words
119 // (e.g. "word:word"). 134 // (e.g. "word:word").
120 bool IsValidContraction(const string16& word, int tag); 135 bool IsValidContraction(const string16& word, int tag);
121 136
122 // Add the given custom word to |hunspell_|. 137 // Add the given custom word to |hunspell_|.
(...skipping 20 matching lines...) Expand all
143 SpellcheckWordIterator text_iterator_; 158 SpellcheckWordIterator text_iterator_;
144 SpellcheckWordIterator contraction_iterator_; 159 SpellcheckWordIterator contraction_iterator_;
145 160
146 // Remember state for auto spell correct. 161 // Remember state for auto spell correct.
147 bool auto_spell_correct_turned_on_; 162 bool auto_spell_correct_turned_on_;
148 163
149 // True if a platform-specific spellchecking engine is being used, 164 // True if a platform-specific spellchecking engine is being used,
150 // and False if hunspell is being used. 165 // and False if hunspell is being used.
151 bool is_using_platform_spelling_engine_; 166 bool is_using_platform_spelling_engine_;
152 167
153 // This flags whether we have ever been initialized, or have asked the browser 168 // This flags is true if we have been intialized.
154 // for a dictionary. The value indicates whether we should request a 169 // The value indicates whether we should request a
155 // dictionary from the browser when the render view asks us to check the 170 // dictionary from the browser when the render view asks us to check the
156 // spelling of a word. 171 // spelling of a word.
157 bool initialized_; 172 bool initialized_;
158 173
174 // This flags is true if we have requested dictionary.
175 bool dictionary_requested_;
176
177 // The parameters of a pending background-spellchecking request. When WebKit
178 // sends a background-spellchecking request before initializing hunspell,
179 // we save its parameters and start spellchecking after we finish initializing
180 // hunspell. (When WebKit sends two or more requests, we cancel the previous
181 // requests so we do not have to use vectors.)
182 scoped_refptr<SpellCheckRequest> pending_request_;
183
159 DISALLOW_COPY_AND_ASSIGN(SpellCheck); 184 DISALLOW_COPY_AND_ASSIGN(SpellCheck);
160 }; 185 };
161 186
162 #endif // CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_ 187 #endif // CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/spellchecker/spellcheck.cc » ('j') | chrome/renderer/spellchecker/spellcheck.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698