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 "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 } kMigrationHangulKeyboardToInputMethodID[] = { | 108 } kMigrationHangulKeyboardToInputMethodID[] = { |
109 { "2", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_2set" }, | 109 { "2", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_2set" }, |
110 { "3f", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3setfinal" }, | 110 { "3f", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3setfinal" }, |
111 { "39", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3set390" }, | 111 { "39", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3set390" }, |
112 { "3s", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3setnoshift" }, | 112 { "3s", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3setnoshift" }, |
113 { "ro", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_romaja" }, | 113 { "ro", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_romaja" }, |
114 }; | 114 }; |
115 | 115 |
116 } // namespace | 116 } // namespace |
117 | 117 |
118 bool InputMethodManagerImpl::IsFullLatinKeyboard( | 118 bool InputMethodManagerImpl::IsLoginKeyboard( |
119 const std::string& layout) const { | 119 const std::string& layout) const { |
120 const std::string& lang = util_.GetLanguageCodeFromInputMethodId(layout); | 120 const InputMethodDescriptor* ime = |
121 return full_latin_keyboard_checker.IsFullLatinKeyboard(layout, lang); | 121 util_.GetInputMethodDescriptorFromId(layout); |
| 122 return ime ? ime->is_login_keyboard() : false; |
122 } | 123 } |
123 | 124 |
124 InputMethodManagerImpl::InputMethodManagerImpl( | 125 InputMethodManagerImpl::InputMethodManagerImpl( |
125 scoped_ptr<InputMethodDelegate> delegate) | 126 scoped_ptr<InputMethodDelegate> delegate) |
126 : delegate_(delegate.Pass()), | 127 : delegate_(delegate.Pass()), |
127 state_(STATE_LOGIN_SCREEN), | 128 state_(STATE_LOGIN_SCREEN), |
128 util_(delegate_.get(), GetSupportedInputMethods()), | 129 util_(delegate_.get(), GetSupportedInputMethods()), |
129 component_extension_ime_manager_(new ComponentExtensionIMEManager()), | 130 component_extension_ime_manager_(new ComponentExtensionIMEManager()), |
130 weak_ptr_factory_(this) { | 131 weak_ptr_factory_(this) { |
131 IBusDaemonController::GetInstance()->AddObserver(this); | 132 IBusDaemonController::GetInstance()->AddObserver(this); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 &candidates); | 240 &candidates); |
240 // Add the hardware keyboard as well. We should always add this so users | 241 // Add the hardware keyboard as well. We should always add this so users |
241 // can use the hardware keyboard on the login screen and the screen locker. | 242 // can use the hardware keyboard on the login screen and the screen locker. |
242 candidates.push_back(util_.GetHardwareInputMethodId()); | 243 candidates.push_back(util_.GetHardwareInputMethodId()); |
243 | 244 |
244 std::vector<std::string> layouts; | 245 std::vector<std::string> layouts; |
245 // First, add the initial input method ID, if it's requested, to | 246 // First, add the initial input method ID, if it's requested, to |
246 // layouts, so it appears first on the list of active input | 247 // layouts, so it appears first on the list of active input |
247 // methods at the input language status menu. | 248 // methods at the input language status menu. |
248 if (util_.IsValidInputMethodId(initial_layout) && | 249 if (util_.IsValidInputMethodId(initial_layout) && |
249 InputMethodUtil::IsKeyboardLayout(initial_layout)) { | 250 IsLoginKeyboard(initial_layout)) { |
250 layouts.push_back(initial_layout); | 251 layouts.push_back(initial_layout); |
251 } else if (!initial_layout.empty()) { | 252 } else if (!initial_layout.empty()) { |
252 DVLOG(1) << "EnableLayouts: ignoring non-keyboard or invalid ID: " | 253 DVLOG(1) << "EnableLayouts: ignoring non-keyboard or invalid ID: " |
253 << initial_layout; | 254 << initial_layout; |
254 } | 255 } |
255 | 256 |
256 // Add candidates to layouts, while skipping duplicates. | 257 // Add candidates to layouts, while skipping duplicates. |
257 for (size_t i = 0; i < candidates.size(); ++i) { | 258 for (size_t i = 0; i < candidates.size(); ++i) { |
258 const std::string& candidate = candidates[i]; | 259 const std::string& candidate = candidates[i]; |
259 // Not efficient, but should be fine, as the two vectors are very | 260 // Not efficient, but should be fine, as the two vectors are very |
260 // short (2-5 items). | 261 // short (2-5 items). |
261 if (!Contains(layouts, candidate)) | 262 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate)) |
262 layouts.push_back(candidate); | 263 layouts.push_back(candidate); |
263 } | 264 } |
264 | 265 |
265 active_input_method_ids_.swap(layouts); | 266 active_input_method_ids_.swap(layouts); |
266 ChangeInputMethod(initial_layout); // you can pass empty |initial_layout|. | 267 ChangeInputMethod(initial_layout); // you can pass empty |initial_layout|. |
267 } | 268 } |
268 | 269 |
269 // Adds new input method to given list. | 270 // Adds new input method to given list. |
270 bool InputMethodManagerImpl::EnableInputMethodImpl( | 271 bool InputMethodManagerImpl::EnableInputMethodImpl( |
271 const std::string& input_method_id, | 272 const std::string& input_method_id, |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 if (state_ == STATE_TERMINATING) | 556 if (state_ == STATE_TERMINATING) |
556 return; | 557 return; |
557 | 558 |
558 if (!extension_ime_util::IsExtensionIME(id) && | 559 if (!extension_ime_util::IsExtensionIME(id) && |
559 !ComponentExtensionIMEManager::IsComponentExtensionIMEId(id)) { | 560 !ComponentExtensionIMEManager::IsComponentExtensionIMEId(id)) { |
560 DVLOG(1) << id << " is not a valid extension input method ID."; | 561 DVLOG(1) << id << " is not a valid extension input method ID."; |
561 return; | 562 return; |
562 } | 563 } |
563 | 564 |
564 extra_input_methods_[id] = | 565 extra_input_methods_[id] = |
565 InputMethodDescriptor(id, name, layouts, languages, options_url); | 566 InputMethodDescriptor(id, name, layouts, languages, false, options_url); |
566 if (Contains(enabled_extension_imes_, id) && | 567 if (Contains(enabled_extension_imes_, id) && |
567 !ComponentExtensionIMEManager::IsComponentExtensionIMEId(id)) { | 568 !ComponentExtensionIMEManager::IsComponentExtensionIMEId(id)) { |
568 if (!Contains(active_input_method_ids_, id)) { | 569 if (!Contains(active_input_method_ids_, id)) { |
569 active_input_method_ids_.push_back(id); | 570 active_input_method_ids_.push_back(id); |
570 } else { | 571 } else { |
571 DVLOG(1) << "AddInputMethodExtension: alread added: " | 572 DVLOG(1) << "AddInputMethodExtension: alread added: " |
572 << id << ", " << name; | 573 << id << ", " << name; |
573 // Call Start() anyway, just in case. | 574 // Call Start() anyway, just in case. |
574 } | 575 } |
575 | 576 |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 // We'll add the hardware keyboard if it's not included in | 919 // We'll add the hardware keyboard if it's not included in |
919 // |active_input_method_list| so that the user can always use the hardware | 920 // |active_input_method_list| so that the user can always use the hardware |
920 // keyboard on the screen locker. | 921 // keyboard on the screen locker. |
921 bool should_add_hardware_keyboard = true; | 922 bool should_add_hardware_keyboard = true; |
922 | 923 |
923 active_input_method_ids_.clear(); | 924 active_input_method_ids_.clear(); |
924 for (size_t i = 0; i < saved_active_input_method_ids_.size(); ++i) { | 925 for (size_t i = 0; i < saved_active_input_method_ids_.size(); ++i) { |
925 const std::string& input_method_id = saved_active_input_method_ids_[i]; | 926 const std::string& input_method_id = saved_active_input_method_ids_[i]; |
926 // Skip if it's not a keyboard layout. Drop input methods including | 927 // Skip if it's not a keyboard layout. Drop input methods including |
927 // extension ones. | 928 // extension ones. |
928 if (!InputMethodUtil::IsKeyboardLayout(input_method_id)) | 929 if (!IsLoginKeyboard(input_method_id)) |
929 continue; | 930 continue; |
930 active_input_method_ids_.push_back(input_method_id); | 931 active_input_method_ids_.push_back(input_method_id); |
931 if (input_method_id == hardware_keyboard_id) | 932 if (input_method_id == hardware_keyboard_id) |
932 should_add_hardware_keyboard = false; | 933 should_add_hardware_keyboard = false; |
933 } | 934 } |
934 if (should_add_hardware_keyboard) | 935 if (should_add_hardware_keyboard) |
935 active_input_method_ids_.push_back(hardware_keyboard_id); | 936 active_input_method_ids_.push_back(hardware_keyboard_id); |
936 | 937 |
937 ChangeInputMethod(current_input_method_.id()); | 938 ChangeInputMethod(current_input_method_.id()); |
938 } | 939 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 else | 971 else |
971 DVLOG(1) << "Failed to initialize the candidate window controller"; | 972 DVLOG(1) << "Failed to initialize the candidate window controller"; |
972 } | 973 } |
973 | 974 |
974 bool InputMethodManagerImpl::IsIBusConnectionAlive() { | 975 bool InputMethodManagerImpl::IsIBusConnectionAlive() { |
975 return DBusThreadManager::Get() && DBusThreadManager::Get()->GetIBusClient(); | 976 return DBusThreadManager::Get() && DBusThreadManager::Get()->GetIBusClient(); |
976 } | 977 } |
977 | 978 |
978 } // namespace input_method | 979 } // namespace input_method |
979 } // namespace chromeos | 980 } // namespace chromeos |
OLD | NEW |