OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/spellchecker.h" | 5 #include "chrome/browser/spellchecker.h" |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/histogram.h" | 9 #include "base/histogram.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "chrome/third_party/hunspell/src/hunspell/hunspell.hxx" | 26 #include "chrome/third_party/hunspell/src/hunspell/hunspell.hxx" |
27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
28 #include "grit/locale_settings.h" | 28 #include "grit/locale_settings.h" |
29 #include "net/url_request/url_request.h" | 29 #include "net/url_request/url_request.h" |
30 | 30 |
31 using base::TimeTicks; | 31 using base::TimeTicks; |
32 | 32 |
33 static const int kMaxSuggestions = 5; // Max number of dictionary suggestions. | 33 static const int kMaxSuggestions = 5; // Max number of dictionary suggestions. |
34 | 34 |
35 namespace { | 35 namespace { |
| 36 |
36 static const struct { | 37 static const struct { |
37 // The language. | 38 // The language. |
38 const wchar_t* language; | 39 const wchar_t* language; |
39 | 40 |
40 // The corresponding language and region, used by the dictionaries. | 41 // The corresponding language and region, used by the dictionaries. |
41 const wchar_t* language_region; | 42 const wchar_t* language_region; |
42 } g_supported_spellchecker_languages[] = { | 43 } g_supported_spellchecker_languages[] = { |
43 {L"en-US", L"en-US"}, | 44 {L"en-US", L"en-US"}, |
44 {L"en-GB", L"en-GB"}, | 45 {L"en-GB", L"en-GB"}, |
45 {L"fr", L"fr-FR"}, | 46 {L"fr", L"fr-FR"}, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // Look for exact match in the Spell Check language list. | 114 // Look for exact match in the Spell Check language list. |
114 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); | 115 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); |
115 ++i) { | 116 ++i) { |
116 Language spellcheck_language( | 117 Language spellcheck_language( |
117 g_supported_spellchecker_languages[i].language); | 118 g_supported_spellchecker_languages[i].language); |
118 if (spellcheck_language == language) | 119 if (spellcheck_language == language) |
119 return language; | 120 return language; |
120 } | 121 } |
121 | 122 |
122 // Look for a match by comparing only language parts. All the 'en-RR' | 123 // Look for a match by comparing only language parts. All the 'en-RR' |
123 // except for 'en-GB' exactly matched in the above loop, will match | 124 // except for 'en-GB' exactly matched in the above loop, will match |
124 // 'en-US'. This is not ideal because 'en-AU', 'en-ZA', 'en-NZ' had | 125 // 'en-US'. This is not ideal because 'en-AU', 'en-ZA', 'en-NZ' had |
125 // better be matched with 'en-GB'. This does not handle cases like | 126 // better be matched with 'en-GB'. This does not handle cases like |
126 // 'az-Latn-AZ' vs 'az-Arab-AZ', either, but we don't use 3-part | 127 // 'az-Latn-AZ' vs 'az-Arab-AZ', either, but we don't use 3-part |
127 // locale ids with a script code in the middle, yet. | 128 // locale ids with a script code in the middle, yet. |
128 // TODO(jungshik): Add a better fallback. | 129 // TODO(jungshik): Add a better fallback. |
129 Language language_part(language, 0, language.find(L'-')); | 130 Language language_part(language, 0, language.find(L'-')); |
130 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); | 131 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); |
131 ++i) { | 132 ++i) { |
132 Language spellcheck_language( | 133 Language spellcheck_language( |
133 g_supported_spellchecker_languages[i].language_region); | 134 g_supported_spellchecker_languages[i].language_region); |
134 if (spellcheck_language.substr(0, spellcheck_language.find(L'-')) == | 135 if (spellcheck_language.substr(0, spellcheck_language.find(L'-')) == |
135 language_part) | 136 language_part) |
136 return spellcheck_language; | 137 return spellcheck_language; |
137 } | 138 } |
138 | 139 |
139 // No match found - return blank. | 140 // No match found - return blank. |
140 return Language(); | 141 return Language(); |
141 } | 142 } |
142 | 143 |
143 int SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu( | 144 int SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu( |
144 Profile* profile, | 145 Profile* profile, |
145 Languages* display_languages) { | 146 Languages* display_languages) { |
146 StringPrefMember accept_languages_pref; | 147 StringPrefMember accept_languages_pref; |
147 StringPrefMember dictionary_language_pref; | 148 StringPrefMember dictionary_language_pref; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // ################################################################ | 337 // ################################################################ |
337 | 338 |
338 std::wstring SpellChecker::GetVersionedFileName(const Language& input_language, | 339 std::wstring SpellChecker::GetVersionedFileName(const Language& input_language, |
339 const std::wstring& dict_dir) { | 340 const std::wstring& dict_dir) { |
340 // The default version string currently in use. | 341 // The default version string currently in use. |
341 static const wchar_t kDefaultVersionString[] = L"-1-2"; | 342 static const wchar_t kDefaultVersionString[] = L"-1-2"; |
342 | 343 |
343 // Use this struct to insert version strings for dictionary files which have | 344 // Use this struct to insert version strings for dictionary files which have |
344 // special version strings, other than the default version string. For eight | 345 // special version strings, other than the default version string. For eight |
345 // languages (included below in the struct), the version is kept at 1-1. The | 346 // languages (included below in the struct), the version is kept at 1-1. The |
346 // others (19 of them) have been updated to new default version 1-2 which | 347 // others (19 of them) have been updated to new default version 1-2 which |
347 // contains many new words. | 348 // contains many new words. |
348 // TODO (sidchat): Work on these 8 languages to bring them upto version 1-2. | 349 // TODO (sidchat): Work on these 8 languages to bring them upto version 1-2. |
349 static const struct { | 350 static const struct { |
350 // The language input. | 351 // The language input. |
351 const char* language; | 352 const char* language; |
352 | 353 |
353 // The corresponding version. | 354 // The corresponding version. |
354 const char* version; | 355 const char* version; |
355 } special_version_string[] = { | 356 } special_version_string[] = { |
356 {"en-GB", "-1-1"}, | 357 {"en-GB", "-1-1"}, |
357 {"es-ES", "-1-1"}, | 358 {"es-ES", "-1-1"}, |
358 {"nl-NL", "-1-1"}, | 359 {"nl-NL", "-1-1"}, |
359 {"ru-RU", "-1-1"}, | 360 {"ru-RU", "-1-1"}, |
360 {"sv-SE", "-1-1"}, | 361 {"sv-SE", "-1-1"}, |
361 {"he-IL", "-1-1"}, | 362 {"he-IL", "-1-1"}, |
362 {"el-GR", "-1-1"}, | 363 {"el-GR", "-1-1"}, |
363 {"hi-IN", "-1-1"} | 364 {"hi-IN", "-1-1"} |
364 }; | 365 }; |
365 | 366 |
366 // Generate the bdict file name using default version string or special | 367 // Generate the bdict file name using default version string or special |
367 // version string, depending on the language. | 368 // version string, depending on the language. |
368 std::wstring language = GetSpellCheckLanguageRegion(input_language); | 369 std::wstring language = GetSpellCheckLanguageRegion(input_language); |
369 std::wstring versioned_bdict_file_name(language + kDefaultVersionString + | 370 std::wstring versioned_bdict_file_name(language + kDefaultVersionString + |
370 L".bdic"); | 371 L".bdic"); |
371 std::string language_string(WideToUTF8(language)); | 372 std::string language_string(WideToUTF8(language)); |
372 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(special_version_string); ++i) { | 373 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(special_version_string); ++i) { |
373 if (language_string == special_version_string[i].language) { | 374 if (language_string == special_version_string[i].language) { |
374 versioned_bdict_file_name = | 375 versioned_bdict_file_name = |
375 language + UTF8ToWide(special_version_string[i].version) + L".bdic"; | 376 language + UTF8ToWide(special_version_string[i].version) + L".bdic"; |
376 break; | 377 break; |
377 } | 378 } |
378 } | 379 } |
379 | 380 |
380 std::wstring bdict_file_name(dict_dir); | 381 std::wstring bdict_file_name(dict_dir); |
381 file_util::AppendToPath(&bdict_file_name, versioned_bdict_file_name); | 382 file_util::AppendToPath(&bdict_file_name, versioned_bdict_file_name); |
382 return bdict_file_name; | 383 return bdict_file_name; |
383 } | 384 } |
384 | 385 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 hunspell_->put_word(word_to_add.c_str()); | 633 hunspell_->put_word(word_to_add.c_str()); |
633 | 634 |
634 // Now add the word to the custom dictionary file. | 635 // Now add the word to the custom dictionary file. |
635 Task* write_word_task = | 636 Task* write_word_task = |
636 new AddWordToCustomDictionaryTask(custom_dictionary_file_name_, word); | 637 new AddWordToCustomDictionaryTask(custom_dictionary_file_name_, word); |
637 if (file_loop_) | 638 if (file_loop_) |
638 file_loop_->PostTask(FROM_HERE, write_word_task); | 639 file_loop_->PostTask(FROM_HERE, write_word_task); |
639 else | 640 else |
640 write_word_task->Run(); | 641 write_word_task->Run(); |
641 } | 642 } |
OLD | NEW |