| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 {"us(intl)", "INTL"}, }; | 160 {"us(intl)", "INTL"}, }; |
| 161 | 161 |
| 162 // The extension ID map for migration. | 162 // The extension ID map for migration. |
| 163 const char* const kExtensionIdMigrationMap[][2] = { | 163 const char* const kExtensionIdMigrationMap[][2] = { |
| 164 // Official Japanese IME extension ID. | 164 // Official Japanese IME extension ID. |
| 165 {"fpfbhcjppmaeaijcidgiibchfbnhbelj", "gjaehgfemfahhmlgpdfknkhdnemmolop"}, | 165 {"fpfbhcjppmaeaijcidgiibchfbnhbelj", "gjaehgfemfahhmlgpdfknkhdnemmolop"}, |
| 166 }; | 166 }; |
| 167 | 167 |
| 168 const size_t kExtensionIdLen = 32; | 168 const size_t kExtensionIdLen = 32; |
| 169 | 169 |
| 170 } // namespace | |
| 171 | |
| 172 namespace chromeos { | |
| 173 | |
| 174 extern const char* kExtensionImePrefix; | |
| 175 | |
| 176 namespace input_method { | |
| 177 | |
| 178 namespace { | |
| 179 | |
| 180 const struct EnglishToResouceId { | 170 const struct EnglishToResouceId { |
| 181 const char* english_string_from_ibus; | 171 const char* english_string_from_ibus; |
| 182 int resource_id; | 172 int resource_id; |
| 183 } kEnglishToResourceIdArray[] = { | 173 } kEnglishToResourceIdArray[] = { |
| 184 // For ibus-mozc-hangul | 174 // For xkb-layouts. |
| 185 { "Hanja mode", IDS_STATUSBAR_IME_KOREAN_HANJA_INPUT_MODE }, | 175 { "xkb:am:phonetic:arm", IDS_STATUSBAR_LAYOUT_ARMENIAN_PHONETIC }, |
| 186 { "Hangul mode", IDS_STATUSBAR_IME_KOREAN_HANGUL_INPUT_MODE }, | |
| 187 | |
| 188 // For ibus-mozc-pinyin. | |
| 189 { "Full/Half width", | |
| 190 IDS_STATUSBAR_IME_CHINESE_PINYIN_TOGGLE_FULL_HALF }, | |
| 191 { "Full/Half width punctuation", | |
| 192 IDS_STATUSBAR_IME_CHINESE_PINYIN_TOGGLE_FULL_HALF_PUNCTUATION }, | |
| 193 // TODO(hsumita): Fixes a typo | |
| 194 { "Simplfied/Traditional Chinese", | |
| 195 IDS_STATUSBAR_IME_CHINESE_PINYIN_TOGGLE_S_T_CHINESE }, | |
| 196 { "Chinese", | |
| 197 IDS_STATUSBAR_IME_CHINESE_PINYIN_TOGGLE_CHINESE_ENGLISH }, | |
| 198 | |
| 199 // For ibus-mozc-chewing. | |
| 200 { "English", | |
| 201 IDS_STATUSBAR_IME_CHINESE_MOZC_CHEWING_ENGLISH_MODE }, | |
| 202 { "_Chinese", | |
| 203 IDS_STATUSBAR_IME_CHINESE_MOZC_CHEWING_CHINESE_MODE }, | |
| 204 { "Full-width English", | |
| 205 IDS_STATUSBAR_IME_CHINESE_MOZC_CHEWING_FULL_WIDTH_ENGLISH_MODE }, | |
| 206 | |
| 207 // For the "Languages and Input" dialog. | |
| 208 { "m17n:ar:kbd", IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD }, | |
| 209 { "m17n:hi:itrans", // also uses the "STANDARD_INPUT_METHOD" id. | |
| 210 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD }, | |
| 211 { "m17n:zh:cangjie", | |
| 212 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_CHINESE_CANGJIE_INPUT_METHOD }, | |
| 213 { "m17n:zh:quick", | |
| 214 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_CHINESE_QUICK_INPUT_METHOD }, | |
| 215 { "m17n:fa:isiri", | |
| 216 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_PERSIAN_ISIRI_2901_INPUT_METHOD }, | |
| 217 { "m17n:th:kesmanee", | |
| 218 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_THAI_KESMANEE_INPUT_METHOD }, | |
| 219 { "m17n:th:tis820", | |
| 220 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_THAI_TIS820_INPUT_METHOD }, | |
| 221 { "m17n:th:pattachote", | |
| 222 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_THAI_PATTACHOTE_INPUT_METHOD }, | |
| 223 { "m17n:vi:tcvn", | |
| 224 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_VIETNAMESE_TCVN_INPUT_METHOD }, | |
| 225 { "m17n:vi:telex", | |
| 226 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_VIETNAMESE_TELEX_INPUT_METHOD }, | |
| 227 { "m17n:vi:viqr", | |
| 228 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_VIETNAMESE_VIQR_INPUT_METHOD }, | |
| 229 { "m17n:vi:vni", | |
| 230 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_VIETNAMESE_VNI_INPUT_METHOD }, | |
| 231 { "m17n:bn:itrans", | |
| 232 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD }, | |
| 233 { "m17n:gu:itrans", | |
| 234 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD }, | |
| 235 { "m17n:ml:itrans", | |
| 236 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD }, | |
| 237 { "m17n:mr:itrans", | |
| 238 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD }, | |
| 239 { "m17n:ta:phonetic", | |
| 240 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_TAMIL_PHONETIC }, | |
| 241 { "m17n:ta:inscript", | |
| 242 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_TAMIL_INSCRIPT }, | |
| 243 { "m17n:ta:tamil99", | |
| 244 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_TAMIL_TAMIL99 }, | |
| 245 { "m17n:ta:itrans", | |
| 246 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_TAMIL_ITRANS }, | |
| 247 { "m17n:ta:typewriter", | |
| 248 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_TAMIL_TYPEWRITER }, | |
| 249 { "m17n:am:sera", | |
| 250 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD }, | |
| 251 { "m17n:te:itrans", | |
| 252 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD }, | |
| 253 { "m17n:kn:itrans", | |
| 254 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD }, | |
| 255 | |
| 256 { "mozc-chewing", | |
| 257 IDS_OPTIONS_SETTINGS_LANGUAGES_CHEWING_INPUT_METHOD }, | |
| 258 { "pinyin", IDS_OPTIONS_SETTINGS_LANGUAGES_PINYIN_INPUT_METHOD }, | |
| 259 { "pinyin-dv", | |
| 260 IDS_OPTIONS_SETTINGS_LANGUAGES_PINYIN_DV_INPUT_METHOD }, | |
| 261 { "zinnia-japanese", | |
| 262 IDS_OPTIONS_SETTINGS_LANGUAGES_JAPANESE_HANDWRITING_INPUT_METHOD }, | |
| 263 { "mozc-hangul", IDS_OPTIONS_SETTINGS_LANGUAGES_KOREAN_INPUT_METHOD }, | |
| 264 | |
| 265 // For ibus-xkb-layouts engine: third_party/ibus-xkb-layouts/files | |
| 266 { "xkb:jp::jpn", IDS_STATUSBAR_LAYOUT_JAPAN }, | |
| 267 { "xkb:si::slv", IDS_STATUSBAR_LAYOUT_SLOVENIA }, | |
| 268 { "xkb:de::ger", IDS_STATUSBAR_LAYOUT_GERMANY }, | |
| 269 { "xkb:de:neo:ger", IDS_STATUSBAR_LAYOUT_GERMANY_NEO2 }, | |
| 270 { "xkb:it::ita", IDS_STATUSBAR_LAYOUT_ITALY }, | |
| 271 { "xkb:ee::est", IDS_STATUSBAR_LAYOUT_ESTONIA }, | |
| 272 { "xkb:hu::hun", IDS_STATUSBAR_LAYOUT_HUNGARY }, | |
| 273 { "xkb:pl::pol", IDS_STATUSBAR_LAYOUT_POLAND }, | |
| 274 { "xkb:dk::dan", IDS_STATUSBAR_LAYOUT_DENMARK }, | |
| 275 { "xkb:hr::scr", IDS_STATUSBAR_LAYOUT_CROATIA }, | |
| 276 { "xkb:br::por", IDS_STATUSBAR_LAYOUT_BRAZIL }, | |
| 277 { "xkb:rs::srp", IDS_STATUSBAR_LAYOUT_SERBIA }, | |
| 278 { "xkb:cz::cze", IDS_STATUSBAR_LAYOUT_CZECHIA }, | |
| 279 { "xkb:cz:qwerty:cze", IDS_STATUSBAR_LAYOUT_CZECHIA_QWERTY }, | |
| 280 { "xkb:us:dvorak:eng", IDS_STATUSBAR_LAYOUT_USA_DVORAK }, | |
| 281 { "xkb:us:colemak:eng", IDS_STATUSBAR_LAYOUT_USA_COLEMAK }, | |
| 282 { "xkb:ro::rum", IDS_STATUSBAR_LAYOUT_ROMANIA }, | |
| 283 { "xkb:us::eng", IDS_STATUSBAR_LAYOUT_USA }, | |
| 284 { "xkb:us:altgr-intl:eng", IDS_STATUSBAR_LAYOUT_USA_EXTENDED }, | |
| 285 { "xkb:us:intl:eng", IDS_STATUSBAR_LAYOUT_USA_INTERNATIONAL }, | |
| 286 { "xkb:lt::lit", IDS_STATUSBAR_LAYOUT_LITHUANIA }, | |
| 287 { "xkb:gb:extd:eng", IDS_STATUSBAR_LAYOUT_UNITED_KINGDOM }, | |
| 288 { "xkb:gb:dvorak:eng", IDS_STATUSBAR_LAYOUT_UNITED_KINGDOM_DVORAK }, | |
| 289 { "xkb:sk::slo", IDS_STATUSBAR_LAYOUT_SLOVAKIA }, | |
| 290 { "xkb:ru::rus", IDS_STATUSBAR_LAYOUT_RUSSIA }, | |
| 291 { "xkb:ru:phonetic:rus", IDS_STATUSBAR_LAYOUT_RUSSIA_PHONETIC }, | |
| 292 { "xkb:gr::gre", IDS_STATUSBAR_LAYOUT_GREECE }, | |
| 293 { "xkb:be::fra", IDS_STATUSBAR_LAYOUT_BELGIUM }, | 176 { "xkb:be::fra", IDS_STATUSBAR_LAYOUT_BELGIUM }, |
| 294 { "xkb:be::ger", IDS_STATUSBAR_LAYOUT_BELGIUM }, | 177 { "xkb:be::ger", IDS_STATUSBAR_LAYOUT_BELGIUM }, |
| 295 { "xkb:be::nld", IDS_STATUSBAR_LAYOUT_BELGIUM }, | 178 { "xkb:be::nld", IDS_STATUSBAR_LAYOUT_BELGIUM }, |
| 296 { "xkb:bg::bul", IDS_STATUSBAR_LAYOUT_BULGARIA }, | 179 { "xkb:bg::bul", IDS_STATUSBAR_LAYOUT_BULGARIA }, |
| 297 { "xkb:bg:phonetic:bul", IDS_STATUSBAR_LAYOUT_BULGARIA_PHONETIC }, | 180 { "xkb:bg:phonetic:bul", IDS_STATUSBAR_LAYOUT_BULGARIA_PHONETIC }, |
| 181 { "xkb:br::por", IDS_STATUSBAR_LAYOUT_BRAZIL }, |
| 182 { "xkb:by::bel", IDS_STATUSBAR_LAYOUT_BELARUSIAN }, |
| 183 { "xkb:ca::fra", IDS_STATUSBAR_LAYOUT_CANADA }, |
| 184 { "xkb:ca:eng:eng", IDS_STATUSBAR_LAYOUT_CANADA_ENGLISH }, |
| 185 { "xkb:ca:multix:fra", IDS_STATUSBAR_LAYOUT_CANADIAN_MULTILINGUAL }, |
| 298 { "xkb:ch::ger", IDS_STATUSBAR_LAYOUT_SWITZERLAND }, | 186 { "xkb:ch::ger", IDS_STATUSBAR_LAYOUT_SWITZERLAND }, |
| 299 { "xkb:ch:fr:fra", IDS_STATUSBAR_LAYOUT_SWITZERLAND_FRENCH }, | 187 { "xkb:ch:fr:fra", IDS_STATUSBAR_LAYOUT_SWITZERLAND_FRENCH }, |
| 188 { "xkb:cz::cze", IDS_STATUSBAR_LAYOUT_CZECHIA }, |
| 189 { "xkb:cz:qwerty:cze", IDS_STATUSBAR_LAYOUT_CZECHIA_QWERTY }, |
| 190 { "xkb:de::ger", IDS_STATUSBAR_LAYOUT_GERMANY }, |
| 191 { "xkb:de:neo:ger", IDS_STATUSBAR_LAYOUT_GERMANY_NEO2 }, |
| 192 { "xkb:dk::dan", IDS_STATUSBAR_LAYOUT_DENMARK }, |
| 193 { "xkb:ee::est", IDS_STATUSBAR_LAYOUT_ESTONIA }, |
| 194 { "xkb:es::spa", IDS_STATUSBAR_LAYOUT_SPAIN }, |
| 195 { "xkb:es:cat:cat", IDS_STATUSBAR_LAYOUT_SPAIN_CATALAN }, |
| 196 { "xkb:fi::fin", IDS_STATUSBAR_LAYOUT_FINLAND }, |
| 197 { "xkb:fr::fra", IDS_STATUSBAR_LAYOUT_FRANCE }, |
| 198 { "xkb:gb:dvorak:eng", IDS_STATUSBAR_LAYOUT_UNITED_KINGDOM_DVORAK }, |
| 199 { "xkb:gb:extd:eng", IDS_STATUSBAR_LAYOUT_UNITED_KINGDOM }, |
| 200 { "xkb:ge::geo", IDS_STATUSBAR_LAYOUT_GEORGIAN }, |
| 201 { "xkb:gr::gre", IDS_STATUSBAR_LAYOUT_GREECE }, |
| 202 { "xkb:hr::scr", IDS_STATUSBAR_LAYOUT_CROATIA }, |
| 203 { "xkb:hu::hun", IDS_STATUSBAR_LAYOUT_HUNGARY }, |
| 204 { "xkb:il::heb", IDS_STATUSBAR_LAYOUT_ISRAEL }, |
| 205 { "xkb:is::ice", IDS_STATUSBAR_LAYOUT_ICELANDIC }, |
| 206 { "xkb:it::ita", IDS_STATUSBAR_LAYOUT_ITALY }, |
| 207 { "xkb:jp::jpn", IDS_STATUSBAR_LAYOUT_JAPAN }, |
| 208 { "xkb:latam::spa", IDS_STATUSBAR_LAYOUT_LATIN_AMERICAN }, |
| 209 { "xkb:lt::lit", IDS_STATUSBAR_LAYOUT_LITHUANIA }, |
| 210 { "xkb:lv:apostrophe:lav", IDS_STATUSBAR_LAYOUT_LATVIA }, |
| 211 { "xkb:mn::mon", IDS_STATUSBAR_LAYOUT_MONGOLIAN }, |
| 212 { "xkb:nl::nld", IDS_STATUSBAR_LAYOUT_NETHERLANDS }, |
| 213 { "xkb:no::nob", IDS_STATUSBAR_LAYOUT_NORWAY }, |
| 214 { "xkb:pl::pol", IDS_STATUSBAR_LAYOUT_POLAND }, |
| 215 { "xkb:pt::por", IDS_STATUSBAR_LAYOUT_PORTUGAL }, |
| 216 { "xkb:ro::rum", IDS_STATUSBAR_LAYOUT_ROMANIA }, |
| 217 { "xkb:rs::srp", IDS_STATUSBAR_LAYOUT_SERBIA }, |
| 218 { "xkb:ru::rus", IDS_STATUSBAR_LAYOUT_RUSSIA }, |
| 219 { "xkb:ru:phonetic:rus", IDS_STATUSBAR_LAYOUT_RUSSIA_PHONETIC }, |
| 220 { "xkb:se::swe", IDS_STATUSBAR_LAYOUT_SWEDEN }, |
| 221 { "xkb:si::slv", IDS_STATUSBAR_LAYOUT_SLOVENIA }, |
| 222 { "xkb:sk::slo", IDS_STATUSBAR_LAYOUT_SLOVAKIA }, |
| 300 { "xkb:tr::tur", IDS_STATUSBAR_LAYOUT_TURKEY }, | 223 { "xkb:tr::tur", IDS_STATUSBAR_LAYOUT_TURKEY }, |
| 301 { "xkb:pt::por", IDS_STATUSBAR_LAYOUT_PORTUGAL }, | |
| 302 { "xkb:es::spa", IDS_STATUSBAR_LAYOUT_SPAIN }, | |
| 303 { "xkb:fi::fin", IDS_STATUSBAR_LAYOUT_FINLAND }, | |
| 304 { "xkb:ua::ukr", IDS_STATUSBAR_LAYOUT_UKRAINE }, | 224 { "xkb:ua::ukr", IDS_STATUSBAR_LAYOUT_UKRAINE }, |
| 305 { "xkb:es:cat:cat", IDS_STATUSBAR_LAYOUT_SPAIN_CATALAN }, | 225 { "xkb:us::eng", IDS_STATUSBAR_LAYOUT_USA }, |
| 306 { "xkb:fr::fra", IDS_STATUSBAR_LAYOUT_FRANCE }, | 226 { "xkb:us:altgr-intl:eng", IDS_STATUSBAR_LAYOUT_USA_EXTENDED }, |
| 307 { "xkb:no::nob", IDS_STATUSBAR_LAYOUT_NORWAY }, | 227 { "xkb:us:colemak:eng", IDS_STATUSBAR_LAYOUT_USA_COLEMAK }, |
| 308 { "xkb:se::swe", IDS_STATUSBAR_LAYOUT_SWEDEN }, | 228 { "xkb:us:dvorak:eng", IDS_STATUSBAR_LAYOUT_USA_DVORAK }, |
| 309 { "xkb:nl::nld", IDS_STATUSBAR_LAYOUT_NETHERLANDS }, | 229 { "xkb:us:intl:eng", IDS_STATUSBAR_LAYOUT_USA_INTERNATIONAL }, |
| 310 { "xkb:latam::spa", IDS_STATUSBAR_LAYOUT_LATIN_AMERICAN }, | |
| 311 { "xkb:lv:apostrophe:lav", IDS_STATUSBAR_LAYOUT_LATVIA }, | |
| 312 { "xkb:ca::fra", IDS_STATUSBAR_LAYOUT_CANADA }, | |
| 313 { "xkb:ca:eng:eng", IDS_STATUSBAR_LAYOUT_CANADA_ENGLISH }, | |
| 314 { "xkb:il::heb", IDS_STATUSBAR_LAYOUT_ISRAEL }, | |
| 315 { "xkb:kr:kr104:kor", IDS_STATUSBAR_LAYOUT_KOREA_104 }, | |
| 316 { "xkb:is::ice", IDS_STATUSBAR_LAYOUT_ICELANDIC }, | |
| 317 { "xkb:ca:multix:fra", IDS_STATUSBAR_LAYOUT_CANADIAN_MULTILINGUAL }, | |
| 318 { "xkb:by::bel", IDS_STATUSBAR_LAYOUT_BELARUSIAN }, | |
| 319 { "xkb:am:phonetic:arm", IDS_STATUSBAR_LAYOUT_ARMENIAN_PHONETIC }, | |
| 320 { "xkb:ge::geo", IDS_STATUSBAR_LAYOUT_GEORGIAN }, | |
| 321 { "xkb:mn::mon", IDS_STATUSBAR_LAYOUT_MONGOLIAN }, | |
| 322 | |
| 323 { "english-m", IDS_STATUSBAR_LAYOUT_USA_MYSTERY }, | |
| 324 }; | 230 }; |
| 325 const size_t kEnglishToResourceIdArraySize = | 231 const size_t kEnglishToResourceIdArraySize = |
| 326 arraysize(kEnglishToResourceIdArray); | 232 arraysize(kEnglishToResourceIdArray); |
| 327 | 233 |
| 328 } // namespace | 234 } // namespace |
| 329 | 235 |
| 236 namespace chromeos { |
| 237 |
| 238 namespace input_method { |
| 239 |
| 330 InputMethodUtil::InputMethodUtil( | 240 InputMethodUtil::InputMethodUtil( |
| 331 InputMethodDelegate* delegate, | 241 InputMethodDelegate* delegate, |
| 332 scoped_ptr<InputMethodDescriptors> supported_input_methods) | 242 scoped_ptr<InputMethodDescriptors> supported_input_methods) |
| 333 : supported_input_methods_(supported_input_methods.Pass()), | 243 : delegate_(delegate) { |
| 334 delegate_(delegate) { | |
| 335 // Makes sure the supported input methods at least have the fallback ime. | 244 // Makes sure the supported input methods at least have the fallback ime. |
| 336 // So that it won't cause massive test failures. | 245 // So that it won't cause massive test failures. |
| 337 if (supported_input_methods_->empty()) | 246 if (supported_input_methods->empty()) |
| 338 supported_input_methods_->push_back(GetFallbackInputMethodDescriptor()); | 247 supported_input_methods->push_back(GetFallbackInputMethodDescriptor()); |
| 339 | 248 |
| 340 ReloadInternalMaps(); | 249 ResetInputMethods(*supported_input_methods); |
| 341 | 250 |
| 342 // Initialize a map from English string to Chrome string resource ID as well. | 251 // Initialize a map from English string to Chrome string resource ID as well. |
| 343 for (size_t i = 0; i < kEnglishToResourceIdArraySize; ++i) { | 252 for (size_t i = 0; i < kEnglishToResourceIdArraySize; ++i) { |
| 344 const EnglishToResouceId& map_entry = kEnglishToResourceIdArray[i]; | 253 const EnglishToResouceId& map_entry = kEnglishToResourceIdArray[i]; |
| 345 const bool result = english_to_resource_id_.insert(std::make_pair( | 254 const bool result = english_to_resource_id_.insert(std::make_pair( |
| 346 map_entry.english_string_from_ibus, map_entry.resource_id)).second; | 255 map_entry.english_string_from_ibus, map_entry.resource_id)).second; |
| 347 DCHECK(result) << "Duplicated string is found: " | 256 DCHECK(result) << "Duplicated string is found: " |
| 348 << map_entry.english_string_from_ibus; | 257 << map_entry.english_string_from_ibus; |
| 349 } | 258 } |
| 350 | 259 |
| 351 // Initialize the map from xkb layout to indicator text. | 260 // Initialize the map from xkb layout to indicator text. |
| 352 for (size_t i = 0; i < arraysize(kXkbIndicators); ++i) { | 261 for (size_t i = 0; i < arraysize(kXkbIndicators); ++i) { |
| 353 xkb_layout_to_indicator_[kXkbIndicators[i][0]] = kXkbIndicators[i][1]; | 262 xkb_layout_to_indicator_[kXkbIndicators[i][0]] = kXkbIndicators[i][1]; |
| 354 } | 263 } |
| 355 } | 264 } |
| 356 | 265 |
| 357 InputMethodUtil::~InputMethodUtil() { | 266 InputMethodUtil::~InputMethodUtil() { |
| 358 } | 267 } |
| 359 | 268 |
| 360 bool InputMethodUtil::TranslateStringInternal( | 269 bool InputMethodUtil::TranslateStringInternal( |
| 361 const std::string& english_string, base::string16 *out_string) const { | 270 const std::string& english_string, base::string16 *out_string) const { |
| 362 DCHECK(out_string); | 271 DCHECK(out_string); |
| 363 HashType::const_iterator iter = english_to_resource_id_.find(english_string); | 272 // |english_string| could be an input method id. So legacy xkb id is required |
| 273 // to get the translated string. |
| 274 std::string key_string = extension_ime_util::MaybeGetLegacyXkbId( |
| 275 english_string); |
| 276 HashType::const_iterator iter = english_to_resource_id_.find(key_string); |
| 277 |
| 364 if (iter == english_to_resource_id_.end()) { | 278 if (iter == english_to_resource_id_.end()) { |
| 365 // TODO(yusukes): Write Autotest which checks if all display names and all | 279 // TODO(yusukes): Write Autotest which checks if all display names and all |
| 366 // property names for supported input methods are listed in the resource | 280 // property names for supported input methods are listed in the resource |
| 367 // ID array (crosbug.com/4572). | 281 // ID array (crosbug.com/4572). |
| 368 LOG(ERROR) << "Resource ID is not found for: " << english_string; | 282 LOG(ERROR) << "Resource ID is not found for: " << english_string |
| 283 << ", " << key_string; |
| 369 return false; | 284 return false; |
| 370 } | 285 } |
| 371 | 286 |
| 372 *out_string = delegate_->GetLocalizedString(iter->second); | 287 *out_string = delegate_->GetLocalizedString(iter->second); |
| 373 return true; | 288 return true; |
| 374 } | 289 } |
| 375 | 290 |
| 376 base::string16 InputMethodUtil::TranslateString( | 291 base::string16 InputMethodUtil::TranslateString( |
| 377 const std::string& english_string) const { | 292 const std::string& english_string) const { |
| 378 base::string16 localized_string; | 293 base::string16 localized_string; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 389 return GetInputMethodDescriptorFromId(input_method_id) != NULL || | 304 return GetInputMethodDescriptorFromId(input_method_id) != NULL || |
| 390 extension_ime_util::IsComponentExtensionIME(input_method_id); | 305 extension_ime_util::IsComponentExtensionIME(input_method_id); |
| 391 } | 306 } |
| 392 | 307 |
| 393 // static | 308 // static |
| 394 bool InputMethodUtil::IsKeyboardLayout(const std::string& input_method_id) { | 309 bool InputMethodUtil::IsKeyboardLayout(const std::string& input_method_id) { |
| 395 return StartsWithASCII(input_method_id, "xkb:", false) || | 310 return StartsWithASCII(input_method_id, "xkb:", false) || |
| 396 extension_ime_util::IsKeyboardLayoutExtension(input_method_id); | 311 extension_ime_util::IsKeyboardLayoutExtension(input_method_id); |
| 397 } | 312 } |
| 398 | 313 |
| 399 std::string InputMethodUtil::GetLanguageCodeFromInputMethodId( | |
| 400 const std::string& input_method_id) const { | |
| 401 // The code should be compatible with one of codes used for UI languages, | |
| 402 // defined in app/l10_util.cc. | |
| 403 const char kDefaultLanguageCode[] = "en-US"; | |
| 404 std::map<std::string, std::string>::const_iterator iter | |
| 405 = id_to_language_code_.find(input_method_id); | |
| 406 return (iter == id_to_language_code_.end()) ? | |
| 407 // Returning |kDefaultLanguageCode| here is not for Chrome OS but for | |
| 408 // Ubuntu where the ibus-xkb-layouts engine could be missing. | |
| 409 kDefaultLanguageCode : iter->second; | |
| 410 } | |
| 411 | |
| 412 std::string InputMethodUtil::GetKeyboardLayoutName( | 314 std::string InputMethodUtil::GetKeyboardLayoutName( |
| 413 const std::string& input_method_id) const { | 315 const std::string& input_method_id) const { |
| 414 InputMethodIdToDescriptorMap::const_iterator iter | 316 InputMethodIdToDescriptorMap::const_iterator iter |
| 415 = id_to_descriptor_.find(input_method_id); | 317 = id_to_descriptor_.find(input_method_id); |
| 416 return (iter == id_to_descriptor_.end()) ? | 318 return (iter == id_to_descriptor_.end()) ? |
| 417 "" : iter->second.GetPreferredKeyboardLayout(); | 319 "" : iter->second.GetPreferredKeyboardLayout(); |
| 418 } | 320 } |
| 419 | 321 |
| 420 std::string InputMethodUtil::GetInputMethodDisplayNameFromId( | 322 std::string InputMethodUtil::GetInputMethodDisplayNameFromId( |
| 421 const std::string& input_method_id) const { | 323 const std::string& input_method_id) const { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 // Special case for German, French and Dutch: these languages have multiple | 404 // Special case for German, French and Dutch: these languages have multiple |
| 503 // keyboard layouts and share the same layout of keyboard (Belgian). We need | 405 // keyboard layouts and share the same layout of keyboard (Belgian). We need |
| 504 // to show explicitly the language for the layout. For Arabic, Amharic, and | 406 // to show explicitly the language for the layout. For Arabic, Amharic, and |
| 505 // Indic languages: they share "Standard Input Method". | 407 // Indic languages: they share "Standard Input Method". |
| 506 const base::string16 standard_input_method_text = | 408 const base::string16 standard_input_method_text = |
| 507 delegate_->GetLocalizedString( | 409 delegate_->GetLocalizedString( |
| 508 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD); | 410 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD); |
| 509 DCHECK(!input_method.language_codes().empty()); | 411 DCHECK(!input_method.language_codes().empty()); |
| 510 const std::string language_code = input_method.language_codes().at(0); | 412 const std::string language_code = input_method.language_codes().at(0); |
| 511 | 413 |
| 512 // Before translate the string, convert the input method id to legacy xkb id | 414 base::string16 text = TranslateString(input_method.id()); |
| 513 // if possible. | |
| 514 // TODO(shuchen): the GetInputMethodLongName() method should be removed when | |
| 515 // finish the wrapping of xkb to extension. | |
| 516 base::string16 text = TranslateString( | |
| 517 extension_ime_util::MaybeGetLegacyXkbId(input_method.id())); | |
| 518 if (text == standard_input_method_text || | 415 if (text == standard_input_method_text || |
| 519 language_code == "de" || | 416 language_code == "de" || |
| 520 language_code == "fr" || | 417 language_code == "fr" || |
| 521 language_code == "nl") { | 418 language_code == "nl") { |
| 522 const base::string16 language_name = delegate_->GetDisplayLanguageName( | 419 const base::string16 language_name = delegate_->GetDisplayLanguageName( |
| 523 language_code); | 420 language_code); |
| 524 | 421 |
| 525 text = language_name + base::UTF8ToUTF16(" - ") + text; | 422 text = language_name + base::UTF8ToUTF16(" - ") + text; |
| 526 } | 423 } |
| 527 | 424 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 if (descriptor && | 518 if (descriptor && |
| 622 descriptor->id() != current_input_method.id() && | 519 descriptor->id() != current_input_method.id() && |
| 623 descriptor->GetPreferredKeyboardLayout() == | 520 descriptor->GetPreferredKeyboardLayout() == |
| 624 current_input_method.GetPreferredKeyboardLayout()) { | 521 current_input_method.GetPreferredKeyboardLayout()) { |
| 625 most_popular_id = input_method_id; | 522 most_popular_id = input_method_id; |
| 626 break; | 523 break; |
| 627 } | 524 } |
| 628 } | 525 } |
| 629 // Add the most popular input method ID, if it's different from the | 526 // Add the most popular input method ID, if it's different from the |
| 630 // current input method. | 527 // current input method. |
| 631 if (most_popular_id != current_input_method.id() && | 528 if (most_popular_id != current_input_method.id()) { |
| 632 // TODO(yusukes): Remove this hack when we remove the "english-m" IME. | |
| 633 most_popular_id != "english-m") { | |
| 634 out_input_method_ids->push_back(most_popular_id); | 529 out_input_method_ids->push_back(most_popular_id); |
| 635 } | 530 } |
| 636 } | 531 } |
| 637 | 532 |
| 638 void InputMethodUtil::GetLanguageCodesFromInputMethodIds( | 533 void InputMethodUtil::GetLanguageCodesFromInputMethodIds( |
| 639 const std::vector<std::string>& input_method_ids, | 534 const std::vector<std::string>& input_method_ids, |
| 640 std::vector<std::string>* out_language_codes) const { | 535 std::vector<std::string>* out_language_codes) const { |
| 641 out_language_codes->clear(); | 536 out_language_codes->clear(); |
| 642 | 537 |
| 643 for (size_t i = 0; i < input_method_ids.size(); ++i) { | 538 for (size_t i = 0; i < input_method_ids.size(); ++i) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 GetInputMethodDescriptorFromId(input_method_id); | 646 GetInputMethodDescriptorFromId(input_method_id); |
| 752 return ime ? ime->is_login_keyboard() : false; | 647 return ime ? ime->is_login_keyboard() : false; |
| 753 } | 648 } |
| 754 | 649 |
| 755 void InputMethodUtil::AppendInputMethods(const InputMethodDescriptors& imes) { | 650 void InputMethodUtil::AppendInputMethods(const InputMethodDescriptors& imes) { |
| 756 for (size_t i = 0; i < imes.size(); ++i) { | 651 for (size_t i = 0; i < imes.size(); ++i) { |
| 757 const InputMethodDescriptor& input_method = imes[i]; | 652 const InputMethodDescriptor& input_method = imes[i]; |
| 758 DCHECK(!input_method.language_codes().empty()); | 653 DCHECK(!input_method.language_codes().empty()); |
| 759 const std::vector<std::string>& language_codes = | 654 const std::vector<std::string>& language_codes = |
| 760 input_method.language_codes(); | 655 input_method.language_codes(); |
| 761 id_to_language_code_[input_method.id()] = language_codes[0]; | |
| 762 id_to_descriptor_[input_method.id()] = input_method; | 656 id_to_descriptor_[input_method.id()] = input_method; |
| 763 | 657 |
| 764 typedef LanguageCodeToIdsMap::const_iterator It; | 658 typedef LanguageCodeToIdsMap::const_iterator It; |
| 765 for (size_t j = 0; j < language_codes.size(); ++j) { | 659 for (size_t j = 0; j < language_codes.size(); ++j) { |
| 766 std::pair<It, It> range = | 660 std::pair<It, It> range = |
| 767 language_code_to_ids_.equal_range(language_codes[j]); | 661 language_code_to_ids_.equal_range(language_codes[j]); |
| 768 It it = range.first; | 662 It it = range.first; |
| 769 for (; it != range.second; ++it) { | 663 for (; it != range.second; ++it) { |
| 770 if (it->second == input_method.id()) | 664 if (it->second == input_method.id()) |
| 771 break; | 665 break; |
| 772 } | 666 } |
| 773 if (it == range.second) | 667 if (it == range.second) |
| 774 language_code_to_ids_.insert( | 668 language_code_to_ids_.insert( |
| 775 std::make_pair(language_codes[j], input_method.id())); | 669 std::make_pair(language_codes[j], input_method.id())); |
| 776 } | 670 } |
| 777 } | 671 } |
| 778 } | 672 } |
| 779 | 673 |
| 780 void InputMethodUtil::ResetInputMethods(const InputMethodDescriptors& imes) { | 674 void InputMethodUtil::ResetInputMethods(const InputMethodDescriptors& imes) { |
| 781 // Clear the existing maps. | 675 // Clear the existing maps. |
| 782 language_code_to_ids_.clear(); | 676 language_code_to_ids_.clear(); |
| 783 id_to_language_code_.clear(); | |
| 784 id_to_descriptor_.clear(); | 677 id_to_descriptor_.clear(); |
| 785 | 678 |
| 786 AppendInputMethods(imes); | 679 AppendInputMethods(imes); |
| 787 } | 680 } |
| 788 | 681 |
| 789 void InputMethodUtil::InitXkbInputMethodsForTesting() { | 682 void InputMethodUtil::InitXkbInputMethodsForTesting() { |
| 790 cached_hardware_layouts_.clear(); | 683 cached_hardware_layouts_.clear(); |
| 791 scoped_ptr<InputMethodDescriptors> original_imes = | 684 ResetInputMethods(*(InputMethodWhitelist().GetSupportedInputMethods())); |
| 792 InputMethodWhitelist().GetSupportedInputMethods(); | 685 } |
| 793 InputMethodDescriptors whitelist_imes; | 686 |
| 794 for (size_t i = 0; i < original_imes->size(); ++i) { | 687 const InputMethodUtil::InputMethodIdToDescriptorMap& |
| 795 const InputMethodDescriptor& ime = (*original_imes)[i]; | 688 InputMethodUtil::GetIdToDesciptorMapForTesting() { |
| 796 whitelist_imes.push_back(InputMethodDescriptor( | 689 return id_to_descriptor_; |
| 797 extension_ime_util::GetInputMethodIDByEngineID(ime.id()), | |
| 798 "", | |
| 799 ime.indicator(), | |
| 800 ime.keyboard_layouts(), | |
| 801 ime.language_codes(), | |
| 802 ime.is_login_keyboard(), | |
| 803 ime.options_page_url(), | |
| 804 ime.input_view_url())); | |
| 805 } | |
| 806 ResetInputMethods(whitelist_imes); | |
| 807 } | 690 } |
| 808 | 691 |
| 809 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { | 692 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { |
| 810 std::vector<std::string> layouts; | 693 std::vector<std::string> layouts; |
| 811 layouts.push_back("us"); | 694 layouts.push_back("us"); |
| 812 std::vector<std::string> languages; | 695 std::vector<std::string> languages; |
| 813 languages.push_back("en-US"); | 696 languages.push_back("en-US"); |
| 814 return InputMethodDescriptor( | 697 return InputMethodDescriptor( |
| 815 extension_ime_util::GetInputMethodIDByEngineID("xkb:us::eng"), | 698 extension_ime_util::GetInputMethodIDByEngineID("xkb:us::eng"), |
| 816 "", | 699 "", |
| 817 "US", | 700 "US", |
| 818 layouts, | 701 layouts, |
| 819 languages, | 702 languages, |
| 820 true, // login keyboard. | 703 true, // login keyboard. |
| 821 GURL(), // options page, not available. | 704 GURL(), // options page, not available. |
| 822 GURL()); // input view page, not available. | 705 GURL()); // input view page, not available. |
| 823 } | 706 } |
| 824 | 707 |
| 825 void InputMethodUtil::ReloadInternalMaps() { | |
| 826 if (supported_input_methods_->size() <= 1) { | |
| 827 DVLOG(1) << "GetSupportedInputMethods returned a fallback ID"; | |
| 828 // TODO(yusukes): Handle this error in nicer way. | |
| 829 } | |
| 830 | |
| 831 // Clear the existing maps. | |
| 832 language_code_to_ids_.clear(); | |
| 833 id_to_language_code_.clear(); | |
| 834 id_to_descriptor_.clear(); | |
| 835 | |
| 836 for (size_t i = 0; i < supported_input_methods_->size(); ++i) { | |
| 837 const InputMethodDescriptor& input_method = supported_input_methods_->at(i); | |
| 838 const std::string input_method_id = | |
| 839 extension_ime_util::GetInputMethodIDByEngineID(input_method.id()); | |
| 840 const std::vector<std::string>& language_codes = | |
| 841 input_method.language_codes(); | |
| 842 | |
| 843 // |input_method_id| may be different than input_method.id(). | |
| 844 id_to_descriptor_.insert( | |
| 845 std::make_pair(input_method_id, | |
| 846 InputMethodDescriptor(input_method_id, | |
| 847 input_method.name(), | |
| 848 input_method.indicator(), | |
| 849 input_method.keyboard_layouts(), | |
| 850 input_method.language_codes(), | |
| 851 input_method.is_login_keyboard(), | |
| 852 input_method.options_page_url(), | |
| 853 input_method.input_view_url()))); | |
| 854 | |
| 855 for (size_t i = 0; i < language_codes.size(); ++i) { | |
| 856 language_code_to_ids_.insert( | |
| 857 std::make_pair(language_codes[i], input_method_id)); | |
| 858 // Remember the pairs. | |
| 859 id_to_language_code_.insert( | |
| 860 std::make_pair(input_method_id, language_codes[i])); | |
| 861 } | |
| 862 } | |
| 863 } | |
| 864 | |
| 865 } // namespace input_method | 708 } // namespace input_method |
| 866 } // namespace chromeos | 709 } // namespace chromeos |
| OLD | NEW |