Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chromeos / ime / input_method_manager.h
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.
4
5 #ifndef CHROMEOS_IME_INPUT_METHOD_MANAGER_H_
6 #define CHROMEOS_IME_INPUT_METHOD_MANAGER_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/ime/input_method_descriptor.h"
16
17 class Profile;
18
19 namespace ui {
20 class Accelerator;
21 }  // namespace ui
22
23 namespace user_manager {
24 class User;
25 }  // namespace user_manager
26
27 namespace chromeos {
28 class ComponentExtensionIMEManager;
29 class InputMethodEngineInterface;
30 namespace input_method {
31 class InputMethodUtil;
32 class ImeKeyboard;
33
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 CHROMEOS_EXPORT InputMethodManager {
38  public:
39   enum UISessionState {
40     STATE_LOGIN_SCREEN = 0,
41     STATE_BROWSER_SCREEN,
42     STATE_LOCK_SCREEN,
43     STATE_TERMINATING,
44   };
45
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;
53   };
54
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;
67   };
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
172   virtual ~InputMethodManager() {}
173
174   // Gets the global instance of InputMethodManager. Initialize() must be called
175   // first.
176   static CHROMEOS_EXPORT InputMethodManager* Get();
177
178   // Sets the global instance. |instance| will be owned by the internal pointer
179   // and deleted by Shutdown().
180   // TODO(nona): Instanciate InputMethodManagerImpl inside of this function once
181   //             crbug.com/164375 is fixed.
182   static CHROMEOS_EXPORT void Initialize(InputMethodManager* instance);
183
184   // Destroy the global instance.
185   static CHROMEOS_EXPORT void Shutdown();
186
187   // Get the current UI session state (e.g. login screen, lock screen, etc.).
188   virtual UISessionState GetUISessionState() = 0;
189
190   // Adds an observer to receive notifications of input method related
191   // changes as desribed in the Observer class above.
192   virtual void AddObserver(Observer* observer) = 0;
193   virtual void AddCandidateWindowObserver(
194       CandidateWindowObserver* observer) = 0;
195   virtual void RemoveObserver(Observer* observer) = 0;
196   virtual void RemoveCandidateWindowObserver(
197       CandidateWindowObserver* observer) = 0;
198
199   // Returns all input methods that are supported, including ones not active.
200   // This function never returns NULL. Note that input method extensions are NOT
201   // included in the result.
202   virtual scoped_ptr<InputMethodDescriptors>
203       GetSupportedInputMethods() const = 0;
204
205   // Activates the input method property specified by the |key|.
206   virtual void ActivateInputMethodMenuItem(const std::string& key) = 0;
207
208   virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const = 0;
209
210   virtual bool IsAltGrUsedByCurrentInputMethod() const = 0;
211
212   // Returns an X keyboard object which could be used to change the current XKB
213   // layout, change the caps lock status, and set the auto repeat rate/interval.
214   virtual ImeKeyboard* GetImeKeyboard() = 0;
215
216   // Returns an InputMethodUtil object.
217   virtual InputMethodUtil* GetInputMethodUtil() = 0;
218
219   // Returns a ComponentExtentionIMEManager object.
220   virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() = 0;
221
222   // If keyboard layout can be uset at login screen
223   virtual bool IsLoginKeyboard(const std::string& layout) const = 0;
224
225   // Migrates the input method id to extension-based input method id.
226   virtual bool MigrateInputMethods(
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;
237 };
238
239 }  // namespace input_method
240 }  // namespace chromeos
241
242 #endif  // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_