summaryrefslogtreecommitdiffstats
path: root/chrome/browser/spellchecker_mac.mm
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/spellchecker_mac.mm
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/spellchecker_mac.mm')
-rw-r--r--chrome/browser/spellchecker_mac.mm38
1 files changed, 36 insertions, 2 deletions
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.