summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-17 15:06:48 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-17 15:06:48 +0000
commitdba6d2c192dcbe1bcede9c7992e6b1e552faa2b8 (patch)
tree6e9f87df55fb585777af1081b38414b3e2c9da1f /chrome/browser
parent0329a07182f593bcbb9ba29f97b89eb64359b18b (diff)
downloadchromium_src-dba6d2c192dcbe1bcede9c7992e6b1e552faa2b8.zip
chromium_src-dba6d2c192dcbe1bcede9c7992e6b1e552faa2b8.tar.gz
chromium_src-dba6d2c192dcbe1bcede9c7992e6b1e552faa2b8.tar.bz2
Adds languages supported by the platform spellchecker to the right
click menu. Also includes a couple of methods which will be needed once support for the spelling panel is finished. Patch from Paul Wicks (pwicks86@gmail.com) BUG=NONE TEST=Context menu on the mac should show and allow switching between languages for the spellchecker git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20951 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/spellchecker.cc9
-rw-r--r--chrome/browser/spellchecker_linux.cc12
-rw-r--r--chrome/browser/spellchecker_mac.mm38
-rw-r--r--chrome/browser/spellchecker_platform_engine.h19
-rw-r--r--chrome/browser/spellchecker_win.cc12
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() {
}