| 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 #ifndef CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 virtual void StopInputMethodProcesses() = 0; | 88 virtual void StopInputMethodProcesses() = 0; |
| 89 | 89 |
| 90 // Controls whether the IME process is started when preload engines are | 90 // Controls whether the IME process is started when preload engines are |
| 91 // specificed, or defered until a non-default method is activated. | 91 // specificed, or defered until a non-default method is activated. |
| 92 virtual void SetDeferImeStartup(bool defer) = 0; | 92 virtual void SetDeferImeStartup(bool defer) = 0; |
| 93 | 93 |
| 94 virtual const InputMethodDescriptor& previous_input_method() const = 0; | 94 virtual const InputMethodDescriptor& previous_input_method() const = 0; |
| 95 virtual const InputMethodDescriptor& current_input_method() const = 0; | 95 virtual const InputMethodDescriptor& current_input_method() const = 0; |
| 96 | 96 |
| 97 virtual const ImePropertyList& current_ime_properties() const = 0; | 97 virtual const ImePropertyList& current_ime_properties() const = 0; |
| 98 }; | |
| 99 | 98 |
| 100 // This class handles the interaction with the ChromeOS language library APIs. | 99 // Get library implementation. |
| 101 // Classes can add themselves as observers. Users can get an instance of this | 100 static InputMethodLibrary* GetImpl(bool stub); |
| 102 // library class like this: InputMethodLibrary::Get() | |
| 103 class InputMethodLibraryImpl : public InputMethodLibrary { | |
| 104 public: | |
| 105 InputMethodLibraryImpl(); | |
| 106 virtual ~InputMethodLibraryImpl(); | |
| 107 | |
| 108 // InputMethodLibrary overrides. | |
| 109 virtual void AddObserver(Observer* observer); | |
| 110 virtual void RemoveObserver(Observer* observer); | |
| 111 virtual InputMethodDescriptors* GetActiveInputMethods(); | |
| 112 virtual size_t GetNumActiveInputMethods(); | |
| 113 virtual InputMethodDescriptors* GetSupportedInputMethods(); | |
| 114 virtual void ChangeInputMethod(const std::string& input_method_id); | |
| 115 virtual void SetImePropertyActivated(const std::string& key, | |
| 116 bool activated); | |
| 117 virtual bool InputMethodIsActivated(const std::string& input_method_id); | |
| 118 virtual bool GetImeConfig( | |
| 119 const char* section, const char* config_name, ImeConfigValue* out_value); | |
| 120 virtual bool SetImeConfig(const char* section, | |
| 121 const char* config_name, | |
| 122 const ImeConfigValue& value); | |
| 123 | |
| 124 virtual const InputMethodDescriptor& previous_input_method() const { | |
| 125 return previous_input_method_; | |
| 126 } | |
| 127 virtual const InputMethodDescriptor& current_input_method() const { | |
| 128 return current_input_method_; | |
| 129 } | |
| 130 | |
| 131 virtual const ImePropertyList& current_ime_properties() const { | |
| 132 return current_ime_properties_; | |
| 133 } | |
| 134 | |
| 135 virtual void StartInputMethodProcesses(); | |
| 136 virtual void StopInputMethodProcesses(); | |
| 137 virtual void SetDeferImeStartup(bool defer); | |
| 138 | |
| 139 private: | |
| 140 // This method is called when there's a change in input method status. | |
| 141 static void InputMethodChangedHandler( | |
| 142 void* object, const InputMethodDescriptor& current_input_method); | |
| 143 | |
| 144 // This method is called when an input method sends "RegisterProperties" | |
| 145 // signal. | |
| 146 static void RegisterPropertiesHandler( | |
| 147 void* object, const ImePropertyList& prop_list); | |
| 148 | |
| 149 // This method is called when an input method sends "UpdateProperty" signal. | |
| 150 static void UpdatePropertyHandler( | |
| 151 void* object, const ImePropertyList& prop_list); | |
| 152 | |
| 153 // This method is called when bus connects or disconnects. | |
| 154 static void ConnectionChangeHandler(void* object, bool connected); | |
| 155 | |
| 156 // Ensures that the monitoring of input method changes is started. Starts | |
| 157 // the monitoring if necessary. Returns true if the monitoring has been | |
| 158 // successfully started. | |
| 159 bool EnsureStarted(); | |
| 160 | |
| 161 // Ensures that the cros library is loaded and the the monitoring is | |
| 162 // started. Loads the cros library and starts the monitoring if | |
| 163 // necessary. Returns true if the two conditions are both met. | |
| 164 bool EnsureLoadedAndStarted(); | |
| 165 | |
| 166 // Called by the handler to update the input method status. | |
| 167 // This will notify all the Observers. | |
| 168 void UpdateCurrentInputMethod( | |
| 169 const InputMethodDescriptor& current_input_method); | |
| 170 | |
| 171 // Called by the handler to register input method properties. | |
| 172 void RegisterProperties(const ImePropertyList& prop_list); | |
| 173 | |
| 174 // Called by the handler to update input method properties. | |
| 175 void UpdateProperty(const ImePropertyList& prop_list); | |
| 176 | |
| 177 void MaybeUpdateImeState(const char* section, const char* config_name, | |
| 178 const ImeConfigValue& value); | |
| 179 | |
| 180 // Tries to send all pending SetImeConfig requests to the input method config | |
| 181 // daemon. | |
| 182 void FlushImeConfig(); | |
| 183 | |
| 184 // Launch any IME processes that should currently be running, but aren't. | |
| 185 void MaybeLaunchIme(); | |
| 186 | |
| 187 // Handle one of the ime processes shutting down. If it was shutdown by us, | |
| 188 // just close the handle. If it crashed, restart it. | |
| 189 static void OnImeShutdown(int pid, int status, | |
| 190 InputMethodLibraryImpl* library); | |
| 191 | |
| 192 // A reference to the language api, to allow callbacks when the input method | |
| 193 // status changes. | |
| 194 InputMethodStatusConnection* input_method_status_connection_; | |
| 195 ObserverList<Observer> observers_; | |
| 196 | |
| 197 // The input method which was/is selected. | |
| 198 InputMethodDescriptor previous_input_method_; | |
| 199 InputMethodDescriptor current_input_method_; | |
| 200 | |
| 201 // The input method properties which the current input method uses. The list | |
| 202 // might be empty when no input method is used. | |
| 203 ImePropertyList current_ime_properties_; | |
| 204 | |
| 205 typedef std::pair<std::string, std::string> ConfigKeyType; | |
| 206 typedef std::map<ConfigKeyType, ImeConfigValue> InputMethodConfigRequests; | |
| 207 // SetImeConfig requests that are not yet completed. | |
| 208 // Use a map to queue config requests, so we only send the last request for | |
| 209 // the same config key (i.e. we'll discard ealier requests for the same | |
| 210 // config key). As we discard old requests for the same config key, the order | |
| 211 // of requests doesn't matter, so it's safe to use a map. | |
| 212 InputMethodConfigRequests pending_config_requests_; | |
| 213 | |
| 214 // Values that have been set via SetImeConfig(). We keep a copy available to | |
| 215 // resend if the ime restarts and loses its state. | |
| 216 InputMethodConfigRequests current_config_values_; | |
| 217 | |
| 218 // A timer for retrying to send |pendning_config_commands_| to the input | |
| 219 // method config daemon. | |
| 220 base::OneShotTimer<InputMethodLibraryImpl> timer_; | |
| 221 | |
| 222 bool ime_running_; | |
| 223 bool ime_connected_; | |
| 224 bool defer_ime_startup_; | |
| 225 std::string active_input_method_; | |
| 226 bool need_input_method_set_; | |
| 227 | |
| 228 int ime_handle_; | |
| 229 int candidate_window_handle_; | |
| 230 | |
| 231 DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryImpl); | |
| 232 }; | 101 }; |
| 233 | 102 |
| 234 } // namespace chromeos | 103 } // namespace chromeos |
| 235 | 104 |
| 236 #endif // CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_ | 105 #endif // CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_ |
| OLD | NEW |