Split ui/base/ime into a new component
[chromium-blink-merge.git] / ui / base / ime / chromeos / input_method_manager.h
bloba7eb3a96dcdb46edb0dba5cfb4b07fd1fcc51225
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
3 // found in the LICENSE file.
5 #ifndef UI_BASE_IME_CHROMEOS_INPUT_METHOD_MANAGER_H_
6 #define UI_BASE_IME_CHROMEOS_INPUT_METHOD_MANAGER_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "ui/base/ime/chromeos/input_method_descriptor.h"
15 #include "ui/base/ime/ui_base_ime_export.h"
17 class Profile;
19 namespace ui {
20 class Accelerator;
21 } // namespace ui
23 namespace user_manager {
24 class User;
25 } // namespace user_manager
27 namespace chromeos {
28 class ComponentExtensionIMEManager;
29 class InputMethodEngineInterface;
30 namespace input_method {
31 class InputMethodUtil;
32 class ImeKeyboard;
34 // This class manages input methodshandles. Classes can add themselves as
35 // observers. Clients can get an instance of this library class by:
36 // InputMethodManager::Get().
37 class UI_BASE_IME_EXPORT InputMethodManager {
38 public:
39 enum UISessionState {
40 STATE_LOGIN_SCREEN = 0,
41 STATE_BROWSER_SCREEN,
42 STATE_LOCK_SCREEN,
43 STATE_TERMINATING,
46 class Observer {
47 public:
48 virtual ~Observer() {}
49 // Called when the current input method is changed. |show_message|
50 // indicates whether the user should be notified of this change.
51 virtual void InputMethodChanged(InputMethodManager* manager,
52 bool show_message) = 0;
55 // CandidateWindowObserver is notified of events related to the candidate
56 // window. The "suggestion window" used by IMEs such as ibus-mozc does not
57 // count as the candidate window (this may change if we later want suggestion
58 // window events as well). These events also won't occur when the virtual
59 // keyboard is used, since it controls its own candidate window.
60 class CandidateWindowObserver {
61 public:
62 virtual ~CandidateWindowObserver() {}
63 // Called when the candidate window is opened.
64 virtual void CandidateWindowOpened(InputMethodManager* manager) = 0;
65 // Called when the candidate window is closed.
66 virtual void CandidateWindowClosed(InputMethodManager* manager) = 0;
69 class State : public base::RefCounted<InputMethodManager::State> {
70 public:
71 // Returns a copy of state.
72 virtual scoped_refptr<State> Clone() const = 0;
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;
81 // Removes an input method extension.
82 virtual void RemoveInputMethodExtension(
83 const std::string& extension_id) = 0;
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;
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;
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;
108 // Filters current state layouts and leaves only suitable for lock screen.
109 virtual void EnableLockScreenLayouts() = 0;
111 // Returns a list of descriptors for all Input Method Extensions.
112 virtual void GetInputMethodExtensions(InputMethodDescriptors* result) = 0;
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;
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;
124 // Returns the number of active input methods including extension input
125 // methods.
126 virtual size_t GetNumActiveInputMethods() const = 0;
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;
134 // Sets the list of extension IME ids which should be enabled.
135 virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) = 0;
137 // Sets current input method to login default (first owners, then hardware).
138 virtual void SetInputMethodLoginDefault() = 0;
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;
146 // Returns whether the input method (or keyboard layout) can be switched
147 // to the next or previous one. Returns false if only one input method is
148 // enabled.
149 virtual bool CanCycleInputMethod() = 0;
151 // Switches the current input method (or keyboard layout) to the next one.
152 virtual void SwitchToNextInputMethod() = 0;
154 // Switches the current input method (or keyboard layout) to the previous
155 // one.
156 virtual void SwitchToPreviousInputMethod() = 0;
158 // Returns true if the input method can be switched to the input method
159 // associated with |accelerator|.
160 virtual bool CanSwitchInputMethod(const ui::Accelerator& accelerator) = 0;
162 // Switches to an input method (or keyboard layout) which is associated with
163 // the |accelerator|.
164 virtual void SwitchInputMethod(const ui::Accelerator& accelerator) = 0;
166 // Gets the descriptor of the input method which is currently selected.
167 virtual InputMethodDescriptor GetCurrentInputMethod() const = 0;
169 // Updates the list of active input method IDs, and then starts or stops the
170 // system input method framework as needed.
171 virtual bool ReplaceEnabledInputMethods(
172 const std::vector<std::string>& new_active_input_method_ids) = 0;
174 protected:
175 friend base::RefCounted<InputMethodManager::State>;
177 virtual ~State();
180 virtual ~InputMethodManager() {}
182 // Gets the global instance of InputMethodManager. Initialize() must be called
183 // first.
184 static UI_BASE_IME_EXPORT InputMethodManager* Get();
186 // Sets the global instance. |instance| will be owned by the internal pointer
187 // and deleted by Shutdown().
188 // TODO(nona): Instanciate InputMethodManagerImpl inside of this function once
189 // crbug.com/164375 is fixed.
190 static UI_BASE_IME_EXPORT void Initialize(InputMethodManager* instance);
192 // Destroy the global instance.
193 static UI_BASE_IME_EXPORT void Shutdown();
195 // Get the current UI session state (e.g. login screen, lock screen, etc.).
196 virtual UISessionState GetUISessionState() = 0;
198 // Adds an observer to receive notifications of input method related
199 // changes as desribed in the Observer class above.
200 virtual void AddObserver(Observer* observer) = 0;
201 virtual void AddCandidateWindowObserver(
202 CandidateWindowObserver* observer) = 0;
203 virtual void RemoveObserver(Observer* observer) = 0;
204 virtual void RemoveCandidateWindowObserver(
205 CandidateWindowObserver* observer) = 0;
207 // Returns all input methods that are supported, including ones not active.
208 // This function never returns NULL. Note that input method extensions are NOT
209 // included in the result.
210 virtual scoped_ptr<InputMethodDescriptors>
211 GetSupportedInputMethods() const = 0;
213 // Activates the input method property specified by the |key|.
214 virtual void ActivateInputMethodMenuItem(const std::string& key) = 0;
216 virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const = 0;
218 virtual bool IsAltGrUsedByCurrentInputMethod() const = 0;
220 // Returns an X keyboard object which could be used to change the current XKB
221 // layout, change the caps lock status, and set the auto repeat rate/interval.
222 virtual ImeKeyboard* GetImeKeyboard() = 0;
224 // Returns an InputMethodUtil object.
225 virtual InputMethodUtil* GetInputMethodUtil() = 0;
227 // Returns a ComponentExtentionIMEManager object.
228 virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() = 0;
230 // If keyboard layout can be uset at login screen
231 virtual bool IsLoginKeyboard(const std::string& layout) const = 0;
233 // Migrates the input method id to extension-based input method id.
234 virtual bool MigrateInputMethods(
235 std::vector<std::string>* input_method_ids) = 0;
237 // Returns new empty state for the |profile|.
238 virtual scoped_refptr<State> CreateNewState(Profile* profile) = 0;
240 // Returns active state.
241 virtual scoped_refptr<InputMethodManager::State> GetActiveIMEState() = 0;
243 // Replaces active state.
244 virtual void SetState(scoped_refptr<State> state) = 0;
247 } // namespace input_method
248 } // namespace chromeos
250 #endif // UI_BASE_IME_CHROMEOS_INPUT_METHOD_MANAGER_H_