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

Side by Side Diff: chrome/browser/spellchecker.h

Issue 150139: [chromium-reviews] Change the use of "Language" in Spell Check files to "SpellCheckLanguage". "L... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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_BROWSER_SPELLCHECKER_H_ 5 #ifndef CHROME_BROWSER_SPELLCHECKER_H_
6 #define CHROME_BROWSER_SPELLCHECKER_H_ 6 #define CHROME_BROWSER_SPELLCHECKER_H_
7 7
8 #include <vector> 8 #include <vector>
9 #include <string> 9 #include <string>
10 10
(...skipping 24 matching lines...) Expand all
35 // This object is not threadsafe. In normal usage (not unit tests) it lives on 35 // This object is not threadsafe. In normal usage (not unit tests) it lives on
36 // the I/O thread of the browser. It is threadsafe refcounted so that I/O thread 36 // the I/O thread of the browser. It is threadsafe refcounted so that I/O thread
37 // and the profile on the main thread (which gives out references to it) can 37 // and the profile on the main thread (which gives out references to it) can
38 // keep it. However, all usage of this must be on the I/O thread. 38 // keep it. However, all usage of this must be on the I/O thread.
39 // 39 //
40 // This object should also be deleted on the I/O thread only. It owns a 40 // This object should also be deleted on the I/O thread only. It owns a
41 // reference to URLRequestContext which in turn owns the cache, etc. and must be 41 // reference to URLRequestContext which in turn owns the cache, etc. and must be
42 // deleted on the I/O thread itself. 42 // deleted on the I/O thread itself.
43 class SpellChecker : public base::RefCountedThreadSafe<SpellChecker> { 43 class SpellChecker : public base::RefCountedThreadSafe<SpellChecker> {
44 public: 44 public:
45 // ASCII string representing a language and/or region, e.g. "en-US".
46 typedef std::string Language;
47 typedef std::vector<Language> Languages;
48
49 // Creates the spellchecker by reading dictionaries from the given directory, 45 // Creates the spellchecker by reading dictionaries from the given directory,
50 // and defaulting to the given language. Both strings must be provided. 46 // and defaulting to the given language. Both strings must be provided.
51 // 47 //
52 // The request context is used to download dictionaries if they do not exist. 48 // The request context is used to download dictionaries if they do not exist.
53 // This can be NULL if you don't want this (like in tests). 49 // This can be NULL if you don't want this (like in tests).
54 // The |custom_dictionary_file_name| should be left blank so that Spellchecker 50 // The |custom_dictionary_file_name| should be left blank so that Spellchecker
55 // can figure out the custom dictionary file. It is non empty only for unit 51 // can figure out the custom dictionary file. It is non empty only for unit
56 // testing. 52 // testing.
57 SpellChecker(const FilePath& dict_dir, 53 SpellChecker(const FilePath& dict_dir,
58 const Language& language, 54 const std::string& language,
59 URLRequestContext* request_context, 55 URLRequestContext* request_context,
60 const FilePath& custom_dictionary_file_name); 56 const FilePath& custom_dictionary_file_name);
61 57
62 // Only delete on the I/O thread (see above). 58 // Only delete on the I/O thread (see above).
63 ~SpellChecker(); 59 ~SpellChecker();
64 60
65 // SpellCheck a word. 61 // SpellCheck a word.
66 // Returns true if spelled correctly, false otherwise. 62 // Returns true if spelled correctly, false otherwise.
67 // If the spellchecker failed to initialize, always returns true. 63 // If the spellchecker failed to initialize, always returns true.
68 // In addition, finds the suggested words for a given word 64 // In addition, finds the suggested words for a given word
(...skipping 16 matching lines...) Expand all
85 // Turn auto spell correct support ON or OFF. 81 // Turn auto spell correct support ON or OFF.
86 // |turn_on| = true means turn ON; false means turn OFF. 82 // |turn_on| = true means turn ON; false means turn OFF.
87 void EnableAutoSpellCorrect(bool turn_on); 83 void EnableAutoSpellCorrect(bool turn_on);
88 84
89 // Add custom word to the dictionary, which means: 85 // Add custom word to the dictionary, which means:
90 // a) Add it to the current hunspell object for immediate use, 86 // a) Add it to the current hunspell object for immediate use,
91 // b) Add the word to a file in disk for custom dictionary. 87 // b) Add the word to a file in disk for custom dictionary.
92 void AddWord(const std::wstring& word); 88 void AddWord(const std::wstring& word);
93 89
94 // Get SpellChecker supported languages. 90 // Get SpellChecker supported languages.
95 static void SpellCheckLanguages(Languages* languages); 91 static void SpellCheckLanguages(std::vector<std::string>* languages);
96 92
97 // This function computes a vector of strings which are to be displayed in 93 // This function computes a vector of strings which are to be displayed in
98 // the context menu over a text area for changing spell check languages. It 94 // the context menu over a text area for changing spell check languages. It
99 // returns the index of the current spell check language in the vector. 95 // returns the index of the current spell check language in the vector.
100 // TODO(port): this should take a vector of string16, but the implementation 96 // TODO(port): this should take a vector of string16, but the implementation
101 // has some dependencies in l10n util that need porting first. 97 // has some dependencies in l10n util that need porting first.
102 static int GetSpellCheckLanguages( 98 static int GetSpellCheckLanguages(
103 Profile* profile, 99 Profile* profile,
104 Languages* languages); 100 std::vector<std::string>* languages);
105 101
106 // This function returns the corresponding language-region code for the 102 // This function returns the corresponding language-region code for the
107 // spell check language. For example, for hi, it returns hi-IN. 103 // spell check language. For example, for hi, it returns hi-IN.
108 static Language GetSpellCheckLanguageRegion(Language input_language); 104 static std::string GetSpellCheckLanguageRegion(std::string input_language);
109 105
110 // This function returns ll (language code) from ll-RR where 'RR' (region 106 // This function returns ll (language code) from ll-RR where 'RR' (region
111 // code) is redundant. However, if the region code matters, it's preserved. 107 // code) is redundant. However, if the region code matters, it's preserved.
112 // That is, it returns 'hi' and 'en-GB' for 'hi-IN' and 'en-GB' respectively. 108 // That is, it returns 'hi' and 'en-GB' for 'hi-IN' and 'en-GB' respectively.
113 static Language GetLanguageFromLanguageRegion(Language input_language); 109 static std::string GetLanguageFromLanguageRegion(std::string input_language);
114 110
115 private: 111 private:
116 112
117 // When called, relays the request to check the spelling to the proper 113 // When called, relays the request to check the spelling to the proper
118 // backend, either hunspell or a platform-specific backend. 114 // backend, either hunspell or a platform-specific backend.
119 bool CheckSpelling(const std::string& word_to_check); 115 bool CheckSpelling(const std::string& word_to_check);
120 116
121 // When called, relays the request to fill the list with suggestions to 117 // When called, relays the request to fill the list with suggestions to
122 // the proper backend, either hunspell or a platform-specific backend. 118 // the proper backend, either hunspell or a platform-specific backend.
123 void FillSuggestionList(const std::string& wrong_word, 119 void FillSuggestionList(const std::string& wrong_word,
(...skipping 14 matching lines...) Expand all
138 // Memory maps the given .bdic file. On success, it will return true and will 134 // Memory maps the given .bdic file. On success, it will return true and will
139 // place the data and length into the given out parameters. 135 // place the data and length into the given out parameters.
140 bool MapBdictFile(const unsigned char** data, size_t* length); 136 bool MapBdictFile(const unsigned char** data, size_t* length);
141 137
142 // Returns whether or not the given word is a contraction of valid words 138 // Returns whether or not the given word is a contraction of valid words
143 // (e.g. "word:word"). 139 // (e.g. "word:word").
144 bool IsValidContraction(const string16& word); 140 bool IsValidContraction(const string16& word);
145 141
146 // Return the file name of the dictionary, including the path and the version 142 // Return the file name of the dictionary, including the path and the version
147 // numbers. 143 // numbers.
148 FilePath GetVersionedFileName(const Language& language, 144 FilePath GetVersionedFileName(const std::string& language,
149 const FilePath& dict_dir); 145 const FilePath& dict_dir);
150 146
151 static Language GetCorrespondingSpellCheckLanguage(const Language& language); 147 static std::string GetCorrespondingSpellCheckLanguage(
148 const std::string& language);
152 149
153 // Path to the spellchecker file. 150 // Path to the spellchecker file.
154 FilePath bdict_file_name_; 151 FilePath bdict_file_name_;
155 152
156 // Path to the custom dictionary file. 153 // Path to the custom dictionary file.
157 FilePath custom_dictionary_file_name_; 154 FilePath custom_dictionary_file_name_;
158 155
159 // We memory-map the BDict file. 156 // We memory-map the BDict file.
160 scoped_ptr<file_util::MemoryMappedFile> bdict_file_; 157 scoped_ptr<file_util::MemoryMappedFile> bdict_file_;
161 158
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 205
209 // Used for generating callbacks to spellchecker, since spellchecker is a 206 // Used for generating callbacks to spellchecker, since spellchecker is a
210 // non-reference counted object. The callback is generated by generating tasks 207 // non-reference counted object. The callback is generated by generating tasks
211 // using NewRunableMethod on these objects. 208 // using NewRunableMethod on these objects.
212 ScopedRunnableMethodFactory<SpellChecker> dic_download_state_changer_factory_; 209 ScopedRunnableMethodFactory<SpellChecker> dic_download_state_changer_factory_;
213 210
214 DISALLOW_COPY_AND_ASSIGN(SpellChecker); 211 DISALLOW_COPY_AND_ASSIGN(SpellChecker);
215 }; 212 };
216 213
217 #endif // CHROME_BROWSER_SPELLCHECKER_H_ 214 #endif // CHROME_BROWSER_SPELLCHECKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698