Chromium Code Reviews| 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 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 const std::string& language_code) { | 607 const std::string& language_code) { |
| 608 std::vector<std::string> candidates; | 608 std::vector<std::string> candidates; |
| 609 GetInputMethodIdsFromLanguageCode( | 609 GetInputMethodIdsFromLanguageCode( |
| 610 language_code, input_method::kKeyboardLayoutsOnly, &candidates); | 610 language_code, input_method::kKeyboardLayoutsOnly, &candidates); |
| 611 if (candidates.size()) | 611 if (candidates.size()) |
| 612 return candidates.front(); | 612 return candidates.front(); |
| 613 | 613 |
| 614 return std::string(); | 614 return std::string(); |
| 615 } | 615 } |
| 616 | 616 |
| 617 std::string InputMethodUtil::GetHardwareInputMethodId() const { | 617 const std::vector<std::string>& |
| 618 const std::string input_method_id = delegate_->GetHardwareKeyboardLayout(); | 618 InputMethodUtil::GetHardwareInputMethodIds() { |
| 619 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 620 if (hardware_layouts_.get()) | |
|
Alexander Alekseev
2014/02/12 14:45:35
Why are hardware_layouts_ and hardware_login_layou
Seigo Nonaka
2014/02/12 16:49:51
Yes, you are right! Changing to plain object.
On
| |
| 621 return *(hardware_layouts_.get()); | |
| 619 | 622 |
| 620 if (input_method_id.empty()) { | 623 hardware_layouts_.reset(new std::vector<std::string>()); |
| 624 | |
| 625 delegate_->GetHardwareKeyboardLayouts(hardware_layouts_.get()); | |
| 626 | |
| 627 if (hardware_layouts_->empty()) { | |
| 621 // This is totally fine if it's empty. The hardware keyboard layout is | 628 // This is totally fine if it's empty. The hardware keyboard layout is |
| 622 // not stored if startup_manifest.json (OEM customization data) is not | 629 // not stored if startup_manifest.json (OEM customization data) is not |
| 623 // present (ex. Cr48 doen't have that file). | 630 // present (ex. Cr48 doen't have that file). |
| 624 return GetFallbackInputMethodDescriptor().id(); | 631 hardware_layouts_->push_back(GetFallbackInputMethodDescriptor().id()); |
| 625 } | 632 } |
| 626 return input_method_id; | 633 return *(hardware_layouts_.get()); |
| 627 } | 634 } |
| 628 | 635 |
| 629 std::string InputMethodUtil::GetHardwareLoginInputMethodId() const { | 636 void InputMethodUtil::InvalidateHardwareInputMethodIdsCache() { |
| 630 const std::string input_method_id = GetHardwareInputMethodId(); | 637 DCHECK(thread_checker_.CalledOnValidThread()); |
| 638 hardware_layouts_.reset(); | |
| 639 hardware_login_layouts_.reset(); | |
| 640 } | |
| 631 | 641 |
| 632 if (!IsLoginKeyboard(input_method_id)) | 642 const std::vector<std::string>& |
| 633 return GetFallbackInputMethodDescriptor().id(); | 643 InputMethodUtil::GetHardwareLoginInputMethodIds() { |
| 644 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 634 | 645 |
| 635 return input_method_id; | 646 if (hardware_login_layouts_.get()) |
| 647 return *(hardware_login_layouts_.get()); | |
| 648 | |
| 649 hardware_login_layouts_.reset(new std::vector<std::string>()); | |
| 650 const std::vector<std::string>& candidates = GetHardwareInputMethodIds(); | |
| 651 | |
| 652 for (size_t i = 0; i < candidates.size(); ++i) { | |
| 653 if (IsLoginKeyboard(candidates[i])) | |
| 654 hardware_login_layouts_->push_back(candidates[i]); | |
| 655 } | |
| 656 | |
| 657 if (hardware_login_layouts_->empty()) | |
| 658 hardware_login_layouts_->push_back(GetFallbackInputMethodDescriptor().id()); | |
| 659 return *(hardware_login_layouts_.get()); | |
| 636 } | 660 } |
| 637 | 661 |
| 638 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) | 662 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) |
| 639 const { | 663 const { |
| 640 const InputMethodDescriptor* ime = | 664 const InputMethodDescriptor* ime = |
| 641 GetInputMethodDescriptorFromId(input_method_id); | 665 GetInputMethodDescriptorFromId(input_method_id); |
| 642 return ime ? ime->is_login_keyboard() : false; | 666 return ime ? ime->is_login_keyboard() : false; |
| 643 } | 667 } |
| 644 | 668 |
| 645 void InputMethodUtil::SetComponentExtensions( | 669 void InputMethodUtil::SetComponentExtensions( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 if (IsKeyboardLayout(input_method.id())) { | 723 if (IsKeyboardLayout(input_method.id())) { |
| 700 xkb_id_to_descriptor_.insert( | 724 xkb_id_to_descriptor_.insert( |
| 701 std::make_pair(input_method.GetPreferredKeyboardLayout(), | 725 std::make_pair(input_method.GetPreferredKeyboardLayout(), |
| 702 input_method)); | 726 input_method)); |
| 703 } | 727 } |
| 704 } | 728 } |
| 705 } | 729 } |
| 706 | 730 |
| 707 } // namespace input_method | 731 } // namespace input_method |
| 708 } // namespace chromeos | 732 } // namespace chromeos |
| OLD | NEW |