| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 if (state_ == STATE_TERMINATING) | 569 if (state_ == STATE_TERMINATING) |
| 569 return; | 570 return; |
| 570 | 571 |
| 571 if (!extension_ime_util::IsExtensionIME(id) && | 572 if (!extension_ime_util::IsExtensionIME(id) && |
| 572 !ComponentExtensionIMEManager::IsComponentExtensionIMEId(id)) { | 573 !ComponentExtensionIMEManager::IsComponentExtensionIMEId(id)) { |
| 573 DVLOG(1) << id << " is not a valid extension input method ID."; | 574 DVLOG(1) << id << " is not a valid extension input method ID."; |
| 574 return; | 575 return; |
| 575 } | 576 } |
| 576 | 577 |
| 577 extra_input_methods_[id] = | 578 extra_input_methods_[id] = |
| 578 InputMethodDescriptor(id, name, layouts, languages, options_url); | 579 InputMethodDescriptor(id, name, layouts, languages, false, options_url); |
| 579 if (Contains(enabled_extension_imes_, id) && | 580 if (Contains(enabled_extension_imes_, id) && |
| 580 !ComponentExtensionIMEManager::IsComponentExtensionIMEId(id)) { | 581 !ComponentExtensionIMEManager::IsComponentExtensionIMEId(id)) { |
| 581 if (!Contains(active_input_method_ids_, id)) { | 582 if (!Contains(active_input_method_ids_, id)) { |
| 582 active_input_method_ids_.push_back(id); | 583 active_input_method_ids_.push_back(id); |
| 583 } else { | 584 } else { |
| 584 DVLOG(1) << "AddInputMethodExtension: alread added: " | 585 DVLOG(1) << "AddInputMethodExtension: alread added: " |
| 585 << id << ", " << name; | 586 << id << ", " << name; |
| 586 // Call Start() anyway, just in case. | 587 // Call Start() anyway, just in case. |
| 587 } | 588 } |
| 588 | 589 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 // We'll add the hardware keyboard if it's not included in | 932 // We'll add the hardware keyboard if it's not included in |
| 932 // |active_input_method_list| so that the user can always use the hardware | 933 // |active_input_method_list| so that the user can always use the hardware |
| 933 // keyboard on the screen locker. | 934 // keyboard on the screen locker. |
| 934 bool should_add_hardware_keyboard = true; | 935 bool should_add_hardware_keyboard = true; |
| 935 | 936 |
| 936 active_input_method_ids_.clear(); | 937 active_input_method_ids_.clear(); |
| 937 for (size_t i = 0; i < saved_active_input_method_ids_.size(); ++i) { | 938 for (size_t i = 0; i < saved_active_input_method_ids_.size(); ++i) { |
| 938 const std::string& input_method_id = saved_active_input_method_ids_[i]; | 939 const std::string& input_method_id = saved_active_input_method_ids_[i]; |
| 939 // Skip if it's not a keyboard layout. Drop input methods including | 940 // Skip if it's not a keyboard layout. Drop input methods including |
| 940 // extension ones. | 941 // extension ones. |
| 941 if (!InputMethodUtil::IsKeyboardLayout(input_method_id)) | 942 if (!IsLoginKeyboard(input_method_id)) |
| 942 continue; | 943 continue; |
| 943 active_input_method_ids_.push_back(input_method_id); | 944 active_input_method_ids_.push_back(input_method_id); |
| 944 if (input_method_id == hardware_keyboard_id) | 945 if (input_method_id == hardware_keyboard_id) |
| 945 should_add_hardware_keyboard = false; | 946 should_add_hardware_keyboard = false; |
| 946 } | 947 } |
| 947 if (should_add_hardware_keyboard) | 948 if (should_add_hardware_keyboard) |
| 948 active_input_method_ids_.push_back(hardware_keyboard_id); | 949 active_input_method_ids_.push_back(hardware_keyboard_id); |
| 949 | 950 |
| 950 ChangeInputMethod(current_input_method_.id()); | 951 ChangeInputMethod(current_input_method_.id()); |
| 951 } | 952 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 else | 984 else |
| 984 DVLOG(1) << "Failed to initialize the candidate window controller"; | 985 DVLOG(1) << "Failed to initialize the candidate window controller"; |
| 985 } | 986 } |
| 986 | 987 |
| 987 bool InputMethodManagerImpl::IsIBusConnectionAlive() { | 988 bool InputMethodManagerImpl::IsIBusConnectionAlive() { |
| 988 return DBusThreadManager::Get() && DBusThreadManager::Get()->GetIBusClient(); | 989 return DBusThreadManager::Get() && DBusThreadManager::Get()->GetIBusClient(); |
| 989 } | 990 } |
| 990 | 991 |
| 991 } // namespace input_method | 992 } // namespace input_method |
| 992 } // namespace chromeos | 993 } // namespace chromeos |
| OLD | NEW |