| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cros/input_method_library.h" | 5 #include "chrome/browser/chromeos/cros/input_method_library.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 result = chromeos::GetSupportedInputMethods( | 100 result = chromeos::GetSupportedInputMethods( |
| 101 input_method_status_connection_); | 101 input_method_status_connection_); |
| 102 } | 102 } |
| 103 if (!result || result->empty()) { | 103 if (!result || result->empty()) { |
| 104 result = CreateFallbackInputMethodDescriptors(); | 104 result = CreateFallbackInputMethodDescriptors(); |
| 105 } | 105 } |
| 106 return result; | 106 return result; |
| 107 } | 107 } |
| 108 | 108 |
| 109 void ChangeInputMethod(const std::string& input_method_id) { | 109 void ChangeInputMethod(const std::string& input_method_id) { |
| 110 active_input_method_ = input_method_id; |
| 110 if (EnsureLoadedAndStarted()) { | 111 if (EnsureLoadedAndStarted()) { |
| 111 if (input_method_id != kHardwareKeyboardLayout) { | 112 if (input_method_id != kHardwareKeyboardLayout) { |
| 112 StartInputMethodProcesses(); | 113 StartInputMethodProcesses(); |
| 113 } | 114 } |
| 114 chromeos::ChangeInputMethod( | 115 chromeos::ChangeInputMethod( |
| 115 input_method_status_connection_, input_method_id.c_str()); | 116 input_method_status_connection_, input_method_id.c_str()); |
| 116 } | 117 } |
| 117 } | 118 } |
| 118 | 119 |
| 119 void SetImePropertyActivated(const std::string& key, | 120 void SetImePropertyActivated(const std::string& key, bool activated) { |
| 120 bool activated) { | |
| 121 DCHECK(!key.empty()); | 121 DCHECK(!key.empty()); |
| 122 if (EnsureLoadedAndStarted()) { | 122 if (EnsureLoadedAndStarted()) { |
| 123 chromeos::SetImePropertyActivated( | 123 chromeos::SetImePropertyActivated( |
| 124 input_method_status_connection_, key.c_str(), activated); | 124 input_method_status_connection_, key.c_str(), activated); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool InputMethodIsActivated( | 128 bool InputMethodIsActivated(const std::string& input_method_id) { |
| 129 const std::string& input_method_id) { | |
| 130 scoped_ptr<InputMethodDescriptors> active_input_method_descriptors( | 129 scoped_ptr<InputMethodDescriptors> active_input_method_descriptors( |
| 131 CrosLibrary::Get()->GetInputMethodLibrary()->GetActiveInputMethods()); | 130 CrosLibrary::Get()->GetInputMethodLibrary()->GetActiveInputMethods()); |
| 132 for (size_t i = 0; i < active_input_method_descriptors->size(); ++i) { | 131 for (size_t i = 0; i < active_input_method_descriptors->size(); ++i) { |
| 133 if (active_input_method_descriptors->at(i).id == input_method_id) { | 132 if (active_input_method_descriptors->at(i).id == input_method_id) { |
| 134 return true; | 133 return true; |
| 135 } | 134 } |
| 136 } | 135 } |
| 137 return false; | 136 return false; |
| 138 } | 137 } |
| 139 | 138 |
| 140 bool GetImeConfig( | 139 bool GetImeConfig(const char* section, const char* config_name, |
| 141 const char* section, | 140 ImeConfigValue* out_value) { |
| 142 const char* config_name, | |
| 143 ImeConfigValue* out_value) { | |
| 144 bool success = false; | 141 bool success = false; |
| 145 if (EnsureLoadedAndStarted()) { | 142 if (EnsureLoadedAndStarted()) { |
| 146 success = chromeos::GetImeConfig( | 143 success = chromeos::GetImeConfig(input_method_status_connection_, |
| 147 input_method_status_connection_, section, config_name, out_value); | 144 section, config_name, out_value); |
| 148 } | 145 } |
| 149 return success; | 146 return success; |
| 150 } | 147 } |
| 151 | 148 |
| 152 bool SetImeConfig( | 149 bool SetImeConfig(const char* section, const char* config_name, |
| 153 const char* section, | 150 const ImeConfigValue& value) { |
| 154 const char* config_name, | |
| 155 const ImeConfigValue& value) { | |
| 156 MaybeUpdateImeState(section, config_name, value); | 151 MaybeUpdateImeState(section, config_name, value); |
| 157 | 152 |
| 158 const ConfigKeyType key = std::make_pair(section, config_name); | 153 const ConfigKeyType key = std::make_pair(section, config_name); |
| 159 current_config_values_[key] = value; | 154 current_config_values_[key] = value; |
| 160 if (ime_connected_) { | 155 if (ime_connected_) { |
| 161 pending_config_requests_[key] = value; | 156 pending_config_requests_[key] = value; |
| 162 FlushImeConfig(); | 157 FlushImeConfig(); |
| 163 } | 158 } |
| 164 return pending_config_requests_.empty(); | 159 return pending_config_requests_.empty(); |
| 165 } | 160 } |
| 166 | 161 |
| 167 virtual const InputMethodDescriptor& previous_input_method() const { | 162 virtual const InputMethodDescriptor& previous_input_method() const { |
| 168 return previous_input_method_; | 163 return previous_input_method_; |
| 169 } | 164 } |
| 170 virtual const InputMethodDescriptor& current_input_method() const { | 165 virtual const InputMethodDescriptor& current_input_method() const { |
| 171 return current_input_method_; | 166 return current_input_method_; |
| 172 } | 167 } |
| 173 | 168 |
| 174 virtual const ImePropertyList& current_ime_properties() const { | 169 virtual const ImePropertyList& current_ime_properties() const { |
| 175 return current_ime_properties_; | 170 return current_ime_properties_; |
| 176 } | 171 } |
| 177 | 172 |
| 178 void StartIme() { | |
| 179 ime_running_ = true; | |
| 180 MaybeLaunchIme(); | |
| 181 } | |
| 182 | |
| 183 void StopIme() { | |
| 184 ime_running_ = false; | |
| 185 if (ime_handle_) { | |
| 186 kill(ime_handle_, SIGTERM); | |
| 187 ime_handle_ = 0; | |
| 188 } | |
| 189 if (candidate_window_handle_) { | |
| 190 kill(candidate_window_handle_, SIGTERM); | |
| 191 candidate_window_handle_ = 0; | |
| 192 } | |
| 193 } | |
| 194 | |
| 195 private: | 173 private: |
| 196 void MaybeUpdateImeState( | 174 void MaybeUpdateImeState( |
| 197 const char* section, | 175 const char* section, |
| 198 const char* config_name, | 176 const char* config_name, |
| 199 const ImeConfigValue& value) { | 177 const ImeConfigValue& value) { |
| 200 if (!strcmp(kGeneralSectionName, section) && | 178 if (!strcmp(kGeneralSectionName, section) && |
| 201 !strcmp(kPreloadEnginesConfigName, config_name)) { | 179 !strcmp(kPreloadEnginesConfigName, config_name)) { |
| 202 if (EnsureLoadedAndStarted()) { | 180 if (EnsureLoadedAndStarted()) { |
| 203 if (value.type == ImeConfigValue::kValueTypeStringList && | 181 if (value.type == ImeConfigValue::kValueTypeStringList && |
| 204 value.string_list_value.size() == 1 && | 182 value.string_list_value.size() == 1 && |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 | 438 |
| 461 library->MaybeLaunchIme(); | 439 library->MaybeLaunchIme(); |
| 462 } | 440 } |
| 463 | 441 |
| 464 void StopInputMethodProcesses() { | 442 void StopInputMethodProcesses() { |
| 465 ime_running_ = false; | 443 ime_running_ = false; |
| 466 if (ime_handle_) { | 444 if (ime_handle_) { |
| 467 kill(ime_handle_, SIGTERM); | 445 kill(ime_handle_, SIGTERM); |
| 468 ime_handle_ = 0; | 446 ime_handle_ = 0; |
| 469 } | 447 } |
| 448 if (candidate_window_handle_) { |
| 449 kill(candidate_window_handle_, SIGTERM); |
| 450 candidate_window_handle_ = 0; |
| 451 } |
| 470 } | 452 } |
| 471 | 453 |
| 472 void SetDeferImeStartup(bool defer) { | 454 void SetDeferImeStartup(bool defer) { |
| 473 defer_ime_startup_ = defer; | 455 defer_ime_startup_ = defer; |
| 474 } | 456 } |
| 475 // A reference to the language api, to allow callbacks when the input method | 457 // A reference to the language api, to allow callbacks when the input method |
| 476 // status changes. | 458 // status changes. |
| 477 InputMethodStatusConnection* input_method_status_connection_; | 459 InputMethodStatusConnection* input_method_status_connection_; |
| 478 ObserverList<Observer> observers_; | 460 ObserverList<Observer> observers_; |
| 479 | 461 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 return new InputMethodLibraryStubImpl(); | 701 return new InputMethodLibraryStubImpl(); |
| 720 else | 702 else |
| 721 return new InputMethodLibraryImpl(); | 703 return new InputMethodLibraryImpl(); |
| 722 } | 704 } |
| 723 | 705 |
| 724 } // namespace chromeos | 706 } // namespace chromeos |
| 725 | 707 |
| 726 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 708 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 727 // won't be deleted until it's last InvokeLater is run. | 709 // won't be deleted until it's last InvokeLater is run. |
| 728 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl); | 710 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl); |
| OLD | NEW |