Chromium Code Reviews| 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 <functional> | 8 #include <functional> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 struct CompareLanguageCodesByLanguageName | 342 struct CompareLanguageCodesByLanguageName |
| 343 : std::binary_function<const std::string&, const std::string&, bool> { | 343 : std::binary_function<const std::string&, const std::string&, bool> { |
| 344 explicit CompareLanguageCodesByLanguageName(icu::Collator* collator) | 344 explicit CompareLanguageCodesByLanguageName(icu::Collator* collator) |
| 345 : collator_(collator) { | 345 : collator_(collator) { |
| 346 } | 346 } |
| 347 | 347 |
| 348 // Calling GetLanguageDisplayNameFromCode() in the comparator is not | 348 // Calling GetLanguageDisplayNameFromCode() in the comparator is not |
| 349 // efficient, but acceptable as the function is cheap, and the language | 349 // efficient, but acceptable as the function is cheap, and the language |
| 350 // list is short (about 40 at most). | 350 // list is short (about 40 at most). |
| 351 bool operator()(const std::string& s1, const std::string& s2) const { | 351 bool operator()(const std::string& s1, const std::string& s2) const { |
| 352 const std::wstring key1 = | 352 const string16 key1 = |
| 353 chromeos::input_method::GetLanguageDisplayNameFromCode(s1); | 353 chromeos::input_method::GetLanguageDisplayNameFromCode(s1); |
| 354 const std::wstring key2 = | 354 const string16 key2 = |
| 355 chromeos::input_method::GetLanguageDisplayNameFromCode(s2); | 355 chromeos::input_method::GetLanguageDisplayNameFromCode(s2); |
|
Evan Martin
2010/12/24 01:00:42
one line?
| |
| 356 return l10n_util::StringComparator<std::wstring>(collator_)(key1, key2); | 356 return l10n_util::StringComparator<string16>(collator_)(key1, key2); |
| 357 } | 357 } |
| 358 | 358 |
| 359 private: | 359 private: |
| 360 icu::Collator* collator_; | 360 icu::Collator* collator_; |
| 361 }; | 361 }; |
| 362 | 362 |
| 363 // The comparator is used for sorting input method ids by their | 363 // The comparator is used for sorting input method ids by their |
| 364 // corresponding language names, using the ICU collator. | 364 // corresponding language names, using the ICU collator. |
| 365 struct CompareInputMethodIdsByLanguageName | 365 struct CompareInputMethodIdsByLanguageName |
| 366 : std::binary_function<const std::string&, const std::string&, bool> { | 366 : std::binary_function<const std::string&, const std::string&, bool> { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 | 571 |
| 572 std::string GetInputMethodDisplayNameFromId( | 572 std::string GetInputMethodDisplayNameFromId( |
| 573 const std::string& input_method_id) { | 573 const std::string& input_method_id) { |
| 574 static const char kDefaultDisplayName[] = "USA"; | 574 static const char kDefaultDisplayName[] = "USA"; |
| 575 std::map<std::string, std::string>::const_iterator iter | 575 std::map<std::string, std::string>::const_iterator iter |
| 576 = IdMaps::GetInstance()->id_to_display_name->find(input_method_id); | 576 = IdMaps::GetInstance()->id_to_display_name->find(input_method_id); |
| 577 return (iter == IdMaps::GetInstance()->id_to_display_name->end()) ? | 577 return (iter == IdMaps::GetInstance()->id_to_display_name->end()) ? |
| 578 kDefaultDisplayName : iter->second; | 578 kDefaultDisplayName : iter->second; |
| 579 } | 579 } |
| 580 | 580 |
| 581 std::wstring GetLanguageDisplayNameFromCode(const std::string& language_code) { | 581 string16 GetLanguageDisplayNameFromCode(const std::string& language_code) { |
| 582 if (!g_browser_process) { | 582 if (!g_browser_process) { |
| 583 return L""; | 583 return string16(); |
| 584 } | 584 } |
| 585 return UTF16ToWide(l10n_util::GetDisplayNameForLocale( | 585 return l10n_util::GetDisplayNameForLocale( |
| 586 language_code, g_browser_process->GetApplicationLocale(), true)); | 586 language_code, g_browser_process->GetApplicationLocale(), true); |
| 587 } | 587 } |
| 588 | 588 |
| 589 std::wstring GetLanguageNativeDisplayNameFromCode( | 589 string16 GetLanguageNativeDisplayNameFromCode( |
| 590 const std::string& language_code) { | 590 const std::string& language_code) { |
| 591 return UTF16ToWide(l10n_util::GetDisplayNameForLocale( | 591 return l10n_util::GetDisplayNameForLocale(language_code, language_code, true); |
| 592 language_code, language_code, true)); | |
| 593 } | 592 } |
| 594 | 593 |
| 595 void SortLanguageCodesByNames(std::vector<std::string>* language_codes) { | 594 void SortLanguageCodesByNames(std::vector<std::string>* language_codes) { |
| 596 if (!g_browser_process) { | 595 if (!g_browser_process) { |
| 597 return; | 596 return; |
| 598 } | 597 } |
| 599 // We should build collator outside of the comparator. We cannot have | 598 // We should build collator outside of the comparator. We cannot have |
| 600 // scoped_ptr<> in the comparator for a subtle STL reason. | 599 // scoped_ptr<> in the comparator for a subtle STL reason. |
| 601 UErrorCode error = U_ZERO_ERROR; | 600 UErrorCode error = U_ZERO_ERROR; |
| 602 icu::Locale locale(g_browser_process->GetApplicationLocale().c_str()); | 601 icu::Locale locale(g_browser_process->GetApplicationLocale().c_str()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 library->ChangeInputMethod(initial_input_method_id); | 692 library->ChangeInputMethod(initial_input_method_id); |
| 694 } | 693 } |
| 695 } | 694 } |
| 696 | 695 |
| 697 void OnLocaleChanged() { | 696 void OnLocaleChanged() { |
| 698 IdMaps::GetInstance()->ReloadMaps(); | 697 IdMaps::GetInstance()->ReloadMaps(); |
| 699 } | 698 } |
| 700 | 699 |
| 701 } // namespace input_method | 700 } // namespace input_method |
| 702 } // namespace chromeos | 701 } // namespace chromeos |
| OLD | NEW |