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 13 matching lines...) Expand all Loading... |
24 #include "chromeos/ime/input_method_whitelist.h" | 24 #include "chromeos/ime/input_method_whitelist.h" |
25 // TODO(nona): move this header from this file. | 25 // TODO(nona): move this header from this file. |
26 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 // A mapping from an input method id to a string for the language indicator. The | 30 // A mapping from an input method id to a string for the language indicator. The |
31 // mapping is necessary since some input methods belong to the same language. | 31 // mapping is necessary since some input methods belong to the same language. |
32 // For example, both "xkb:us::eng" and "xkb:us:dvorak:eng" are for US English. | 32 // For example, both "xkb:us::eng" and "xkb:us:dvorak:eng" are for US English. |
33 const struct { | 33 const struct { |
34 const char* input_method_id; | 34 const char* engine_id; |
35 const char* indicator_text; | 35 const char* indicator_text; |
36 } kMappingFromIdToIndicatorText[] = { | 36 } kMappingFromIdToIndicatorText[] = { |
37 // To distinguish from "xkb:jp::jpn" | 37 // To distinguish from "xkb:jp::jpn" |
38 // TODO(nona): Make following variables configurable. http://crbug.com/232260. | 38 // TODO(nona): Make following variables configurable. http://crbug.com/232260. |
39 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopnacl_mozc_us", "\xe3\x81\x82" }, | 39 { "nacl_mozc_us", "\xe3\x81\x82" }, |
40 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopnacl_mozc_jp", "\xe3\x81\x82" }, | 40 { "nacl_mozc_jp", "\xe3\x81\x82" }, |
41 { "_comp_ime_bbaiamgfapehflhememkfglaehiobjnknacl_mozc_us", "\xe3\x81\x82" }, | |
42 { "_comp_ime_bbaiamgfapehflhememkfglaehiobjnknacl_mozc_jp", "\xe3\x81\x82" }, | |
43 // For simplified Chinese input methods | 41 // For simplified Chinese input methods |
44 { "pinyin", "\xe6\x8b\xbc" }, // U+62FC | 42 { "zh-t-i0-pinyin", "\xe6\x8b\xbc" }, // U+62FC |
45 { "_comp_ime_cpgalbafkoofkjmaeonnfijgpfennjjnzh-t-i0-pinyin", | 43 { "zh-t-i0-wubi-1986", "\xe4\xba\x94" }, // U+4E94 |
46 "\xe6\x8b\xbc" }, | |
47 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-pinyin", | |
48 "\xe6\x8b\xbc" }, | |
49 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-wubi-1986", | |
50 "\xe4\xba\x94" }, // U+4E94 | |
51 { "pinyin-dv", "\xe6\x8b\xbc" }, | |
52 // For traditional Chinese input methods | 44 // For traditional Chinese input methods |
53 { "mozc-chewing", "\xe9\x85\xb7" }, // U+9177 | 45 { "zh-hant-t-i0-und", "\xE6\xB3\xA8" }, // U+9177 |
54 { "_comp_ime_ekbifjdfhkmdeeajnolmgdlmkllopefizh-hant-t-i0-und", | 46 { "zh-hant-t-i0-cangjie-1987", "\xe5\x80\x89" }, // U+5009 |
55 "\xE6\xB3\xA8" }, // U+6CE8 | 47 { "zh-hant-t-i0-cangjie-1987-x-m0-simplified", "\xe9\x80\x9f" }, // U+901F |
56 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-hant-t-i0-und", | |
57 "\xE6\xB3\xA8" }, // U+6CE8 | |
58 { "m17n:zh:cangjie", "\xe5\x80\x89" }, // U+5009 | |
59 { "_comp_ime_aeebooiibjahgpgmhkeocbeekccfknbjzh-hant-t-i0-cangjie-1987", | |
60 "\xe5\x80\x89" }, // U+5009 | |
61 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-hant-t-i0-cangjie-1987", | |
62 "\xe5\x80\x89" }, // U+5009 | |
63 { "m17n:zh:quick", "\xe9\x80\x9f" }, // U+901F | |
64 // For Hangul input method. | 48 // For Hangul input method. |
65 { "mozc-hangul", "\xed\x95\x9c" }, // U+D55C | 49 { "hangul_2set", "\xed\x95\x9c" }, // U+D55C |
66 { "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_2set", "\xed\x95\x9c" }, | 50 { "hangul_3set390", "\xed\x95\x9c" }, // U+D55C |
67 { "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3set390", | 51 { "hangul_3setfinal", "\xed\x95\x9c" }, // U+D55C |
68 "\xed\x95\x9c" }, | 52 { "hangul_3setnoshift", "\xed\x95\x9c" }, // U+D55C |
69 { "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3setfinal", | 53 { "hangul_romaja", "\xed\x95\x9c" }, // U+D55C |
70 "\xed\x95\x9c" }, | |
71 { "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3setnoshift", | |
72 "\xed\x95\x9c" }, | |
73 { "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_romaja", "\xed\x95\x9c" }, | |
74 { extension_misc::kBrailleImeEngineId, | 54 { extension_misc::kBrailleImeEngineId, |
75 // U+2803 U+2817 U+2807 (Unicode braille patterns for the letters 'brl' in | 55 // U+2803 U+2817 U+2807 (Unicode braille patterns for the letters 'brl' in |
76 // English (and many other) braille codes. | 56 // English (and many other) braille codes. |
77 "\xe2\xa0\x83\xe2\xa0\x97\xe2\xa0\x87" }, | 57 "\xe2\xa0\x83\xe2\xa0\x97\xe2\xa0\x87" }, |
78 }; | 58 }; |
79 | 59 |
80 const size_t kMappingFromIdToIndicatorTextLen = | 60 const size_t kMappingFromIdToIndicatorTextLen = |
81 ARRAYSIZE_UNSAFE(kMappingFromIdToIndicatorText); | 61 ARRAYSIZE_UNSAFE(kMappingFromIdToIndicatorText); |
82 | 62 |
83 // A mapping from an input method id to a resource id for a | 63 // A mapping from an input method id to a resource id for a |
84 // medium length language indicator. | 64 // medium length language indicator. |
85 // For those languages that want to display a slightly longer text in the | 65 // For those languages that want to display a slightly longer text in the |
86 // "Your input method has changed to..." bubble than in the status tray. | 66 // "Your input method has changed to..." bubble than in the status tray. |
87 // If an entry is not found in this table the short name is used. | 67 // If an entry is not found in this table the short name is used. |
88 const struct { | 68 const struct { |
89 const char* input_method_id; | 69 const char* engine_id; |
90 const int resource_id; | 70 const int resource_id; |
91 } kMappingImeIdToMediumLenNameResourceId[] = { | 71 } kMappingImeIdToMediumLenNameResourceId[] = { |
92 { "m17n:zh:cangjie", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, | 72 { "hangul_2set", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN }, |
93 { "m17n:zh:quick", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, | 73 { "hangul_3set390", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN }, |
94 { "mozc-chewing", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, | 74 { "hangul_3setfinal", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN }, |
95 { "mozc-hangul", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN }, | 75 { "hangul_3setnoshift", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN }, |
96 { "pinyin", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_SIMPLIFIED }, | 76 { "hangul_3setromaja", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN }, |
97 { "pinyin-dv", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_SIMPLIFIED }, | 77 { "zh-t-i0-pinyin", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_SIMPLIFIED}, |
98 { "_comp_ime_cpgalbafkoofkjmaeonnfijgpfennjjnzh-t-i0-pinyin", | 78 { "zh-t-i0-wubi-1986", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_SIMPLIFIED }, |
99 IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_SIMPLIFIED}, | 79 { "zh-hant-t-i0-und", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, |
100 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-pinyin", | 80 { "zh-hant-t-i0-cangjie-1987", |
101 IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_SIMPLIFIED }, | |
102 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-wubi-1986", | |
103 IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_SIMPLIFIED }, | |
104 { "_comp_ime_ekbifjdfhkmdeeajnolmgdlmkllopefizh-hant-t-i0-und", | |
105 IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, | 81 IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, |
106 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-hant-t-i0-und", | 82 { "zh-hant-t-i0-cangjie-1987-x-m0-simplified", |
107 IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, | |
108 { "_comp_ime_aeebooiibjahgpgmhkeocbeekccfknbjzh-hant-t-i0-cangjie-1987", | |
109 IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, | |
110 { "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-hant-t-i0-cangjie-1987", | |
111 IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, | 83 IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, |
112 { extension_misc::kBrailleImeEngineId, | 84 { extension_misc::kBrailleImeEngineId, |
113 IDS_LANGUAGES_MEDIUM_LEN_NAME_BRAILLE }, | 85 IDS_LANGUAGES_MEDIUM_LEN_NAME_BRAILLE }, |
114 }; | 86 }; |
115 const size_t kMappingImeIdToMediumLenNameResourceIdLen = | 87 const size_t kMappingImeIdToMediumLenNameResourceIdLen = |
116 ARRAYSIZE_UNSAFE(kMappingImeIdToMediumLenNameResourceId); | 88 ARRAYSIZE_UNSAFE(kMappingImeIdToMediumLenNameResourceId); |
117 | 89 |
118 // Due to asynchronous initialization of component extension manager, | 90 // Due to asynchronous initialization of component extension manager, |
119 // GetFirstLogingInputMethodIds may miss component extension IMEs. To enable | 91 // GetFirstLogingInputMethodIds may miss component extension IMEs. To enable |
120 // component extension IME as the first loging input method, we have to prepare | 92 // component extension IME as the first loging input method, we have to prepare |
121 // component extension IME IDs. | 93 // component extension IME IDs. |
122 const struct { | 94 const struct { |
123 const char* locale; | 95 const char* locale; |
124 const char* layout; | 96 const char* layout; |
125 const char* input_method_id; | 97 const char* engine_id; |
126 } kDefaultInputMethodRecommendation[] = { | 98 } kDefaultInputMethodRecommendation[] = { |
127 { "ja", "us", "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopnacl_mozc_us" }, | 99 { "ja", "us", "nacl_mozc_us" }, |
128 { "ja", "jp", "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopnacl_mozc_jp" }, | 100 { "ja", "jp", "nacl_mozc_jp" }, |
129 { "zh-CN", "us", "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-pinyin" }, | 101 { "zh-CN", "us", "zh-t-i0-pinyin" }, |
130 { "zh-TW", "us", | 102 { "zh-TW", "us", "zh-hant-t-i0-und" }, |
131 "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopzh-hant-t-i0-und" }, | 103 { "th", "us", "vkd_th" }, |
132 #if defined(OFFICIAL_BUILD) | 104 { "vi", "us", "vkd_vi_tcvn" }, |
133 { "th", "us", "_comp_ime_habcdindjejkmepknlhkkloncjcpcnbfvkd_th" }, | |
134 { "vi", "us", "_comp_ime_habcdindjejkmepknlhkkloncjcpcnbfvkd_vi_tcvn" }, | |
135 { "vi", "us", "_comp_ime_habcdindjejkmepknlhkkloncjcpcnbfvkd_vi_tcvn" }, | |
136 #else | |
137 { "th", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_th" }, | |
138 { "vi", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_vi_tcvn" }, | |
139 { "vi", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_vi_tcvn" }, | |
140 #endif | |
141 }; | 105 }; |
142 | 106 |
143 // The map from xkb layout to the indicator text. | 107 // The map from xkb layout to the indicator text. |
144 // Refer to crbug.com/349829. | 108 // Refer to crbug.com/349829. |
145 const char* const kXkbIndicators[][2] = {{"am", "AM"}, | 109 const char* const kXkbIndicators[][2] = {{"am", "AM"}, |
146 {"be", "BE"}, | 110 {"be", "BE"}, |
147 {"bg", "BG"}, | 111 {"bg", "BG"}, |
148 {"bg(phonetic)", "BG"}, | 112 {"bg(phonetic)", "BG"}, |
149 {"br", "BR"}, | 113 {"br", "BR"}, |
150 {"by", "BY"}, | 114 {"by", "BY"}, |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 // "US" and "JP". | 434 // "US" and "JP". |
471 | 435 |
472 // Use the indicator string if set. | 436 // Use the indicator string if set. |
473 if (!input_method.indicator().empty()) { | 437 if (!input_method.indicator().empty()) { |
474 return base::UTF8ToUTF16(input_method.indicator()); | 438 return base::UTF8ToUTF16(input_method.indicator()); |
475 } | 439 } |
476 | 440 |
477 base::string16 text; | 441 base::string16 text; |
478 // Check special cases first. | 442 // Check special cases first. |
479 for (size_t i = 0; i < kMappingFromIdToIndicatorTextLen; ++i) { | 443 for (size_t i = 0; i < kMappingFromIdToIndicatorTextLen; ++i) { |
480 if (kMappingFromIdToIndicatorText[i].input_method_id == | 444 if (extension_ime_util::GetInputMethodIDByEngineID( |
481 input_method.id()) { | 445 kMappingFromIdToIndicatorText[i].engine_id) == input_method.id()) { |
482 text = base::UTF8ToUTF16(kMappingFromIdToIndicatorText[i].indicator_text); | 446 text = base::UTF8ToUTF16(kMappingFromIdToIndicatorText[i].indicator_text); |
483 break; | 447 break; |
484 } | 448 } |
485 } | 449 } |
486 | 450 |
487 // Display the keyboard layout name when using a keyboard layout. | 451 // Display the keyboard layout name when using a keyboard layout. |
488 if (text.empty() && IsKeyboardLayout(input_method.id())) { | 452 if (text.empty() && IsKeyboardLayout(input_method.id())) { |
489 std::map<std::string, std::string>::const_iterator it = | 453 std::map<std::string, std::string>::const_iterator it = |
490 xkb_layout_to_indicator_.find(GetKeyboardLayoutName(input_method.id())); | 454 xkb_layout_to_indicator_.find(GetKeyboardLayoutName(input_method.id())); |
491 if (it != xkb_layout_to_indicator_.end()) | 455 if (it != xkb_layout_to_indicator_.end()) |
(...skipping 16 matching lines...) Expand all Loading... |
508 DCHECK(!text.empty()) << input_method.id(); | 472 DCHECK(!text.empty()) << input_method.id(); |
509 return text; | 473 return text; |
510 } | 474 } |
511 | 475 |
512 base::string16 InputMethodUtil::GetInputMethodMediumName( | 476 base::string16 InputMethodUtil::GetInputMethodMediumName( |
513 const InputMethodDescriptor& input_method) const { | 477 const InputMethodDescriptor& input_method) const { |
514 // For the "Your input method has changed to..." bubble. In most cases | 478 // For the "Your input method has changed to..." bubble. In most cases |
515 // it uses the same name as the short name, unless found in a table | 479 // it uses the same name as the short name, unless found in a table |
516 // for medium length names. | 480 // for medium length names. |
517 for (size_t i = 0; i < kMappingImeIdToMediumLenNameResourceIdLen; ++i) { | 481 for (size_t i = 0; i < kMappingImeIdToMediumLenNameResourceIdLen; ++i) { |
518 if (kMappingImeIdToMediumLenNameResourceId[i].input_method_id == | 482 if (extension_ime_util::GetInputMethodIDByEngineID( |
| 483 kMappingImeIdToMediumLenNameResourceId[i].engine_id) == |
519 input_method.id()) { | 484 input_method.id()) { |
520 return delegate_->GetLocalizedString( | 485 return delegate_->GetLocalizedString( |
521 kMappingImeIdToMediumLenNameResourceId[i].resource_id); | 486 kMappingImeIdToMediumLenNameResourceId[i].resource_id); |
522 } | 487 } |
523 } | 488 } |
524 return GetInputMethodShortName(input_method); | 489 return GetInputMethodShortName(input_method); |
525 } | 490 } |
526 | 491 |
527 base::string16 InputMethodUtil::GetInputMethodLongName( | 492 base::string16 InputMethodUtil::GetInputMethodLongName( |
528 const InputMethodDescriptor& input_method) const { | 493 const InputMethodDescriptor& input_method) const { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 // First, add the current keyboard layout (one used on the login screen). | 582 // First, add the current keyboard layout (one used on the login screen). |
618 out_input_method_ids->push_back(current_input_method.id()); | 583 out_input_method_ids->push_back(current_input_method.id()); |
619 | 584 |
620 const std::string current_layout | 585 const std::string current_layout |
621 = current_input_method.GetPreferredKeyboardLayout(); | 586 = current_input_method.GetPreferredKeyboardLayout(); |
622 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultInputMethodRecommendation); | 587 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultInputMethodRecommendation); |
623 ++i) { | 588 ++i) { |
624 if (kDefaultInputMethodRecommendation[i].locale == language_code && | 589 if (kDefaultInputMethodRecommendation[i].locale == language_code && |
625 kDefaultInputMethodRecommendation[i].layout == current_layout) { | 590 kDefaultInputMethodRecommendation[i].layout == current_layout) { |
626 out_input_method_ids->push_back( | 591 out_input_method_ids->push_back( |
627 kDefaultInputMethodRecommendation[i].input_method_id); | 592 extension_ime_util::GetInputMethodIDByEngineID( |
| 593 kDefaultInputMethodRecommendation[i].engine_id)); |
628 return; | 594 return; |
629 } | 595 } |
630 } | 596 } |
631 | 597 |
632 // Second, find the most popular input method associated with the | 598 // Second, find the most popular input method associated with the |
633 // current UI language. The input method IDs returned from | 599 // current UI language. The input method IDs returned from |
634 // GetInputMethodIdsFromLanguageCode() are sorted by popularity, hence | 600 // GetInputMethodIdsFromLanguageCode() are sorted by popularity, hence |
635 // our basic strategy is to pick the first one, but it's a bit more | 601 // our basic strategy is to pick the first one, but it's a bit more |
636 // complicated as shown below. | 602 // complicated as shown below. |
637 std::string most_popular_id; | 603 std::string most_popular_id; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 | 668 |
703 return std::string(); | 669 return std::string(); |
704 } | 670 } |
705 | 671 |
706 bool InputMethodUtil::MigrateInputMethods( | 672 bool InputMethodUtil::MigrateInputMethods( |
707 std::vector<std::string>* input_method_ids) { | 673 std::vector<std::string>* input_method_ids) { |
708 bool rewritten = false; | 674 bool rewritten = false; |
709 std::vector<std::string>& ids = *input_method_ids; | 675 std::vector<std::string>& ids = *input_method_ids; |
710 for (size_t i = 0; i < ids.size(); ++i) { | 676 for (size_t i = 0; i < ids.size(); ++i) { |
711 std::string id = | 677 std::string id = |
712 extension_ime_util::GetInputMethodIDByKeyboardLayout(ids[i]); | 678 extension_ime_util::GetInputMethodIDByEngineID(ids[i]); |
713 // Migrates old ime id's to new ones. | 679 // Migrates old ime id's to new ones. |
714 for (size_t j = 0; j < arraysize(kExtensionIdMigrationMap); ++j) { | 680 for (size_t j = 0; j < arraysize(kExtensionIdMigrationMap); ++j) { |
715 size_t pos = id.find(kExtensionIdMigrationMap[j][0]); | 681 size_t pos = id.find(kExtensionIdMigrationMap[j][0]); |
716 if (pos != std::string::npos) | 682 if (pos != std::string::npos) |
717 id.replace(pos, kExtensionIdLen, kExtensionIdMigrationMap[j][1]); | 683 id.replace(pos, kExtensionIdLen, kExtensionIdMigrationMap[j][1]); |
718 if (id != ids[i]) { | 684 if (id != ids[i]) { |
719 ids[i] = id; | 685 ids[i] = id; |
720 rewritten = true; | 686 rewritten = true; |
721 } | 687 } |
722 } | 688 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 // Clear the existing maps. | 781 // Clear the existing maps. |
816 language_code_to_ids_.clear(); | 782 language_code_to_ids_.clear(); |
817 id_to_language_code_.clear(); | 783 id_to_language_code_.clear(); |
818 id_to_descriptor_.clear(); | 784 id_to_descriptor_.clear(); |
819 | 785 |
820 AppendInputMethods(imes); | 786 AppendInputMethods(imes); |
821 } | 787 } |
822 | 788 |
823 void InputMethodUtil::InitXkbInputMethodsForTesting() { | 789 void InputMethodUtil::InitXkbInputMethodsForTesting() { |
824 cached_hardware_layouts_.clear(); | 790 cached_hardware_layouts_.clear(); |
825 if (!extension_ime_util::UseWrappedExtensionKeyboardLayouts()) | |
826 return; | |
827 scoped_ptr<InputMethodDescriptors> original_imes = | 791 scoped_ptr<InputMethodDescriptors> original_imes = |
828 InputMethodWhitelist().GetSupportedInputMethods(); | 792 InputMethodWhitelist().GetSupportedInputMethods(); |
829 InputMethodDescriptors whitelist_imes; | 793 InputMethodDescriptors whitelist_imes; |
830 for (size_t i = 0; i < original_imes->size(); ++i) { | 794 for (size_t i = 0; i < original_imes->size(); ++i) { |
831 const InputMethodDescriptor& ime = (*original_imes)[i]; | 795 const InputMethodDescriptor& ime = (*original_imes)[i]; |
832 whitelist_imes.push_back(InputMethodDescriptor( | 796 whitelist_imes.push_back(InputMethodDescriptor( |
833 extension_ime_util::GetInputMethodIDByKeyboardLayout(ime.id()), | 797 extension_ime_util::GetInputMethodIDByEngineID(ime.id()), |
834 "", | 798 "", |
835 ime.indicator(), | 799 ime.indicator(), |
836 ime.keyboard_layouts(), | 800 ime.keyboard_layouts(), |
837 ime.language_codes(), | 801 ime.language_codes(), |
838 ime.is_login_keyboard(), | 802 ime.is_login_keyboard(), |
839 ime.options_page_url(), | 803 ime.options_page_url(), |
840 ime.input_view_url())); | 804 ime.input_view_url())); |
841 } | 805 } |
842 ResetInputMethods(whitelist_imes); | 806 ResetInputMethods(whitelist_imes); |
843 } | 807 } |
844 | 808 |
845 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { | 809 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { |
846 std::vector<std::string> layouts; | 810 std::vector<std::string> layouts; |
847 layouts.push_back("us"); | 811 layouts.push_back("us"); |
848 std::vector<std::string> languages; | 812 std::vector<std::string> languages; |
849 languages.push_back("en-US"); | 813 languages.push_back("en-US"); |
850 return InputMethodDescriptor( | 814 return InputMethodDescriptor( |
851 extension_ime_util::GetInputMethodIDByKeyboardLayout("xkb:us::eng"), | 815 extension_ime_util::GetInputMethodIDByEngineID("xkb:us::eng"), |
852 "", | 816 "", |
853 "US", | 817 "US", |
854 layouts, | 818 layouts, |
855 languages, | 819 languages, |
856 true, // login keyboard. | 820 true, // login keyboard. |
857 GURL(), // options page, not available. | 821 GURL(), // options page, not available. |
858 GURL()); // input view page, not available. | 822 GURL()); // input view page, not available. |
859 } | 823 } |
860 | 824 |
861 void InputMethodUtil::ReloadInternalMaps() { | 825 void InputMethodUtil::ReloadInternalMaps() { |
862 if (supported_input_methods_->size() <= 1) { | 826 if (supported_input_methods_->size() <= 1) { |
863 DVLOG(1) << "GetSupportedInputMethods returned a fallback ID"; | 827 DVLOG(1) << "GetSupportedInputMethods returned a fallback ID"; |
864 // TODO(yusukes): Handle this error in nicer way. | 828 // TODO(yusukes): Handle this error in nicer way. |
865 } | 829 } |
866 | 830 |
867 // Clear the existing maps. | 831 // Clear the existing maps. |
868 language_code_to_ids_.clear(); | 832 language_code_to_ids_.clear(); |
869 id_to_language_code_.clear(); | 833 id_to_language_code_.clear(); |
870 id_to_descriptor_.clear(); | 834 id_to_descriptor_.clear(); |
871 | 835 |
872 for (size_t i = 0; i < supported_input_methods_->size(); ++i) { | 836 for (size_t i = 0; i < supported_input_methods_->size(); ++i) { |
873 const InputMethodDescriptor& input_method = supported_input_methods_->at(i); | 837 const InputMethodDescriptor& input_method = supported_input_methods_->at(i); |
874 const std::string input_method_id = | 838 const std::string input_method_id = |
875 extension_ime_util::GetInputMethodIDByKeyboardLayout(input_method.id()); | 839 extension_ime_util::GetInputMethodIDByEngineID(input_method.id()); |
876 const std::vector<std::string>& language_codes = | 840 const std::vector<std::string>& language_codes = |
877 input_method.language_codes(); | 841 input_method.language_codes(); |
878 | 842 |
879 // |input_method_id| may be different than input_method.id(). | 843 // |input_method_id| may be different than input_method.id(). |
880 id_to_descriptor_.insert( | 844 id_to_descriptor_.insert( |
881 std::make_pair(input_method_id, | 845 std::make_pair(input_method_id, |
882 InputMethodDescriptor(input_method_id, | 846 InputMethodDescriptor(input_method_id, |
883 input_method.name(), | 847 input_method.name(), |
884 input_method.indicator(), | 848 input_method.indicator(), |
885 input_method.keyboard_layouts(), | 849 input_method.keyboard_layouts(), |
886 input_method.language_codes(), | 850 input_method.language_codes(), |
887 input_method.is_login_keyboard(), | 851 input_method.is_login_keyboard(), |
888 input_method.options_page_url(), | 852 input_method.options_page_url(), |
889 input_method.input_view_url()))); | 853 input_method.input_view_url()))); |
890 | 854 |
891 for (size_t i = 0; i < language_codes.size(); ++i) { | 855 for (size_t i = 0; i < language_codes.size(); ++i) { |
892 language_code_to_ids_.insert( | 856 language_code_to_ids_.insert( |
893 std::make_pair(language_codes[i], input_method_id)); | 857 std::make_pair(language_codes[i], input_method_id)); |
894 // Remember the pairs. | 858 // Remember the pairs. |
895 id_to_language_code_.insert( | 859 id_to_language_code_.insert( |
896 std::make_pair(input_method_id, language_codes[i])); | 860 std::make_pair(input_method_id, language_codes[i])); |
897 } | 861 } |
898 } | 862 } |
899 } | 863 } |
900 | 864 |
901 } // namespace input_method | 865 } // namespace input_method |
902 } // namespace chromeos | 866 } // namespace chromeos |
OLD | NEW |