Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(841)

Side by Side Diff: chromeos/ime/input_method_manager.h

Issue 419293002: IME refactoring: ChromeOS introduce input methods State. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit test fixed. Re-sorted methods of StateImpl and IMM. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Returns a copy of state.
72 virtual scoped_refptr<State> Clone() const = 0;
73
74 // Adds an input method extension. This function does not takes ownership of
75 // |instance|.
76 virtual void AddInputMethodExtension(
77 const std::string& extension_id,
78 const InputMethodDescriptors& descriptors,
79 InputMethodEngineInterface* instance) = 0;
80
81 // Removes an input method extension.
82 virtual void RemoveInputMethodExtension(
83 const std::string& extension_id) = 0;
84
85 // Changes the current input method to |input_method_id|. If
86 // |input_method_id|
87 // is not active, switch to the first one in the active input method list.
88 virtual void ChangeInputMethod(const std::string& input_method_id,
89 bool show_message) = 0;
90
91 // Adds one entry to the list of active input method IDs, and then starts or
92 // stops the system input method framework as needed.
93 virtual bool EnableInputMethod(
94 const std::string& new_active_input_method_id) = 0;
95
96 // Enables "login" keyboard layouts (e.g. US Qwerty, US Dvorak, French
97 // Azerty) that are necessary for the |language_code| and then switches to
98 // |initial_layouts| if the given list is not empty. For example, if
99 // |language_code| is "en-US", US Qwerty, US International, US Extended, US
100 // Dvorak, and US Colemak layouts would be enabled. Likewise, for Germany
101 // locale, US Qwerty which corresponds to the hardware keyboard layout and
102 // several keyboard layouts for Germany would be enabled.
103 // Only layouts suitable for login screen are enabled.
104 virtual void EnableLoginLayouts(
105 const std::string& language_code,
106 const std::vector<std::string>& initial_layouts) = 0;
107
108 // Filters current state layouts and leaves only suitable for lock screen.
109 virtual void EnableLockScreenLayouts() = 0;
110
111 // Returns a list of descriptors for all Input Method Extensions.
112 virtual void GetInputMethodExtensions(InputMethodDescriptors* result) = 0;
113
114 // Returns the list of input methods we can select (i.e. active) including
115 // extension input methods.
116 virtual scoped_ptr<InputMethodDescriptors> GetActiveInputMethods()
117 const = 0;
118
119 // Returns the list of input methods we can select (i.e. active) including
120 // extension input methods.
121 // The same as GetActiveInputMethods but returns reference to internal list.
122 virtual const std::vector<std::string>& GetActiveInputMethodIds() const = 0;
123
124 // Returns the number of active input methods including extension input
125 // methods.
126 virtual size_t GetNumActiveInputMethods() const = 0;
127
128 // Returns the input method descriptor from the given input method id
129 // string.
130 // If the given input method id is invalid, returns NULL.
131 virtual const InputMethodDescriptor* GetInputMethodFromId(
132 const std::string& input_method_id) const = 0;
133
134 // Sets the list of extension IME ids which should be enabled.
135 virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) = 0;
136
137 // Sets current input method to login default (first owners, then hardware).
138 virtual void SetInputMethodLoginDefault() = 0;
139
140 // Sets current input method to login default with the given locale and
141 // layout info from VPD.
142 virtual void SetInputMethodLoginDefaultFromVPD(
143 const std::string& locale,
144 const std::string& layout) = 0;
145
146 // Switches the current input method (or keyboard layout) to the next one.
147 virtual bool SwitchToNextInputMethod() = 0;
148
149 // Switches the current input method (or keyboard layout) to the previous
150 // one.
151 virtual bool SwitchToPreviousInputMethod(
152 const ui::Accelerator& accelerator) = 0;
153
154 // Switches to an input method (or keyboard layout) which is associated with
155 // the |accelerator|.
156 virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) = 0;
157
158 // Gets the descriptor of the input method which is currently selected.
159 virtual InputMethodDescriptor GetCurrentInputMethod() const = 0;
160
161 // Updates the list of active input method IDs, and then starts or stops the
162 // system input method framework as needed.
163 virtual bool ReplaceEnabledInputMethods(
164 const std::vector<std::string>& new_active_input_method_ids) = 0;
165
166 protected:
167 friend base::RefCounted<InputMethodManager::State>;
168
169 virtual ~State();
170 };
171
64 virtual ~InputMethodManager() {} 172 virtual ~InputMethodManager() {}
65 173
66 // Gets the global instance of InputMethodManager. Initialize() must be called 174 // Gets the global instance of InputMethodManager. Initialize() must be called
67 // first. 175 // first.
68 static CHROMEOS_EXPORT InputMethodManager* Get(); 176 static CHROMEOS_EXPORT InputMethodManager* Get();
69 177
70 // Sets the global instance. |instance| will be owned by the internal pointer 178 // Sets the global instance. |instance| will be owned by the internal pointer
71 // and deleted by Shutdown(). 179 // and deleted by Shutdown().
72 // TODO(nona): Instanciate InputMethodManagerImpl inside of this function once 180 // TODO(nona): Instanciate InputMethodManagerImpl inside of this function once
73 // crbug.com/164375 is fixed. 181 // crbug.com/164375 is fixed.
74 static CHROMEOS_EXPORT void Initialize(InputMethodManager* instance); 182 static CHROMEOS_EXPORT void Initialize(InputMethodManager* instance);
75 183
76 // Destroy the global instance. 184 // Destroy the global instance.
77 static CHROMEOS_EXPORT void Shutdown(); 185 static CHROMEOS_EXPORT void Shutdown();
78 186
79 // Get the current UI session state (e.g. login screen, lock screen, etc.). 187 // Get the current UI session state (e.g. login screen, lock screen, etc.).
80 virtual State GetState() = 0; 188 virtual UISessionState GetUISessionState() = 0;
81 189
82 // Adds an observer to receive notifications of input method related 190 // Adds an observer to receive notifications of input method related
83 // changes as desribed in the Observer class above. 191 // changes as desribed in the Observer class above.
84 virtual void AddObserver(Observer* observer) = 0; 192 virtual void AddObserver(Observer* observer) = 0;
85 virtual void AddCandidateWindowObserver( 193 virtual void AddCandidateWindowObserver(
86 CandidateWindowObserver* observer) = 0; 194 CandidateWindowObserver* observer) = 0;
87 virtual void RemoveObserver(Observer* observer) = 0; 195 virtual void RemoveObserver(Observer* observer) = 0;
88 virtual void RemoveCandidateWindowObserver( 196 virtual void RemoveCandidateWindowObserver(
89 CandidateWindowObserver* observer) = 0; 197 CandidateWindowObserver* observer) = 0;
90 198
91 // Returns all input methods that are supported, including ones not active. 199 // Returns all input methods that are supported, including ones not active.
92 // This function never returns NULL. Note that input method extensions are NOT 200 // This function never returns NULL. Note that input method extensions are NOT
93 // included in the result. 201 // included in the result.
94 virtual scoped_ptr<InputMethodDescriptors> 202 virtual scoped_ptr<InputMethodDescriptors>
95 GetSupportedInputMethods() const = 0; 203 GetSupportedInputMethods() const = 0;
96 204
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|. 205 // Activates the input method property specified by the |key|.
132 virtual void ActivateInputMethodMenuItem(const std::string& key) = 0; 206 virtual void ActivateInputMethodMenuItem(const std::string& key) = 0;
133 207
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; 208 virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const = 0;
172 209
173 virtual bool IsAltGrUsedByCurrentInputMethod() const = 0; 210 virtual bool IsAltGrUsedByCurrentInputMethod() const = 0;
174 211
175 // Returns an X keyboard object which could be used to change the current XKB 212 // 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. 213 // layout, change the caps lock status, and set the auto repeat rate/interval.
177 virtual ImeKeyboard* GetImeKeyboard() = 0; 214 virtual ImeKeyboard* GetImeKeyboard() = 0;
178 215
179 // Returns an InputMethodUtil object. 216 // Returns an InputMethodUtil object.
180 virtual InputMethodUtil* GetInputMethodUtil() = 0; 217 virtual InputMethodUtil* GetInputMethodUtil() = 0;
181 218
182 // Returns a ComponentExtentionIMEManager object. 219 // Returns a ComponentExtentionIMEManager object.
183 virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() = 0; 220 virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() = 0;
184 221
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 222 // If keyboard layout can be uset at login screen
197 virtual bool IsLoginKeyboard(const std::string& layout) const = 0; 223 virtual bool IsLoginKeyboard(const std::string& layout) const = 0;
198 224
199 // Migrates the input method id to extension-based input method id. 225 // Migrates the input method id to extension-based input method id.
200 virtual bool MigrateInputMethods( 226 virtual bool MigrateInputMethods(
201 std::vector<std::string>* input_method_ids) = 0; 227 std::vector<std::string>* input_method_ids) = 0;
228
229 // Returns new empty state for the |profile|.
230 virtual scoped_refptr<State> CreateNewState(Profile* profile) = 0;
231
232 // Returns active state.
233 virtual scoped_refptr<InputMethodManager::State> GetActiveIMEState() = 0;
234
235 // Replaces active state.
236 virtual void SetState(scoped_refptr<State> state) = 0;
202 }; 237 };
203 238
204 } // namespace input_method 239 } // namespace input_method
205 } // namespace chromeos 240 } // namespace chromeos
206 241
207 #endif // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_ 242 #endif // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_
OLDNEW
« no previous file with comments | « chromeos/ime/component_extension_ime_manager_unittest.cc ('k') | chromeos/ime/input_method_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698