| 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 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | |
| 11 #include <string> | 10 #include <string> |
| 12 #include <utility> | |
| 13 #include <vector> | |
| 14 | 11 |
| 15 #include "base/observer_list.h" | 12 #include "base/logging.h" // for NOTIMPLEMENTED() |
| 16 #include "base/time.h" | |
| 17 #include "base/timer.h" | |
| 18 #include "chrome/browser/chromeos/input_method/input_method_config.h" | 13 #include "chrome/browser/chromeos/input_method/input_method_config.h" |
| 19 #include "chrome/browser/chromeos/input_method/input_method_descriptor.h" | 14 #include "chrome/browser/chromeos/input_method/input_method_descriptor.h" |
| 20 #include "chrome/browser/chromeos/input_method/input_method_property.h" | 15 #include "chrome/browser/chromeos/input_method/input_method_property.h" |
| 21 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 16 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 22 | 17 |
| 23 class GURL; | |
| 24 | |
| 25 namespace ui { | 18 namespace ui { |
| 26 class Accelerator; | 19 class Accelerator; |
| 27 } // namespace ui | 20 } // namespace ui |
| 28 | 21 |
| 29 namespace chromeos { | 22 namespace chromeos { |
| 30 namespace input_method { | 23 namespace input_method { |
| 31 | 24 |
| 32 class HotkeyManager; | |
| 33 class VirtualKeyboard; | |
| 34 class XKeyboard; | 25 class XKeyboard; |
| 35 | 26 |
| 36 // This class manages input methodshandles. Classes can add themselves as | 27 // This class manages input methodshandles. Classes can add themselves as |
| 37 // observers. Clients can get an instance of this library class by: | 28 // observers. Clients can get an instance of this library class by: |
| 38 // InputMethodManager::GetInstance(). | 29 // InputMethodManager::GetInstance(). |
| 39 class InputMethodManager { | 30 class InputMethodManager { |
| 40 public: | 31 public: |
| 41 enum State { | 32 enum State { |
| 42 STATE_LOGIN_SCREEN = 0, | 33 STATE_LOGIN_SCREEN = 0, |
| 43 // The user entered the correct password (= NOTIFICATION_LOGIN_USER_CHANGED | |
| 44 // has been sent), but NOTIFICATION_SESSION_STARTED has not. | |
| 45 STATE_LOGGING_IN, | |
| 46 // The browser window for user session is ready. | |
| 47 STATE_BROWSER_SCREEN, | 34 STATE_BROWSER_SCREEN, |
| 48 STATE_LOCK_SCREEN, | 35 STATE_LOCK_SCREEN, |
| 49 STATE_TERMINATING, | 36 STATE_TERMINATING, |
| 50 }; | 37 }; |
| 51 | 38 |
| 52 class Observer { | 39 class Observer { |
| 53 public: | 40 public: |
| 54 virtual ~Observer() {} | 41 virtual ~Observer() {} |
| 55 | |
| 56 // Called when the current input method is changed. | 42 // Called when the current input method is changed. |
| 57 virtual void InputMethodChanged( | 43 virtual void InputMethodChanged(InputMethodManager* manager) = 0; |
| 58 InputMethodManager* manager, | |
| 59 const InputMethodDescriptor& current_input_method, | |
| 60 size_t num_active_input_methods) = 0; | |
| 61 | |
| 62 // Called when the active input methods are changed. | |
| 63 // TODO(yusukes): Remove this method in R20. | |
| 64 virtual void ActiveInputMethodsChanged( | |
| 65 InputMethodManager* manager, | |
| 66 const InputMethodDescriptor& current_input_method, | |
| 67 size_t num_active_input_methods) = 0; | |
| 68 | |
| 69 // Called when the list of properties is changed. | 44 // Called when the list of properties is changed. |
| 70 // TODO(yusukes): Remove this method in R20. | 45 virtual void InputMethodPropertyChanged(InputMethodManager* manager) = 0; |
| 71 virtual void PropertyListChanged( | |
| 72 InputMethodManager* manager, | |
| 73 const InputMethodPropertyList& current_ime_properties) = 0; | |
| 74 }; | 46 }; |
| 75 | 47 |
| 76 // CandidateWindowObserver is notified of events related to the candidate | 48 // CandidateWindowObserver is notified of events related to the candidate |
| 77 // window. The "suggestion window" used by IMEs such as ibus-mozc does not | 49 // window. The "suggestion window" used by IMEs such as ibus-mozc does not |
| 78 // count as the candidate window (this may change if we later want suggestion | 50 // count as the candidate window (this may change if we later want suggestion |
| 79 // window events as well). These events also won't occur when the virtual | 51 // window events as well). These events also won't occur when the virtual |
| 80 // keyboard is used, since it controls its own candidate window. | 52 // keyboard is used, since it controls its own candidate window. |
| 81 class CandidateWindowObserver { | 53 class CandidateWindowObserver { |
| 82 public: | 54 public: |
| 83 virtual ~CandidateWindowObserver() {} | 55 virtual ~CandidateWindowObserver() {} |
| 84 | |
| 85 // Called when the candidate window is opened. | 56 // Called when the candidate window is opened. |
| 86 virtual void CandidateWindowOpened(InputMethodManager* manager) = 0; | 57 virtual void CandidateWindowOpened(InputMethodManager* manager) = 0; |
| 87 | |
| 88 // Called when the candidate window is closed. | 58 // Called when the candidate window is closed. |
| 89 virtual void CandidateWindowClosed(InputMethodManager* manager) = 0; | 59 virtual void CandidateWindowClosed(InputMethodManager* manager) = 0; |
| 90 }; | 60 }; |
| 91 | 61 |
| 92 class VirtualKeyboardObserver { | |
| 93 public: | |
| 94 virtual ~VirtualKeyboardObserver() {} | |
| 95 // Called when the current virtual keyboard is changed. | |
| 96 virtual void VirtualKeyboardChanged( | |
| 97 InputMethodManager* manager, | |
| 98 const VirtualKeyboard& virtual_keyboard, | |
| 99 const std::string& virtual_keyboard_layout) = 0; | |
| 100 }; | |
| 101 | |
| 102 virtual ~InputMethodManager() {} | 62 virtual ~InputMethodManager() {} |
| 103 | 63 |
| 104 static InputMethodManager* GetInstance(); | |
| 105 | |
| 106 // Adds an observer to receive notifications of input method related | 64 // Adds an observer to receive notifications of input method related |
| 107 // changes as desribed in the Observer class above. | 65 // changes as desribed in the Observer class above. |
| 108 virtual void AddObserver(Observer* observer) = 0; | 66 virtual void AddObserver(Observer* observer) = 0; |
| 109 virtual void AddCandidateWindowObserver( | 67 virtual void AddCandidateWindowObserver( |
| 110 CandidateWindowObserver* observer) = 0; | 68 CandidateWindowObserver* observer) = 0; |
| 111 virtual void AddVirtualKeyboardObserver( | |
| 112 VirtualKeyboardObserver* observer) = 0; | |
| 113 virtual void RemoveObserver(Observer* observer) = 0; | 69 virtual void RemoveObserver(Observer* observer) = 0; |
| 114 virtual void RemoveCandidateWindowObserver( | 70 virtual void RemoveCandidateWindowObserver( |
| 115 CandidateWindowObserver* observer) = 0; | 71 CandidateWindowObserver* observer) = 0; |
| 116 virtual void RemoveVirtualKeyboardObserver( | 72 |
| 117 VirtualKeyboardObserver* observer) = 0; | 73 // Sets the current browser status. |
| 74 virtual void SetState(State new_state) = 0; |
| 118 | 75 |
| 119 // Returns all input methods that are supported, including ones not active. | 76 // Returns all input methods that are supported, including ones not active. |
| 120 // Caller has to delete the returned list. This function never returns NULL. | 77 // Caller has to delete the returned list. This function never returns NULL. |
| 121 virtual InputMethodDescriptors* GetSupportedInputMethods() = 0; | 78 // Note that input method extensions are NOT included in the result. |
| 79 virtual InputMethodDescriptors* GetSupportedInputMethods() const = 0; |
| 122 | 80 |
| 123 // Returns the list of input methods we can select (i.e. active). If the cros | 81 // Returns the list of input methods we can select (i.e. active) including |
| 124 // library is not found or IBus/DBus daemon is not alive, this function | 82 // extension input methods. Caller has to delete the returned list. |
| 125 // returns a fallback input method list (and never returns NULL). Caller has | 83 virtual InputMethodDescriptors* GetActiveInputMethods() const = 0; |
| 126 // to delete the returned list. | |
| 127 virtual InputMethodDescriptors* GetActiveInputMethods() = 0; | |
| 128 | 84 |
| 129 // Returns the number of active input methods. | 85 // Returns the number of active input methods including extension input |
| 130 virtual size_t GetNumActiveInputMethods() = 0; | 86 // methods. |
| 87 virtual size_t GetNumActiveInputMethods() const = 0; |
| 131 | 88 |
| 132 // Changes the current input method to |input_method_id|. | 89 // Changes the current input method to |input_method_id|. If |input_method_id| |
| 90 // is not active, switch to the first one in the active input method list. |
| 133 virtual void ChangeInputMethod(const std::string& input_method_id) = 0; | 91 virtual void ChangeInputMethod(const std::string& input_method_id) = 0; |
| 134 | 92 |
| 135 // Enables input methods (e.g. Chinese, Japanese) and keyboard layouts (e.g. | 93 // Enables keyboard layouts (e.g. US Qwerty, US Dvorak, French Azerty) that |
| 136 // US qwerty, US dvorak, French azerty) that are necessary for the language | 94 // are necessary for the |language_code| and then switches to |initial_layout| |
| 137 // code and then switches to |initial_input_method_id| if the string is not | 95 // if the string is not empty. For example, if |language_code| is "en-US", US |
| 138 // empty. For example, if |language_code| is "en-US", US qwerty and US dvorak | 96 // Qwerty, US International, US Extended, US Dvorak, and US Colemak layouts |
| 139 // layouts would be enabled. Likewise, for Germany locale, US qwerty layout | 97 // would be enabled. Likewise, for Germany locale, US Qwerty which corresponds |
| 140 // and several keyboard layouts for Germany would be enabled. | 98 // to the hardware keyboard layout and several keyboard layouts for Germany |
| 141 // | 99 // would be enabled. |
| 142 // Note that this function does not save the input methods in the user's | 100 // This method is for setting up i18n keyboard layouts for the login screen. |
| 143 // preferences, as this function is designed for the login screen and the | 101 virtual void EnableLayouts(const std::string& language_code, |
| 144 // screen locker, where we shouldn't change the user's preferences. | 102 const std::string& initial_layout) = 0; |
| 145 virtual void EnableLayouts( | |
| 146 const std::string& language_code, | |
| 147 const std::string& initial_input_method_id) = 0; | |
| 148 | 103 |
| 149 // Sets whether the input method property specified by |key| is activated. If | 104 // Activates the input method property specified by the |key|. |
| 150 // |activated| is true, activates the property. If |activate| is false, | 105 virtual void ActivateInputMethodProperty(const std::string& key) = 0; |
| 151 // deactivates the property. Examples of keys: | |
| 152 // - "InputMode.Katakana" | |
| 153 // - "InputMode.HalfWidthKatakana" | |
| 154 // - "TypingMode.Romaji" | |
| 155 // - "TypingMode.Kana" | |
| 156 virtual void SetImePropertyActivated(const std::string& key, | |
| 157 bool activated) = 0; | |
| 158 | 106 |
| 159 // Returns true if the input method specified by |input_method_id| is active. | 107 // Updates the list of active input method IDs, and then starts or stops the |
| 160 virtual bool InputMethodIsActivated(const std::string& input_method_id) = 0; | 108 // system input method framework as needed. |
| 109 virtual bool EnableInputMethods( |
| 110 const std::vector<std::string>& new_active_input_method_ids) = 0; |
| 161 | 111 |
| 162 // Updates a configuration of ibus-daemon or IBus engines with |value|. | 112 // Updates a configuration of a system input method engine with |value|. |
| 163 // Returns true if the configuration (and all pending configurations, if any) | 113 // Returns true if the configuration is correctly set. |
| 164 // are processed. If ibus-daemon is not running, this function just queues | |
| 165 // the request and returns false. | |
| 166 // When you would like to set 'panel/custom_font', |section| should | |
| 167 // be "panel", and |config_name| should be "custom_font". | |
| 168 // Notice: This function might call the Observer::ActiveInputMethodsChanged() | |
| 169 // callback function immediately, before returning from the | |
| 170 // SetInputMethodConfig function. See also http://crosbug.com/5217. | |
| 171 virtual bool SetInputMethodConfig(const std::string& section, | 114 virtual bool SetInputMethodConfig(const std::string& section, |
| 172 const std::string& config_name, | 115 const std::string& config_name, |
| 173 const InputMethodConfigValue& value) = 0; | 116 const InputMethodConfigValue& value) = 0; |
| 174 | 117 |
| 175 // Add an input method to insert into the language menu. | 118 // Adds an input method extension. |
| 176 virtual void AddActiveIme(const std::string& id, | 119 virtual void AddInputMethodExtension(const std::string& id, |
| 177 const std::string& name, | 120 const std::string& name, |
| 178 const std::vector<std::string>& layouts, | 121 const std::vector<std::string>& layouts, |
| 179 const std::string& language) = 0; | 122 const std::string& language) = 0; |
| 180 | 123 |
| 181 // Remove an input method from the language menu. | 124 // Removes an input method extension. |
| 182 virtual void RemoveActiveIme(const std::string& id) = 0; | 125 virtual void RemoveInputMethodExtension(const std::string& id) = 0; |
| 183 | 126 |
| 184 virtual bool GetExtraDescriptor(const std::string& id, | 127 // Gets the descriptor of the input method which is currently selected. |
| 185 InputMethodDescriptor* descriptor) = 0; | 128 virtual InputMethodDescriptor GetCurrentInputMethod() const = 0; |
| 186 | 129 |
| 187 // Sets the IME state to enabled, and launches input method daemon if needed. | 130 // Gets the list of input method properties. The list could be empty(). |
| 188 // Returns true if the daemon is started. Otherwise, e.g. the daemon is | 131 virtual InputMethodPropertyList GetCurrentInputMethodProperties() const = 0; |
| 189 // already started, returns false. | |
| 190 virtual bool StartInputMethodDaemon() = 0; | |
| 191 | |
| 192 // Disables the IME, and kills the daemon process if they are running. | |
| 193 // Returns true if the daemon is stopped. Otherwise, e.g. the daemon is | |
| 194 // already stopped, returns false. | |
| 195 virtual bool StopInputMethodDaemon() = 0; | |
| 196 | |
| 197 // Controls whether the IME process is stopped when all non-default preload | |
| 198 // engines are removed. | |
| 199 virtual void SetEnableAutoImeShutdown(bool enable) = 0; | |
| 200 | |
| 201 // Controls whether extension IME are displayed in the language menu, and can | |
| 202 // be selected. | |
| 203 virtual void SetEnableExtensionIMEs(bool enable) = 0; | |
| 204 | |
| 205 // Sends a handwriting stroke to libcros. See chromeos::SendHandwritingStroke | |
| 206 // for details. | |
| 207 virtual void SendHandwritingStroke( | |
| 208 const HandwritingStroke& stroke) = 0; | |
| 209 | |
| 210 // Clears last N handwriting strokes in libcros. See | |
| 211 // chromeos::CancelHandwriting for details. | |
| 212 virtual void CancelHandwritingStrokes(int stroke_count) = 0; | |
| 213 | |
| 214 // Registers a new virtual keyboard for |layouts|. Set |is_system| true when | |
| 215 // the keyboard is provided as a content extension. System virtual keyboards | |
| 216 // have lower priority than non-system ones. See virtual_keyboard_selector.h | |
| 217 // for details. | |
| 218 // TODO(yusukes): Add UnregisterVirtualKeyboard function as well. | |
| 219 virtual void RegisterVirtualKeyboard(const GURL& launch_url, | |
| 220 const std::string& name, | |
| 221 const std::set<std::string>& layouts, | |
| 222 bool is_system) = 0; | |
| 223 | |
| 224 // Sets user preference on virtual keyboard selection. | |
| 225 // See virtual_keyboard_selector.h for details. | |
| 226 virtual bool SetVirtualKeyboardPreference(const std::string& input_method_id, | |
| 227 const GURL& extention_url) = 0; | |
| 228 | |
| 229 // Clears all preferences on virtual keyboard selection. | |
| 230 // See virtual_keyboard_selector.h for details. | |
| 231 virtual void ClearAllVirtualKeyboardPreferences() = 0; | |
| 232 | |
| 233 // Returns a map from extension URL to virtual keyboard extension. | |
| 234 virtual const std::map<GURL, const VirtualKeyboard*>& | |
| 235 GetUrlToKeyboardMapping() const = 0; | |
| 236 | |
| 237 // Returns a multi map from layout name to virtual keyboard extension. | |
| 238 virtual const std::multimap<std::string, const VirtualKeyboard*>& | |
| 239 GetLayoutNameToKeyboardMapping() const = 0; | |
| 240 | 132 |
| 241 // Returns an X keyboard object which could be used to change the current XKB | 133 // Returns an X keyboard object which could be used to change the current XKB |
| 242 // layout, change the caps lock status, and set the auto repeat rate/interval. | 134 // layout, change the caps lock status, and set the auto repeat rate/interval. |
| 243 virtual XKeyboard* GetXKeyboard() = 0; | 135 virtual XKeyboard* GetXKeyboard() = 0; |
| 244 | 136 |
| 245 // Returns a InputMethodUtil object. | 137 // Returns an InputMethodUtil object. |
| 246 virtual InputMethodUtil* GetInputMethodUtil() = 0; | 138 virtual InputMethodUtil* GetInputMethodUtil() = 0; |
| 247 | 139 |
| 248 // Enable all input method hotkeys. | 140 // Enables all input method hotkeys such as Alt+Shift. Note that all hotkeys |
| 141 // are enabled on startup. |
| 249 virtual void EnableHotkeys() = 0; | 142 virtual void EnableHotkeys() = 0; |
| 250 // Disable all input method hotkeys. | 143 |
| 144 // Disables all input method hotkeys. |
| 251 virtual void DisableHotkeys() = 0; | 145 virtual void DisableHotkeys() = 0; |
| 252 | 146 |
| 253 // Switches the current input method (or keyboard layout) to the next one. | 147 // Switches the current input method (or keyboard layout) to the next one. |
| 254 virtual bool SwitchToNextInputMethod() = 0; | 148 virtual bool SwitchToNextInputMethod() = 0; |
| 149 |
| 255 // Switches the current input method (or keyboard layout) to the previous one. | 150 // Switches the current input method (or keyboard layout) to the previous one. |
| 256 virtual bool SwitchToPreviousInputMethod() = 0; | 151 virtual bool SwitchToPreviousInputMethod() = 0; |
| 152 |
| 257 // Switches to an input method (or keyboard layout) which is associated with | 153 // Switches to an input method (or keyboard layout) which is associated with |
| 258 // the |accelerator|. | 154 // the |accelerator|. |
| 259 virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) = 0; | 155 virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) = 0; |
| 260 | 156 |
| 261 virtual InputMethodDescriptor GetPreviousInputMethod() const = 0; | 157 // Sets the global instance. Must be called before any calls to GetInstance(). |
| 262 virtual InputMethodDescriptor GetCurrentInputMethod() const = 0; | 158 // We explicitly initialize and shut down the global object, rather than |
| 159 // making it a Singleton, to ensure clean startup and shutdown. |
| 160 static void Initialize(); |
| 263 | 161 |
| 264 virtual InputMethodPropertyList GetCurrentInputMethodProperties() const = 0; | 162 // Similar to Initialize(), but can inject an alternative |
| 163 // InputMethodManager such as MockInputMethodManager for testing. |
| 164 // The injected object will be owned by the internal pointer and deleted |
| 165 // by Shutdown(). |
| 166 static void InitializeForTesting(InputMethodManager* mock_manager); |
| 167 |
| 168 // Destroys the global instance. |
| 169 static void Shutdown(); |
| 170 |
| 171 // Gets the global instance. Initialize() or InitializeForTesting() must be |
| 172 // called first. |
| 173 static InputMethodManager* GetInstance(); |
| 265 }; | 174 }; |
| 266 | 175 |
| 267 } // namespace input_method | 176 } // namespace input_method |
| 268 } // namespace chromeos | 177 } // namespace chromeos |
| 269 | 178 |
| 179 // TODO(yusukes): Adding back the Virtual Keyboard support to somewhere in |
| 180 // input_method/. Adding it directly to this class is probably not the right |
| 181 // thing to do. |
| 182 |
| 270 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_ | 183 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_ |
| OLD | NEW |