| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include <glib.h> | 9 #include <glib.h> |
| 10 | 10 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 122 } |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| 125 | 125 |
| 126 } // namespace | 126 } // namespace |
| 127 | 127 |
| 128 namespace chromeos { | 128 namespace chromeos { |
| 129 namespace input_method { | 129 namespace input_method { |
| 130 | 130 |
| 131 // The implementation of InputMethodManager. | 131 // The implementation of InputMethodManager. |
| 132 class InputMethodManagerImpl : public HotkeyManager::Observer, | 132 class InputMethodManagerImpl |
| 133 public InputMethodManager, | 133 : public HotkeyManager::Observer, |
| 134 public content::NotificationObserver, | 134 public InputMethodManager, |
| 135 public IBusController::Observer { | 135 public content::NotificationObserver, |
| 136 #if !defined(USE_VIRTUAL_KEYBOARD) |
| 137 public CandidateWindowController::Observer, |
| 138 #endif |
| 139 public IBusController::Observer { |
| 136 public: | 140 public: |
| 137 InputMethodManagerImpl() | 141 InputMethodManagerImpl() |
| 138 : ibus_controller_(IBusController::Create()), | 142 : ibus_controller_(IBusController::Create()), |
| 139 should_launch_ime_(false), | 143 should_launch_ime_(false), |
| 140 ime_connected_(false), | 144 ime_connected_(false), |
| 141 defer_ime_startup_(false), | 145 defer_ime_startup_(false), |
| 142 enable_auto_ime_shutdown_(true), | 146 enable_auto_ime_shutdown_(true), |
| 143 shutting_down_(false), | 147 shutting_down_(false), |
| 144 ibus_daemon_process_handle_(base::kNullProcessHandle), | 148 ibus_daemon_process_handle_(base::kNullProcessHandle), |
| 145 util_(ibus_controller_->GetSupportedInputMethods()), | 149 util_(ibus_controller_->GetSupportedInputMethods()), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 171 } | 175 } |
| 172 } | 176 } |
| 173 | 177 |
| 174 AddHotkeys(); | 178 AddHotkeys(); |
| 175 hotkey_manager_.AddObserver(this); | 179 hotkey_manager_.AddObserver(this); |
| 176 } | 180 } |
| 177 | 181 |
| 178 virtual ~InputMethodManagerImpl() { | 182 virtual ~InputMethodManagerImpl() { |
| 179 hotkey_manager_.RemoveObserver(this); | 183 hotkey_manager_.RemoveObserver(this); |
| 180 ibus_controller_->RemoveObserver(this); | 184 ibus_controller_->RemoveObserver(this); |
| 185 #if !defined(USE_VIRTUAL_KEYBOARD) |
| 186 if (candidate_window_controller_.get()) |
| 187 candidate_window_controller_->RemoveObserver(this); |
| 188 #endif |
| 181 } | 189 } |
| 182 | 190 |
| 183 virtual void AddObserver(InputMethodManager::Observer* observer) { | 191 virtual void AddObserver(InputMethodManager::Observer* observer) { |
| 184 observers_.AddObserver(observer); | 192 observers_.AddObserver(observer); |
| 185 } | 193 } |
| 186 | 194 |
| 187 virtual void RemoveObserver(InputMethodManager::Observer* observer) { | 195 virtual void RemoveObserver(InputMethodManager::Observer* observer) { |
| 188 observers_.RemoveObserver(observer); | 196 observers_.RemoveObserver(observer); |
| 189 } | 197 } |
| 190 | 198 |
| 199 virtual void AddCandidateWindowObserver( |
| 200 InputMethodManager::CandidateWindowObserver* observer) { |
| 201 candidate_window_observers_.AddObserver(observer); |
| 202 } |
| 203 |
| 204 virtual void RemoveCandidateWindowObserver( |
| 205 InputMethodManager::CandidateWindowObserver* observer) { |
| 206 candidate_window_observers_.RemoveObserver(observer); |
| 207 } |
| 208 |
| 191 virtual void AddPreLoginPreferenceObserver( | 209 virtual void AddPreLoginPreferenceObserver( |
| 192 InputMethodManager::PreferenceObserver* observer) { | 210 InputMethodManager::PreferenceObserver* observer) { |
| 193 if (!pre_login_preference_observers_.size()) { | 211 if (!pre_login_preference_observers_.size()) { |
| 194 observer->FirstObserverIsAdded(this); | 212 observer->FirstObserverIsAdded(this); |
| 195 } | 213 } |
| 196 pre_login_preference_observers_.AddObserver(observer); | 214 pre_login_preference_observers_.AddObserver(observer); |
| 197 } | 215 } |
| 198 | 216 |
| 199 virtual void RemovePreLoginPreferenceObserver( | 217 virtual void RemovePreLoginPreferenceObserver( |
| 200 InputMethodManager::PreferenceObserver* observer) { | 218 InputMethodManager::PreferenceObserver* observer) { |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 break; | 540 break; |
| 523 case kJapaneseInputMethod: | 541 case kJapaneseInputMethod: |
| 524 case kJapaneseLayout: | 542 case kJapaneseLayout: |
| 525 case kJapaneseInputMethodOrLayout: | 543 case kJapaneseInputMethodOrLayout: |
| 526 case kKoreanInputMethodOrLayout: | 544 case kKoreanInputMethodOrLayout: |
| 527 SwitchToInputMethod(event); | 545 SwitchToInputMethod(event); |
| 528 break; | 546 break; |
| 529 } | 547 } |
| 530 } | 548 } |
| 531 | 549 |
| 550 virtual void CandidateWindowOpened() { |
| 551 FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver, |
| 552 candidate_window_observers_, |
| 553 CandidateWindowOpened(this)); |
| 554 } |
| 555 |
| 556 virtual void CandidateWindowClosed() { |
| 557 FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver, |
| 558 candidate_window_observers_, |
| 559 CandidateWindowClosed(this)); |
| 560 } |
| 561 |
| 532 virtual void SwitchToNextInputMethod() { | 562 virtual void SwitchToNextInputMethod() { |
| 533 // Sanity checks. | 563 // Sanity checks. |
| 534 if (active_input_method_ids_.empty()) { | 564 if (active_input_method_ids_.empty()) { |
| 535 LOG(ERROR) << "active input method is empty"; | 565 LOG(ERROR) << "active input method is empty"; |
| 536 return; | 566 return; |
| 537 } | 567 } |
| 538 if (current_input_method_.id().empty()) { | 568 if (current_input_method_.id().empty()) { |
| 539 LOG(ERROR) << "current_input_method_ is unknown"; | 569 LOG(ERROR) << "current_input_method_ is unknown"; |
| 540 return; | 570 return; |
| 541 } | 571 } |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 } | 1128 } |
| 1099 | 1129 |
| 1100 if (shutting_down_) { | 1130 if (shutting_down_) { |
| 1101 NOTREACHED() << "Trying to launch input method while shutting down"; | 1131 NOTREACHED() << "Trying to launch input method while shutting down"; |
| 1102 return false; | 1132 return false; |
| 1103 } | 1133 } |
| 1104 | 1134 |
| 1105 #if !defined(USE_VIRTUAL_KEYBOARD) | 1135 #if !defined(USE_VIRTUAL_KEYBOARD) |
| 1106 if (!candidate_window_controller_.get()) { | 1136 if (!candidate_window_controller_.get()) { |
| 1107 candidate_window_controller_.reset(new CandidateWindowController); | 1137 candidate_window_controller_.reset(new CandidateWindowController); |
| 1108 if (!candidate_window_controller_->Init()) { | 1138 if (candidate_window_controller_->Init()) { |
| 1139 candidate_window_controller_->AddObserver(this); |
| 1140 } else { |
| 1109 LOG(WARNING) << "Failed to initialize the candidate window controller"; | 1141 LOG(WARNING) << "Failed to initialize the candidate window controller"; |
| 1110 } | 1142 } |
| 1111 } | 1143 } |
| 1112 #endif | 1144 #endif |
| 1113 | 1145 |
| 1114 if (ibus_daemon_process_handle_ != base::kNullProcessHandle) { | 1146 if (ibus_daemon_process_handle_ != base::kNullProcessHandle) { |
| 1115 return false; // ibus-daemon is already running. | 1147 return false; // ibus-daemon is already running. |
| 1116 } | 1148 } |
| 1117 | 1149 |
| 1118 // TODO(zork): Send output to /var/log/ibus.log | 1150 // TODO(zork): Send output to /var/log/ibus.log |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 // content::NotificationObserver implementation: | 1206 // content::NotificationObserver implementation: |
| 1175 void Observe(int type, | 1207 void Observe(int type, |
| 1176 const content::NotificationSource& source, | 1208 const content::NotificationSource& source, |
| 1177 const content::NotificationDetails& details) { | 1209 const content::NotificationDetails& details) { |
| 1178 // Stop the input method daemon on browser shutdown. | 1210 // Stop the input method daemon on browser shutdown. |
| 1179 if (type == content::NOTIFICATION_APP_TERMINATING) { | 1211 if (type == content::NOTIFICATION_APP_TERMINATING) { |
| 1180 shutting_down_ = true; | 1212 shutting_down_ = true; |
| 1181 notification_registrar_.RemoveAll(); | 1213 notification_registrar_.RemoveAll(); |
| 1182 StopInputMethodDaemon(); | 1214 StopInputMethodDaemon(); |
| 1183 #if !defined(USE_VIRTUAL_KEYBOARD) | 1215 #if !defined(USE_VIRTUAL_KEYBOARD) |
| 1216 if (candidate_window_controller_.get()) |
| 1217 candidate_window_controller_->RemoveObserver(this); |
| 1184 candidate_window_controller_.reset(NULL); | 1218 candidate_window_controller_.reset(NULL); |
| 1185 #endif | 1219 #endif |
| 1186 } | 1220 } |
| 1187 } | 1221 } |
| 1188 | 1222 |
| 1189 void UpdateInputMethodSpecificHotkeys() { | 1223 void UpdateInputMethodSpecificHotkeys() { |
| 1190 // Remove all input method specific hotkeys first. | 1224 // Remove all input method specific hotkeys first. |
| 1191 for (size_t i = 0; i < kInputMethodSpecificHotkeySettingsLen; ++i) { | 1225 for (size_t i = 0; i < kInputMethodSpecificHotkeySettingsLen; ++i) { |
| 1192 hotkey_manager_.RemoveHotkey( | 1226 hotkey_manager_.RemoveHotkey( |
| 1193 kInputMethodSpecificHotkeySettings[i].event_id); | 1227 kInputMethodSpecificHotkeySettings[i].event_id); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 if (iter == ids.end()) { | 1328 if (iter == ids.end()) { |
| 1295 iter = ids.begin(); | 1329 iter = ids.begin(); |
| 1296 } | 1330 } |
| 1297 ChangeInputMethod(*iter); | 1331 ChangeInputMethod(*iter); |
| 1298 } | 1332 } |
| 1299 | 1333 |
| 1300 // The IBus controller is used to control the input method status and | 1334 // The IBus controller is used to control the input method status and |
| 1301 // allow allow callbacks when the input method status changes. | 1335 // allow allow callbacks when the input method status changes. |
| 1302 scoped_ptr<IBusController> ibus_controller_; | 1336 scoped_ptr<IBusController> ibus_controller_; |
| 1303 ObserverList<InputMethodManager::Observer> observers_; | 1337 ObserverList<InputMethodManager::Observer> observers_; |
| 1338 ObserverList<InputMethodManager::CandidateWindowObserver> |
| 1339 candidate_window_observers_; |
| 1304 ObserverList<PreferenceObserver> pre_login_preference_observers_; | 1340 ObserverList<PreferenceObserver> pre_login_preference_observers_; |
| 1305 ObserverList<PreferenceObserver> post_login_preference_observers_; | 1341 ObserverList<PreferenceObserver> post_login_preference_observers_; |
| 1306 ObserverList<VirtualKeyboardObserver> virtual_keyboard_observers_; | 1342 ObserverList<VirtualKeyboardObserver> virtual_keyboard_observers_; |
| 1307 | 1343 |
| 1308 // The input method which was/is selected. | 1344 // The input method which was/is selected. |
| 1309 InputMethodDescriptor previous_input_method_; | 1345 InputMethodDescriptor previous_input_method_; |
| 1310 InputMethodDescriptor current_input_method_; | 1346 InputMethodDescriptor current_input_method_; |
| 1311 | 1347 |
| 1312 // The input method properties which the current input method uses. The list | 1348 // The input method properties which the current input method uses. The list |
| 1313 // might be empty when no input method is used. | 1349 // might be empty when no input method is used. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1392 return InputMethodManagerImpl::GetInstance(); | 1428 return InputMethodManagerImpl::GetInstance(); |
| 1393 } | 1429 } |
| 1394 | 1430 |
| 1395 } // namespace input_method | 1431 } // namespace input_method |
| 1396 } // namespace chromeos | 1432 } // namespace chromeos |
| 1397 | 1433 |
| 1398 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 1434 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 1399 // won't be deleted until it's last InvokeLater is run. | 1435 // won't be deleted until it's last InvokeLater is run. |
| 1400 DISABLE_RUNNABLE_METHOD_REFCOUNT( | 1436 DISABLE_RUNNABLE_METHOD_REFCOUNT( |
| 1401 chromeos::input_method::InputMethodManagerImpl); | 1437 chromeos::input_method::InputMethodManagerImpl); |
| OLD | NEW |