Add ICU message format support
[chromium-blink-merge.git] / ui / base / ime / chromeos / input_method_manager.h
blob0b903dfd6f71e217661a483790cd0afffd5f56d7
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 Profile* profile,
53 bool show_message) = 0;
56 // CandidateWindowObserver is notified of events related to the candidate
57 // window. The "suggestion window" used by IMEs such as ibus-mozc does not
58 // count as the candidate window (this may change if we later want suggestion
59 // window events as well). These events also won't occur when the virtual
60 // keyboard is used, since it controls its own candidate window.
61 class CandidateWindowObserver {
62 public:
63 virtual ~CandidateWindowObserver() {}
64 // Called when the candidate window is opened.
65 virtual void CandidateWindowOpened(InputMethodManager* manager) = 0;
66 // Called when the candidate window is closed.
67 virtual void CandidateWindowClosed(InputMethodManager* manager) = 0;
70 class State : public base::RefCounted<InputMethodManager::State> {
71 public:
72 // Returns a copy of state.
73 virtual scoped_refptr<State> Clone() const = 0;
75 // Adds an input method extension. This function does not takes ownership of
76 // |instance|.
77 virtual void AddInputMethodExtension(
78 const std::string& extension_id,
79 const InputMethodDescriptors& descriptors,
80 InputMethodEngineInterface* instance) = 0;
82 // Removes an input method extension.
83 virtual void RemoveInputMethodExtension(
84 const std::string& extension_id) = 0;
86 // Changes the current input method to |input_method_id|. If
87 // |input_method_id|
88 // is not active, switch to the first one in the active input method list.
89 virtual void ChangeInputMethod(const std::string& input_method_id,
90 bool show_message) = 0;
92 // Adds one entry to the list of active input method IDs, and then starts or
93 // stops the system input method framework as needed.
94 virtual bool EnableInputMethod(
95 const std::string& new_active_input_method_id) = 0;
97 // Enables "login" keyboard layouts (e.g. US Qwerty, US Dvorak, French
98 // Azerty) that are necessary for the |language_code| and then switches to
99 // |initial_layouts| if the given list is not empty. For example, if
100 // |language_code| is "en-US", US Qwerty, US International, US Extended, US
101 // Dvorak, and US Colemak layouts would be enabled. Likewise, for Germany
102 // locale, US Qwerty which corresponds to the hardware keyboard layout and
103 // several keyboard layouts for Germany would be enabled.
104 // Only layouts suitable for login screen are enabled.
105 virtual void EnableLoginLayouts(
106 const std::string& language_code,
107 const std::vector<std::string>& initial_layouts) = 0;
109 // Filters current state layouts and leaves only suitable for lock screen.
110 virtual void EnableLockScreenLayouts() = 0;
112 // Returns a list of descriptors for all Input Method Extensions.
113 virtual void GetInputMethodExtensions(InputMethodDescriptors* result) = 0;
115 // Returns the list of input methods we can select (i.e. active) including
116 // extension input methods.
117 virtual scoped_ptr<InputMethodDescriptors> GetActiveInputMethods()
118 const = 0;
120 // Returns the list of input methods we can select (i.e. active) including
121 // extension input methods.
122 // The same as GetActiveInputMethods but returns reference to internal list.
123 virtual const std::vector<std::string>& GetActiveInputMethodIds() const = 0;
125 // Returns the number of active input methods including extension input
126 // methods.
127 virtual size_t GetNumActiveInputMethods() const = 0;
129 // Returns the input method descriptor from the given input method id
130 // string.
131 // If the given input method id is invalid, returns NULL.
132 virtual const InputMethodDescriptor* GetInputMethodFromId(
133 const std::string& input_method_id) const = 0;
135 // Sets the list of extension IME ids which should be enabled.
136 virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) = 0;
138 // Sets current input method to login default (first owners, then hardware).
139 virtual void SetInputMethodLoginDefault() = 0;
141 // Sets current input method to login default with the given locale and
142 // layout info from VPD.
143 virtual void SetInputMethodLoginDefaultFromVPD(
144 const std::string& locale,
145 const std::string& layout) = 0;
147 // Returns whether the input method (or keyboard layout) can be switched
148 // to the next or previous one. Returns false if only one input method is
149 // enabled.
150 virtual bool CanCycleInputMethod() = 0;
152 // Switches the current input method (or keyboard layout) to the next one.
153 virtual void SwitchToNextInputMethod() = 0;
155 // Switches the current input method (or keyboard layout) to the previous
156 // one.
157 virtual void SwitchToPreviousInputMethod() = 0;
159 // Returns true if the input method can be switched to the input method
160 // associated with |accelerator|.
161 virtual bool CanSwitchInputMethod(const ui::Accelerator& accelerator) = 0;
163 // Switches to an input method (or keyboard layout) which is associated with
164 // the |accelerator|.
165 virtual void SwitchInputMethod(const ui::Accelerator& accelerator) = 0;
167 // Gets the descriptor of the input method which is currently selected.
168 virtual InputMethodDescriptor GetCurrentInputMethod() const = 0;
170 // Updates the list of active input method IDs, and then starts or stops the
171 // system input method framework as needed.
172 virtual bool ReplaceEnabledInputMethods(
173 const std::vector<std::string>& new_active_input_method_ids) = 0;
175 protected:
176 friend base::RefCounted<InputMethodManager::State>;
178 virtual ~State();
181 virtual ~InputMethodManager() {}
183 // Gets the global instance of InputMethodManager. Initialize() must be called
184 // first.
185 static UI_BASE_IME_EXPORT InputMethodManager* Get();
187 // Sets the global instance. |instance| will be owned by the internal pointer
188 // and deleted by Shutdown().
189 // TODO(nona): Instanciate InputMethodManagerImpl inside of this function once
190 // crbug.com/164375 is fixed.
191 static UI_BASE_IME_EXPORT void Initialize(InputMethodManager* instance);
193 // Destroy the global instance.
194 static UI_BASE_IME_EXPORT void Shutdown();
196 // Get the current UI session state (e.g. login screen, lock screen, etc.).
197 virtual UISessionState GetUISessionState() = 0;
199 // Adds an observer to receive notifications of input method related
200 // changes as desribed in the Observer class above.
201 virtual void AddObserver(Observer* observer) = 0;
202 virtual void AddCandidateWindowObserver(
203 CandidateWindowObserver* observer) = 0;
204 virtual void RemoveObserver(Observer* observer) = 0;
205 virtual void RemoveCandidateWindowObserver(
206 CandidateWindowObserver* observer) = 0;
208 // Returns all input methods that are supported, including ones not active.
209 // This function never returns NULL. Note that input method extensions are NOT
210 // included in the result.
211 virtual scoped_ptr<InputMethodDescriptors>
212 GetSupportedInputMethods() const = 0;
214 // Activates the input method property specified by the |key|.
215 virtual void ActivateInputMethodMenuItem(const std::string& key) = 0;
217 virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const = 0;
219 virtual bool IsAltGrUsedByCurrentInputMethod() const = 0;
221 // Returns an X keyboard object which could be used to change the current XKB
222 // layout, change the caps lock status, and set the auto repeat rate/interval.
223 virtual ImeKeyboard* GetImeKeyboard() = 0;
225 // Returns an InputMethodUtil object.
226 virtual InputMethodUtil* GetInputMethodUtil() = 0;
228 // Returns a ComponentExtentionIMEManager object.
229 virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() = 0;
231 // If keyboard layout can be uset at login screen
232 virtual bool IsLoginKeyboard(const std::string& layout) const = 0;
234 // Migrates the input method id to extension-based input method id.
235 virtual bool MigrateInputMethods(
236 std::vector<std::string>* input_method_ids) = 0;
238 // Returns new empty state for the |profile|.
239 virtual scoped_refptr<State> CreateNewState(Profile* profile) = 0;
241 // Returns active state.
242 virtual scoped_refptr<InputMethodManager::State> GetActiveIMEState() = 0;
244 // Replaces active state.
245 virtual void SetState(scoped_refptr<State> state) = 0;
248 } // namespace input_method
249 } // namespace chromeos
251 #endif // UI_BASE_IME_CHROMEOS_INPUT_METHOD_MANAGER_H_