Upstream version 9.38.198.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/scoped_ptr.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/ime/input_method_descriptor.h"
15
16 class Profile;
17
18 namespace ui {
19 class Accelerator;
20 }  // namespace ui
21
22 namespace chromeos {
23 class ComponentExtensionIMEManager;
24 class InputMethodEngineInterface;
25 namespace input_method {
26 class InputMethodUtil;
27 class ImeKeyboard;
28
29 // This class manages input methodshandles.  Classes can add themselves as
30 // observers. Clients can get an instance of this library class by:
31 // InputMethodManager::Get().
32 class CHROMEOS_EXPORT InputMethodManager {
33  public:
34   enum State {
35     STATE_LOGIN_SCREEN = 0,
36     STATE_BROWSER_SCREEN,
37     STATE_LOCK_SCREEN,
38     STATE_TERMINATING,
39   };
40
41   class Observer {
42    public:
43     virtual ~Observer() {}
44     // Called when the current input method is changed.  |show_message|
45     // indicates whether the user should be notified of this change.
46     virtual void InputMethodChanged(InputMethodManager* manager,
47                                     bool show_message) = 0;
48   };
49
50   // CandidateWindowObserver is notified of events related to the candidate
51   // 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
53   // window events as well).  These events also won't occur when the virtual
54   // keyboard is used, since it controls its own candidate window.
55   class CandidateWindowObserver {
56    public:
57     virtual ~CandidateWindowObserver() {}
58     // Called when the candidate window is opened.
59     virtual void CandidateWindowOpened(InputMethodManager* manager) = 0;
60     // Called when the candidate window is closed.
61     virtual void CandidateWindowClosed(InputMethodManager* manager) = 0;
62   };
63
64   virtual ~InputMethodManager() {}
65
66   // Gets the global instance of InputMethodManager. Initialize() must be called
67   // first.
68   static CHROMEOS_EXPORT InputMethodManager* Get();
69
70   // Sets the global instance. |instance| will be owned by the internal pointer
71   // and deleted by Shutdown().
72   // TODO(nona): Instanciate InputMethodManagerImpl inside of this function once
73   //             crbug.com/164375 is fixed.
74   static CHROMEOS_EXPORT void Initialize(InputMethodManager* instance);
75
76   // Destroy the global instance.
77   static CHROMEOS_EXPORT void Shutdown();
78
79   // Get the current UI session state (e.g. login screen, lock screen, etc.).
80   virtual State GetState() = 0;
81
82   // Adds an observer to receive notifications of input method related
83   // changes as desribed in the Observer class above.
84   virtual void AddObserver(Observer* observer) = 0;
85   virtual void AddCandidateWindowObserver(
86       CandidateWindowObserver* observer) = 0;
87   virtual void RemoveObserver(Observer* observer) = 0;
88   virtual void RemoveCandidateWindowObserver(
89       CandidateWindowObserver* observer) = 0;
90
91   // Returns all input methods that are supported, including ones not active.
92   // This function never returns NULL. Note that input method extensions are NOT
93   // included in the result.
94   virtual scoped_ptr<InputMethodDescriptors>
95       GetSupportedInputMethods() const = 0;
96
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|.
132   virtual void ActivateInputMethodMenuItem(const std::string& key) = 0;
133
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;
172
173   virtual bool IsAltGrUsedByCurrentInputMethod() const = 0;
174
175   // 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.
177   virtual ImeKeyboard* GetImeKeyboard() = 0;
178
179   // Returns an InputMethodUtil object.
180   virtual InputMethodUtil* GetInputMethodUtil() = 0;
181
182   // Returns a ComponentExtentionIMEManager object.
183   virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() = 0;
184
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
197   virtual bool IsLoginKeyboard(const std::string& layout) const = 0;
198
199   // Migrates the input method id to extension-based input method id.
200   virtual bool MigrateInputMethods(
201       std::vector<std::string>* input_method_ids) = 0;
202 };
203
204 }  // namespace input_method
205 }  // namespace chromeos
206
207 #endif  // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_