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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 input_method.id()) { | 518 input_method.id()) { |
519 return delegate_->GetLocalizedString( | 519 return delegate_->GetLocalizedString( |
520 kMappingImeIdToMediumLenNameResourceId[i].resource_id); | 520 kMappingImeIdToMediumLenNameResourceId[i].resource_id); |
521 } | 521 } |
522 } | 522 } |
523 return GetInputMethodShortName(input_method); | 523 return GetInputMethodShortName(input_method); |
524 } | 524 } |
525 | 525 |
526 base::string16 InputMethodUtil::GetInputMethodLongName( | 526 base::string16 InputMethodUtil::GetInputMethodLongName( |
527 const InputMethodDescriptor& input_method) const { | 527 const InputMethodDescriptor& input_method) const { |
528 if (!input_method.name().empty()) { | 528 if (!input_method.name().empty() && !IsKeyboardLayout(input_method.id())) { |
529 // If the descriptor has a name, use it. | 529 // If the descriptor has a name, use it. |
530 return base::UTF8ToUTF16(input_method.name()); | 530 return base::UTF8ToUTF16(input_method.name()); |
531 } | 531 } |
532 | 532 |
533 // We don't show language here. Name of keyboard layout or input method | 533 // We don't show language here. Name of keyboard layout or input method |
534 // usually imply (or explicitly include) its language. | 534 // usually imply (or explicitly include) its language. |
535 | 535 |
536 // Special case for German, French and Dutch: these languages have multiple | 536 // Special case for German, French and Dutch: these languages have multiple |
537 // keyboard layouts and share the same layout of keyboard (Belgian). We need | 537 // keyboard layouts and share the same layout of keyboard (Belgian). We need |
538 // to show explicitly the language for the layout. For Arabic, Amharic, and | 538 // to show explicitly the language for the layout. For Arabic, Amharic, and |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 } | 737 } |
738 ids.swap(new_ids); | 738 ids.swap(new_ids); |
739 } | 739 } |
740 return rewritten; | 740 return rewritten; |
741 } | 741 } |
742 | 742 |
743 void InputMethodUtil::UpdateHardwareLayoutCache() { | 743 void InputMethodUtil::UpdateHardwareLayoutCache() { |
744 DCHECK(thread_checker_.CalledOnValidThread()); | 744 DCHECK(thread_checker_.CalledOnValidThread()); |
745 hardware_layouts_.clear(); | 745 hardware_layouts_.clear(); |
746 hardware_login_layouts_.clear(); | 746 hardware_login_layouts_.clear(); |
747 Tokenize(delegate_->GetHardwareKeyboardLayouts(), ",", &hardware_layouts_); | 747 if (cached_hardware_layouts_.empty()) |
| 748 Tokenize(delegate_->GetHardwareKeyboardLayouts(), ",", |
| 749 &cached_hardware_layouts_); |
| 750 hardware_layouts_ = cached_hardware_layouts_; |
748 MigrateXkbInputMethods(&hardware_layouts_); | 751 MigrateXkbInputMethods(&hardware_layouts_); |
749 | 752 |
750 for (size_t i = 0; i < hardware_layouts_.size(); ++i) { | 753 for (size_t i = 0; i < hardware_layouts_.size(); ++i) { |
751 if (IsLoginKeyboard(hardware_layouts_[i])) | 754 if (IsLoginKeyboard(hardware_layouts_[i])) |
752 hardware_login_layouts_.push_back(hardware_layouts_[i]); | 755 hardware_login_layouts_.push_back(hardware_layouts_[i]); |
753 } | 756 } |
754 if (hardware_layouts_.empty()) { | 757 if (hardware_layouts_.empty()) { |
755 // This is totally fine if it's empty. The hardware keyboard layout is | 758 // This is totally fine if it's empty. The hardware keyboard layout is |
756 // not stored if startup_manifest.json (OEM customization data) is not | 759 // not stored if startup_manifest.json (OEM customization data) is not |
757 // present (ex. Cr48 doen't have that file). | 760 // present (ex. Cr48 doen't have that file). |
758 hardware_layouts_.push_back(GetFallbackInputMethodDescriptor().id()); | 761 hardware_layouts_.push_back(GetFallbackInputMethodDescriptor().id()); |
759 } | 762 } |
760 | 763 |
761 if (hardware_login_layouts_.empty()) | 764 if (hardware_login_layouts_.empty()) |
762 hardware_login_layouts_.push_back(GetFallbackInputMethodDescriptor().id()); | 765 hardware_login_layouts_.push_back(GetFallbackInputMethodDescriptor().id()); |
763 } | 766 } |
764 | 767 |
765 void InputMethodUtil::SetHardwareKeyboardLayoutForTesting( | 768 void InputMethodUtil::SetHardwareKeyboardLayoutForTesting( |
766 const std::string& layout) { | 769 const std::string& layout) { |
767 delegate_->SetHardwareKeyboardLayoutForTesting(layout); | 770 delegate_->SetHardwareKeyboardLayoutForTesting(layout); |
| 771 cached_hardware_layouts_.clear(); |
768 UpdateHardwareLayoutCache(); | 772 UpdateHardwareLayoutCache(); |
769 } | 773 } |
770 | 774 |
771 const std::vector<std::string>& | 775 const std::vector<std::string>& |
772 InputMethodUtil::GetHardwareInputMethodIds() { | 776 InputMethodUtil::GetHardwareInputMethodIds() { |
773 DCHECK(thread_checker_.CalledOnValidThread()); | 777 DCHECK(thread_checker_.CalledOnValidThread()); |
774 // Once the initialization is done, at least one input method should be set. | 778 UpdateHardwareLayoutCache(); |
775 if (hardware_layouts_.empty()) | |
776 UpdateHardwareLayoutCache(); | |
777 return hardware_layouts_; | 779 return hardware_layouts_; |
778 } | 780 } |
779 | 781 |
780 const std::vector<std::string>& | 782 const std::vector<std::string>& |
781 InputMethodUtil::GetHardwareLoginInputMethodIds() { | 783 InputMethodUtil::GetHardwareLoginInputMethodIds() { |
782 DCHECK(thread_checker_.CalledOnValidThread()); | 784 DCHECK(thread_checker_.CalledOnValidThread()); |
783 // Once the initialization is done, at least one input method should be set. | 785 UpdateHardwareLayoutCache(); |
784 if (hardware_login_layouts_.empty()) | |
785 UpdateHardwareLayoutCache(); | |
786 return hardware_login_layouts_; | 786 return hardware_login_layouts_; |
787 } | 787 } |
788 | 788 |
789 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) | 789 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) |
790 const { | 790 const { |
791 const InputMethodDescriptor* ime = | 791 const InputMethodDescriptor* ime = |
792 GetInputMethodDescriptorFromId(input_method_id); | 792 GetInputMethodDescriptorFromId(input_method_id); |
793 return ime ? ime->is_login_keyboard() : false; | 793 return ime ? ime->is_login_keyboard() : false; |
794 } | 794 } |
795 | 795 |
(...skipping 17 matching lines...) Expand all Loading... |
813 break; | 813 break; |
814 } | 814 } |
815 if (it == range.second) | 815 if (it == range.second) |
816 language_code_to_ids_.insert( | 816 language_code_to_ids_.insert( |
817 std::make_pair(language_codes[j], input_method.id())); | 817 std::make_pair(language_codes[j], input_method.id())); |
818 } | 818 } |
819 } | 819 } |
820 } | 820 } |
821 | 821 |
822 void InputMethodUtil::InitXkbInputMethodsForTesting() { | 822 void InputMethodUtil::InitXkbInputMethodsForTesting() { |
| 823 cached_hardware_layouts_.clear(); |
823 if (!extension_ime_util::UseWrappedExtensionKeyboardLayouts()) | 824 if (!extension_ime_util::UseWrappedExtensionKeyboardLayouts()) |
824 return; | 825 return; |
825 scoped_ptr<InputMethodDescriptors> original_imes = | 826 scoped_ptr<InputMethodDescriptors> original_imes = |
826 InputMethodWhitelist().GetSupportedInputMethods(); | 827 InputMethodWhitelist().GetSupportedInputMethods(); |
827 InputMethodDescriptors whitelist_imes; | 828 InputMethodDescriptors whitelist_imes; |
828 for (size_t i = 0; i < original_imes->size(); ++i) { | 829 for (size_t i = 0; i < original_imes->size(); ++i) { |
829 const InputMethodDescriptor& ime = (*original_imes)[i]; | 830 const InputMethodDescriptor& ime = (*original_imes)[i]; |
830 whitelist_imes.push_back(InputMethodDescriptor( | 831 whitelist_imes.push_back(InputMethodDescriptor( |
831 extension_ime_util::GetInputMethodIDByKeyboardLayout(ime.id()), | 832 extension_ime_util::GetInputMethodIDByKeyboardLayout(ime.id()), |
832 "", | 833 "", |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 if (IsKeyboardLayout(input_method.id())) { | 886 if (IsKeyboardLayout(input_method.id())) { |
886 xkb_id_to_descriptor_.insert( | 887 xkb_id_to_descriptor_.insert( |
887 std::make_pair(input_method.GetPreferredKeyboardLayout(), | 888 std::make_pair(input_method.GetPreferredKeyboardLayout(), |
888 input_method)); | 889 input_method)); |
889 } | 890 } |
890 } | 891 } |
891 } | 892 } |
892 | 893 |
893 } // namespace input_method | 894 } // namespace input_method |
894 } // namespace chromeos | 895 } // namespace chromeos |
OLD | NEW |