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 12 matching lines...) Expand all Loading... |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 // A mapping from an input method id to a string for the language indicator. The | 26 // A mapping from an input method id to a string for the language indicator. The |
27 // mapping is necessary since some input methods belong to the same language. | 27 // mapping is necessary since some input methods belong to the same language. |
28 // For example, both "xkb:us::eng" and "xkb:us:dvorak:eng" are for US English. | 28 // For example, both "xkb:us::eng" and "xkb:us:dvorak:eng" are for US English. |
29 const struct { | 29 const struct { |
30 const char* input_method_id; | 30 const char* input_method_id; |
31 const char* indicator_text; | 31 const char* indicator_text; |
32 } kMappingFromIdToIndicatorText[] = { | 32 } kMappingFromIdToIndicatorText[] = { |
33 // To distinguish from "xkb:us::eng" | |
34 { "xkb:us:altgr-intl:eng", "EXTD" }, | |
35 { "xkb:us:dvorak:eng", "DV" }, | |
36 { "xkb:us:intl:eng", "INTL" }, | |
37 { "xkb:us:colemak:eng", "CO" }, | |
38 { "english-m", "??" }, | |
39 { "xkb:de:neo:ger", "NEO" }, | |
40 // To distinguish from "xkb:es::spa" | |
41 { "xkb:es:cat:cat", "CAS" }, | |
42 // To distinguish from "xkb:gb::eng" | |
43 { "xkb:gb:dvorak:eng", "DV" }, | |
44 // To distinguish from "xkb:jp::jpn" | 33 // To distinguish from "xkb:jp::jpn" |
45 // TODO(nona): Make following variables configurable. http://crbug.com/232260. | 34 // TODO(nona): Make following variables configurable. http://crbug.com/232260. |
46 { "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_us", "\xe3\x81\x82" }, | 35 { "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_us", "\xe3\x81\x82" }, |
47 { "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_jp", "\xe3\x81\x82" }, | 36 { "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_jp", "\xe3\x81\x82" }, |
48 { "_comp_ime_bbaiamgfapehflhememkfglaehiobjnknacl_mozc_us", "\xe3\x81\x82" }, | 37 { "_comp_ime_bbaiamgfapehflhememkfglaehiobjnknacl_mozc_us", "\xe3\x81\x82" }, |
49 { "_comp_ime_bbaiamgfapehflhememkfglaehiobjnknacl_mozc_jp", "\xe3\x81\x82" }, | 38 { "_comp_ime_bbaiamgfapehflhememkfglaehiobjnknacl_mozc_jp", "\xe3\x81\x82" }, |
50 // For simplified Chinese input methods | 39 // For simplified Chinese input methods |
51 { "pinyin", "\xe6\x8b\xbc" }, // U+62FC | 40 { "pinyin", "\xe6\x8b\xbc" }, // U+62FC |
52 { "_comp_ime_cpgalbafkoofkjmaeonnfijgpfennjjnzh-t-i0-pinyin", | 41 { "_comp_ime_cpgalbafkoofkjmaeonnfijgpfennjjnzh-t-i0-pinyin", |
53 "\xe6\x8b\xbc" }, | 42 "\xe6\x8b\xbc" }, |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 return base::UTF16ToUTF8(display_name); | 372 return base::UTF16ToUTF8(display_name); |
384 } | 373 } |
385 // Return an empty string if the display name is not found. | 374 // Return an empty string if the display name is not found. |
386 return ""; | 375 return ""; |
387 } | 376 } |
388 | 377 |
389 base::string16 InputMethodUtil::GetInputMethodShortName( | 378 base::string16 InputMethodUtil::GetInputMethodShortName( |
390 const InputMethodDescriptor& input_method) const { | 379 const InputMethodDescriptor& input_method) const { |
391 // For the status area, we use two-letter, upper-case language code like | 380 // For the status area, we use two-letter, upper-case language code like |
392 // "US" and "JP". | 381 // "US" and "JP". |
| 382 |
| 383 // Use the indicator string if set. |
| 384 if (!input_method.indicator().empty()) { |
| 385 return base::UTF8ToUTF16(input_method.indicator()); |
| 386 } |
| 387 |
393 base::string16 text; | 388 base::string16 text; |
394 | |
395 // Check special cases first. | 389 // Check special cases first. |
396 for (size_t i = 0; i < kMappingFromIdToIndicatorTextLen; ++i) { | 390 for (size_t i = 0; i < kMappingFromIdToIndicatorTextLen; ++i) { |
397 if (kMappingFromIdToIndicatorText[i].input_method_id == input_method.id()) { | 391 if (kMappingFromIdToIndicatorText[i].input_method_id == |
| 392 input_method.id()) { |
398 text = base::UTF8ToUTF16(kMappingFromIdToIndicatorText[i].indicator_text); | 393 text = base::UTF8ToUTF16(kMappingFromIdToIndicatorText[i].indicator_text); |
399 break; | 394 break; |
400 } | 395 } |
401 } | 396 } |
402 | 397 |
403 // Display the keyboard layout name when using a keyboard layout. | 398 // Display the keyboard layout name when using a keyboard layout. |
404 if (text.empty() && | 399 if (text.empty() && |
405 IsKeyboardLayout(input_method.id())) { | 400 IsKeyboardLayout(input_method.id())) { |
406 const size_t kMaxKeyboardLayoutNameLen = 2; | 401 const size_t kMaxKeyboardLayoutNameLen = 2; |
407 const base::string16 keyboard_layout = | 402 const base::string16 keyboard_layout = |
408 base::UTF8ToUTF16(GetKeyboardLayoutName(input_method.id())); | 403 base::UTF8ToUTF16(GetKeyboardLayoutName(input_method.id())); |
409 text = StringToUpperASCII(keyboard_layout).substr( | 404 text = StringToUpperASCII(keyboard_layout).substr( |
410 0, kMaxKeyboardLayoutNameLen); | 405 0, kMaxKeyboardLayoutNameLen); |
411 } | 406 } |
412 | 407 |
413 // TODO(yusukes): Some languages have two or more input methods. For example, | 408 // TODO(yusukes): Some languages have two or more input methods. For example, |
414 // Thai has 3, Vietnamese has 4. If these input methods could be activated at | 409 // Thai has 3, Vietnamese has 4. If these input methods could be activated at |
415 // the same time, we should do either of the following: | 410 // the same time, we should do either of the following: |
416 // (1) Add mappings to |kMappingFromIdToIndicatorText| | 411 // (1) Add mappings to |kMappingFromIdToIndicatorText| |
417 // (2) Add suffix (1, 2, ...) to |text| when ambiguous. | 412 // (2) Add suffix (1, 2, ...) to |text| when ambiguous. |
418 | 413 |
419 if (text.empty()) { | 414 if (text.empty()) { |
420 const size_t kMaxLanguageNameLen = 2; | 415 const size_t kMaxLanguageNameLen = 2; |
421 DCHECK(!input_method.language_codes().empty()); | 416 DCHECK(!input_method.language_codes().empty()); |
422 const std::string language_code = input_method.language_codes().at(0); | 417 const std::string language_code = input_method.language_codes().at(0); |
423 text = StringToUpperASCII(base::UTF8ToUTF16(language_code)).substr( | 418 text = StringToUpperASCII(base::UTF8ToUTF16(language_code)).substr( |
424 0, kMaxLanguageNameLen); | 419 0, kMaxLanguageNameLen); |
425 } | 420 } |
426 DCHECK(!text.empty()); | 421 DCHECK(!text.empty()) << input_method.id(); |
427 return text; | 422 return text; |
428 } | 423 } |
429 | 424 |
430 base::string16 InputMethodUtil::GetInputMethodMediumName( | 425 base::string16 InputMethodUtil::GetInputMethodMediumName( |
431 const InputMethodDescriptor& input_method) const { | 426 const InputMethodDescriptor& input_method) const { |
432 // For the "Your input method has changed to..." bubble. In most cases | 427 // For the "Your input method has changed to..." bubble. In most cases |
433 // it uses the same name as the short name, unless found in a table | 428 // it uses the same name as the short name, unless found in a table |
434 // for medium length names. | 429 // for medium length names. |
435 for (size_t i = 0; i < kMappingImeIdToMediumLenNameResourceIdLen; ++i) { | 430 for (size_t i = 0; i < kMappingImeIdToMediumLenNameResourceIdLen; ++i) { |
436 if (kMappingImeIdToMediumLenNameResourceId[i].input_method_id == | 431 if (kMappingImeIdToMediumLenNameResourceId[i].input_method_id == |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 } | 651 } |
657 } | 652 } |
658 | 653 |
659 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { | 654 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { |
660 std::vector<std::string> layouts; | 655 std::vector<std::string> layouts; |
661 layouts.push_back("us"); | 656 layouts.push_back("us"); |
662 std::vector<std::string> languages; | 657 std::vector<std::string> languages; |
663 languages.push_back("en-US"); | 658 languages.push_back("en-US"); |
664 return InputMethodDescriptor("xkb:us::eng", | 659 return InputMethodDescriptor("xkb:us::eng", |
665 "", | 660 "", |
| 661 "US", |
666 layouts, | 662 layouts, |
667 languages, | 663 languages, |
668 true, // login keyboard. | 664 true, // login keyboard. |
669 GURL(), // options page, not available. | 665 GURL(), // options page, not available. |
670 GURL()); // input view page, not available. | 666 GURL()); // input view page, not available. |
671 } | 667 } |
672 | 668 |
673 void InputMethodUtil::ReloadInternalMaps() { | 669 void InputMethodUtil::ReloadInternalMaps() { |
674 if (supported_input_methods_->size() <= 1) { | 670 if (supported_input_methods_->size() <= 1) { |
675 DVLOG(1) << "GetSupportedInputMethods returned a fallback ID"; | 671 DVLOG(1) << "GetSupportedInputMethods returned a fallback ID"; |
(...skipping 23 matching lines...) Expand all Loading... |
699 if (IsKeyboardLayout(input_method.id())) { | 695 if (IsKeyboardLayout(input_method.id())) { |
700 xkb_id_to_descriptor_.insert( | 696 xkb_id_to_descriptor_.insert( |
701 std::make_pair(input_method.GetPreferredKeyboardLayout(), | 697 std::make_pair(input_method.GetPreferredKeyboardLayout(), |
702 input_method)); | 698 input_method)); |
703 } | 699 } |
704 } | 700 } |
705 } | 701 } |
706 | 702 |
707 } // namespace input_method | 703 } // namespace input_method |
708 } // namespace chromeos | 704 } // namespace chromeos |
OLD | NEW |