Skip to content

Commit

Permalink
Move all white-listed input method indicator text from InputMethodUti…
Browse files Browse the repository at this point in the history
…l to manifests of IME extensions.

BUG=232260
TEST=Verified on linux_chromeos.

Review URL: https://codereview.chromium.org/608183002

Cr-Commit-Position: refs/heads/master@{#297357}
  • Loading branch information
shuchen authored and Commit bot committed Sep 30, 2014
1 parent aebcdf8 commit bc91aaa
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ bool ComponentExtensionIMEManagerImpl::ReadEngineComponent(
return false;
if (!dict.GetString(extensions::manifest_keys::kName, &out->display_name))
return false;
if (!dict.GetString(extensions::manifest_keys::kIndicator, &out->indicator))
out->indicator = "";

// Localizes the input method name.
if (out->display_name.find("__MSG_") == 0) {
Expand Down
139 changes: 3 additions & 136 deletions chrome/browser/chromeos/input_method/input_method_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,6 @@

namespace {

// A mapping from an input method id to a string for the language indicator. The
// mapping is necessary since some input methods belong to the same language.
// For example, both "xkb:us::eng" and "xkb:us:dvorak:eng" are for US English.
const struct {
const char* engine_id;
const char* indicator_text;
} kMappingFromIdToIndicatorText[] = {
// To distinguish from "xkb:jp::jpn"
// TODO(nona): Make following variables configurable. http://crbug.com/232260.
{ "nacl_mozc_us", "\xe3\x81\x82" },
{ "nacl_mozc_jp", "\xe3\x81\x82" },
// For simplified Chinese input methods
{ "zh-t-i0-pinyin", "\xe6\x8b\xbc" }, // U+62FC
{ "zh-t-i0-wubi-1986", "\xe4\xba\x94" }, // U+4E94
// For traditional Chinese input methods
{ "zh-hant-t-i0-pinyin", "\xe6\x8b\xbc" }, // U+62FC
{ "zh-hant-t-i0-und", "\xE6\xB3\xA8" }, // U+9177
{ "zh-hant-t-i0-cangjie-1987", "\xe5\x80\x89" }, // U+5009
{ "zh-hant-t-i0-cangjie-1987-x-m0-simplified", "\xe9\x80\x9f" }, // U+901F
// For Hangul input method.
{ "hangul_ahnmatae", "\xed\x95\x9c" }, // U+D55C
{ "hangul_2set", "\xed\x95\x9c" }, // U+D55C
{ "hangul_3set390", "\xed\x95\x9c" }, // U+D55C
{ "hangul_3setfinal", "\xed\x95\x9c" }, // U+D55C
{ "hangul_3setnoshift", "\xed\x95\x9c" }, // U+D55C
{ "hangul_romaja", "\xed\x95\x9c" }, // U+D55C
{ extension_misc::kBrailleImeEngineId,
// U+2803 U+2817 U+2807 (Unicode braille patterns for the letters 'brl' in
// English (and many other) braille codes.
"\xe2\xa0\x83\xe2\xa0\x97\xe2\xa0\x87" },
};

const size_t kMappingFromIdToIndicatorTextLen =
ARRAYSIZE_UNSAFE(kMappingFromIdToIndicatorText);

// A mapping from an input method id to a resource id for a
// medium length language indicator.
// For those languages that want to display a slightly longer text in the
Expand Down Expand Up @@ -106,61 +71,6 @@ const struct {
{ "vi", "us", "vkd_vi_tcvn" },
};

// The map from xkb layout to the indicator text.
// Refer to crbug.com/349829.
const char* const kXkbIndicators[][2] = {{"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"}, };

// The extension ID map for migration.
const char* const kExtensionIdMigrationMap[][2] = {
// Official Japanese IME extension ID.
Expand Down Expand Up @@ -299,11 +209,6 @@ InputMethodUtil::InputMethodUtil(InputMethodDelegate* delegate)
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() {
Expand Down Expand Up @@ -375,47 +280,9 @@ std::string InputMethodUtil::GetInputMethodDisplayNameFromId(

base::string16 InputMethodUtil::GetInputMethodShortName(
const InputMethodDescriptor& input_method) const {
// For the status area, we use two-letter, upper-case language code like
// "US" and "JP".

// Use the indicator string if set.
if (!input_method.indicator().empty()) {
return base::UTF8ToUTF16(input_method.indicator());
}

base::string16 text;
// Check special cases first.
for (size_t i = 0; i < kMappingFromIdToIndicatorTextLen; ++i) {
if (extension_ime_util::GetInputMethodIDByEngineID(
kMappingFromIdToIndicatorText[i].engine_id) == input_method.id()) {
text = base::UTF8ToUTF16(kMappingFromIdToIndicatorText[i].indicator_text);
break;
}
}

// Display the keyboard layout name when using a keyboard layout.
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,
// Thai has 3, Vietnamese has 4. If these input methods could be activated at
// the same time, we should do either of the following:
// (1) Add mappings to |kMappingFromIdToIndicatorText|
// (2) Add suffix (1, 2, ...) to |text| when ambiguous.

if (text.empty()) {
const size_t kMaxLanguageNameLen = 2;
DCHECK(!input_method.language_codes().empty());
const std::string language_code = input_method.language_codes().at(0);
text = StringToUpperASCII(base::UTF8ToUTF16(language_code)).substr(
0, kMaxLanguageNameLen);
}
DCHECK(!text.empty()) << input_method.id();
return text;
// TODO(shuchen): remove this method, as the client can directly use
// input_method.GetIndicator().
return base::UTF8ToUTF16(input_method.GetIndicator());
}

base::string16 InputMethodUtil::GetInputMethodMediumName(
Expand Down
1 change: 0 additions & 1 deletion chrome/browser/chromeos/input_method/input_method_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ class InputMethodUtil {

LanguageCodeToIdsMap language_code_to_ids_;
InputMethodIdToDescriptorMap id_to_descriptor_;
std::map<std::string, std::string> xkb_layout_to_indicator_;

typedef base::hash_map<std::string, int> HashType;
HashType english_to_resource_id_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) {
}
{
InputMethodDescriptor desc =
GetDesc(pinyin_ime_id, "us", "zh-CN", "");
GetDesc(pinyin_ime_id, "us", "zh-CN", "\xe6\x8b\xbc");
EXPECT_EQ(base::UTF8ToUTF16("\xe6\x8b\xbc"),
util_.GetInputMethodShortName(desc));
}
{
InputMethodDescriptor desc = GetDesc(zhuyin_ime_id, "us", "zh-TW", "");
InputMethodDescriptor desc =
GetDesc(zhuyin_ime_id, "us", "zh-TW", "\xE6\xB3\xA8");
EXPECT_EQ(base::UTF8ToUTF16("\xE6\xB3\xA8"),
util_.GetInputMethodShortName(desc));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"name": "Braille Keyboard",
"type": "ime",
"id": "braille",
"indicator": "\u2803\u2817\u2807", // Unicode of 'brl' in English (and many other) braille codes.
"language": ["None"],
"description": "Braille hardware keyboard"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"name": "__MSG_inputmethod_cangjie__",
"type": "ime",
"id": "zh-hant-t-i0-cangjie-1987",
"indicator": "\u5009",
"description": "Cangjie",
"language": ["zh-TW", "zh"],
"layouts": ["us"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"name": "__MSG_inputmethod_pinyin__",
"type": "ime",
"id": "zh-t-i0-pinyin",
"indicator": "\u62FC",
"description": "Pinyin",
"language": ["zh-CN", "zh"],
"layouts": ["us"],
Expand All @@ -34,6 +35,7 @@
"name": "__MSG_inputmethod_traditional_pinyin__",
"type": "ime",
"id": "zh-hant-t-i0-pinyin",
"indicator": "\u62FC",
"description": "Pinyin for Tranditional Chinese",
"language": ["zh-TW", "zh"],
"layouts": ["us"],
Expand All @@ -44,6 +46,7 @@
"name": "__MSG_inputmethod_cangjie__",
"type": "ime",
"id": "zh-hant-t-i0-cangjie-1987",
"indicator": "\u5009",
"description": "Cangjie",
"language": ["zh-TW", "zh"],
"layouts": ["us"],
Expand All @@ -53,6 +56,7 @@
"name": "__MSG_inputmethod_quick__",
"type": "ime",
"id": "zh-hant-t-i0-cangjie-1987-x-m0-simplified",
"indicator": "\u901F",
"description": "Quick",
"language": ["zh-TW", "zh"],
"layouts": ["us"],
Expand All @@ -62,6 +66,7 @@
"name": "__MSG_inputmethod_wubi__",
"type": "ime",
"id": "zh-t-i0-wubi-1986",
"indicator": "\u4E94",
"description": "Wubi",
"language": ["zh-CN", "zh"],
"layouts": ["us"],
Expand All @@ -71,6 +76,7 @@
"name": "__MSG_inputmethod_array__",
"type": "ime",
"id": "zh-hant-t-i0-array-1992",
"indicator": "\u884C\u5217",
"description": "Array",
"language": ["zh-TW", "zh"],
"layouts": ["us"],
Expand All @@ -80,6 +86,7 @@
"name": "__MSG_inputmethod_dayi__",
"type": "ime",
"id": "zh-hant-t-i0-dayi-1988",
"indicator": "\u5927\u6613",
"description": "Dayi",
"language": ["zh-TW", "zh"],
"layouts": ["us"],
Expand All @@ -89,6 +96,7 @@
"name": "__MSG_inputmethod_zhuyin__",
"type": "ime",
"id": "zh-hant-t-i0-und",
"indicator": "\u9177",
"description": "Zhuyin",
"language": ["zh-TW", "zh"],
"layouts": ["us"],
Expand Down Expand Up @@ -279,6 +287,7 @@
"name": "__MSG_inputmethod_mozc_us__",
"type": "ime",
"id": "nacl_mozc_us",
"indicator": "\u3042",
"description": "Japanese input method.",
"language": "ja",
"layouts": ["us"],
Expand All @@ -289,6 +298,7 @@
"name": "__MSG_inputmethod_mozc_jp__",
"type": "ime",
"id": "nacl_mozc_jp",
"indicator": "\u3042",
"description": "Japanese input method.",
"language": "ja",
"layouts": ["jp"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"name": "__MSG_keyboard_us_international__",
"type": "ime",
"id": "xkb:us:intl:eng",
"indicator": "INTL",
"description": "",
"language": ["en", "en-US"],
"layouts": ["us(intl)"],
Expand All @@ -76,6 +77,7 @@
"name": "__MSG_keyboard_us_international__",
"type": "ime",
"id": "xkb:us:intl:nld",
"indicator": "INTL",
"description": "",
"language": ["nl"],
"layouts": ["us(intl)"],
Expand All @@ -86,6 +88,7 @@
"name": "__MSG_keyboard_us_international__",
"type": "ime",
"id": "xkb:us:intl:por",
"indicator": "INTL",
"description": "",
"language": ["pt-BR"],
"layouts": ["us(intl)"],
Expand All @@ -96,6 +99,7 @@
"name": "__MSG_keyboard_us_extended__",
"type": "ime",
"id": "xkb:us:altgr-intl:eng",
"indicator": "EXTD",
"description": "",
"language": ["en", "en-US"],
"layouts": ["us(altgr-intl)"],
Expand All @@ -106,6 +110,7 @@
"name": "__MSG_keyboard_us_dvorak__",
"type": "ime",
"id": "xkb:us:dvorak:eng",
"indicator": "DV",
"description": "",
"language": ["en", "en-US"],
"layouts": ["us(dvorak)"],
Expand All @@ -116,6 +121,7 @@
"name": "__MSG_keyboard_us_colemak__",
"type": "ime",
"id": "xkb:us:colemak:eng",
"indicator": "CO",
"description": "",
"language": ["en", "en-US"],
"layouts": ["us(colemak)"],
Expand Down Expand Up @@ -196,6 +202,7 @@
"name": "__MSG_keyboard_german_neo_2__",
"type": "ime",
"id": "xkb:de:neo:ger",
"indicator": "NEO",
"description": "",
"language": ["de", "de-DE"],
"layouts": ["de(neo)"],
Expand Down Expand Up @@ -226,6 +233,7 @@
"name": "__MSG_keyboard_japanese__",
"type": "ime",
"id": "xkb:jp::jpn",
"indicator": "JA",
"description": "",
"language": ["ja"],
"layouts": ["jp"],
Expand Down Expand Up @@ -306,6 +314,7 @@
"name": "__MSG_keyboard_czech_qwerty__",
"type": "ime",
"id": "xkb:cz:qwerty:cze",
"indicator": "CS",
"description": "",
"language": ["cs"],
"layouts": ["cz(qwerty)"],
Expand Down Expand Up @@ -336,6 +345,7 @@
"name": "__MSG_keyboard_catalan__",
"type": "ime",
"id": "xkb:es:cat:cat",
"indicator": "CAS",
"description": "",
"language": ["ca"],
"layouts": ["es(cat)"],
Expand Down Expand Up @@ -376,6 +386,7 @@
"name": "__MSG_keyboard_latin_american__",
"type": "ime",
"id": "xkb:latam::spa",
"indicator": "LA",
"description": "",
"language": ["es", "es-419"],
"layouts": ["latam"],
Expand Down Expand Up @@ -426,6 +437,7 @@
"name": "__MSG_keyboard_uk_dvorak__",
"type": "ime",
"id": "xkb:gb:dvorak:eng",
"indicator": "DV",
"description": "",
"language": ["en", "en-GB"],
"layouts": ["gb(dvorak)"],
Expand Down
Loading

0 comments on commit bc91aaa

Please sign in to comment.