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_manager_impl.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" |
6 | 6 |
7 #include <algorithm> // std::find | 7 #include <algorithm> // std::find |
8 | 8 |
9 #include "ash/ime/input_method_menu_item.h" | 9 #include "ash/ime/input_method_menu_item.h" |
10 #include "ash/ime/input_method_menu_manager.h" | 10 #include "ash/ime/input_method_menu_manager.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "chromeos/ime/ime_keyboard.h" | 28 #include "chromeos/ime/ime_keyboard.h" |
29 #include "chromeos/ime/input_method_delegate.h" | 29 #include "chromeos/ime/input_method_delegate.h" |
30 #include "third_party/icu/source/common/unicode/uloc.h" | 30 #include "third_party/icu/source/common/unicode/uloc.h" |
31 #include "ui/base/accelerators/accelerator.h" | 31 #include "ui/base/accelerators/accelerator.h" |
32 | 32 |
33 namespace chromeos { | 33 namespace chromeos { |
34 namespace input_method { | 34 namespace input_method { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 const char nacl_mozc_jp_id[] = | |
39 "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopnacl_mozc_jp"; | |
40 | |
41 bool Contains(const std::vector<std::string>& container, | 38 bool Contains(const std::vector<std::string>& container, |
42 const std::string& value) { | 39 const std::string& value) { |
43 return std::find(container.begin(), container.end(), value) != | 40 return std::find(container.begin(), container.end(), value) != |
44 container.end(); | 41 container.end(); |
45 } | 42 } |
46 | 43 |
47 } // namespace | 44 } // namespace |
48 | 45 |
49 bool InputMethodManagerImpl::IsLoginKeyboard( | 46 bool InputMethodManagerImpl::IsLoginKeyboard( |
50 const std::string& layout) const { | 47 const std::string& layout) const { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 candidate_window_controller_.reset(); | 105 candidate_window_controller_.reset(); |
109 break; | 106 break; |
110 } | 107 } |
111 } | 108 } |
112 } | 109 } |
113 | 110 |
114 scoped_ptr<InputMethodDescriptors> | 111 scoped_ptr<InputMethodDescriptors> |
115 InputMethodManagerImpl::GetSupportedInputMethods() const { | 112 InputMethodManagerImpl::GetSupportedInputMethods() const { |
116 scoped_ptr<InputMethodDescriptors> whitelist_imes = | 113 scoped_ptr<InputMethodDescriptors> whitelist_imes = |
117 whitelist_.GetSupportedInputMethods(); | 114 whitelist_.GetSupportedInputMethods(); |
118 if (!extension_ime_util::UseWrappedExtensionKeyboardLayouts()) | 115 if (!component_extension_ime_manager_->IsInitialized()) |
119 return whitelist_imes.Pass(); | 116 return whitelist_imes.Pass(); |
120 return scoped_ptr<InputMethodDescriptors>(new InputMethodDescriptors).Pass(); | 117 return scoped_ptr<InputMethodDescriptors>(new InputMethodDescriptors).Pass(); |
121 } | 118 } |
122 | 119 |
123 scoped_ptr<InputMethodDescriptors> | 120 scoped_ptr<InputMethodDescriptors> |
124 InputMethodManagerImpl::GetActiveInputMethods() const { | 121 InputMethodManagerImpl::GetActiveInputMethods() const { |
125 scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors); | 122 scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors); |
126 // Build the active input method descriptors from the active input | 123 // Build the active input method descriptors from the active input |
127 // methods cache |active_input_method_ids_|. | 124 // methods cache |active_input_method_ids_|. |
128 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { | 125 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 active_input_method_ids_.swap(layouts); | 219 active_input_method_ids_.swap(layouts); |
223 | 220 |
224 // Initialize candidate window controller and widgets such as | 221 // Initialize candidate window controller and widgets such as |
225 // candidate window, infolist and mode indicator. Note, mode | 222 // candidate window, infolist and mode indicator. Note, mode |
226 // indicator is used by only keyboard layout input methods. | 223 // indicator is used by only keyboard layout input methods. |
227 if (active_input_method_ids_.size() > 1) | 224 if (active_input_method_ids_.size() > 1) |
228 MaybeInitializeCandidateWindowController(); | 225 MaybeInitializeCandidateWindowController(); |
229 | 226 |
230 // you can pass empty |initial_layout|. | 227 // you can pass empty |initial_layout|. |
231 ChangeInputMethod(initial_layouts.empty() ? "" : | 228 ChangeInputMethod(initial_layouts.empty() ? "" : |
232 extension_ime_util::GetInputMethodIDByKeyboardLayout( | 229 extension_ime_util::GetInputMethodIDByEngineID(initial_layouts[0])); |
233 initial_layouts[0])); | |
234 } | 230 } |
235 | 231 |
236 // Adds new input method to given list. | 232 // Adds new input method to given list. |
237 bool InputMethodManagerImpl::EnableInputMethodImpl( | 233 bool InputMethodManagerImpl::EnableInputMethodImpl( |
238 const std::string& input_method_id, | 234 const std::string& input_method_id, |
239 std::vector<std::string>* new_active_input_method_ids) const { | 235 std::vector<std::string>* new_active_input_method_ids) const { |
240 DCHECK(new_active_input_method_ids); | 236 DCHECK(new_active_input_method_ids); |
241 if (!util_.IsValidInputMethodId(input_method_id)) { | 237 if (!util_.IsValidInputMethodId(input_method_id)) { |
242 DVLOG(1) << "EnableInputMethod: Invalid ID: " << input_method_id; | 238 DVLOG(1) << "EnableInputMethod: Invalid ID: " << input_method_id; |
243 return false; | 239 return false; |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 if (active_input_method_ids_.empty()) { | 659 if (active_input_method_ids_.empty()) { |
664 DVLOG(1) << "active input method is empty"; | 660 DVLOG(1) << "active input method is empty"; |
665 return false; | 661 return false; |
666 } | 662 } |
667 | 663 |
668 // Get the list of input method ids for the |accelerator|. For example, get | 664 // Get the list of input method ids for the |accelerator|. For example, get |
669 // { "mozc-hangul", "xkb:kr:kr104:kor" } for ui::VKEY_DBE_SBCSCHAR. | 665 // { "mozc-hangul", "xkb:kr:kr104:kor" } for ui::VKEY_DBE_SBCSCHAR. |
670 std::vector<std::string> input_method_ids_to_switch; | 666 std::vector<std::string> input_method_ids_to_switch; |
671 switch (accelerator.key_code()) { | 667 switch (accelerator.key_code()) { |
672 case ui::VKEY_CONVERT: // Henkan key on JP106 keyboard | 668 case ui::VKEY_CONVERT: // Henkan key on JP106 keyboard |
673 input_method_ids_to_switch.push_back(nacl_mozc_jp_id); | 669 input_method_ids_to_switch.push_back( |
| 670 extension_ime_util::GetInputMethodIDByEngineID("nacl_mozc_jp")); |
674 break; | 671 break; |
675 case ui::VKEY_NONCONVERT: // Muhenkan key on JP106 keyboard | 672 case ui::VKEY_NONCONVERT: // Muhenkan key on JP106 keyboard |
676 input_method_ids_to_switch.push_back("xkb:jp::jpn"); | 673 input_method_ids_to_switch.push_back( |
| 674 extension_ime_util::GetInputMethodIDByEngineID("xkb:jp::jpn")); |
677 break; | 675 break; |
678 case ui::VKEY_DBE_SBCSCHAR: // ZenkakuHankaku key on JP106 keyboard | 676 case ui::VKEY_DBE_SBCSCHAR: // ZenkakuHankaku key on JP106 keyboard |
679 case ui::VKEY_DBE_DBCSCHAR: | 677 case ui::VKEY_DBE_DBCSCHAR: |
680 input_method_ids_to_switch.push_back(nacl_mozc_jp_id); | 678 input_method_ids_to_switch.push_back( |
681 input_method_ids_to_switch.push_back("xkb:jp::jpn"); | 679 extension_ime_util::GetInputMethodIDByEngineID("nacl_mozc_jp")); |
| 680 input_method_ids_to_switch.push_back( |
| 681 extension_ime_util::GetInputMethodIDByEngineID("xkb:jp::jpn")); |
682 break; | 682 break; |
683 default: | 683 default: |
684 NOTREACHED(); | 684 NOTREACHED(); |
685 break; | 685 break; |
686 } | 686 } |
687 if (input_method_ids_to_switch.empty()) { | 687 if (input_method_ids_to_switch.empty()) { |
688 DVLOG(1) << "Unexpected VKEY: " << accelerator.key_code(); | 688 DVLOG(1) << "Unexpected VKEY: " << accelerator.key_code(); |
689 return false; | 689 return false; |
690 } | 690 } |
691 | 691 |
692 MigrateInputMethods(&input_method_ids_to_switch); | |
693 | |
694 // Obtain the intersection of input_method_ids_to_switch and | 692 // Obtain the intersection of input_method_ids_to_switch and |
695 // active_input_method_ids_. The order of IDs in active_input_method_ids_ is | 693 // active_input_method_ids_. The order of IDs in active_input_method_ids_ is |
696 // preserved. | 694 // preserved. |
697 std::vector<std::string> ids; | 695 std::vector<std::string> ids; |
698 for (size_t i = 0; i < input_method_ids_to_switch.size(); ++i) { | 696 for (size_t i = 0; i < input_method_ids_to_switch.size(); ++i) { |
699 const std::string& id = input_method_ids_to_switch[i]; | 697 const std::string& id = input_method_ids_to_switch[i]; |
700 if (Contains(active_input_method_ids_, id)) | 698 if (Contains(active_input_method_ids_, id)) |
701 ids.push_back(id); | 699 ids.push_back(id); |
702 } | 700 } |
703 if (ids.empty()) { | 701 if (ids.empty()) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 CandidateWindowController::CreateCandidateWindowController()); | 867 CandidateWindowController::CreateCandidateWindowController()); |
870 candidate_window_controller_->AddObserver(this); | 868 candidate_window_controller_->AddObserver(this); |
871 } | 869 } |
872 | 870 |
873 Profile* InputMethodManagerImpl::GetProfile() const { | 871 Profile* InputMethodManagerImpl::GetProfile() const { |
874 return ProfileManager::GetActiveUserProfile(); | 872 return ProfileManager::GetActiveUserProfile(); |
875 } | 873 } |
876 | 874 |
877 } // namespace input_method | 875 } // namespace input_method |
878 } // namespace chromeos | 876 } // namespace chromeos |
OLD | NEW |