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 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 const std::string& language_code) { | 604 const std::string& language_code) { |
605 std::vector<std::string> candidates; | 605 std::vector<std::string> candidates; |
606 GetInputMethodIdsFromLanguageCode( | 606 GetInputMethodIdsFromLanguageCode( |
607 language_code, input_method::kKeyboardLayoutsOnly, &candidates); | 607 language_code, input_method::kKeyboardLayoutsOnly, &candidates); |
608 if (candidates.size()) | 608 if (candidates.size()) |
609 return candidates.front(); | 609 return candidates.front(); |
610 | 610 |
611 return std::string(); | 611 return std::string(); |
612 } | 612 } |
613 | 613 |
| 614 bool InputMethodUtil::MigrateXkbInputMethods( |
| 615 std::vector<std::string>* input_method_ids) { |
| 616 bool rewritten = false; |
| 617 std::vector<std::string>& ids = *input_method_ids; |
| 618 for (size_t i = 0; i < ids.size(); ++i) { |
| 619 std::string id = |
| 620 extension_ime_util::GetInputMethodIDByKeyboardLayout(ids[i]); |
| 621 if (id != ids[i]) { |
| 622 ids[i] = id; |
| 623 rewritten = true; |
| 624 } |
| 625 } |
| 626 if (rewritten) { |
| 627 // Removes the duplicates. |
| 628 size_t t = 0, j = 0; |
| 629 for (size_t i = 0; i < ids.size(); ++i) { |
| 630 for (j = 0; j < t; ++j) { |
| 631 if (ids[i] == ids[j]) |
| 632 break; |
| 633 } |
| 634 if (t == j) // no dup. |
| 635 ids[t++] = ids[i]; |
| 636 } |
| 637 ids.resize(t); |
| 638 } |
| 639 return rewritten; |
| 640 } |
| 641 |
614 void InputMethodUtil::UpdateHardwareLayoutCache() { | 642 void InputMethodUtil::UpdateHardwareLayoutCache() { |
615 DCHECK(thread_checker_.CalledOnValidThread()); | 643 DCHECK(thread_checker_.CalledOnValidThread()); |
616 hardware_layouts_.clear(); | 644 hardware_layouts_.clear(); |
617 hardware_login_layouts_.clear(); | 645 hardware_login_layouts_.clear(); |
618 Tokenize(delegate_->GetHardwareKeyboardLayouts(), ",", &hardware_layouts_); | 646 Tokenize(delegate_->GetHardwareKeyboardLayouts(), ",", &hardware_layouts_); |
| 647 MigrateXkbInputMethods(&hardware_layouts_); |
619 | 648 |
620 for (size_t i = 0; i < hardware_layouts_.size(); ++i) { | 649 for (size_t i = 0; i < hardware_layouts_.size(); ++i) { |
621 if (IsLoginKeyboard(hardware_layouts_[i])) | 650 if (IsLoginKeyboard(hardware_layouts_[i])) |
622 hardware_login_layouts_.push_back(hardware_layouts_[i]); | 651 hardware_login_layouts_.push_back(hardware_layouts_[i]); |
623 } | 652 } |
624 if (hardware_layouts_.empty()) { | 653 if (hardware_layouts_.empty()) { |
625 // This is totally fine if it's empty. The hardware keyboard layout is | 654 // This is totally fine if it's empty. The hardware keyboard layout is |
626 // not stored if startup_manifest.json (OEM customization data) is not | 655 // not stored if startup_manifest.json (OEM customization data) is not |
627 // present (ex. Cr48 doen't have that file). | 656 // present (ex. Cr48 doen't have that file). |
628 hardware_layouts_.push_back(GetFallbackInputMethodDescriptor().id()); | 657 hardware_layouts_.push_back(GetFallbackInputMethodDescriptor().id()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 id_to_descriptor_.insert( | 704 id_to_descriptor_.insert( |
676 std::make_pair(input_method.id(), input_method)); | 705 std::make_pair(input_method.id(), input_method)); |
677 } | 706 } |
678 } | 707 } |
679 | 708 |
680 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { | 709 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { |
681 std::vector<std::string> layouts; | 710 std::vector<std::string> layouts; |
682 layouts.push_back("us"); | 711 layouts.push_back("us"); |
683 std::vector<std::string> languages; | 712 std::vector<std::string> languages; |
684 languages.push_back("en-US"); | 713 languages.push_back("en-US"); |
685 return InputMethodDescriptor("xkb:us::eng", | 714 return InputMethodDescriptor( |
686 "", | 715 extension_ime_util::GetInputMethodIDByKeyboardLayout("xkb:us::eng"), |
687 "US", | 716 "", |
688 layouts, | 717 "US", |
689 languages, | 718 layouts, |
690 true, // login keyboard. | 719 languages, |
691 GURL(), // options page, not available. | 720 true, // login keyboard. |
692 GURL()); // input view page, not available. | 721 GURL(), // options page, not available. |
| 722 GURL()); // input view page, not available. |
693 } | 723 } |
694 | 724 |
695 void InputMethodUtil::ReloadInternalMaps() { | 725 void InputMethodUtil::ReloadInternalMaps() { |
696 if (supported_input_methods_->size() <= 1) { | 726 if (supported_input_methods_->size() <= 1) { |
697 DVLOG(1) << "GetSupportedInputMethods returned a fallback ID"; | 727 DVLOG(1) << "GetSupportedInputMethods returned a fallback ID"; |
698 // TODO(yusukes): Handle this error in nicer way. | 728 // TODO(yusukes): Handle this error in nicer way. |
699 } | 729 } |
700 | 730 |
701 // Clear the existing maps. | 731 // Clear the existing maps. |
702 language_code_to_ids_.clear(); | 732 language_code_to_ids_.clear(); |
(...skipping 18 matching lines...) Expand all Loading... |
721 if (IsKeyboardLayout(input_method.id())) { | 751 if (IsKeyboardLayout(input_method.id())) { |
722 xkb_id_to_descriptor_.insert( | 752 xkb_id_to_descriptor_.insert( |
723 std::make_pair(input_method.GetPreferredKeyboardLayout(), | 753 std::make_pair(input_method.GetPreferredKeyboardLayout(), |
724 input_method)); | 754 input_method)); |
725 } | 755 } |
726 } | 756 } |
727 } | 757 } |
728 | 758 |
729 } // namespace input_method | 759 } // namespace input_method |
730 } // namespace chromeos | 760 } // namespace chromeos |
OLD | NEW |