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/scoped_ptr.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/ime/input_method_descriptor.h"
23 class ComponentExtensionIMEManager;
24 class InputMethodEngineInterface;
25 namespace input_method {
26 class InputMethodUtil;
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 {
35 STATE_LOGIN_SCREEN = 0,
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;
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 {
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;
64 virtual ~InputMethodManager() {}
66 // Gets the global instance of InputMethodManager. Initialize() must be called
68 static CHROMEOS_EXPORT InputMethodManager* Get();
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);
76 // Destroy the global instance.
77 static CHROMEOS_EXPORT void Shutdown();
79 // Get the current UI session state (e.g. login screen, lock screen, etc.).
80 virtual State GetState() = 0;
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;
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;
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;
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;
106 // Returns the number of active input methods including extension input
108 virtual size_t GetNumActiveInputMethods() const = 0;
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;
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;
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;
131 // Activates the input method property specified by the |key|.
132 virtual void ActivateInputMethodMenuItem(const std::string& key) = 0;
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;
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;
144 // Adds an input method extension. This function does not takes ownership of
146 virtual void AddInputMethodExtension(
147 const std::string& extension_id,
148 const InputMethodDescriptors& descriptors,
149 InputMethodEngineInterface* instance) = 0;
151 // Removes an input method extension.
152 virtual void RemoveInputMethodExtension(const std::string& extension_id) = 0;
154 // Returns a list of descriptors for all Input Method Extensions.
155 virtual void GetInputMethodExtensions(InputMethodDescriptors* result) = 0;
157 // Sets the list of extension IME ids which should be enabled.
158 virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) = 0;
160 // Sets current input method to login default (first owners, then hardware).
161 virtual void SetInputMethodLoginDefault() = 0;
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;
168 // Gets the descriptor of the input method which is currently selected.
169 virtual InputMethodDescriptor GetCurrentInputMethod() const = 0;
171 virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const = 0;
173 virtual bool IsAltGrUsedByCurrentInputMethod() const = 0;
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;
179 // Returns an InputMethodUtil object.
180 virtual InputMethodUtil* GetInputMethodUtil() = 0;
182 // Returns a ComponentExtentionIMEManager object.
183 virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() = 0;
185 // Switches the current input method (or keyboard layout) to the next one.
186 virtual bool SwitchToNextInputMethod() = 0;
188 // Switches the current input method (or keyboard layout) to the previous one.
189 virtual bool SwitchToPreviousInputMethod(
190 const ui::Accelerator& accelerator) = 0;
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;
196 // If keyboard layout can be uset at login screen
197 virtual bool IsLoginKeyboard(const std::string& layout) const = 0;
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;
204 } // namespace input_method
205 } // namespace chromeos
207 #endif // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_