| 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_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_us", "\xe3\x81\x82" }, | 39 { "nacl_mozc_us", "\xe3\x81\x82" }, |
| 40 { "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_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_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_us" }, | 99 { "ja", "us", "nacl_mozc_us" }, |
| 128 { "ja", "jp", "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 // "US" and "JP". | 440 // "US" and "JP". |
| 477 | 441 |
| 478 // Use the indicator string if set. | 442 // Use the indicator string if set. |
| 479 if (!input_method.indicator().empty()) { | 443 if (!input_method.indicator().empty()) { |
| 480 return base::UTF8ToUTF16(input_method.indicator()); | 444 return base::UTF8ToUTF16(input_method.indicator()); |
| 481 } | 445 } |
| 482 | 446 |
| 483 base::string16 text; | 447 base::string16 text; |
| 484 // Check special cases first. | 448 // Check special cases first. |
| 485 for (size_t i = 0; i < kMappingFromIdToIndicatorTextLen; ++i) { | 449 for (size_t i = 0; i < kMappingFromIdToIndicatorTextLen; ++i) { |
| 486 if (kMappingFromIdToIndicatorText[i].input_method_id == | 450 if (extension_ime_util::GetInputMethodIDByEngineID( |
| 487 input_method.id()) { | 451 kMappingFromIdToIndicatorText[i].engine_id) == input_method.id()) { |
| 488 text = base::UTF8ToUTF16(kMappingFromIdToIndicatorText[i].indicator_text); | 452 text = base::UTF8ToUTF16(kMappingFromIdToIndicatorText[i].indicator_text); |
| 489 break; | 453 break; |
| 490 } | 454 } |
| 491 } | 455 } |
| 492 | 456 |
| 493 // Display the keyboard layout name when using a keyboard layout. | 457 // Display the keyboard layout name when using a keyboard layout. |
| 494 if (text.empty() && IsKeyboardLayout(input_method.id())) { | 458 if (text.empty() && IsKeyboardLayout(input_method.id())) { |
| 495 std::map<std::string, std::string>::const_iterator it = | 459 std::map<std::string, std::string>::const_iterator it = |
| 496 xkb_layout_to_indicator_.find(GetKeyboardLayoutName(input_method.id())); | 460 xkb_layout_to_indicator_.find(GetKeyboardLayoutName(input_method.id())); |
| 497 if (it != xkb_layout_to_indicator_.end()) | 461 if (it != xkb_layout_to_indicator_.end()) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 514 DCHECK(!text.empty()) << input_method.id(); | 478 DCHECK(!text.empty()) << input_method.id(); |
| 515 return text; | 479 return text; |
| 516 } | 480 } |
| 517 | 481 |
| 518 base::string16 InputMethodUtil::GetInputMethodMediumName( | 482 base::string16 InputMethodUtil::GetInputMethodMediumName( |
| 519 const InputMethodDescriptor& input_method) const { | 483 const InputMethodDescriptor& input_method) const { |
| 520 // For the "Your input method has changed to..." bubble. In most cases | 484 // For the "Your input method has changed to..." bubble. In most cases |
| 521 // it uses the same name as the short name, unless found in a table | 485 // it uses the same name as the short name, unless found in a table |
| 522 // for medium length names. | 486 // for medium length names. |
| 523 for (size_t i = 0; i < kMappingImeIdToMediumLenNameResourceIdLen; ++i) { | 487 for (size_t i = 0; i < kMappingImeIdToMediumLenNameResourceIdLen; ++i) { |
| 524 if (kMappingImeIdToMediumLenNameResourceId[i].input_method_id == | 488 if (extension_ime_util::GetInputMethodIDByEngineID( |
| 489 kMappingImeIdToMediumLenNameResourceId[i].engine_id) == |
| 525 input_method.id()) { | 490 input_method.id()) { |
| 526 return delegate_->GetLocalizedString( | 491 return delegate_->GetLocalizedString( |
| 527 kMappingImeIdToMediumLenNameResourceId[i].resource_id); | 492 kMappingImeIdToMediumLenNameResourceId[i].resource_id); |
| 528 } | 493 } |
| 529 } | 494 } |
| 530 return GetInputMethodShortName(input_method); | 495 return GetInputMethodShortName(input_method); |
| 531 } | 496 } |
| 532 | 497 |
| 533 base::string16 InputMethodUtil::GetInputMethodLongName( | 498 base::string16 InputMethodUtil::GetInputMethodLongName( |
| 534 const InputMethodDescriptor& input_method) const { | 499 const InputMethodDescriptor& input_method) const { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 // First, add the current keyboard layout (one used on the login screen). | 588 // First, add the current keyboard layout (one used on the login screen). |
| 624 out_input_method_ids->push_back(current_input_method.id()); | 589 out_input_method_ids->push_back(current_input_method.id()); |
| 625 | 590 |
| 626 const std::string current_layout | 591 const std::string current_layout |
| 627 = current_input_method.GetPreferredKeyboardLayout(); | 592 = current_input_method.GetPreferredKeyboardLayout(); |
| 628 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultInputMethodRecommendation); | 593 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultInputMethodRecommendation); |
| 629 ++i) { | 594 ++i) { |
| 630 if (kDefaultInputMethodRecommendation[i].locale == language_code && | 595 if (kDefaultInputMethodRecommendation[i].locale == language_code && |
| 631 kDefaultInputMethodRecommendation[i].layout == current_layout) { | 596 kDefaultInputMethodRecommendation[i].layout == current_layout) { |
| 632 out_input_method_ids->push_back( | 597 out_input_method_ids->push_back( |
| 633 kDefaultInputMethodRecommendation[i].input_method_id); | 598 extension_ime_util::GetInputMethodIDByEngineID( |
| 599 kDefaultInputMethodRecommendation[i].engine_id)); |
| 634 return; | 600 return; |
| 635 } | 601 } |
| 636 } | 602 } |
| 637 | 603 |
| 638 // Second, find the most popular input method associated with the | 604 // Second, find the most popular input method associated with the |
| 639 // current UI language. The input method IDs returned from | 605 // current UI language. The input method IDs returned from |
| 640 // GetInputMethodIdsFromLanguageCode() are sorted by popularity, hence | 606 // GetInputMethodIdsFromLanguageCode() are sorted by popularity, hence |
| 641 // our basic strategy is to pick the first one, but it's a bit more | 607 // our basic strategy is to pick the first one, but it's a bit more |
| 642 // complicated as shown below. | 608 // complicated as shown below. |
| 643 std::string most_popular_id; | 609 std::string most_popular_id; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 | 674 |
| 709 return std::string(); | 675 return std::string(); |
| 710 } | 676 } |
| 711 | 677 |
| 712 bool InputMethodUtil::MigrateXkbInputMethods( | 678 bool InputMethodUtil::MigrateXkbInputMethods( |
| 713 std::vector<std::string>* input_method_ids) { | 679 std::vector<std::string>* input_method_ids) { |
| 714 bool rewritten = false; | 680 bool rewritten = false; |
| 715 std::vector<std::string>& ids = *input_method_ids; | 681 std::vector<std::string>& ids = *input_method_ids; |
| 716 for (size_t i = 0; i < ids.size(); ++i) { | 682 for (size_t i = 0; i < ids.size(); ++i) { |
| 717 std::string id = | 683 std::string id = |
| 718 extension_ime_util::GetInputMethodIDByKeyboardLayout(ids[i]); | 684 extension_ime_util::GetInputMethodIDByEngineID(ids[i]); |
| 719 // Migrates the old chinese ime id to new ones. | 685 // Migrates the old chinese ime id to new ones. |
| 720 // TODO(shuchen): Change the function name to MigrateInputMethods, | 686 // TODO(shuchen): Change the function name to MigrateInputMethods, |
| 721 // and create an abstract layer to map a comprehensive input method id to | 687 // and create an abstract layer to map a comprehensive input method id to |
| 722 // the real extension based input method id. | 688 // the real extension based input method id. |
| 723 // e.g. "zh-t-i0-pinyin" maps to | 689 // e.g. "zh-t-i0-pinyin" maps to |
| 724 // "_comp_id_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-pinyin". | 690 // "_comp_id_gjaehgfemfahhmlgpdfknkhdnemmolopzh-t-i0-pinyin". |
| 725 // See crbug.com/358083. | 691 // See crbug.com/358083. |
| 726 for (size_t j = 0; j < arraysize(kOldChineseExtensionIds); ++j) { | 692 for (size_t j = 0; j < arraysize(kOldChineseExtensionIds); ++j) { |
| 727 size_t pos = id.find(kOldChineseExtensionIds[j]); | 693 size_t pos = id.find(kOldChineseExtensionIds[j]); |
| 728 if (pos != std::string::npos) { | 694 if (pos != std::string::npos) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 } | 787 } |
| 822 if (it == range.second) | 788 if (it == range.second) |
| 823 language_code_to_ids_.insert( | 789 language_code_to_ids_.insert( |
| 824 std::make_pair(language_codes[j], input_method.id())); | 790 std::make_pair(language_codes[j], input_method.id())); |
| 825 } | 791 } |
| 826 } | 792 } |
| 827 } | 793 } |
| 828 | 794 |
| 829 void InputMethodUtil::InitXkbInputMethodsForTesting() { | 795 void InputMethodUtil::InitXkbInputMethodsForTesting() { |
| 830 cached_hardware_layouts_.clear(); | 796 cached_hardware_layouts_.clear(); |
| 831 if (!extension_ime_util::UseWrappedExtensionKeyboardLayouts()) | |
| 832 return; | |
| 833 scoped_ptr<InputMethodDescriptors> original_imes = | 797 scoped_ptr<InputMethodDescriptors> original_imes = |
| 834 InputMethodWhitelist().GetSupportedInputMethods(); | 798 InputMethodWhitelist().GetSupportedInputMethods(); |
| 835 InputMethodDescriptors whitelist_imes; | 799 InputMethodDescriptors whitelist_imes; |
| 836 for (size_t i = 0; i < original_imes->size(); ++i) { | 800 for (size_t i = 0; i < original_imes->size(); ++i) { |
| 837 const InputMethodDescriptor& ime = (*original_imes)[i]; | 801 const InputMethodDescriptor& ime = (*original_imes)[i]; |
| 838 whitelist_imes.push_back(InputMethodDescriptor( | 802 whitelist_imes.push_back(InputMethodDescriptor( |
| 839 extension_ime_util::GetInputMethodIDByKeyboardLayout(ime.id()), | 803 extension_ime_util::GetInputMethodIDByEngineID(ime.id()), |
| 840 "", | 804 "", |
| 841 ime.indicator(), | 805 ime.indicator(), |
| 842 ime.keyboard_layouts(), | 806 ime.keyboard_layouts(), |
| 843 ime.language_codes(), | 807 ime.language_codes(), |
| 844 ime.is_login_keyboard(), | 808 ime.is_login_keyboard(), |
| 845 ime.options_page_url(), | 809 ime.options_page_url(), |
| 846 ime.input_view_url())); | 810 ime.input_view_url())); |
| 847 } | 811 } |
| 848 SetComponentExtensions(whitelist_imes); | 812 SetComponentExtensions(whitelist_imes); |
| 849 } | 813 } |
| 850 | 814 |
| 851 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { | 815 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { |
| 852 std::vector<std::string> layouts; | 816 std::vector<std::string> layouts; |
| 853 layouts.push_back("us"); | 817 layouts.push_back("us"); |
| 854 std::vector<std::string> languages; | 818 std::vector<std::string> languages; |
| 855 languages.push_back("en-US"); | 819 languages.push_back("en-US"); |
| 856 return InputMethodDescriptor( | 820 return InputMethodDescriptor( |
| 857 extension_ime_util::GetInputMethodIDByKeyboardLayout("xkb:us::eng"), | 821 extension_ime_util::GetInputMethodIDByEngineID("xkb:us::eng"), |
| 858 "", | 822 "", |
| 859 "US", | 823 "US", |
| 860 layouts, | 824 layouts, |
| 861 languages, | 825 languages, |
| 862 true, // login keyboard. | 826 true, // login keyboard. |
| 863 GURL(), // options page, not available. | 827 GURL(), // options page, not available. |
| 864 GURL()); // input view page, not available. | 828 GURL()); // input view page, not available. |
| 865 } | 829 } |
| 866 | 830 |
| 867 void InputMethodUtil::ReloadInternalMaps() { | 831 void InputMethodUtil::ReloadInternalMaps() { |
| 868 if (supported_input_methods_->size() <= 1) { | 832 if (supported_input_methods_->size() <= 1) { |
| 869 DVLOG(1) << "GetSupportedInputMethods returned a fallback ID"; | 833 DVLOG(1) << "GetSupportedInputMethods returned a fallback ID"; |
| 870 // TODO(yusukes): Handle this error in nicer way. | 834 // TODO(yusukes): Handle this error in nicer way. |
| 871 } | 835 } |
| 872 | 836 |
| 873 // Clear the existing maps. | 837 // Clear the existing maps. |
| 874 language_code_to_ids_.clear(); | 838 language_code_to_ids_.clear(); |
| 875 id_to_language_code_.clear(); | 839 id_to_language_code_.clear(); |
| 876 id_to_descriptor_.clear(); | 840 id_to_descriptor_.clear(); |
| 877 | 841 |
| 878 for (size_t i = 0; i < supported_input_methods_->size(); ++i) { | 842 for (size_t i = 0; i < supported_input_methods_->size(); ++i) { |
| 879 const InputMethodDescriptor& input_method = supported_input_methods_->at(i); | 843 const InputMethodDescriptor& input_method = supported_input_methods_->at(i); |
| 880 const std::string input_method_id = | 844 const std::string input_method_id = |
| 881 extension_ime_util::GetInputMethodIDByKeyboardLayout(input_method.id()); | 845 extension_ime_util::GetInputMethodIDByEngineID(input_method.id()); |
| 882 const std::vector<std::string>& language_codes = | 846 const std::vector<std::string>& language_codes = |
| 883 input_method.language_codes(); | 847 input_method.language_codes(); |
| 884 | 848 |
| 885 // |input_method_id| may be different than input_method.id(). | 849 // |input_method_id| may be different than input_method.id(). |
| 886 id_to_descriptor_.insert( | 850 id_to_descriptor_.insert( |
| 887 std::make_pair(input_method_id, | 851 std::make_pair(input_method_id, |
| 888 InputMethodDescriptor(input_method_id, | 852 InputMethodDescriptor(input_method_id, |
| 889 input_method.name(), | 853 input_method.name(), |
| 890 input_method.indicator(), | 854 input_method.indicator(), |
| 891 input_method.keyboard_layouts(), | 855 input_method.keyboard_layouts(), |
| 892 input_method.language_codes(), | 856 input_method.language_codes(), |
| 893 input_method.is_login_keyboard(), | 857 input_method.is_login_keyboard(), |
| 894 input_method.options_page_url(), | 858 input_method.options_page_url(), |
| 895 input_method.input_view_url()))); | 859 input_method.input_view_url()))); |
| 896 | 860 |
| 897 for (size_t i = 0; i < language_codes.size(); ++i) { | 861 for (size_t i = 0; i < language_codes.size(); ++i) { |
| 898 language_code_to_ids_.insert( | 862 language_code_to_ids_.insert( |
| 899 std::make_pair(language_codes[i], input_method_id)); | 863 std::make_pair(language_codes[i], input_method_id)); |
| 900 // Remember the pairs. | 864 // Remember the pairs. |
| 901 id_to_language_code_.insert( | 865 id_to_language_code_.insert( |
| 902 std::make_pair(input_method_id, language_codes[i])); | 866 std::make_pair(input_method_id, language_codes[i])); |
| 903 } | 867 } |
| 904 } | 868 } |
| 905 } | 869 } |
| 906 | 870 |
| 907 } // namespace input_method | 871 } // namespace input_method |
| 908 } // namespace chromeos | 872 } // namespace chromeos |
| OLD | NEW |