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 CHROMEOS_IME_INPUT_METHOD_MANAGER_H_ | 5 #ifndef CHROMEOS_IME_INPUT_METHOD_MANAGER_H_ |
6 #define CHROMEOS_IME_INPUT_METHOD_MANAGER_H_ | 6 #define CHROMEOS_IME_INPUT_METHOD_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "chromeos/chromeos_export.h" | 14 #include "chromeos/chromeos_export.h" |
14 #include "chromeos/ime/input_method_descriptor.h" | 15 #include "chromeos/ime/input_method_descriptor.h" |
15 | 16 |
16 class Profile; | 17 class Profile; |
17 | 18 |
18 namespace ui { | 19 namespace ui { |
19 class Accelerator; | 20 class Accelerator; |
20 } // namespace ui | 21 } // namespace ui |
21 | 22 |
| 23 namespace user_manager { |
| 24 class User; |
| 25 } // namespace user_manager |
| 26 |
22 namespace chromeos { | 27 namespace chromeos { |
23 class ComponentExtensionIMEManager; | 28 class ComponentExtensionIMEManager; |
24 class InputMethodEngineInterface; | 29 class InputMethodEngineInterface; |
25 namespace input_method { | 30 namespace input_method { |
26 class InputMethodUtil; | 31 class InputMethodUtil; |
27 class ImeKeyboard; | 32 class ImeKeyboard; |
28 | 33 |
29 // This class manages input methodshandles. Classes can add themselves as | 34 // This class manages input methodshandles. Classes can add themselves as |
30 // observers. Clients can get an instance of this library class by: | 35 // observers. Clients can get an instance of this library class by: |
31 // InputMethodManager::Get(). | 36 // InputMethodManager::Get(). |
32 class CHROMEOS_EXPORT InputMethodManager { | 37 class CHROMEOS_EXPORT InputMethodManager { |
33 public: | 38 public: |
34 enum State { | 39 enum UISessionState { |
35 STATE_LOGIN_SCREEN = 0, | 40 STATE_LOGIN_SCREEN = 0, |
36 STATE_BROWSER_SCREEN, | 41 STATE_BROWSER_SCREEN, |
37 STATE_LOCK_SCREEN, | 42 STATE_LOCK_SCREEN, |
38 STATE_TERMINATING, | 43 STATE_TERMINATING, |
39 }; | 44 }; |
40 | 45 |
41 class Observer { | 46 class Observer { |
42 public: | 47 public: |
43 virtual ~Observer() {} | 48 virtual ~Observer() {} |
44 // Called when the current input method is changed. |show_message| | 49 // Called when the current input method is changed. |show_message| |
45 // indicates whether the user should be notified of this change. | 50 // indicates whether the user should be notified of this change. |
46 virtual void InputMethodChanged(InputMethodManager* manager, | 51 virtual void InputMethodChanged(InputMethodManager* manager, |
47 bool show_message) = 0; | 52 bool show_message) = 0; |
48 }; | 53 }; |
49 | 54 |
50 // CandidateWindowObserver is notified of events related to the candidate | 55 // CandidateWindowObserver is notified of events related to the candidate |
51 // window. The "suggestion window" used by IMEs such as ibus-mozc does not | 56 // window. The "suggestion window" used by IMEs such as ibus-mozc does not |
52 // count as the candidate window (this may change if we later want suggestion | 57 // count as the candidate window (this may change if we later want suggestion |
53 // window events as well). These events also won't occur when the virtual | 58 // window events as well). These events also won't occur when the virtual |
54 // keyboard is used, since it controls its own candidate window. | 59 // keyboard is used, since it controls its own candidate window. |
55 class CandidateWindowObserver { | 60 class CandidateWindowObserver { |
56 public: | 61 public: |
57 virtual ~CandidateWindowObserver() {} | 62 virtual ~CandidateWindowObserver() {} |
58 // Called when the candidate window is opened. | 63 // Called when the candidate window is opened. |
59 virtual void CandidateWindowOpened(InputMethodManager* manager) = 0; | 64 virtual void CandidateWindowOpened(InputMethodManager* manager) = 0; |
60 // Called when the candidate window is closed. | 65 // Called when the candidate window is closed. |
61 virtual void CandidateWindowClosed(InputMethodManager* manager) = 0; | 66 virtual void CandidateWindowClosed(InputMethodManager* manager) = 0; |
62 }; | 67 }; |
63 | 68 |
| 69 class State : public base::RefCounted<InputMethodManager::State> { |
| 70 public: |
| 71 // Adds an input method extension. This function does not takes ownership of |
| 72 // |instance|. |
| 73 virtual void AddInputMethodExtension( |
| 74 const std::string& extension_id, |
| 75 const InputMethodDescriptors& descriptors, |
| 76 InputMethodEngineInterface* instance) = 0; |
| 77 |
| 78 // Removes an input method extension. |
| 79 virtual void RemoveInputMethodExtension( |
| 80 const std::string& extension_id) = 0; |
| 81 |
| 82 // Changes the current input method to |input_method_id|. If |
| 83 // |input_method_id| |
| 84 // is not active, switch to the first one in the active input method list. |
| 85 virtual void ChangeInputMethod(const std::string& input_method_id, |
| 86 bool show_message) = 0; |
| 87 |
| 88 // Adds one entry to the list of active input method IDs, and then starts or |
| 89 // stops the system input method framework as needed. |
| 90 virtual bool EnableInputMethod( |
| 91 const std::string& new_active_input_method_id) = 0; |
| 92 |
| 93 // Enables "login" keyboard layouts (e.g. US Qwerty, US Dvorak, French |
| 94 // Azerty) that are necessary for the |language_code| and then switches to |
| 95 // |initial_layouts| if the given list is not empty. For example, if |
| 96 // |language_code| is "en-US", US Qwerty, US International, US Extended, US |
| 97 // Dvorak, and US Colemak layouts would be enabled. Likewise, for Germany |
| 98 // locale, US Qwerty which corresponds to the hardware keyboard layout and |
| 99 // several keyboard layouts for Germany would be enabled. |
| 100 // Only layouts suitable for login screen are enabled. |
| 101 virtual void EnableLoginLayouts( |
| 102 const std::string& language_code, |
| 103 const std::vector<std::string>& initial_layouts) = 0; |
| 104 |
| 105 // Filters current state layouts and leaves only suitable for lock screen. |
| 106 virtual void EnableLockScreenLayouts() = 0; |
| 107 |
| 108 // Returns a list of descriptors for all Input Method Extensions. |
| 109 virtual void GetInputMethodExtensions(InputMethodDescriptors* result) = 0; |
| 110 |
| 111 // Returns the list of input methods we can select (i.e. active) including |
| 112 // extension input methods. |
| 113 virtual scoped_ptr<InputMethodDescriptors> GetActiveInputMethods() |
| 114 const = 0; |
| 115 |
| 116 // Returns the list of input methods we can select (i.e. active) including |
| 117 // extension input methods. |
| 118 // The same as GetActiveInputMethods but returns reference to internal list. |
| 119 virtual const std::vector<std::string>& GetActiveInputMethodIds() const = 0; |
| 120 |
| 121 // Returns the number of active input methods including extension input |
| 122 // methods. |
| 123 virtual size_t GetNumActiveInputMethods() const = 0; |
| 124 |
| 125 // Returns the input method descriptor from the given input method id |
| 126 // string. |
| 127 // If the given input method id is invalid, returns NULL. |
| 128 virtual const InputMethodDescriptor* GetInputMethodFromId( |
| 129 const std::string& input_method_id) const = 0; |
| 130 |
| 131 // Sets the list of extension IME ids which should be enabled. |
| 132 virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) = 0; |
| 133 |
| 134 // Sets current input method to login default (first owners, then hardware). |
| 135 virtual void SetInputMethodLoginDefault() = 0; |
| 136 |
| 137 // Sets current input method to login default with the given locale and |
| 138 // layout info from VPD. |
| 139 virtual void SetInputMethodLoginDefaultFromVPD( |
| 140 const std::string& locale, |
| 141 const std::string& layout) = 0; |
| 142 |
| 143 // Switches the current input method (or keyboard layout) to the next one. |
| 144 virtual bool SwitchToNextInputMethod() = 0; |
| 145 |
| 146 // Switches the current input method (or keyboard layout) to the previous |
| 147 // one. |
| 148 virtual bool SwitchToPreviousInputMethod( |
| 149 const ui::Accelerator& accelerator) = 0; |
| 150 |
| 151 // Switches to an input method (or keyboard layout) which is associated with |
| 152 // the |accelerator|. |
| 153 virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) = 0; |
| 154 |
| 155 // Gets the descriptor of the input method which is currently selected. |
| 156 virtual InputMethodDescriptor GetCurrentInputMethod() const = 0; |
| 157 |
| 158 // Updates the list of active input method IDs, and then starts or stops the |
| 159 // system input method framework as needed. |
| 160 virtual bool ReplaceEnabledInputMethods( |
| 161 const std::vector<std::string>& new_active_input_method_ids) = 0; |
| 162 |
| 163 protected: |
| 164 friend base::RefCounted<InputMethodManager::State>; |
| 165 |
| 166 virtual ~State(); |
| 167 }; |
| 168 |
64 virtual ~InputMethodManager() {} | 169 virtual ~InputMethodManager() {} |
65 | 170 |
66 // Gets the global instance of InputMethodManager. Initialize() must be called | 171 // Gets the global instance of InputMethodManager. Initialize() must be called |
67 // first. | 172 // first. |
68 static CHROMEOS_EXPORT InputMethodManager* Get(); | 173 static CHROMEOS_EXPORT InputMethodManager* Get(); |
69 | 174 |
70 // Sets the global instance. |instance| will be owned by the internal pointer | 175 // Sets the global instance. |instance| will be owned by the internal pointer |
71 // and deleted by Shutdown(). | 176 // and deleted by Shutdown(). |
72 // TODO(nona): Instanciate InputMethodManagerImpl inside of this function once | 177 // TODO(nona): Instanciate InputMethodManagerImpl inside of this function once |
73 // crbug.com/164375 is fixed. | 178 // crbug.com/164375 is fixed. |
74 static CHROMEOS_EXPORT void Initialize(InputMethodManager* instance); | 179 static CHROMEOS_EXPORT void Initialize(InputMethodManager* instance); |
75 | 180 |
76 // Destroy the global instance. | 181 // Destroy the global instance. |
77 static CHROMEOS_EXPORT void Shutdown(); | 182 static CHROMEOS_EXPORT void Shutdown(); |
78 | 183 |
79 // Initialize component extensions. | 184 // Initialize component extensions. |
80 virtual void InitializeComponentExtension() = 0; | 185 virtual void InitializeComponentExtension(Profile* profile) = 0; |
81 | 186 |
82 // Adds an observer to receive notifications of input method related | 187 // Adds an observer to receive notifications of input method related |
83 // changes as desribed in the Observer class above. | 188 // changes as desribed in the Observer class above. |
84 virtual void AddObserver(Observer* observer) = 0; | 189 virtual void AddObserver(Observer* observer) = 0; |
85 virtual void AddCandidateWindowObserver( | 190 virtual void AddCandidateWindowObserver( |
86 CandidateWindowObserver* observer) = 0; | 191 CandidateWindowObserver* observer) = 0; |
87 virtual void RemoveObserver(Observer* observer) = 0; | 192 virtual void RemoveObserver(Observer* observer) = 0; |
88 virtual void RemoveCandidateWindowObserver( | 193 virtual void RemoveCandidateWindowObserver( |
89 CandidateWindowObserver* observer) = 0; | 194 CandidateWindowObserver* observer) = 0; |
90 | 195 |
91 // Returns all input methods that are supported, including ones not active. | 196 // Returns all input methods that are supported, including ones not active. |
92 // This function never returns NULL. Note that input method extensions are NOT | 197 // This function never returns NULL. Note that input method extensions are NOT |
93 // included in the result. | 198 // included in the result. |
94 virtual scoped_ptr<InputMethodDescriptors> | 199 virtual scoped_ptr<InputMethodDescriptors> |
95 GetSupportedInputMethods() const = 0; | 200 GetSupportedInputMethods() const = 0; |
96 | 201 |
97 // Returns the list of input methods we can select (i.e. active) including | |
98 // extension input methods. | |
99 virtual scoped_ptr<InputMethodDescriptors> GetActiveInputMethods() const = 0; | |
100 | |
101 // Returns the list of input methods we can select (i.e. active) including | |
102 // extension input methods. | |
103 // The same as GetActiveInputMethods but returns reference to internal list. | |
104 virtual const std::vector<std::string>& GetActiveInputMethodIds() const = 0; | |
105 | |
106 // Returns the number of active input methods including extension input | |
107 // methods. | |
108 virtual size_t GetNumActiveInputMethods() const = 0; | |
109 | |
110 // Returns the input method descriptor from the given input method id string. | |
111 // If the given input method id is invalid, returns NULL. | |
112 virtual const InputMethodDescriptor* GetInputMethodFromId( | |
113 const std::string& input_method_id) const = 0; | |
114 | |
115 // Changes the current input method to |input_method_id|. If |input_method_id| | |
116 // is not active, switch to the first one in the active input method list. | |
117 virtual void ChangeInputMethod(const std::string& input_method_id) = 0; | |
118 | |
119 // Enables "login" keyboard layouts (e.g. US Qwerty, US Dvorak, French | |
120 // Azerty) that are necessary for the |language_code| and then switches to | |
121 // |initial_layouts| if the given list is not empty. For example, if | |
122 // |language_code| is "en-US", US Qwerty, US International, US Extended, US | |
123 // Dvorak, and US Colemak layouts would be enabled. Likewise, for Germany | |
124 // locale, US Qwerty which corresponds to the hardware keyboard layout and | |
125 // several keyboard layouts for Germany would be enabled. | |
126 // Only layouts suitable for login screen are enabled. | |
127 virtual void EnableLoginLayouts( | |
128 const std::string& language_code, | |
129 const std::vector<std::string>& initial_layouts) = 0; | |
130 | |
131 // Activates the input method property specified by the |key|. | 202 // Activates the input method property specified by the |key|. |
132 virtual void ActivateInputMethodMenuItem(const std::string& key) = 0; | 203 virtual void ActivateInputMethodMenuItem(const std::string& key) = 0; |
133 | 204 |
134 // Updates the list of active input method IDs, and then starts or stops the | |
135 // system input method framework as needed. | |
136 virtual bool ReplaceEnabledInputMethods( | |
137 const std::vector<std::string>& new_active_input_method_ids) = 0; | |
138 | |
139 // Adds one entry to the list of active input method IDs, and then starts or | |
140 // stops the system input method framework as needed. | |
141 virtual bool EnableInputMethod( | |
142 const std::string& new_active_input_method_id) = 0; | |
143 | |
144 // Adds an input method extension. This function does not takes ownership of | |
145 // |instance|. | |
146 virtual void AddInputMethodExtension( | |
147 const std::string& extension_id, | |
148 const InputMethodDescriptors& descriptors, | |
149 InputMethodEngineInterface* instance) = 0; | |
150 | |
151 // Removes an input method extension. | |
152 virtual void RemoveInputMethodExtension(const std::string& extension_id) = 0; | |
153 | |
154 // Returns a list of descriptors for all Input Method Extensions. | |
155 virtual void GetInputMethodExtensions(InputMethodDescriptors* result) = 0; | |
156 | |
157 // Sets the list of extension IME ids which should be enabled. | |
158 virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) = 0; | |
159 | |
160 // Sets current input method to login default (first owners, then hardware). | |
161 virtual void SetInputMethodLoginDefault() = 0; | |
162 | |
163 // Sets current input method to login default with the given locale and | |
164 // layout info from VPD. | |
165 virtual void SetInputMethodLoginDefaultFromVPD( | |
166 const std::string& locale, const std::string& layout) = 0; | |
167 | |
168 // Gets the descriptor of the input method which is currently selected. | |
169 virtual InputMethodDescriptor GetCurrentInputMethod() const = 0; | |
170 | |
171 virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const = 0; | 205 virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const = 0; |
172 | 206 |
173 virtual bool IsAltGrUsedByCurrentInputMethod() const = 0; | 207 virtual bool IsAltGrUsedByCurrentInputMethod() const = 0; |
174 | 208 |
175 // Returns an X keyboard object which could be used to change the current XKB | 209 // Returns an X keyboard object which could be used to change the current XKB |
176 // layout, change the caps lock status, and set the auto repeat rate/interval. | 210 // layout, change the caps lock status, and set the auto repeat rate/interval. |
177 virtual ImeKeyboard* GetImeKeyboard() = 0; | 211 virtual ImeKeyboard* GetImeKeyboard() = 0; |
178 | 212 |
179 // Returns an InputMethodUtil object. | 213 // Returns an InputMethodUtil object. |
180 virtual InputMethodUtil* GetInputMethodUtil() = 0; | 214 virtual InputMethodUtil* GetInputMethodUtil() = 0; |
181 | 215 |
182 // Returns a ComponentExtentionIMEManager object. | 216 // Returns a ComponentExtentionIMEManager object. |
183 virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() = 0; | 217 virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() = 0; |
184 | 218 |
185 // Switches the current input method (or keyboard layout) to the next one. | |
186 virtual bool SwitchToNextInputMethod() = 0; | |
187 | |
188 // Switches the current input method (or keyboard layout) to the previous one. | |
189 virtual bool SwitchToPreviousInputMethod( | |
190 const ui::Accelerator& accelerator) = 0; | |
191 | |
192 // Switches to an input method (or keyboard layout) which is associated with | |
193 // the |accelerator|. | |
194 virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) = 0; | |
195 | |
196 // If keyboard layout can be uset at login screen | 219 // If keyboard layout can be uset at login screen |
197 virtual bool IsLoginKeyboard(const std::string& layout) const = 0; | 220 virtual bool IsLoginKeyboard(const std::string& layout) const = 0; |
198 | 221 |
199 // Migrates the input method id to extension-based input method id. | 222 // Migrates the input method id to extension-based input method id. |
200 virtual bool MigrateInputMethods( | 223 virtual bool MigrateInputMethods( |
201 std::vector<std::string>* input_method_ids) = 0; | 224 std::vector<std::string>* input_method_ids) = 0; |
| 225 |
| 226 // Returns default state for the |profile|. |
| 227 virtual scoped_refptr<State> GetDefaultState(Profile* profile) = 0; |
| 228 |
| 229 // Returns active state. |
| 230 virtual scoped_refptr<InputMethodManager::State> GetActiveIMEState() = 0; |
| 231 |
| 232 // Returns a copy of state. |
| 233 virtual scoped_refptr<InputMethodManager::State> CloneState( |
| 234 const InputMethodManager::State* state) = 0; |
| 235 |
| 236 // Replaces active state. |
| 237 virtual void SetState(scoped_refptr<State> state) = 0; |
202 }; | 238 }; |
203 | 239 |
204 } // namespace input_method | 240 } // namespace input_method |
205 } // namespace chromeos | 241 } // namespace chromeos |
206 | 242 |
207 #endif // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_ | 243 #endif // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_ |
OLD | NEW |