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.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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 }, | 106 }, |
107 }; | 107 }; |
108 | 108 |
109 const size_t kInputMethodSpecificHotkeySettingsLen = | 109 const size_t kInputMethodSpecificHotkeySettingsLen = |
110 arraysize(kInputMethodSpecificHotkeySettings); | 110 arraysize(kInputMethodSpecificHotkeySettings); |
111 #endif | 111 #endif |
112 | 112 |
113 // Finds a property which has |new_prop.key| from |prop_list|, and replaces the | 113 // Finds a property which has |new_prop.key| from |prop_list|, and replaces the |
114 // property with |new_prop|. Returns true if such a property is found. | 114 // property with |new_prop|. Returns true if such a property is found. |
115 bool FindAndUpdateProperty( | 115 bool FindAndUpdateProperty( |
116 const chromeos::input_method::ImeProperty& new_prop, | 116 const chromeos::input_method::InputMethodProperty& new_prop, |
117 chromeos::input_method::ImePropertyList* prop_list) { | 117 chromeos::input_method::InputMethodPropertyList* prop_list) { |
118 for (size_t i = 0; i < prop_list->size(); ++i) { | 118 for (size_t i = 0; i < prop_list->size(); ++i) { |
119 chromeos::input_method::ImeProperty& prop = prop_list->at(i); | 119 chromeos::input_method::InputMethodProperty& prop = prop_list->at(i); |
120 if (prop.key == new_prop.key) { | 120 if (prop.key == new_prop.key) { |
121 const int saved_id = prop.selection_item_id; | 121 const int saved_id = prop.selection_item_id; |
122 // Update the list except the radio id. As written in | 122 // Update the list except the radio id. As written in |
123 // chromeos_input_method.h, |prop.selection_item_id| is dummy. | 123 // chromeos_input_method.h, |prop.selection_item_id| is dummy. |
124 prop = new_prop; | 124 prop = new_prop; |
125 prop.selection_item_id = saved_id; | 125 prop.selection_item_id = saved_id; |
126 return true; | 126 return true; |
127 } | 127 } |
128 } | 128 } |
129 return false; | 129 return false; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 if (InputMethodUtil::IsKeyboardLayout(input_method_id) | 308 if (InputMethodUtil::IsKeyboardLayout(input_method_id) |
309 #if !defined(USE_AURA) | 309 #if !defined(USE_AURA) |
310 // TODO(yusukes): Remove this code when R18 stable is shipped. | 310 // TODO(yusukes): Remove this code when R18 stable is shipped. |
311 // crosbug.com/26245 | 311 // crosbug.com/26245 |
312 && ibus_daemon_process_handle_ == base::kNullProcessHandle | 312 && ibus_daemon_process_handle_ == base::kNullProcessHandle |
313 #endif | 313 #endif |
314 ) { | 314 ) { |
315 // We shouldn't use SetCurrentKeyboardLayoutByName() here. See | 315 // We shouldn't use SetCurrentKeyboardLayoutByName() here. See |
316 // comments at ChangeCurrentInputMethod() for details. | 316 // comments at ChangeCurrentInputMethod() for details. |
317 ChangeCurrentInputMethodFromId(input_method_id); | 317 ChangeCurrentInputMethodFromId(input_method_id); |
318 OnRegisterImeProperties(ImePropertyList()); // notify the button. | 318 OnRegisterImeProperties(InputMethodPropertyList()); // notify the button. |
319 } else { | 319 } else { |
320 // Otherwise, start the input method daemon, and change the input | 320 // Otherwise, start the input method daemon, and change the input |
321 // method via the daemon. | 321 // method via the daemon. |
322 StartInputMethodDaemon(); | 322 StartInputMethodDaemon(); |
323 // ChangeInputMethodViaIBus() fails if the IBus daemon is not | 323 // ChangeInputMethodViaIBus() fails if the IBus daemon is not |
324 // ready yet. In this case, we'll defer the input method change | 324 // ready yet. In this case, we'll defer the input method change |
325 // until the daemon is ready. | 325 // until the daemon is ready. |
326 if (!ChangeInputMethodViaIBus(input_method_id)) { | 326 if (!ChangeInputMethodViaIBus(input_method_id)) { |
327 VLOG(1) << "Failed to change the input method to " << input_method_id | 327 VLOG(1) << "Failed to change the input method to " << input_method_id |
328 << " (deferring)"; | 328 << " (deferring)"; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 std::map<std::string, InputMethodDescriptor>::const_iterator ix = | 470 std::map<std::string, InputMethodDescriptor>::const_iterator ix = |
471 extra_input_method_ids_.find(id); | 471 extra_input_method_ids_.find(id); |
472 if (ix != extra_input_method_ids_.end()) { | 472 if (ix != extra_input_method_ids_.end()) { |
473 *descriptor = ix->second; | 473 *descriptor = ix->second; |
474 return true; | 474 return true; |
475 } else { | 475 } else { |
476 return false; | 476 return false; |
477 } | 477 } |
478 } | 478 } |
479 | 479 |
480 virtual InputMethodDescriptor previous_input_method() const { | 480 virtual InputMethodDescriptor GetPreviousInputMethod() const { |
481 if (previous_input_method_.id().empty()) { | 481 if (previous_input_method_.id().empty()) { |
482 return InputMethodDescriptor::GetFallbackInputMethodDescriptor(); | 482 return InputMethodDescriptor::GetFallbackInputMethodDescriptor(); |
483 } | 483 } |
484 return previous_input_method_; | 484 return previous_input_method_; |
485 } | 485 } |
486 | 486 |
487 virtual InputMethodDescriptor current_input_method() const { | 487 virtual InputMethodDescriptor GetCurrentInputMethod() const { |
488 if (current_input_method_.id().empty()) { | 488 if (current_input_method_.id().empty()) { |
489 return InputMethodDescriptor::GetFallbackInputMethodDescriptor(); | 489 return InputMethodDescriptor::GetFallbackInputMethodDescriptor(); |
490 } | 490 } |
491 return current_input_method_; | 491 return current_input_method_; |
492 } | 492 } |
493 | 493 |
494 virtual ImePropertyList current_ime_properties() const { | 494 virtual InputMethodPropertyList GetCurrentInputMethodProperties() const { |
495 if (should_hide_properties_ || | 495 if (should_hide_properties_ || |
496 InputMethodUtil::IsKeyboardLayout(current_input_method().id())) { | 496 InputMethodUtil::IsKeyboardLayout(GetCurrentInputMethod().id())) { |
497 return ImePropertyList(); | 497 return InputMethodPropertyList(); |
498 } | 498 } |
499 return current_ime_properties_; | 499 return current_ime_properties_; |
500 } | 500 } |
501 | 501 |
502 virtual void SendHandwritingStroke(const HandwritingStroke& stroke) { | 502 virtual void SendHandwritingStroke(const HandwritingStroke& stroke) { |
503 ibus_controller_->SendHandwritingStroke(stroke); | 503 ibus_controller_->SendHandwritingStroke(stroke); |
504 } | 504 } |
505 | 505 |
506 virtual void CancelHandwritingStrokes(int stroke_count) { | 506 virtual void CancelHandwritingStrokes(int stroke_count) { |
507 // TODO(yusukes): Rename the function to CancelHandwritingStrokes. | 507 // TODO(yusukes): Rename the function to CancelHandwritingStrokes. |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 ChangeCurrentInputMethodFromId(value.string_list_value[0]); | 869 ChangeCurrentInputMethodFromId(value.string_list_value[0]); |
870 } | 870 } |
871 DCHECK(!current_input_method_.id().empty()); | 871 DCHECK(!current_input_method_.id().empty()); |
872 | 872 |
873 // Update the indicator. | 873 // Update the indicator. |
874 // TODO(yusukes): Remove ActiveInputMethodsChanged notification in | 874 // TODO(yusukes): Remove ActiveInputMethodsChanged notification in |
875 // FlushImeConfig(). | 875 // FlushImeConfig(). |
876 const size_t num_active_input_methods = GetNumActiveInputMethods(); | 876 const size_t num_active_input_methods = GetNumActiveInputMethods(); |
877 FOR_EACH_OBSERVER(InputMethodManager::Observer, observers_, | 877 FOR_EACH_OBSERVER(InputMethodManager::Observer, observers_, |
878 ActiveInputMethodsChanged(this, | 878 ActiveInputMethodsChanged(this, |
879 current_input_method(), | 879 GetCurrentInputMethod(), |
880 num_active_input_methods)); | 880 num_active_input_methods)); |
881 } | 881 } |
882 } | 882 } |
883 | 883 |
884 // Changes the current input method to |input_method_id| via IBus | 884 // Changes the current input method to |input_method_id| via IBus |
885 // daemon. If the id is not in the preload_engine list, this function | 885 // daemon. If the id is not in the preload_engine list, this function |
886 // changes the current method to the first preloaded engine. Returns | 886 // changes the current method to the first preloaded engine. Returns |
887 // true if the current engine is switched to |input_method_id| or the | 887 // true if the current engine is switched to |input_method_id| or the |
888 // first one. | 888 // first one. |
889 bool ChangeInputMethodViaIBus(const std::string& input_method_id) { | 889 bool ChangeInputMethodViaIBus(const std::string& input_method_id) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 1015 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
1016 LOG(ERROR) << "Not on UI thread"; | 1016 LOG(ERROR) << "Not on UI thread"; |
1017 return; | 1017 return; |
1018 } | 1018 } |
1019 | 1019 |
1020 ChangeCurrentInputMethod(current_input_method); | 1020 ChangeCurrentInputMethod(current_input_method); |
1021 } | 1021 } |
1022 | 1022 |
1023 // IBusController override. | 1023 // IBusController override. |
1024 virtual void OnRegisterImeProperties( | 1024 virtual void OnRegisterImeProperties( |
1025 const ImePropertyList& prop_list) { | 1025 const InputMethodPropertyList& prop_list) { |
1026 // See comments in InputMethodChangedHandler. | 1026 // See comments in InputMethodChangedHandler. |
1027 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 1027 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
1028 LOG(ERROR) << "Not on UI thread"; | 1028 LOG(ERROR) << "Not on UI thread"; |
1029 return; | 1029 return; |
1030 } | 1030 } |
1031 | 1031 |
1032 RegisterProperties(prop_list); | 1032 RegisterProperties(prop_list); |
1033 } | 1033 } |
1034 | 1034 |
1035 // IBusController override. | 1035 // IBusController override. |
1036 virtual void OnUpdateImeProperty( | 1036 virtual void OnUpdateImeProperty( |
1037 const ImePropertyList& prop_list) { | 1037 const InputMethodPropertyList& prop_list) { |
1038 // See comments in InputMethodChangedHandler. | 1038 // See comments in InputMethodChangedHandler. |
1039 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 1039 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
1040 LOG(ERROR) << "Not on UI thread"; | 1040 LOG(ERROR) << "Not on UI thread"; |
1041 return; | 1041 return; |
1042 } | 1042 } |
1043 | 1043 |
1044 UpdateProperty(prop_list); | 1044 UpdateProperty(prop_list); |
1045 } | 1045 } |
1046 | 1046 |
1047 // IBusController override. | 1047 // IBusController override. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 const InputMethodDescriptor* descriptor = | 1192 const InputMethodDescriptor* descriptor = |
1193 util_.GetInputMethodDescriptorFromId(input_method_id); | 1193 util_.GetInputMethodDescriptorFromId(input_method_id); |
1194 if (descriptor) { | 1194 if (descriptor) { |
1195 ChangeCurrentInputMethod(*descriptor); | 1195 ChangeCurrentInputMethod(*descriptor); |
1196 } else { | 1196 } else { |
1197 LOG(ERROR) << "Descriptor is not found for: " << input_method_id; | 1197 LOG(ERROR) << "Descriptor is not found for: " << input_method_id; |
1198 } | 1198 } |
1199 } | 1199 } |
1200 | 1200 |
1201 // Registers the properties used by the current input method. | 1201 // Registers the properties used by the current input method. |
1202 void RegisterProperties(const ImePropertyList& prop_list) { | 1202 void RegisterProperties(const InputMethodPropertyList& prop_list) { |
1203 // |prop_list| might be empty. This means "hide properties." | 1203 // |prop_list| might be empty. This means "hide properties." |
1204 if (prop_list.empty()) { | 1204 if (prop_list.empty()) { |
1205 should_hide_properties_ = true; | 1205 should_hide_properties_ = true; |
1206 } else { | 1206 } else { |
1207 should_hide_properties_ = false; | 1207 should_hide_properties_ = false; |
1208 current_ime_properties_ = prop_list; | 1208 current_ime_properties_ = prop_list; |
1209 } | 1209 } |
1210 // Update input method menu | 1210 // Update input method menu |
1211 FOR_EACH_OBSERVER(InputMethodManager::Observer, observers_, | 1211 FOR_EACH_OBSERVER(InputMethodManager::Observer, observers_, |
1212 PropertyListChanged(this, current_ime_properties())); | 1212 PropertyListChanged(this, |
| 1213 GetCurrentInputMethodProperties())); |
1213 } | 1214 } |
1214 | 1215 |
1215 // Starts the input method daemon. Unlike MaybeStopInputMethodDaemon(), | 1216 // Starts the input method daemon. Unlike MaybeStopInputMethodDaemon(), |
1216 // this function always starts the daemon. Returns true if the daemon is | 1217 // this function always starts the daemon. Returns true if the daemon is |
1217 // started. Otherwise, e.g. the daemon is already started, returns false. | 1218 // started. Otherwise, e.g. the daemon is already started, returns false. |
1218 bool StartInputMethodDaemon() { | 1219 bool StartInputMethodDaemon() { |
1219 should_launch_ime_ = true; | 1220 should_launch_ime_ = true; |
1220 return MaybeLaunchInputMethodDaemon(); | 1221 return MaybeLaunchInputMethodDaemon(); |
1221 } | 1222 } |
1222 | 1223 |
1223 // Updates the properties used by the current input method. | 1224 // Updates the properties used by the current input method. |
1224 void UpdateProperty(const ImePropertyList& prop_list) { | 1225 void UpdateProperty(const InputMethodPropertyList& prop_list) { |
1225 for (size_t i = 0; i < prop_list.size(); ++i) { | 1226 for (size_t i = 0; i < prop_list.size(); ++i) { |
1226 FindAndUpdateProperty(prop_list[i], ¤t_ime_properties_); | 1227 FindAndUpdateProperty(prop_list[i], ¤t_ime_properties_); |
1227 } | 1228 } |
1228 | 1229 |
1229 // Update input method menu | 1230 // Update input method menu |
1230 FOR_EACH_OBSERVER(InputMethodManager::Observer, observers_, | 1231 FOR_EACH_OBSERVER(InputMethodManager::Observer, observers_, |
1231 PropertyListChanged(this, current_ime_properties())); | 1232 PropertyListChanged(this, |
| 1233 GetCurrentInputMethodProperties())); |
1232 } | 1234 } |
1233 | 1235 |
1234 // Launches an input method procsess specified by the given command | 1236 // Launches an input method procsess specified by the given command |
1235 // line. On success, returns true and stores the process handle in | 1237 // line. On success, returns true and stores the process handle in |
1236 // |process_handle|. Otherwise, returns false, and the contents of | 1238 // |process_handle|. Otherwise, returns false, and the contents of |
1237 // |process_handle| is untouched. OnImeShutdown will be called when the | 1239 // |process_handle| is untouched. OnImeShutdown will be called when the |
1238 // process terminates. | 1240 // process terminates. |
1239 bool LaunchInputMethodProcess(const std::string& command_line, | 1241 bool LaunchInputMethodProcess(const std::string& command_line, |
1240 base::ProcessHandle* process_handle) { | 1242 base::ProcessHandle* process_handle) { |
1241 std::vector<std::string> argv; | 1243 std::vector<std::string> argv; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 ObserverList<PreferenceObserver> pre_login_preference_observers_; | 1456 ObserverList<PreferenceObserver> pre_login_preference_observers_; |
1455 ObserverList<PreferenceObserver> post_login_preference_observers_; | 1457 ObserverList<PreferenceObserver> post_login_preference_observers_; |
1456 ObserverList<VirtualKeyboardObserver> virtual_keyboard_observers_; | 1458 ObserverList<VirtualKeyboardObserver> virtual_keyboard_observers_; |
1457 | 1459 |
1458 // The input method which was/is selected. | 1460 // The input method which was/is selected. |
1459 InputMethodDescriptor previous_input_method_; | 1461 InputMethodDescriptor previous_input_method_; |
1460 InputMethodDescriptor current_input_method_; | 1462 InputMethodDescriptor current_input_method_; |
1461 | 1463 |
1462 // The input method properties which the current input method uses. The list | 1464 // The input method properties which the current input method uses. The list |
1463 // might be empty when no input method is used. | 1465 // might be empty when no input method is used. |
1464 ImePropertyList current_ime_properties_; | 1466 InputMethodPropertyList current_ime_properties_; |
1465 bool should_hide_properties_; | 1467 bool should_hide_properties_; |
1466 | 1468 |
1467 typedef std::pair<std::string, std::string> ConfigKeyType; | 1469 typedef std::pair<std::string, std::string> ConfigKeyType; |
1468 typedef std::map< | 1470 typedef std::map< |
1469 ConfigKeyType, InputMethodConfigValue> InputMethodConfigRequests; | 1471 ConfigKeyType, InputMethodConfigValue> InputMethodConfigRequests; |
1470 // SetInputMethodConfig requests that are not yet completed. | 1472 // SetInputMethodConfig requests that are not yet completed. |
1471 // Use a map to queue config requests, so we only send the last request for | 1473 // Use a map to queue config requests, so we only send the last request for |
1472 // the same config key (i.e. we'll discard ealier requests for the same | 1474 // the same config key (i.e. we'll discard ealier requests for the same |
1473 // config key). As we discard old requests for the same config key, the order | 1475 // config key). As we discard old requests for the same config key, the order |
1474 // of requests doesn't matter, so it's safe to use a map. | 1476 // of requests doesn't matter, so it's safe to use a map. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl); | 1546 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl); |
1545 }; | 1547 }; |
1546 | 1548 |
1547 // static | 1549 // static |
1548 InputMethodManager* InputMethodManager::GetInstance() { | 1550 InputMethodManager* InputMethodManager::GetInstance() { |
1549 return InputMethodManagerImpl::GetInstance(); | 1551 return InputMethodManagerImpl::GetInstance(); |
1550 } | 1552 } |
1551 | 1553 |
1552 } // namespace input_method | 1554 } // namespace input_method |
1553 } // namespace chromeos | 1555 } // namespace chromeos |
OLD | NEW |