diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/spellchecker.cc | 9 | ||||
-rw-r--r-- | chrome/browser/spellchecker_linux.cc | 12 | ||||
-rw-r--r-- | chrome/browser/spellchecker_mac.mm | 38 | ||||
-rw-r--r-- | chrome/browser/spellchecker_platform_engine.h | 19 | ||||
-rw-r--r-- | chrome/browser/spellchecker_win.cc | 12 |
5 files changed, 85 insertions, 5 deletions
diff --git a/chrome/browser/spellchecker.cc b/chrome/browser/spellchecker.cc index 7abab66..cbc0f7a 100644 --- a/chrome/browser/spellchecker.cc +++ b/chrome/browser/spellchecker.cc @@ -172,8 +172,13 @@ int SpellChecker::GetSpellCheckLanguages( // Now scan through the list of accept languages, and find possible mappings // from this list to the existing list of spell check languages. std::vector<std::string> accept_languages; - SplitString(WideToASCII(accept_languages_pref.GetValue()), ',', - &accept_languages); + + if (SpellCheckerPlatform::SpellCheckerAvailable()) { + SpellCheckerPlatform::GetAvailableLanguages(&accept_languages); + } else { + SplitString(WideToASCII(accept_languages_pref.GetValue()), ',', + &accept_languages); + } for (std::vector<std::string>::const_iterator i = accept_languages.begin(); i != accept_languages.end(); ++i) { std::string language = GetCorrespondingSpellCheckLanguage(*i); diff --git a/chrome/browser/spellchecker_linux.cc b/chrome/browser/spellchecker_linux.cc index 086e627..1452f74 100644 --- a/chrome/browser/spellchecker_linux.cc +++ b/chrome/browser/spellchecker_linux.cc @@ -20,6 +20,18 @@ bool PlatformSupportsLanguage(const std::string& current_language) { return false; } +void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) { + spellcheck_languages->clear(); +} + +bool SpellCheckerProvidesPanel() { + return false; +} + +bool SpellCheckerPanelVisible() { + return false; +} + void Init() { } diff --git a/chrome/browser/spellchecker_mac.mm b/chrome/browser/spellchecker_mac.mm index bcb6db1..f9bfac6 100644 --- a/chrome/browser/spellchecker_mac.mm +++ b/chrome/browser/spellchecker_mac.mm @@ -20,8 +20,8 @@ const unsigned int kShortLanguageCodeSize = 2; // A private utility function to convert hunspell language codes to os x // language codes. -NSString* ConvertLanguageCodeToMac(const std::string& lang_code) { - NSString* whole_code = base::SysUTF8ToNSString(lang_code); +NSString* ConvertLanguageCodeToMac(const std::string& hunspell_lang_code) { + NSString* whole_code = base::SysUTF8ToNSString(hunspell_lang_code); if ([whole_code length] > kShortLanguageCodeSize) { NSString* lang_code = [whole_code @@ -53,9 +53,33 @@ NSString* ConvertLanguageCodeToMac(const std::string& lang_code) { return whole_code; } } + +std::string ConvertLanguageCodeFromMac(NSString* lang_code) { + // TODO(pwicks):figure out what to do about Multilingual + // Guards for strange cases. + if ([lang_code isEqualToString:@"en"]) return std::string("en-US"); + if ([lang_code isEqualToString:@"pt"]) return std::string("pt-PT"); + + if ([lang_code length] > kShortLanguageCodeSize && + [lang_code characterAtIndex:kShortLanguageCodeSize] == '_') { + return base::SysNSStringToUTF8([NSString stringWithFormat:@"%@-%@", + [lang_code substringToIndex:kShortLanguageCodeSize], + [lang_code substringFromIndex:(kShortLanguageCodeSize + 1)]]); + } + return base::SysNSStringToUTF8(lang_code); +} + } // namespace namespace SpellCheckerPlatform { +void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) { + NSArray* availableLanguages = [[NSSpellChecker sharedSpellChecker] + availableLanguages]; + for (NSString* lang_code in availableLanguages) { + spellcheck_languages->push_back( + ConvertLanguageCodeFromMac(lang_code)); + } +} bool SpellCheckerAvailable() { // If this file was compiled, then we know that we are on OS X 10.5 at least @@ -63,6 +87,16 @@ bool SpellCheckerAvailable() { return true; } +bool SpellCheckerProvidesPanel() { + // OS X has a Spelling Panel, so we can return true here. + return true; +} + +bool SpellCheckerPanelVisible() { + return [[[NSSpellChecker sharedSpellChecker] spellingPanel] + isVisible] ? true : false; +} + void Init() { // This call must be made before the call to // [NSSpellchecker sharedSpellChecker] or it will return nil. diff --git a/chrome/browser/spellchecker_platform_engine.h b/chrome/browser/spellchecker_platform_engine.h index b73253a..ddfe64b 100644 --- a/chrome/browser/spellchecker_platform_engine.h +++ b/chrome/browser/spellchecker_platform_engine.h @@ -14,8 +14,20 @@ #include "chrome/browser/spellchecker_common.h" namespace SpellCheckerPlatform { -// Returns true if there is an platform-specific spellchecker. +// Get the languages supported by the platform spellchecker and store them in +// |spellcheck_languages|. Note that they must be converted to +// Chromium style codes (en-US not en_US). See spellchecker.cc for a full list. +void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages); + +// Returns true if there is a platform-specific spellchecker that can be used. bool SpellCheckerAvailable(); + +// Returns true if the platform spellchecker has a spelling panel. +bool SpellCheckerProvidesPanel(); + +// Returns true if the platform spellchecker panel is visible. +bool SpellCheckerPanelVisible(); + // Do any initialization needed for spellchecker. void Init(); // TODO(pwicks): should we add a companion to this, TearDown or something? @@ -25,18 +37,23 @@ void Init(); // supports. If the platform-specific spellchecker supports the language, // then returns true, otherwise false. bool PlatformSupportsLanguage(const std::string& current_language); + // Sets the language for the platform-specific spellchecker. void SetLanguage(const std::string& lang_to_set); + // Checks the spelling of the given string, using the platform-specific // spellchecker. Returns true if the word is spelled correctly. bool CheckSpelling(const std::string& word_to_check); + // Fills the given vector |optional_suggestions| with a number (up to // kMaxSuggestions, which is defined in spellchecker_common.h) of suggestions // for the string |wrong_word|. void FillSuggestionList(const std::string& wrong_word, std::vector<std::wstring>* optional_suggestions); + // Adds the given word to the platform dictionary. void AddWord(const std::wstring& word); + // Remove a given word from the platform dictionary. void RemoveWord(const std::wstring& word); } diff --git a/chrome/browser/spellchecker_win.cc b/chrome/browser/spellchecker_win.cc index d553b02..73db800 100644 --- a/chrome/browser/spellchecker_win.cc +++ b/chrome/browser/spellchecker_win.cc @@ -20,6 +20,18 @@ bool PlatformSupportsLanguage(const std::string& current_language) { return false; } +void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) { + spellcheck_languages->clear(); +} + +bool SpellCheckerProvidesPanel() { + return false; +} + +bool SpellCheckerPanelVisible() { + return false; +} + void Init() { } |