Commit dcac15dc authored by shuchen@chromium.org's avatar shuchen@chromium.org

Adds whitelisted non-extension-based input methods if no component extensions...

Adds whitelisted non-extension-based input methods if no component extensions are at present (e.g. linux_chromeos).
And also clean up some useless code.

BUG=364712
TEST=Verified it works on linux_chromeos and no regression on Pixel device.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274589 0039d316-1c4b-4281-b951-d872f2087c98
parent cd3f8a6d
...@@ -110,10 +110,8 @@ void InputMethodManagerImpl::SetState(State new_state) { ...@@ -110,10 +110,8 @@ void InputMethodManagerImpl::SetState(State new_state) {
scoped_ptr<InputMethodDescriptors> scoped_ptr<InputMethodDescriptors>
InputMethodManagerImpl::GetSupportedInputMethods() const { InputMethodManagerImpl::GetSupportedInputMethods() const {
scoped_ptr<InputMethodDescriptors> whitelist_imes = if (!IsXkbComponentExtensionAvailable())
whitelist_.GetSupportedInputMethods(); return whitelist_.GetSupportedInputMethods().Pass();
if (!component_extension_ime_manager_->IsInitialized())
return whitelist_imes.Pass();
return scoped_ptr<InputMethodDescriptors>(new InputMethodDescriptors).Pass(); return scoped_ptr<InputMethodDescriptors>(new InputMethodDescriptors).Pass();
} }
...@@ -325,9 +323,7 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal( ...@@ -325,9 +323,7 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal(
} }
if (!component_extension_ime_manager_->IsInitialized() && if (!component_extension_ime_manager_->IsInitialized() &&
(!InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch) || !InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) {
extension_ime_util::IsKeyboardLayoutExtension(
input_method_id_to_switch))) {
// We can't change input method before the initialization of // We can't change input method before the initialization of
// component extension ime manager. ChangeInputMethod will be // component extension ime manager. ChangeInputMethod will be
// called with |pending_input_method_| when the initialization is // called with |pending_input_method_| when the initialization is
...@@ -405,6 +401,18 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal( ...@@ -405,6 +401,18 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal(
return true; return true;
} }
bool InputMethodManagerImpl::IsXkbComponentExtensionAvailable() const {
if (!component_extension_ime_manager_->IsInitialized())
return false;
InputMethodDescriptors imes =
component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor();
for (size_t i = 0; i < imes.size(); ++i) {
if (StartsWithASCII(imes[i].id(), "xkb:", true))
return true;
}
return false;
}
void InputMethodManagerImpl::OnComponentExtensionInitialized( void InputMethodManagerImpl::OnComponentExtensionInitialized(
scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
...@@ -413,14 +421,7 @@ void InputMethodManagerImpl::OnComponentExtensionInitialized( ...@@ -413,14 +421,7 @@ void InputMethodManagerImpl::OnComponentExtensionInitialized(
component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor(); component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor();
// In case of XKB extension is not available (e.g. linux_chromeos), don't // In case of XKB extension is not available (e.g. linux_chromeos), don't
// reset the input methods in InputMethodUtil, Instead append input methods. // reset the input methods in InputMethodUtil, Instead append input methods.
bool xkb_found = false; if (IsXkbComponentExtensionAvailable())
for (size_t i = 0; i < imes.size(); ++i) {
if (StartsWithASCII(imes[i].id(), "xkb:", true)) {
xkb_found = true;
break;
}
}
if (xkb_found)
util_.ResetInputMethods(imes); util_.ResetInputMethods(imes);
else else
util_.AppendInputMethods(imes); util_.AppendInputMethods(imes);
......
...@@ -142,6 +142,10 @@ class InputMethodManagerImpl : public InputMethodManager, ...@@ -142,6 +142,10 @@ class InputMethodManagerImpl : public InputMethodManager,
bool ChangeInputMethodInternal(const std::string& input_method_id, bool ChangeInputMethodInternal(const std::string& input_method_id,
bool show_message); bool show_message);
// Gets whether the XKB extension is loaded successfully by checking the XKB
// input methods in input methods in |component_extension_ime_manager_|.
bool IsXkbComponentExtensionAvailable() const;
// Called when the ComponentExtensionIMEManagerDelegate is initialized. // Called when the ComponentExtensionIMEManagerDelegate is initialized.
void OnComponentExtensionInitialized( void OnComponentExtensionInitialized(
scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate); scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate);
......
...@@ -167,177 +167,86 @@ const char* const kExtensionIdMigrationMap[][2] = { ...@@ -167,177 +167,86 @@ const char* const kExtensionIdMigrationMap[][2] = {
const size_t kExtensionIdLen = 32; const size_t kExtensionIdLen = 32;
} // namespace
namespace chromeos {
extern const char* kExtensionImePrefix;
namespace input_method {
namespace {
const struct EnglishToResouceId { const struct EnglishToResouceId {
const char* english_string_from_ibus; const char* english_string_from_ibus;
int resource_id; int resource_id;
} kEnglishToResourceIdArray[] = { } kEnglishToResourceIdArray[] = {
// For ibus-mozc-hangul // For xkb-layouts.
{ "Hanja mode", IDS_STATUSBAR_IME_KOREAN_HANJA_INPUT_MODE }, { "xkb:am:phonetic:arm", IDS_STATUSBAR_LAYOUT_ARMENIAN_PHONETIC },
{ "Hangul mode", IDS_STATUSBAR_IME_KOREAN_HANGUL_INPUT_MODE },
// For ibus-mozc-pinyin.
{ "Full/Half width",
IDS_STATUSBAR_IME_CHINESE_PINYIN_TOGGLE_FULL_HALF },
{ "Full/Half width punctuation",
IDS_STATUSBAR_IME_CHINESE_PINYIN_TOGGLE_FULL_HALF_PUNCTUATION },
// TODO(hsumita): Fixes a typo
{ "Simplfied/Traditional Chinese",
IDS_STATUSBAR_IME_CHINESE_PINYIN_TOGGLE_S_T_CHINESE },
{ "Chinese",
IDS_STATUSBAR_IME_CHINESE_PINYIN_TOGGLE_CHINESE_ENGLISH },
// For ibus-mozc-chewing.
{ "English",
IDS_STATUSBAR_IME_CHINESE_MOZC_CHEWING_ENGLISH_MODE },
{ "_Chinese",
IDS_STATUSBAR_IME_CHINESE_MOZC_CHEWING_CHINESE_MODE },
{ "Full-width English",
IDS_STATUSBAR_IME_CHINESE_MOZC_CHEWING_FULL_WIDTH_ENGLISH_MODE },
// For the "Languages and Input" dialog.
{ "m17n:ar:kbd", IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD },
{ "m17n:hi:itrans", // also uses the "STANDARD_INPUT_METHOD" id.
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD },
{ "m17n:zh:cangjie",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_CHINESE_CANGJIE_INPUT_METHOD },
{ "m17n:zh:quick",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_CHINESE_QUICK_INPUT_METHOD },
{ "m17n:fa:isiri",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_PERSIAN_ISIRI_2901_INPUT_METHOD },
{ "m17n:th:kesmanee",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_THAI_KESMANEE_INPUT_METHOD },
{ "m17n:th:tis820",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_THAI_TIS820_INPUT_METHOD },
{ "m17n:th:pattachote",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_THAI_PATTACHOTE_INPUT_METHOD },
{ "m17n:vi:tcvn",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_VIETNAMESE_TCVN_INPUT_METHOD },
{ "m17n:vi:telex",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_VIETNAMESE_TELEX_INPUT_METHOD },
{ "m17n:vi:viqr",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_VIETNAMESE_VIQR_INPUT_METHOD },
{ "m17n:vi:vni",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_VIETNAMESE_VNI_INPUT_METHOD },
{ "m17n:bn:itrans",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD },
{ "m17n:gu:itrans",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD },
{ "m17n:ml:itrans",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD },
{ "m17n:mr:itrans",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD },
{ "m17n:ta:phonetic",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_TAMIL_PHONETIC },
{ "m17n:ta:inscript",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_TAMIL_INSCRIPT },
{ "m17n:ta:tamil99",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_TAMIL_TAMIL99 },
{ "m17n:ta:itrans",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_TAMIL_ITRANS },
{ "m17n:ta:typewriter",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_TAMIL_TYPEWRITER },
{ "m17n:am:sera",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD },
{ "m17n:te:itrans",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD },
{ "m17n:kn:itrans",
IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD },
{ "mozc-chewing",
IDS_OPTIONS_SETTINGS_LANGUAGES_CHEWING_INPUT_METHOD },
{ "pinyin", IDS_OPTIONS_SETTINGS_LANGUAGES_PINYIN_INPUT_METHOD },
{ "pinyin-dv",
IDS_OPTIONS_SETTINGS_LANGUAGES_PINYIN_DV_INPUT_METHOD },
{ "zinnia-japanese",
IDS_OPTIONS_SETTINGS_LANGUAGES_JAPANESE_HANDWRITING_INPUT_METHOD },
{ "mozc-hangul", IDS_OPTIONS_SETTINGS_LANGUAGES_KOREAN_INPUT_METHOD },
// For ibus-xkb-layouts engine: third_party/ibus-xkb-layouts/files
{ "xkb:jp::jpn", IDS_STATUSBAR_LAYOUT_JAPAN },
{ "xkb:si::slv", IDS_STATUSBAR_LAYOUT_SLOVENIA },
{ "xkb:de::ger", IDS_STATUSBAR_LAYOUT_GERMANY },
{ "xkb:de:neo:ger", IDS_STATUSBAR_LAYOUT_GERMANY_NEO2 },
{ "xkb:it::ita", IDS_STATUSBAR_LAYOUT_ITALY },
{ "xkb:ee::est", IDS_STATUSBAR_LAYOUT_ESTONIA },
{ "xkb:hu::hun", IDS_STATUSBAR_LAYOUT_HUNGARY },
{ "xkb:pl::pol", IDS_STATUSBAR_LAYOUT_POLAND },
{ "xkb:dk::dan", IDS_STATUSBAR_LAYOUT_DENMARK },
{ "xkb:hr::scr", IDS_STATUSBAR_LAYOUT_CROATIA },
{ "xkb:br::por", IDS_STATUSBAR_LAYOUT_BRAZIL },
{ "xkb:rs::srp", IDS_STATUSBAR_LAYOUT_SERBIA },
{ "xkb:cz::cze", IDS_STATUSBAR_LAYOUT_CZECHIA },
{ "xkb:cz:qwerty:cze", IDS_STATUSBAR_LAYOUT_CZECHIA_QWERTY },
{ "xkb:us:dvorak:eng", IDS_STATUSBAR_LAYOUT_USA_DVORAK },
{ "xkb:us:colemak:eng", IDS_STATUSBAR_LAYOUT_USA_COLEMAK },
{ "xkb:ro::rum", IDS_STATUSBAR_LAYOUT_ROMANIA },
{ "xkb:us::eng", IDS_STATUSBAR_LAYOUT_USA },
{ "xkb:us:altgr-intl:eng", IDS_STATUSBAR_LAYOUT_USA_EXTENDED },
{ "xkb:us:intl:eng", IDS_STATUSBAR_LAYOUT_USA_INTERNATIONAL },
{ "xkb:lt::lit", IDS_STATUSBAR_LAYOUT_LITHUANIA },
{ "xkb:gb:extd:eng", IDS_STATUSBAR_LAYOUT_UNITED_KINGDOM },
{ "xkb:gb:dvorak:eng", IDS_STATUSBAR_LAYOUT_UNITED_KINGDOM_DVORAK },
{ "xkb:sk::slo", IDS_STATUSBAR_LAYOUT_SLOVAKIA },
{ "xkb:ru::rus", IDS_STATUSBAR_LAYOUT_RUSSIA },
{ "xkb:ru:phonetic:rus", IDS_STATUSBAR_LAYOUT_RUSSIA_PHONETIC },
{ "xkb:gr::gre", IDS_STATUSBAR_LAYOUT_GREECE },
{ "xkb:be::fra", IDS_STATUSBAR_LAYOUT_BELGIUM }, { "xkb:be::fra", IDS_STATUSBAR_LAYOUT_BELGIUM },
{ "xkb:be::ger", IDS_STATUSBAR_LAYOUT_BELGIUM }, { "xkb:be::ger", IDS_STATUSBAR_LAYOUT_BELGIUM },
{ "xkb:be::nld", IDS_STATUSBAR_LAYOUT_BELGIUM }, { "xkb:be::nld", IDS_STATUSBAR_LAYOUT_BELGIUM },
{ "xkb:bg::bul", IDS_STATUSBAR_LAYOUT_BULGARIA }, { "xkb:bg::bul", IDS_STATUSBAR_LAYOUT_BULGARIA },
{ "xkb:bg:phonetic:bul", IDS_STATUSBAR_LAYOUT_BULGARIA_PHONETIC }, { "xkb:bg:phonetic:bul", IDS_STATUSBAR_LAYOUT_BULGARIA_PHONETIC },
{ "xkb:br::por", IDS_STATUSBAR_LAYOUT_BRAZIL },
{ "xkb:by::bel", IDS_STATUSBAR_LAYOUT_BELARUSIAN },
{ "xkb:ca::fra", IDS_STATUSBAR_LAYOUT_CANADA },
{ "xkb:ca:eng:eng", IDS_STATUSBAR_LAYOUT_CANADA_ENGLISH },
{ "xkb:ca:multix:fra", IDS_STATUSBAR_LAYOUT_CANADIAN_MULTILINGUAL },
{ "xkb:ch::ger", IDS_STATUSBAR_LAYOUT_SWITZERLAND }, { "xkb:ch::ger", IDS_STATUSBAR_LAYOUT_SWITZERLAND },
{ "xkb:ch:fr:fra", IDS_STATUSBAR_LAYOUT_SWITZERLAND_FRENCH }, { "xkb:ch:fr:fra", IDS_STATUSBAR_LAYOUT_SWITZERLAND_FRENCH },
{ "xkb:tr::tur", IDS_STATUSBAR_LAYOUT_TURKEY }, { "xkb:cz::cze", IDS_STATUSBAR_LAYOUT_CZECHIA },
{ "xkb:pt::por", IDS_STATUSBAR_LAYOUT_PORTUGAL }, { "xkb:cz:qwerty:cze", IDS_STATUSBAR_LAYOUT_CZECHIA_QWERTY },
{ "xkb:de::ger", IDS_STATUSBAR_LAYOUT_GERMANY },
{ "xkb:de:neo:ger", IDS_STATUSBAR_LAYOUT_GERMANY_NEO2 },
{ "xkb:dk::dan", IDS_STATUSBAR_LAYOUT_DENMARK },
{ "xkb:ee::est", IDS_STATUSBAR_LAYOUT_ESTONIA },
{ "xkb:es::spa", IDS_STATUSBAR_LAYOUT_SPAIN }, { "xkb:es::spa", IDS_STATUSBAR_LAYOUT_SPAIN },
{ "xkb:fi::fin", IDS_STATUSBAR_LAYOUT_FINLAND },
{ "xkb:ua::ukr", IDS_STATUSBAR_LAYOUT_UKRAINE },
{ "xkb:es:cat:cat", IDS_STATUSBAR_LAYOUT_SPAIN_CATALAN }, { "xkb:es:cat:cat", IDS_STATUSBAR_LAYOUT_SPAIN_CATALAN },
{ "xkb:fi::fin", IDS_STATUSBAR_LAYOUT_FINLAND },
{ "xkb:fr::fra", IDS_STATUSBAR_LAYOUT_FRANCE }, { "xkb:fr::fra", IDS_STATUSBAR_LAYOUT_FRANCE },
{ "xkb:no::nob", IDS_STATUSBAR_LAYOUT_NORWAY }, { "xkb:gb:dvorak:eng", IDS_STATUSBAR_LAYOUT_UNITED_KINGDOM_DVORAK },
{ "xkb:se::swe", IDS_STATUSBAR_LAYOUT_SWEDEN }, { "xkb:gb:extd:eng", IDS_STATUSBAR_LAYOUT_UNITED_KINGDOM },
{ "xkb:nl::nld", IDS_STATUSBAR_LAYOUT_NETHERLANDS }, { "xkb:ge::geo", IDS_STATUSBAR_LAYOUT_GEORGIAN },
{ "xkb:latam::spa", IDS_STATUSBAR_LAYOUT_LATIN_AMERICAN }, { "xkb:gr::gre", IDS_STATUSBAR_LAYOUT_GREECE },
{ "xkb:lv:apostrophe:lav", IDS_STATUSBAR_LAYOUT_LATVIA }, { "xkb:hr::scr", IDS_STATUSBAR_LAYOUT_CROATIA },
{ "xkb:ca::fra", IDS_STATUSBAR_LAYOUT_CANADA }, { "xkb:hu::hun", IDS_STATUSBAR_LAYOUT_HUNGARY },
{ "xkb:ca:eng:eng", IDS_STATUSBAR_LAYOUT_CANADA_ENGLISH },
{ "xkb:il::heb", IDS_STATUSBAR_LAYOUT_ISRAEL }, { "xkb:il::heb", IDS_STATUSBAR_LAYOUT_ISRAEL },
{ "xkb:kr:kr104:kor", IDS_STATUSBAR_LAYOUT_KOREA_104 },
{ "xkb:is::ice", IDS_STATUSBAR_LAYOUT_ICELANDIC }, { "xkb:is::ice", IDS_STATUSBAR_LAYOUT_ICELANDIC },
{ "xkb:ca:multix:fra", IDS_STATUSBAR_LAYOUT_CANADIAN_MULTILINGUAL }, { "xkb:it::ita", IDS_STATUSBAR_LAYOUT_ITALY },
{ "xkb:by::bel", IDS_STATUSBAR_LAYOUT_BELARUSIAN }, { "xkb:jp::jpn", IDS_STATUSBAR_LAYOUT_JAPAN },
{ "xkb:am:phonetic:arm", IDS_STATUSBAR_LAYOUT_ARMENIAN_PHONETIC }, { "xkb:latam::spa", IDS_STATUSBAR_LAYOUT_LATIN_AMERICAN },
{ "xkb:ge::geo", IDS_STATUSBAR_LAYOUT_GEORGIAN }, { "xkb:lt::lit", IDS_STATUSBAR_LAYOUT_LITHUANIA },
{ "xkb:lv:apostrophe:lav", IDS_STATUSBAR_LAYOUT_LATVIA },
{ "xkb:mn::mon", IDS_STATUSBAR_LAYOUT_MONGOLIAN }, { "xkb:mn::mon", IDS_STATUSBAR_LAYOUT_MONGOLIAN },
{ "xkb:nl::nld", IDS_STATUSBAR_LAYOUT_NETHERLANDS },
{ "english-m", IDS_STATUSBAR_LAYOUT_USA_MYSTERY }, { "xkb:no::nob", IDS_STATUSBAR_LAYOUT_NORWAY },
{ "xkb:pl::pol", IDS_STATUSBAR_LAYOUT_POLAND },
{ "xkb:pt::por", IDS_STATUSBAR_LAYOUT_PORTUGAL },
{ "xkb:ro::rum", IDS_STATUSBAR_LAYOUT_ROMANIA },
{ "xkb:rs::srp", IDS_STATUSBAR_LAYOUT_SERBIA },
{ "xkb:ru::rus", IDS_STATUSBAR_LAYOUT_RUSSIA },
{ "xkb:ru:phonetic:rus", IDS_STATUSBAR_LAYOUT_RUSSIA_PHONETIC },
{ "xkb:se::swe", IDS_STATUSBAR_LAYOUT_SWEDEN },
{ "xkb:si::slv", IDS_STATUSBAR_LAYOUT_SLOVENIA },
{ "xkb:sk::slo", IDS_STATUSBAR_LAYOUT_SLOVAKIA },
{ "xkb:tr::tur", IDS_STATUSBAR_LAYOUT_TURKEY },
{ "xkb:ua::ukr", IDS_STATUSBAR_LAYOUT_UKRAINE },
{ "xkb:us::eng", IDS_STATUSBAR_LAYOUT_USA },
{ "xkb:us:altgr-intl:eng", IDS_STATUSBAR_LAYOUT_USA_EXTENDED },
{ "xkb:us:colemak:eng", IDS_STATUSBAR_LAYOUT_USA_COLEMAK },
{ "xkb:us:dvorak:eng", IDS_STATUSBAR_LAYOUT_USA_DVORAK },
{ "xkb:us:intl:eng", IDS_STATUSBAR_LAYOUT_USA_INTERNATIONAL },
}; };
const size_t kEnglishToResourceIdArraySize = const size_t kEnglishToResourceIdArraySize =
arraysize(kEnglishToResourceIdArray); arraysize(kEnglishToResourceIdArray);
} // namespace } // namespace
namespace chromeos {
namespace input_method {
InputMethodUtil::InputMethodUtil( InputMethodUtil::InputMethodUtil(
InputMethodDelegate* delegate, InputMethodDelegate* delegate,
scoped_ptr<InputMethodDescriptors> supported_input_methods) scoped_ptr<InputMethodDescriptors> supported_input_methods)
: supported_input_methods_(supported_input_methods.Pass()), : delegate_(delegate) {
delegate_(delegate) {
// Makes sure the supported input methods at least have the fallback ime. // Makes sure the supported input methods at least have the fallback ime.
// So that it won't cause massive test failures. // So that it won't cause massive test failures.
if (supported_input_methods_->empty()) if (supported_input_methods->empty())
supported_input_methods_->push_back(GetFallbackInputMethodDescriptor()); supported_input_methods->push_back(GetFallbackInputMethodDescriptor());
ReloadInternalMaps(); ResetInputMethods(*supported_input_methods);
// Initialize a map from English string to Chrome string resource ID as well. // Initialize a map from English string to Chrome string resource ID as well.
for (size_t i = 0; i < kEnglishToResourceIdArraySize; ++i) { for (size_t i = 0; i < kEnglishToResourceIdArraySize; ++i) {
...@@ -360,12 +269,18 @@ InputMethodUtil::~InputMethodUtil() { ...@@ -360,12 +269,18 @@ InputMethodUtil::~InputMethodUtil() {
bool InputMethodUtil::TranslateStringInternal( bool InputMethodUtil::TranslateStringInternal(
const std::string& english_string, base::string16 *out_string) const { const std::string& english_string, base::string16 *out_string) const {
DCHECK(out_string); DCHECK(out_string);
HashType::const_iterator iter = english_to_resource_id_.find(english_string); // |english_string| could be an input method id. So legacy xkb id is required
// to get the translated string.
std::string key_string = extension_ime_util::MaybeGetLegacyXkbId(
english_string);
HashType::const_iterator iter = english_to_resource_id_.find(key_string);
if (iter == english_to_resource_id_.end()) { if (iter == english_to_resource_id_.end()) {
// TODO(yusukes): Write Autotest which checks if all display names and all // TODO(yusukes): Write Autotest which checks if all display names and all
// property names for supported input methods are listed in the resource // property names for supported input methods are listed in the resource
// ID array (crosbug.com/4572). // ID array (crosbug.com/4572).
LOG(ERROR) << "Resource ID is not found for: " << english_string; LOG(ERROR) << "Resource ID is not found for: " << english_string
<< ", " << key_string;
return false; return false;
} }
...@@ -396,19 +311,6 @@ bool InputMethodUtil::IsKeyboardLayout(const std::string& input_method_id) { ...@@ -396,19 +311,6 @@ bool InputMethodUtil::IsKeyboardLayout(const std::string& input_method_id) {
extension_ime_util::IsKeyboardLayoutExtension(input_method_id); extension_ime_util::IsKeyboardLayoutExtension(input_method_id);
} }
std::string InputMethodUtil::GetLanguageCodeFromInputMethodId(
const std::string& input_method_id) const {
// The code should be compatible with one of codes used for UI languages,
// defined in app/l10_util.cc.
const char kDefaultLanguageCode[] = "en-US";
std::map<std::string, std::string>::const_iterator iter
= id_to_language_code_.find(input_method_id);
return (iter == id_to_language_code_.end()) ?
// Returning |kDefaultLanguageCode| here is not for Chrome OS but for
// Ubuntu where the ibus-xkb-layouts engine could be missing.
kDefaultLanguageCode : iter->second;
}
std::string InputMethodUtil::GetKeyboardLayoutName( std::string InputMethodUtil::GetKeyboardLayoutName(
const std::string& input_method_id) const { const std::string& input_method_id) const {
InputMethodIdToDescriptorMap::const_iterator iter InputMethodIdToDescriptorMap::const_iterator iter
...@@ -509,12 +411,7 @@ base::string16 InputMethodUtil::GetInputMethodLongName( ...@@ -509,12 +411,7 @@ base::string16 InputMethodUtil::GetInputMethodLongName(
DCHECK(!input_method.language_codes().empty()); DCHECK(!input_method.language_codes().empty());
const std::string language_code = input_method.language_codes().at(0); const std::string language_code = input_method.language_codes().at(0);
// Before translate the string, convert the input method id to legacy xkb id base::string16 text = TranslateString(input_method.id());
// if possible.
// TODO(shuchen): the GetInputMethodLongName() method should be removed when
// finish the wrapping of xkb to extension.
base::string16 text = TranslateString(
extension_ime_util::MaybeGetLegacyXkbId(input_method.id()));
if (text == standard_input_method_text || if (text == standard_input_method_text ||
language_code == "de" || language_code == "de" ||
language_code == "fr" || language_code == "fr" ||
...@@ -628,9 +525,7 @@ void InputMethodUtil::GetFirstLoginInputMethodIds( ...@@ -628,9 +525,7 @@ void InputMethodUtil::GetFirstLoginInputMethodIds(
} }
// Add the most popular input method ID, if it's different from the // Add the most popular input method ID, if it's different from the
// current input method. // current input method.
if (most_popular_id != current_input_method.id() && if (most_popular_id != current_input_method.id()) {
// TODO(yusukes): Remove this hack when we remove the "english-m" IME.
most_popular_id != "english-m") {
out_input_method_ids->push_back(most_popular_id); out_input_method_ids->push_back(most_popular_id);
} }
} }
...@@ -758,7 +653,6 @@ void InputMethodUtil::AppendInputMethods(const InputMethodDescriptors& imes) { ...@@ -758,7 +653,6 @@ void InputMethodUtil::AppendInputMethods(const InputMethodDescriptors& imes) {
DCHECK(!input_method.language_codes().empty()); DCHECK(!input_method.language_codes().empty());
const std::vector<std::string>& language_codes = const std::vector<std::string>& language_codes =
input_method.language_codes(); input_method.language_codes();
id_to_language_code_[input_method.id()] = language_codes[0];
id_to_descriptor_[input_method.id()] = input_method; id_to_descriptor_[input_method.id()] = input_method;
typedef LanguageCodeToIdsMap::const_iterator It; typedef LanguageCodeToIdsMap::const_iterator It;
...@@ -780,7 +674,6 @@ void InputMethodUtil::AppendInputMethods(const InputMethodDescriptors& imes) { ...@@ -780,7 +674,6 @@ void InputMethodUtil::AppendInputMethods(const InputMethodDescriptors& imes) {
void InputMethodUtil::ResetInputMethods(const InputMethodDescriptors& imes) { void InputMethodUtil::ResetInputMethods(const InputMethodDescriptors& imes) {
// Clear the existing maps. // Clear the existing maps.
language_code_to_ids_.clear(); language_code_to_ids_.clear();
id_to_language_code_.clear();
id_to_descriptor_.clear(); id_to_descriptor_.clear();
AppendInputMethods(imes); AppendInputMethods(imes);
...@@ -788,22 +681,12 @@ void InputMethodUtil::ResetInputMethods(const InputMethodDescriptors& imes) { ...@@ -788,22 +681,12 @@ void InputMethodUtil::ResetInputMethods(const InputMethodDescriptors& imes) {
void InputMethodUtil::InitXkbInputMethodsForTesting() { void InputMethodUtil::InitXkbInputMethodsForTesting() {
cached_hardware_layouts_.clear(); cached_hardware_layouts_.clear();
scoped_ptr<InputMethodDescriptors> original_imes = ResetInputMethods(*(InputMethodWhitelist().GetSupportedInputMethods()));
InputMethodWhitelist().GetSupportedInputMethods(); }
InputMethodDescriptors whitelist_imes;
for (size_t i = 0; i < original_imes->size(); ++i) { const InputMethodUtil::InputMethodIdToDescriptorMap&
const InputMethodDescriptor& ime = (*original_imes)[i]; InputMethodUtil::GetIdToDesciptorMapForTesting() {
whitelist_imes.push_back(InputMethodDescriptor( return id_to_descriptor_;
extension_ime_util::GetInputMethodIDByEngineID(ime.id()),
"",
ime.indicator(),
ime.keyboard_layouts(),
ime.language_codes(),
ime.is_login_keyboard(),
ime.options_page_url(),
ime.input_view_url()));
}
ResetInputMethods(whitelist_imes);
} }
InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() {
...@@ -822,45 +705,5 @@ InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { ...@@ -822,45 +705,5 @@ InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() {
GURL()); // input view page, not available. GURL()); // input view page, not available.
} }
void InputMethodUtil::ReloadInternalMaps() {
if (supported_input_methods_->size() <= 1) {
DVLOG(1) << "GetSupportedInputMethods returned a fallback ID";
// TODO(yusukes): Handle this error in nicer way.
}
// Clear the existing maps.
language_code_to_ids_.clear();
id_to_language_code_.clear();
id_to_descriptor_.clear();
for (size_t i = 0; i < supported_input_methods_->size(); ++i) {
const InputMethodDescriptor& input_method = supported_input_methods_->at(i);
const std::string input_method_id =
extension_ime_util::GetInputMethodIDByEngineID(input_method.id());
const std::vector<std::string>& language_codes =
input_method.language_codes();
// |input_method_id| may be different than input_method.id().
id_to_descriptor_.insert(
std::make_pair(input_method_id,
InputMethodDescriptor(input_method_id,
input_method.name(),
input_method.indicator(),
input_method.keyboard_layouts(),
input_method.language_codes(),
input_method.is_login_keyboard(),
input_method.options_page_url(),
input_method.input_view_url())));
for (size_t i = 0; i < language_codes.size(); ++i) {
language_code_to_ids_.insert(
std::make_pair(language_codes[i], input_method_id));
// Remember the pairs.
id_to_language_code_.insert(
std::make_pair(input_method_id, language_codes[i]));
}
}
}
} // namespace input_method } // namespace input_method
} // namespace chromeos } // namespace chromeos
...@@ -145,6 +145,13 @@ class InputMethodUtil { ...@@ -145,6 +145,13 @@ class InputMethodUtil {
// Initializes the extension based xkb IMEs for testing. // Initializes the extension based xkb IMEs for testing.
void InitXkbInputMethodsForTesting(); void InitXkbInputMethodsForTesting();
// Map from input method ID to associated input method descriptor.
typedef std::map<
std::string, InputMethodDescriptor> InputMethodIdToDescriptorMap;
// Gets the id to desctiptor map for testing.
const InputMethodIdToDescriptorMap& GetIdToDesciptorMapForTesting();
// Returns the fallback input method descriptor (the very basic US // Returns the fallback input method descriptor (the very basic US
// keyboard). This function is mostly used for testing, but may be used // keyboard). This function is mostly used for testing, but may be used
// as the fallback, when there is no other choice. // as the fallback, when there is no other choice.
...@@ -158,13 +165,6 @@ class InputMethodUtil { ...@@ -158,13 +165,6 @@ class InputMethodUtil {
InputMethodType type, InputMethodType type,
std::vector<std::string>* out_input_method_ids) const; std::vector<std::string>* out_input_method_ids) const;
// protected: for unit testing as well.
void ReloadInternalMaps();
// All input methods that are supported, including ones not active.
// protected: for testing.
scoped_ptr<InputMethodDescriptors> supported_input_methods_;
// Gets the keyboard layout name from the given input method ID. // Gets the keyboard layout name from the given input method ID.
// If the ID is invalid, an empty string will be returned. // If the ID is invalid, an empty string will be returned.
// This function only supports xkb layouts. // This function only supports xkb layouts.
...@@ -183,14 +183,8 @@ class InputMethodUtil { ...@@ -183,14 +183,8 @@ class InputMethodUtil {
// Map from language code to associated input method IDs, etc. // Map from language code to associated input method IDs, etc.
typedef std::multimap<std::string, std::string> LanguageCodeToIdsMap; typedef std::multimap<std::string, std::string> LanguageCodeToIdsMap;
// Map from input method ID to associated input method descriptor.
typedef std::map<
std::string, InputMethodDescriptor> InputMethodIdToDescriptorMap;
// Map from component extention IME id to associated input method descriptor.
typedef std::map<std::string, InputMethodDescriptor> ComponentExtIMEMap;
LanguageCodeToIdsMap language_code_to_ids_; LanguageCodeToIdsMap language_code_to_ids_;
std::map<std::string, std::string> id_to_language_code_;
InputMethodIdToDescriptorMap id_to_descriptor_; InputMethodIdToDescriptorMap id_to_descriptor_;
std::map<std::string, std::string> xkb_layout_to_indicator_; std::map<std::string, std::string> xkb_layout_to_indicator_;
......
...@@ -39,8 +39,6 @@ class TestableInputMethodUtil : public InputMethodUtil { ...@@ -39,8 +39,6 @@ class TestableInputMethodUtil : public InputMethodUtil {
// Change access rights. // Change access rights.
using InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal; using InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal;
using InputMethodUtil::GetKeyboardLayoutName; using InputMethodUtil::GetKeyboardLayoutName;
using InputMethodUtil::ReloadInternalMaps;
using InputMethodUtil::supported_input_methods_;
}; };
} // namespace } // namespace
...@@ -121,19 +119,7 @@ class InputMethodUtilTest : public testing::Test { ...@@ -121,19 +119,7 @@ class InputMethodUtilTest : public testing::Test {
}; };
TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) { TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) {
// Test normal cases. Two-letter language code should be returned. // Test invalid cases. Two-letter language code should be returned.
{
InputMethodDescriptor desc = GetDesc("vkd_fa", // input method id
"us", // keyboard layout name
"fa", // language name
""); // indicator
EXPECT_EQ(ASCIIToUTF16("FA"), util_.GetInputMethodShortName(desc));
}
{
InputMethodDescriptor desc = GetDesc("hangul_2set", "us", "ko", "");
EXPECT_EQ(base::UTF8ToUTF16("\xed\x95\x9c"),
util_.GetInputMethodShortName(desc));
}
{ {
InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", ""); InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", "");
// Upper-case string of the unknown language code, "xx", should be returned. // Upper-case string of the unknown language code, "xx", should be returned.
...@@ -305,11 +291,6 @@ TEST_F(InputMethodUtilTest, TestGetKeyboardLayoutName) { ...@@ -305,11 +291,6 @@ TEST_F(InputMethodUtilTest, TestGetKeyboardLayoutName) {
EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName(Id("xkb:de:neo:ger"))); EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName(Id("xkb:de:neo:ger")));
} }
TEST_F(InputMethodUtilTest, TestGetLanguageCodeFromInputMethodId) {
// Make sure that the -CN is added properly.
EXPECT_EQ("zh-CN", util_.GetLanguageCodeFromInputMethodId(Id(pinyin_ime_id)));
}
TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) { TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) {
EXPECT_EQ("US", EXPECT_EQ("US",
util_.GetInputMethodDisplayNameFromId("xkb:us::eng")); util_.GetInputMethodDisplayNameFromId("xkb:us::eng"));
...@@ -448,9 +429,11 @@ TEST_F(InputMethodUtilTest, TestGetLanguageCodesFromInputMethodIds) { ...@@ -448,9 +429,11 @@ TEST_F(InputMethodUtilTest, TestGetLanguageCodesFromInputMethodIds) {
// Test all supported descriptors to detect a typo in input_methods.txt. // Test all supported descriptors to detect a typo in input_methods.txt.
TEST_F(InputMethodUtilTest, TestIBusInputMethodText) { TEST_F(InputMethodUtilTest, TestIBusInputMethodText) {
for (size_t i = 0; i < util_.supported_input_methods_->size(); ++i) { const std::map<std::string, InputMethodDescriptor>& id_to_descriptor =
const std::string language_code = util_.GetIdToDesciptorMapForTesting();
util_.supported_input_methods_->at(i).language_codes().at(0); for (std::map<std::string, InputMethodDescriptor>::const_iterator it =
id_to_descriptor.begin(); it != id_to_descriptor.end(); ++it) {
const std::string language_code = it->second.language_codes().at(0);
const base::string16 display_name = const base::string16 display_name =
l10n_util::GetDisplayNameForLocale(language_code, "en", false); l10n_util::GetDisplayNameForLocale(language_code, "en", false);
// Only two formats, like "fr" (lower case) and "en-US" (lower-upper), are // Only two formats, like "fr" (lower case) and "en-US" (lower-upper), are
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <vector> #include <vector>
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chromeos/ime/extension_ime_util.h"
#include "chromeos/ime/input_method_descriptor.h" #include "chromeos/ime/input_method_descriptor.h"
#include "chromeos/ime/input_methods.h" #include "chromeos/ime/input_methods.h"
...@@ -42,7 +43,8 @@ InputMethodWhitelist::GetSupportedInputMethods() const { ...@@ -42,7 +43,8 @@ InputMethodWhitelist::GetSupportedInputMethods() const {
DCHECK(!languages.empty()); DCHECK(!languages.empty());
input_methods->push_back(InputMethodDescriptor( input_methods->push_back(InputMethodDescriptor(
kInputMethods[i].input_method_id, extension_ime_util::GetInputMethodIDByEngineID(
kInputMethods[i].input_method_id),
"", "",
kInputMethods[i].indicator, kInputMethods[i].indicator,
layouts, layouts,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment