| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 // Add country codes to language codes of some XKB input methods to make | 428 // Add country codes to language codes of some XKB input methods to make |
| 429 // these compatible with Chrome's application locale codes like "en-US". | 429 // these compatible with Chrome's application locale codes like "en-US". |
| 430 // TODO(satorux): Maybe we need to handle "es" for "es-419". | 430 // TODO(satorux): Maybe we need to handle "es" for "es-419". |
| 431 // TODO: We should not rely on the format of the engine name. Should we add | 431 // TODO: We should not rely on the format of the engine name. Should we add |
| 432 // |country_code| in InputMethodDescriptor? | 432 // |country_code| in InputMethodDescriptor? |
| 433 if (IsKeyboardLayout(descriptor.id) && | 433 if (IsKeyboardLayout(descriptor.id) && |
| 434 (language_code == "en" || | 434 (language_code == "en" || |
| 435 language_code == "zh" || | 435 language_code == "zh" || |
| 436 language_code == "pt")) { | 436 language_code == "pt")) { |
| 437 std::vector<std::string> portions; | 437 std::vector<std::string> portions; |
| 438 SplitString(descriptor.id, ':', &portions); | 438 base::SplitString(descriptor.id, ':', &portions); |
| 439 if (portions.size() >= 2 && !portions[1].empty()) { | 439 if (portions.size() >= 2 && !portions[1].empty()) { |
| 440 language_code.append("-"); | 440 language_code.append("-"); |
| 441 language_code.append(StringToUpperASCII(portions[1])); | 441 language_code.append(StringToUpperASCII(portions[1])); |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 return language_code; | 444 return language_code; |
| 445 } | 445 } |
| 446 | 446 |
| 447 std::string GetLanguageCodeFromInputMethodId( | 447 std::string GetLanguageCodeFromInputMethodId( |
| 448 const std::string& input_method_id) { | 448 const std::string& input_method_id) { |
| 449 // The code should be compatible with one of codes used for UI languages, | 449 // The code should be compatible with one of codes used for UI languages, |
| 450 // defined in app/l10_util.cc. | 450 // defined in app/l10_util.cc. |
| 451 const char kDefaultLanguageCode[] = "en-US"; | 451 const char kDefaultLanguageCode[] = "en-US"; |
| 452 std::map<std::string, std::string>::const_iterator iter | 452 std::map<std::string, std::string>::const_iterator iter |
| 453 = Singleton<IdMaps>::get()->id_to_language_code->find(input_method_id); | 453 = Singleton<IdMaps>::get()->id_to_language_code->find(input_method_id); |
| 454 return (iter == Singleton<IdMaps>::get()->id_to_language_code->end()) ? | 454 return (iter == Singleton<IdMaps>::get()->id_to_language_code->end()) ? |
| 455 // Returning |kDefaultLanguageCode| here is not for Chrome OS but for | 455 // Returning |kDefaultLanguageCode| here is not for Chrome OS but for |
| 456 // Ubuntu where the ibus-xkb-layouts engine could be missing. | 456 // Ubuntu where the ibus-xkb-layouts engine could be missing. |
| 457 kDefaultLanguageCode : iter->second; | 457 kDefaultLanguageCode : iter->second; |
| 458 } | 458 } |
| 459 | 459 |
| 460 std::string GetKeyboardLayoutName(const std::string& input_method_id) { | 460 std::string GetKeyboardLayoutName(const std::string& input_method_id) { |
| 461 if (!StartsWithASCII(input_method_id, "xkb:", true)) { | 461 if (!StartsWithASCII(input_method_id, "xkb:", true)) { |
| 462 return ""; | 462 return ""; |
| 463 } | 463 } |
| 464 | 464 |
| 465 std::vector<std::string> splitted_id; | 465 std::vector<std::string> splitted_id; |
| 466 SplitString(input_method_id, ':', &splitted_id); | 466 base::SplitString(input_method_id, ':', &splitted_id); |
| 467 return (splitted_id.size() > 1) ? splitted_id[1] : ""; | 467 return (splitted_id.size() > 1) ? splitted_id[1] : ""; |
| 468 } | 468 } |
| 469 | 469 |
| 470 std::string GetInputMethodDisplayNameFromId( | 470 std::string GetInputMethodDisplayNameFromId( |
| 471 const std::string& input_method_id) { | 471 const std::string& input_method_id) { |
| 472 static const char kDefaultDisplayName[] = "USA"; | 472 static const char kDefaultDisplayName[] = "USA"; |
| 473 std::map<std::string, std::string>::const_iterator iter | 473 std::map<std::string, std::string>::const_iterator iter |
| 474 = Singleton<IdMaps>::get()->id_to_display_name->find(input_method_id); | 474 = Singleton<IdMaps>::get()->id_to_display_name->find(input_method_id); |
| 475 return (iter == Singleton<IdMaps>::get()->id_to_display_name->end()) ? | 475 return (iter == Singleton<IdMaps>::get()->id_to_display_name->end()) ? |
| 476 kDefaultDisplayName : iter->second; | 476 kDefaultDisplayName : iter->second; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 library->ChangeInputMethod(initial_input_method_id); | 591 library->ChangeInputMethod(initial_input_method_id); |
| 592 } | 592 } |
| 593 } | 593 } |
| 594 | 594 |
| 595 void OnLocaleChanged() { | 595 void OnLocaleChanged() { |
| 596 Singleton<IdMaps>::get()->ReloadMaps(); | 596 Singleton<IdMaps>::get()->ReloadMaps(); |
| 597 } | 597 } |
| 598 | 598 |
| 599 } // namespace input_method | 599 } // namespace input_method |
| 600 } // namespace chromeos | 600 } // namespace chromeos |
| OLD | NEW |