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 CHROMEOS_IME_INPUT_METHOD_MANAGER_H_
6 #define CHROMEOS_IME_INPUT_METHOD_MANAGER_H_
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"
23 namespace user_manager
{
25 } // namespace user_manager
28 class ComponentExtensionIMEManager
;
29 class InputMethodEngineInterface
;
30 namespace input_method
{
31 class InputMethodUtil
;
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
{
40 STATE_LOGIN_SCREEN
= 0,
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
{
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
> {
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
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
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()
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
126 virtual size_t GetNumActiveInputMethods() const = 0;
128 // Returns the input method descriptor from the given input method id
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 // Switches the current input method (or keyboard layout) to the next one.
147 virtual bool SwitchToNextInputMethod() = 0;
149 // Switches the current input method (or keyboard layout) to the previous
151 virtual bool SwitchToPreviousInputMethod(
152 const ui::Accelerator
& accelerator
) = 0;
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;
158 // Gets the descriptor of the input method which is currently selected.
159 virtual InputMethodDescriptor
GetCurrentInputMethod() const = 0;
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;
167 friend base::RefCounted
<InputMethodManager::State
>;
172 virtual ~InputMethodManager() {}
174 // Gets the global instance of InputMethodManager. Initialize() must be called
176 static CHROMEOS_EXPORT InputMethodManager
* Get();
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
);
184 // Destroy the global instance.
185 static CHROMEOS_EXPORT
void Shutdown();
187 // Get the current UI session state (e.g. login screen, lock screen, etc.).
188 virtual UISessionState
GetUISessionState() = 0;
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;
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;
205 // Activates the input method property specified by the |key|.
206 virtual void ActivateInputMethodMenuItem(const std::string
& key
) = 0;
208 virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const = 0;
210 virtual bool IsAltGrUsedByCurrentInputMethod() const = 0;
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;
216 // Returns an InputMethodUtil object.
217 virtual InputMethodUtil
* GetInputMethodUtil() = 0;
219 // Returns a ComponentExtentionIMEManager object.
220 virtual ComponentExtensionIMEManager
* GetComponentExtensionIMEManager() = 0;
222 // If keyboard layout can be uset at login screen
223 virtual bool IsLoginKeyboard(const std::string
& layout
) const = 0;
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;
229 // Returns new empty state for the |profile|.
230 virtual scoped_refptr
<State
> CreateNewState(Profile
* profile
) = 0;
232 // Returns active state.
233 virtual scoped_refptr
<InputMethodManager::State
> GetActiveIMEState() = 0;
235 // Replaces active state.
236 virtual void SetState(scoped_refptr
<State
> state
) = 0;
239 } // namespace input_method
240 } // namespace chromeos
242 #endif // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_