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"
21 class ComponentExtensionIMEManager
;
22 class InputMethodEngineInterface
;
23 namespace input_method
{
24 class InputMethodUtil
;
27 // This class manages input methodshandles. Classes can add themselves as
28 // observers. Clients can get an instance of this library class by:
29 // InputMethodManager::Get().
30 class CHROMEOS_EXPORT InputMethodManager
{
33 STATE_LOGIN_SCREEN
= 0,
41 virtual ~Observer() {}
42 // Called when the current input method is changed. |show_message|
43 // indicates whether the user should be notified of this change.
44 virtual void InputMethodChanged(InputMethodManager
* manager
,
45 bool show_message
) = 0;
48 // CandidateWindowObserver is notified of events related to the candidate
49 // window. The "suggestion window" used by IMEs such as ibus-mozc does not
50 // count as the candidate window (this may change if we later want suggestion
51 // window events as well). These events also won't occur when the virtual
52 // keyboard is used, since it controls its own candidate window.
53 class CandidateWindowObserver
{
55 virtual ~CandidateWindowObserver() {}
56 // Called when the candidate window is opened.
57 virtual void CandidateWindowOpened(InputMethodManager
* manager
) = 0;
58 // Called when the candidate window is closed.
59 virtual void CandidateWindowClosed(InputMethodManager
* manager
) = 0;
62 virtual ~InputMethodManager() {}
64 // Gets the global instance of InputMethodManager. Initialize() must be called
66 static CHROMEOS_EXPORT InputMethodManager
* Get();
68 // Sets the global instance. |instance| will be owned by the internal pointer
69 // and deleted by Shutdown().
70 // TODO(nona): Instanciate InputMethodManagerImpl inside of this function once
71 // crbug.com/164375 is fixed.
72 static CHROMEOS_EXPORT
void Initialize(InputMethodManager
* instance
);
74 // Destroy the global instance.
75 static CHROMEOS_EXPORT
void Shutdown();
77 // Adds an observer to receive notifications of input method related
78 // changes as desribed in the Observer class above.
79 virtual void AddObserver(Observer
* observer
) = 0;
80 virtual void AddCandidateWindowObserver(
81 CandidateWindowObserver
* observer
) = 0;
82 virtual void RemoveObserver(Observer
* observer
) = 0;
83 virtual void RemoveCandidateWindowObserver(
84 CandidateWindowObserver
* observer
) = 0;
86 // Returns all input methods that are supported, including ones not active.
87 // This function never returns NULL. Note that input method extensions are NOT
88 // included in the result.
89 virtual scoped_ptr
<InputMethodDescriptors
>
90 GetSupportedInputMethods() const = 0;
92 // Returns the list of input methods we can select (i.e. active) including
93 // extension input methods.
94 virtual scoped_ptr
<InputMethodDescriptors
> GetActiveInputMethods() const = 0;
96 // Returns the list of input methods we can select (i.e. active) including
97 // extension input methods.
98 // The same as GetActiveInputMethods but returns reference to internal list.
99 virtual const std::vector
<std::string
>& GetActiveInputMethodIds() const = 0;
101 // Returns the number of active input methods including extension input
103 virtual size_t GetNumActiveInputMethods() const = 0;
105 // Returns the input method descriptor from the given input method id string.
106 // If the given input method id is invalid, returns NULL.
107 virtual const InputMethodDescriptor
* GetInputMethodFromId(
108 const std::string
& input_method_id
) const = 0;
110 // Changes the current input method to |input_method_id|. If |input_method_id|
111 // is not active, switch to the first one in the active input method list.
112 virtual void ChangeInputMethod(const std::string
& input_method_id
) = 0;
114 // Enables "login" keyboard layouts (e.g. US Qwerty, US Dvorak, French
115 // Azerty) that are necessary for the |language_code| and then switches to
116 // |initial_layouts| if the given list is not empty. For example, if
117 // |language_code| is "en-US", US Qwerty, US International, US Extended, US
118 // Dvorak, and US Colemak layouts would be enabled. Likewise, for Germany
119 // locale, US Qwerty which corresponds to the hardware keyboard layout and
120 // several keyboard layouts for Germany would be enabled.
121 // Only layouts suitable for login screen are enabled.
122 virtual void EnableLoginLayouts(
123 const std::string
& language_code
,
124 const std::vector
<std::string
>& initial_layouts
) = 0;
126 // Activates the input method property specified by the |key|.
127 virtual void ActivateInputMethodMenuItem(const std::string
& key
) = 0;
129 // Updates the list of active input method IDs, and then starts or stops the
130 // system input method framework as needed.
131 virtual bool ReplaceEnabledInputMethods(
132 const std::vector
<std::string
>& new_active_input_method_ids
) = 0;
134 // Adds one entry to the list of active input method IDs, and then starts or
135 // stops the system input method framework as needed.
136 virtual bool EnableInputMethod(
137 const std::string
& new_active_input_method_id
) = 0;
139 // Adds an input method extension. This function does not takes ownership of
141 virtual void AddInputMethodExtension(
142 const std::string
& imm_id
,
143 InputMethodEngineInterface
* instance
) = 0;
145 // Removes an input method extension.
146 virtual void RemoveInputMethodExtension(const std::string
& id
) = 0;
148 // Returns a list of descriptors for all Input Method Extensions.
149 virtual void GetInputMethodExtensions(InputMethodDescriptors
* result
) = 0;
151 // Sets the list of extension IME ids which should be enabled.
152 virtual void SetEnabledExtensionImes(std::vector
<std::string
>* ids
) = 0;
154 // Sets current input method to login default (first owners, then hardware).
155 virtual void SetInputMethodLoginDefault() = 0;
157 // Gets the descriptor of the input method which is currently selected.
158 virtual InputMethodDescriptor
GetCurrentInputMethod() const = 0;
160 virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const = 0;
162 virtual bool IsAltGrUsedByCurrentInputMethod() const = 0;
164 // Returns an X keyboard object which could be used to change the current XKB
165 // layout, change the caps lock status, and set the auto repeat rate/interval.
166 virtual ImeKeyboard
* GetImeKeyboard() = 0;
168 // Returns an InputMethodUtil object.
169 virtual InputMethodUtil
* GetInputMethodUtil() = 0;
171 // Returns a ComponentExtentionIMEManager object.
172 virtual ComponentExtensionIMEManager
* GetComponentExtensionIMEManager() = 0;
174 // Switches the current input method (or keyboard layout) to the next one.
175 virtual bool SwitchToNextInputMethod() = 0;
177 // Switches the current input method (or keyboard layout) to the previous one.
178 virtual bool SwitchToPreviousInputMethod(
179 const ui::Accelerator
& accelerator
) = 0;
181 // Switches to an input method (or keyboard layout) which is associated with
182 // the |accelerator|.
183 virtual bool SwitchInputMethod(const ui::Accelerator
& accelerator
) = 0;
185 // If keyboard layout can be uset at login screen
186 virtual bool IsLoginKeyboard(const std::string
& layout
) const = 0;
188 // Migrates the input method id to extension-based input method id.
189 virtual bool MigrateInputMethods(
190 std::vector
<std::string
>* input_method_ids
) = 0;
193 } // namespace input_method
194 } // namespace chromeos
196 #endif // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_