Chromium Code Reviews| Index: chrome/browser/chromeos/input_method/input_method_util.cc |
| diff --git a/chrome/browser/chromeos/input_method/input_method_util.cc b/chrome/browser/chromeos/input_method/input_method_util.cc |
| index 920ff9826a525b6db8936ab73e5219e27d84cd6c..d53f64db020f3718de42c41572f332504956628c 100644 |
| --- a/chrome/browser/chromeos/input_method/input_method_util.cc |
| +++ b/chrome/browser/chromeos/input_method/input_method_util.cc |
| @@ -126,6 +126,63 @@ const struct { |
| { "vi", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_vi_tcvn" }, |
| }; |
| +// The map from xkb layout to the indicator text. |
| +// Refer to crbug.com/349829. |
| +const char* const kXkbIndicators[][2] = { |
|
Alexander Alekseev
2014/03/07 13:19:31
Will this be translated?
Shu Chen
2014/03/07 13:22:26
Thanks for your quick review.
There is no need to
|
| + {"am", "AM"}, |
| + {"be", "BE"}, |
| + {"bg", "BG"}, |
| + {"bg(phonetic)", "BG"}, |
| + {"br", "BR"}, |
| + {"by", "BY"}, |
| + {"ca", "CA"}, |
| + {"ca(eng)", "CA"}, |
| + {"ca(multix)", "CA"}, |
| + {"ch", "CH"}, |
| + {"ch(fr)", "CH"}, |
| + {"cz", "CZ"}, |
| + {"cz(qwerty)", "CS"}, |
| + {"de", "DE"}, |
| + {"de(neo)", "NEO"}, |
| + {"dk", "DK"}, |
| + {"ee", "EE"}, |
| + {"es", "ES"}, |
| + {"es(cat)", "CAS"}, |
| + {"fi", "FI"}, |
| + {"fr", "FR"}, |
| + {"gb(dvorak)", "DV"}, |
| + {"gb(extd)", "GB"}, |
| + {"ge", "GE"}, |
| + {"gr", "GR"}, |
| + {"hr", "HR"}, |
| + {"hu", "HU"}, |
| + {"il", "IL"}, |
| + {"is", "IS"}, |
| + {"it", "IT"}, |
| + {"jp", "JA"}, |
| + {"latam", "LA"}, |
| + {"lt", "LT"}, |
| + {"lv(apostrophe)", "LV"}, |
| + {"mn", "MN"}, |
| + {"no", "NO"}, |
| + {"pl", "PL"}, |
| + {"pt", "PT"}, |
| + {"ro", "RO"}, |
| + {"rs", "RS"}, |
| + {"ru", "RU"}, |
| + {"ru(phonetic)", "RU"}, |
| + {"se", "SE"}, |
| + {"si", "SI"}, |
| + {"sk", "SK"}, |
| + {"tr", "TR"}, |
| + {"ua", "UA"}, |
| + {"us", "US"}, |
| + {"us(altgr-intl)", "EXTD"}, |
| + {"us(colemak)", "CO"}, |
| + {"us(dvorak)", "DV"}, |
| + {"us(intl)", "INTL"}, |
| +}; |
| + |
| } // namespace |
| namespace chromeos { |
| @@ -301,6 +358,12 @@ InputMethodUtil::InputMethodUtil( |
| DCHECK(result) << "Duplicated string is found: " |
| << map_entry.english_string_from_ibus; |
| } |
| + |
| + // Initialize the map from xkb layout to indicator text. |
| + for (size_t i = 0; i < arraysize(kXkbIndicators); ++i) { |
| + xkb_layout_to_indicator_[kXkbIndicators[i][0]] = |
| + kXkbIndicators[i][1]; |
| + } |
| } |
| InputMethodUtil::~InputMethodUtil() { |
| @@ -398,13 +461,12 @@ base::string16 InputMethodUtil::GetInputMethodShortName( |
| } |
| // Display the keyboard layout name when using a keyboard layout. |
| - if (text.empty() && |
| - IsKeyboardLayout(input_method.id())) { |
| - const size_t kMaxKeyboardLayoutNameLen = 2; |
| - const base::string16 keyboard_layout = |
| - base::UTF8ToUTF16(GetKeyboardLayoutName(input_method.id())); |
| - text = StringToUpperASCII(keyboard_layout).substr( |
| - 0, kMaxKeyboardLayoutNameLen); |
| + if (text.empty() && IsKeyboardLayout(input_method.id())) { |
| + std::map<std::string, std::string>::const_iterator it = |
| + xkb_layout_to_indicator_.find(GetKeyboardLayoutName( |
| + input_method.id())); |
| + if (it != xkb_layout_to_indicator_.end()) |
| + text = base::UTF8ToUTF16(it->second); |
| } |
| // TODO(yusukes): Some languages have two or more input methods. For example, |
| @@ -483,19 +545,8 @@ const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromId( |
| const std::string& input_method_id) const { |
| InputMethodIdToDescriptorMap::const_iterator iter |
| = id_to_descriptor_.find(input_method_id); |
| - if (iter == id_to_descriptor_.end()) { |
| - // If failed to find the descriptor for given id, it may because of the id |
| - // is a component extension xkb id (_comp_ime_...xkb:...). |
| - // So try to convert it to legacy xkb id and find again. |
| - // This hack is mainly for OOBE session, which requires a sync call to get |
| - // the input method descriptor for extension xkb id. |
| - // TODO(shuchen): need to support async wait for component extension |
| - // loading in OOBE session. This hack won't be needed when it's been done. |
| - iter = id_to_descriptor_.find( |
| - extension_ime_util::MaybeGetLegacyXkbId(input_method_id)); |
| - if (iter == id_to_descriptor_.end()) |
| - return NULL; |
| - } |
| + if (iter == id_to_descriptor_.end()) |
| + return NULL; |
| return &(iter->second); |
| } |
| @@ -708,15 +759,17 @@ bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) |
| void InputMethodUtil::SetComponentExtensions( |
| const InputMethodDescriptors& imes) { |
| - component_extension_ime_id_to_descriptor_.clear(); |
| for (size_t i = 0; i < imes.size(); ++i) { |
| - const InputMethodDescriptor& input_method = imes.at(i); |
| + const InputMethodDescriptor& input_method = imes[i]; |
| DCHECK(!input_method.language_codes().empty()); |
| - const std::string language_code = input_method.language_codes().at(0); |
| - id_to_language_code_.insert( |
| - std::make_pair(input_method.id(), language_code)); |
| - id_to_descriptor_.insert( |
| - std::make_pair(input_method.id(), input_method)); |
| + const std::vector<std::string>& language_codes = |
| + input_method.language_codes(); |
| + id_to_language_code_[input_method.id()] = language_codes[0]; |
| + id_to_descriptor_[input_method.id()] = input_method; |
| + for (size_t j = 0; j < language_codes.size(); ++j) { |
| + language_code_to_ids_.insert( |
| + std::make_pair(language_codes[j], input_method.id())); |
| + } |
| } |
| } |