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> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "chromeos/ime/component_extension_ime_manager.h" | 18 #include "chromeos/ime/component_extension_ime_manager.h" |
19 #include "chromeos/ime/extension_ime_util.h" | 19 #include "chromeos/ime/extension_ime_util.h" |
20 // For SetHardwareKeyboardLayoutForTesting. | |
21 #include "chromeos/ime/fake_input_method_delegate.h" | |
20 #include "chromeos/ime/input_method_delegate.h" | 22 #include "chromeos/ime/input_method_delegate.h" |
21 // TODO(nona): move this header from this file. | 23 // TODO(nona): move this header from this file. |
22 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 // A mapping from an input method id to a string for the language indicator. The | 28 // A mapping from an input method id to a string for the language indicator. The |
27 // mapping is necessary since some input methods belong to the same language. | 29 // mapping is necessary since some input methods belong to the same language. |
28 // For example, both "xkb:us::eng" and "xkb:us:dvorak:eng" are for US English. | 30 // For example, both "xkb:us::eng" and "xkb:us:dvorak:eng" are for US English. |
29 const struct { | 31 const struct { |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 const std::string& language_code) { | 609 const std::string& language_code) { |
608 std::vector<std::string> candidates; | 610 std::vector<std::string> candidates; |
609 GetInputMethodIdsFromLanguageCode( | 611 GetInputMethodIdsFromLanguageCode( |
610 language_code, input_method::kKeyboardLayoutsOnly, &candidates); | 612 language_code, input_method::kKeyboardLayoutsOnly, &candidates); |
611 if (candidates.size()) | 613 if (candidates.size()) |
612 return candidates.front(); | 614 return candidates.front(); |
613 | 615 |
614 return std::string(); | 616 return std::string(); |
615 } | 617 } |
616 | 618 |
617 std::string InputMethodUtil::GetHardwareInputMethodId() const { | 619 void InputMethodUtil::UpdateHardwareLayoutCache() { |
618 const std::string input_method_id = delegate_->GetHardwareKeyboardLayout(); | 620 DCHECK(thread_checker_.CalledOnValidThread()); |
621 hardware_layouts_.clear(); | |
622 hardware_login_layouts_.clear(); | |
623 Tokenize(delegate_->GetHardwareKeyboardLayouts(), ",", &hardware_layouts_); | |
619 | 624 |
620 if (input_method_id.empty()) { | 625 for (size_t i = 0; i < hardware_layouts_.size(); ++i) { |
626 if (IsLoginKeyboard(hardware_layouts_[i])) | |
627 hardware_login_layouts_.push_back(hardware_layouts_[i]); | |
628 } | |
629 if (hardware_layouts_.empty()) { | |
621 // This is totally fine if it's empty. The hardware keyboard layout is | 630 // 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 | 631 // not stored if startup_manifest.json (OEM customization data) is not |
623 // present (ex. Cr48 doen't have that file). | 632 // present (ex. Cr48 doen't have that file). |
624 return GetFallbackInputMethodDescriptor().id(); | 633 hardware_layouts_.push_back(GetFallbackInputMethodDescriptor().id()); |
625 } | 634 } |
626 return input_method_id; | 635 |
636 if (hardware_login_layouts_.empty()) | |
637 hardware_login_layouts_.push_back(GetFallbackInputMethodDescriptor().id()); | |
627 } | 638 } |
628 | 639 |
629 std::string InputMethodUtil::GetHardwareLoginInputMethodId() const { | 640 void InputMethodUtil::SetHardwareKeyboardLayoutForTesting( |
630 const std::string input_method_id = GetHardwareInputMethodId(); | 641 const std::string& layout) { |
642 FakeInputMethodDelegate* fake_delegate = | |
643 static_cast<FakeInputMethodDelegate*>(delegate_); | |
644 CHECK(fake_delegate) | |
645 << "To use SetHardwareKeyboardLayoutForTesting, " | |
646 << "need to set FakeInputMethodDelegate to constructor."; | |
647 fake_delegate->set_hardware_keyboard_layout(layout); | |
Alexander Alekseev
2014/02/13 12:47:04
Probably it would be better to add
virtual InputM
Seigo Nonaka
2014/02/14 03:51:45
Added SetHardwareKeyboardLayoutForTesting.
On 201
| |
648 UpdateHardwareLayoutCache(); | |
649 } | |
631 | 650 |
632 if (!IsLoginKeyboard(input_method_id)) | 651 const std::vector<std::string>& |
633 return GetFallbackInputMethodDescriptor().id(); | 652 InputMethodUtil::GetHardwareInputMethodIds() { |
653 DCHECK(thread_checker_.CalledOnValidThread()); | |
654 // Once the initialization is done, at least one input method should be set. | |
655 if (hardware_layouts_.empty()) | |
656 UpdateHardwareLayoutCache(); | |
657 return hardware_layouts_; | |
658 } | |
634 | 659 |
635 return input_method_id; | 660 const std::vector<std::string>& |
661 InputMethodUtil::GetHardwareLoginInputMethodIds() { | |
662 DCHECK(thread_checker_.CalledOnValidThread()); | |
663 // Once the initialization is done, at least one input method should be set. | |
664 if (hardware_login_layouts_.empty()) | |
665 UpdateHardwareLayoutCache(); | |
666 return hardware_login_layouts_; | |
636 } | 667 } |
637 | 668 |
638 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) | 669 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) |
639 const { | 670 const { |
640 const InputMethodDescriptor* ime = | 671 const InputMethodDescriptor* ime = |
641 GetInputMethodDescriptorFromId(input_method_id); | 672 GetInputMethodDescriptorFromId(input_method_id); |
642 return ime ? ime->is_login_keyboard() : false; | 673 return ime ? ime->is_login_keyboard() : false; |
643 } | 674 } |
644 | 675 |
645 void InputMethodUtil::SetComponentExtensions( | 676 void InputMethodUtil::SetComponentExtensions( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
699 if (IsKeyboardLayout(input_method.id())) { | 730 if (IsKeyboardLayout(input_method.id())) { |
700 xkb_id_to_descriptor_.insert( | 731 xkb_id_to_descriptor_.insert( |
701 std::make_pair(input_method.GetPreferredKeyboardLayout(), | 732 std::make_pair(input_method.GetPreferredKeyboardLayout(), |
702 input_method)); | 733 input_method)); |
703 } | 734 } |
704 } | 735 } |
705 } | 736 } |
706 | 737 |
707 } // namespace input_method | 738 } // namespace input_method |
708 } // namespace chromeos | 739 } // namespace chromeos |
OLD | NEW |