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_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 if (active_input_method_ids_.empty()) { | 644 if (active_input_method_ids_.empty()) { |
649 DVLOG(1) << "active input method is empty"; | 645 DVLOG(1) << "active input method is empty"; |
650 return false; | 646 return false; |
651 } | 647 } |
652 | 648 |
653 // Get the list of input method ids for the |accelerator|. For example, get | 649 // Get the list of input method ids for the |accelerator|. For example, get |
654 // { "mozc-hangul", "xkb:kr:kr104:kor" } for ui::VKEY_DBE_SBCSCHAR. | 650 // { "mozc-hangul", "xkb:kr:kr104:kor" } for ui::VKEY_DBE_SBCSCHAR. |
655 std::vector<std::string> input_method_ids_to_switch; | 651 std::vector<std::string> input_method_ids_to_switch; |
656 switch (accelerator.key_code()) { | 652 switch (accelerator.key_code()) { |
657 case ui::VKEY_CONVERT: // Henkan key on JP106 keyboard | 653 case ui::VKEY_CONVERT: // Henkan key on JP106 keyboard |
658 input_method_ids_to_switch.push_back(nacl_mozc_jp_id); | 654 input_method_ids_to_switch.push_back( |
| 655 extension_ime_util::GetInputMethodIDByEngineID("nacl_mozc_jp")); |
659 break; | 656 break; |
660 case ui::VKEY_NONCONVERT: // Muhenkan key on JP106 keyboard | 657 case ui::VKEY_NONCONVERT: // Muhenkan key on JP106 keyboard |
661 input_method_ids_to_switch.push_back("xkb:jp::jpn"); | 658 input_method_ids_to_switch.push_back( |
| 659 extension_ime_util::GetInputMethodIDByEngineID("xkb:jp::jpn")); |
662 break; | 660 break; |
663 case ui::VKEY_DBE_SBCSCHAR: // ZenkakuHankaku key on JP106 keyboard | 661 case ui::VKEY_DBE_SBCSCHAR: // ZenkakuHankaku key on JP106 keyboard |
664 case ui::VKEY_DBE_DBCSCHAR: | 662 case ui::VKEY_DBE_DBCSCHAR: |
665 input_method_ids_to_switch.push_back(nacl_mozc_jp_id); | 663 input_method_ids_to_switch.push_back( |
666 input_method_ids_to_switch.push_back("xkb:jp::jpn"); | 664 extension_ime_util::GetInputMethodIDByEngineID("nacl_mozc_jp")); |
| 665 input_method_ids_to_switch.push_back( |
| 666 extension_ime_util::GetInputMethodIDByEngineID("xkb:jp::jpn")); |
667 break; | 667 break; |
668 default: | 668 default: |
669 NOTREACHED(); | 669 NOTREACHED(); |
670 break; | 670 break; |
671 } | 671 } |
672 if (input_method_ids_to_switch.empty()) { | 672 if (input_method_ids_to_switch.empty()) { |
673 DVLOG(1) << "Unexpected VKEY: " << accelerator.key_code(); | 673 DVLOG(1) << "Unexpected VKEY: " << accelerator.key_code(); |
674 return false; | 674 return false; |
675 } | 675 } |
676 | 676 |
677 MigrateXkbInputMethods(&input_method_ids_to_switch); | |
678 | |
679 // Obtain the intersection of input_method_ids_to_switch and | 677 // Obtain the intersection of input_method_ids_to_switch and |
680 // active_input_method_ids_. The order of IDs in active_input_method_ids_ is | 678 // active_input_method_ids_. The order of IDs in active_input_method_ids_ is |
681 // preserved. | 679 // preserved. |
682 std::vector<std::string> ids; | 680 std::vector<std::string> ids; |
683 for (size_t i = 0; i < input_method_ids_to_switch.size(); ++i) { | 681 for (size_t i = 0; i < input_method_ids_to_switch.size(); ++i) { |
684 const std::string& id = input_method_ids_to_switch[i]; | 682 const std::string& id = input_method_ids_to_switch[i]; |
685 if (Contains(active_input_method_ids_, id)) | 683 if (Contains(active_input_method_ids_, id)) |
686 ids.push_back(id); | 684 ids.push_back(id); |
687 } | 685 } |
688 if (ids.empty()) { | 686 if (ids.empty()) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 CandidateWindowController::CreateCandidateWindowController()); | 852 CandidateWindowController::CreateCandidateWindowController()); |
855 candidate_window_controller_->AddObserver(this); | 853 candidate_window_controller_->AddObserver(this); |
856 } | 854 } |
857 | 855 |
858 Profile* InputMethodManagerImpl::GetProfile() const { | 856 Profile* InputMethodManagerImpl::GetProfile() const { |
859 return ProfileManager::GetActiveUserProfile(); | 857 return ProfileManager::GetActiveUserProfile(); |
860 } | 858 } |
861 | 859 |
862 } // namespace input_method | 860 } // namespace input_method |
863 } // namespace chromeos | 861 } // namespace chromeos |
OLD | NEW |