Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1680)

Unified Diff: chrome/browser/chromeos/input_method/input_method_util.cc

Issue 190033005: [IME] Removes the duplicated IMEs in chrome://settings/languages, and support async component IMEs … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..08579e48d4ec36f907983e1b4363710a621feb11 100644
--- a/chrome/browser/chromeos/input_method/input_method_util.cc
+++ b/chrome/browser/chromeos/input_method/input_method_util.cc
@@ -126,6 +126,69 @@ const struct {
{ "vi", "us", "_comp_ime_jhffeifommiaekmbkkjlpmilogcfdohpvkd_vi_tcvn" },
};
+struct _XkbConfigItem {
Yuki 2014/03/07 07:47:04 Do not start with the underscore followed by a cap
Shu Chen 2014/03/07 08:24:09 Done.
+ std::string layout_name;
+ std::string indicator;
+ bool allow_login;
+};
+
+const _XkbConfigItem kXkbIndicators[] = {
Seigo Nonaka 2014/03/07 07:21:21 nit: Please leave comment this is related to crbug
Shu Chen 2014/03/07 07:30:29 Done.
Yuki 2014/03/07 07:47:04 Static initialization of non-trivial types are pro
Shu Chen 2014/03/07 08:24:09 Sorry I forgot to remove the type _XkbConfigItem.
+ {"am", "AM"},
+ {"be", "BE"},
+ {"be", "BE"},
+ {"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 +364,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].layout_name] =
+ kXkbIndicators[i].indicator;
+ }
}
InputMethodUtil::~InputMethodUtil() {
@@ -398,13 +467,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 +551,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())
+ if (iter == id_to_descriptor_.end())
return NULL;
Yuki 2014/03/07 07:47:04 nit: Fix the indent. 4 spaces => 2 spaces.
Shu Chen 2014/03/07 08:24:09 Done.
- }
return &(iter->second);
}
@@ -708,15 +765,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()));
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698