| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/input_method/input_method_util.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 { "english-m", "??" }, | 39 { "english-m", "??" }, |
| 40 { "xkb:de:neo:ger", "NEO" }, | 40 { "xkb:de:neo:ger", "NEO" }, |
| 41 // To distinguish from "xkb:es::spa" | 41 // To distinguish from "xkb:es::spa" |
| 42 { "xkb:es:cat:cat", "CAS" }, | 42 { "xkb:es:cat:cat", "CAS" }, |
| 43 // To distinguish from "xkb:gb::eng" | 43 // To distinguish from "xkb:gb::eng" |
| 44 { "xkb:gb:dvorak:eng", "DV" }, | 44 { "xkb:gb:dvorak:eng", "DV" }, |
| 45 // To distinguish from "xkb:jp::jpn" | 45 // To distinguish from "xkb:jp::jpn" |
| 46 { "mozc", "\xe3\x81\x82" }, // U+3042, Japanese Hiragana letter A in UTF-8. | 46 { "mozc", "\xe3\x81\x82" }, // U+3042, Japanese Hiragana letter A in UTF-8. |
| 47 { "mozc-dv", "\xe3\x81\x82" }, | 47 { "mozc-dv", "\xe3\x81\x82" }, |
| 48 { "mozc-jp", "\xe3\x81\x82" }, | 48 { "mozc-jp", "\xe3\x81\x82" }, |
| 49 { "zinnia-japanese", "\xe6\x89\x8b" }, // U+624B, "hand" | |
| 50 // For simplified Chinese input methods | 49 // For simplified Chinese input methods |
| 51 { "pinyin", "\xe6\x8b\xbc" }, // U+62FC | 50 { "pinyin", "\xe6\x8b\xbc" }, // U+62FC |
| 52 { "pinyin-dv", "\xe6\x8b\xbc" }, | 51 { "pinyin-dv", "\xe6\x8b\xbc" }, |
| 53 // For traditional Chinese input methods | 52 // For traditional Chinese input methods |
| 54 { "mozc-chewing", "\xe9\x85\xb7" }, // U+9177 | 53 { "mozc-chewing", "\xe9\x85\xb7" }, // U+9177 |
| 55 { "m17n:zh:cangjie", "\xe5\x80\x89" }, // U+5009 | 54 { "m17n:zh:cangjie", "\xe5\x80\x89" }, // U+5009 |
| 56 { "m17n:zh:quick", "\xe9\x80\x9f" }, // U+901F | 55 { "m17n:zh:quick", "\xe9\x80\x9f" }, // U+901F |
| 57 // For Hangul input method. | 56 // For Hangul input method. |
| 58 { "mozc-hangul", "\xed\x95\x9c" }, // U+D55C | 57 { "mozc-hangul", "\xed\x95\x9c" }, // U+D55C |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 const size_t kMappingFromIdToIndicatorTextLen = | 60 const size_t kMappingFromIdToIndicatorTextLen = |
| 62 ARRAYSIZE_UNSAFE(kMappingFromIdToIndicatorText); | 61 ARRAYSIZE_UNSAFE(kMappingFromIdToIndicatorText); |
| 63 | 62 |
| 63 // A mapping from an input method id to a resource id for a |
| 64 // medium length language indicator. |
| 65 // For those languages that want to display a slightly longer text in the |
| 66 // "Your input method has changed to..." bubble than in the status tray. |
| 67 // If an entry is not found in this table the short name is used. |
| 68 const struct { |
| 69 const char* input_method_id; |
| 70 const int resource_id; |
| 71 } kMappingImeIdToMediumLenNameResourceId[] = { |
| 72 { "m17n:zh:cangjie", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, |
| 73 { "m17n:zh:quick", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, |
| 74 { "mozc", IDS_LANGUAGES_MEDIUM_LEN_NAME_JAPANESE }, |
| 75 { "mozc-chewing", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, |
| 76 { "mozc-dv", IDS_LANGUAGES_MEDIUM_LEN_NAME_JAPANESE }, |
| 77 { "mozc-hangul", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN }, |
| 78 { "mozc-jp", IDS_LANGUAGES_MEDIUM_LEN_NAME_JAPANESE }, |
| 79 { "pinyin", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_SIMPLIFIED }, |
| 80 { "pinyin-dv", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_SIMPLIFIED }, |
| 81 }; |
| 82 const size_t kMappingImeIdToMediumLenNameResourceIdLen = |
| 83 ARRAYSIZE_UNSAFE(kMappingImeIdToMediumLenNameResourceId); |
| 84 |
| 64 string16 GetLanguageName(const std::string& language_code) { | 85 string16 GetLanguageName(const std::string& language_code) { |
| 65 const string16 language_name = l10n_util::GetDisplayNameForLocale( | 86 const string16 language_name = l10n_util::GetDisplayNameForLocale( |
| 66 language_code, g_browser_process->GetApplicationLocale(), true); | 87 language_code, g_browser_process->GetApplicationLocale(), true); |
| 67 return language_name; | 88 return language_name; |
| 68 } | 89 } |
| 69 | 90 |
| 70 } | 91 } |
| 71 | 92 |
| 72 namespace chromeos { | 93 namespace chromeos { |
| 73 | 94 |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 if (text.empty()) { | 439 if (text.empty()) { |
| 419 const size_t kMaxLanguageNameLen = 2; | 440 const size_t kMaxLanguageNameLen = 2; |
| 420 const std::string language_code = input_method.language_code(); | 441 const std::string language_code = input_method.language_code(); |
| 421 text = StringToUpperASCII(UTF8ToUTF16(language_code)).substr( | 442 text = StringToUpperASCII(UTF8ToUTF16(language_code)).substr( |
| 422 0, kMaxLanguageNameLen); | 443 0, kMaxLanguageNameLen); |
| 423 } | 444 } |
| 424 DCHECK(!text.empty()); | 445 DCHECK(!text.empty()); |
| 425 return text; | 446 return text; |
| 426 } | 447 } |
| 427 | 448 |
| 449 string16 InputMethodUtil::GetInputMethodMediumName( |
| 450 const InputMethodDescriptor& input_method) const { |
| 451 // For the "Your input method has changed to..." bubble. In most cases |
| 452 // it uses the same name as the short name, unless found in a table |
| 453 // for medium length names. |
| 454 for (size_t i = 0; i < kMappingImeIdToMediumLenNameResourceIdLen; ++i) { |
| 455 if (kMappingImeIdToMediumLenNameResourceId[i].input_method_id == |
| 456 input_method.id()) { |
| 457 return l10n_util::GetStringUTF16( |
| 458 kMappingImeIdToMediumLenNameResourceId[i].resource_id); |
| 459 } |
| 460 } |
| 461 return GetInputMethodShortName(input_method); |
| 462 } |
| 463 |
| 428 string16 InputMethodUtil::GetInputMethodLongName( | 464 string16 InputMethodUtil::GetInputMethodLongName( |
| 429 const InputMethodDescriptor& input_method) const { | 465 const InputMethodDescriptor& input_method) const { |
| 430 if (!input_method.name().empty()) { | 466 if (!input_method.name().empty()) { |
| 431 // If the descriptor has a name, use it. | 467 // If the descriptor has a name, use it. |
| 432 return UTF8ToUTF16(input_method.name()); | 468 return UTF8ToUTF16(input_method.name()); |
| 433 } | 469 } |
| 434 | 470 |
| 435 // We don't show language here. Name of keyboard layout or input method | 471 // We don't show language here. Name of keyboard layout or input method |
| 436 // usually imply (or explicitly include) its language. | 472 // usually imply (or explicitly include) its language. |
| 437 | 473 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 ReloadInternalMaps(); | 726 ReloadInternalMaps(); |
| 691 } | 727 } |
| 692 | 728 |
| 693 void InputMethodUtil::SetHardwareInputMethodIdForTesting( | 729 void InputMethodUtil::SetHardwareInputMethodIdForTesting( |
| 694 const std::string& input_method_id) { | 730 const std::string& input_method_id) { |
| 695 hardware_input_method_id_for_testing_ = input_method_id; | 731 hardware_input_method_id_for_testing_ = input_method_id; |
| 696 } | 732 } |
| 697 | 733 |
| 698 } // namespace input_method | 734 } // namespace input_method |
| 699 } // namespace chromeos | 735 } // namespace chromeos |
| OLD | NEW |