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_config.h"
15 #include "chromeos/ime/input_method_descriptor.h"
16 #include "chromeos/ime/input_method_property.h"
23 class ComponentExtensionIMEManager;
24 class InputMethodEngine;
25 namespace input_method {
27 class InputMethodUtil;
30 // This class manages input methodshandles. Classes can add themselves as
31 // observers. Clients can get an instance of this library class by:
32 // GetInputMethodManager().
33 class CHROMEOS_EXPORT InputMethodManager {
36 STATE_LOGIN_SCREEN = 0,
44 virtual ~Observer() {}
45 // Called when the current input method is changed. |show_message|
46 // indicates whether the user should be notified of this change.
47 virtual void InputMethodChanged(InputMethodManager* manager,
48 bool show_message) = 0;
49 // Called when the list of properties is changed.
50 virtual void InputMethodPropertyChanged(InputMethodManager* manager) = 0;
53 // CandidateWindowObserver is notified of events related to the candidate
54 // window. The "suggestion window" used by IMEs such as ibus-mozc does not
55 // count as the candidate window (this may change if we later want suggestion
56 // window events as well). These events also won't occur when the virtual
57 // keyboard is used, since it controls its own candidate window.
58 class CandidateWindowObserver {
60 virtual ~CandidateWindowObserver() {}
61 // Called when the candidate window is opened.
62 virtual void CandidateWindowOpened(InputMethodManager* manager) = 0;
63 // Called when the candidate window is closed.
64 virtual void CandidateWindowClosed(InputMethodManager* manager) = 0;
67 virtual ~InputMethodManager() {}
69 // Gets the global instance of InputMethodManager. Initialize() must be called
71 static CHROMEOS_EXPORT InputMethodManager* Get();
73 // Sets the global instance. |instance| will be owned by the internal pointer
74 // and deleted by Shutdown().
75 // TODO(nona): Instanciate InputMethodManagerImpl inside of this function once
76 // crbug.com/164375 is fixed.
77 static CHROMEOS_EXPORT void Initialize(InputMethodManager* instance);
79 // Destroy the global instance.
80 static CHROMEOS_EXPORT void Shutdown();
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 // 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 keyboard layouts (e.g. US Qwerty, US Dvorak, French Azerty) that
115 // are necessary for the |language_code| and then switches to |initial_layout|
116 // if the string is not empty. For example, if |language_code| is "en-US", US
117 // Qwerty, US International, US Extended, US Dvorak, and US Colemak layouts
118 // would be enabled. Likewise, for Germany locale, US Qwerty which corresponds
119 // to the hardware keyboard layout and several keyboard layouts for Germany
121 // This method is for setting up i18n keyboard layouts for the login screen.
122 virtual void EnableLayouts(const std::string& language_code,
123 const std::string& initial_layout) = 0;
125 // Activates the input method property specified by the |key|.
126 virtual void ActivateInputMethodProperty(const std::string& key) = 0;
128 // Updates the list of active input method IDs, and then starts or stops the
129 // system input method framework as needed.
130 virtual bool EnableInputMethods(
131 const std::vector<std::string>& new_active_input_method_ids) = 0;
133 // Adds one entry to the list of active input method IDs, and then starts or
134 // stops the system input method framework as needed.
135 virtual bool EnableInputMethod(
136 const std::string& new_active_input_method_id) = 0;
138 // Adds an input method extension. This function does not takes ownership of
140 virtual void AddInputMethodExtension(
141 const std::string& id,
142 const std::string& name,
143 const std::vector<std::string>& layouts,
144 const std::vector<std::string>& languages,
145 const GURL& options_url,
146 InputMethodEngine* instance) = 0;
148 // Removes an input method extension.
149 virtual void RemoveInputMethodExtension(const std::string& id) = 0;
151 // Returns a list of descriptors for all Input Method Extensions.
152 virtual void GetInputMethodExtensions(InputMethodDescriptors* result) = 0;
154 // Sets the list of extension IME ids which should be enabled.
155 virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) = 0;
157 // Sets current input method to default (first owners, then hardware).
158 virtual void SetInputMethodDefault() = 0;
160 // Gets the descriptor of the input method which is currently selected.
161 virtual InputMethodDescriptor GetCurrentInputMethod() const = 0;
163 // Gets the list of input method properties. The list could be empty().
164 virtual InputMethodPropertyList GetCurrentInputMethodProperties() const = 0;
166 // Returns an X keyboard object which could be used to change the current XKB
167 // layout, change the caps lock status, and set the auto repeat rate/interval.
168 virtual XKeyboard* GetXKeyboard() = 0;
170 // Returns an InputMethodUtil object.
171 virtual InputMethodUtil* GetInputMethodUtil() = 0;
173 // Returns a ComponentExtentionIMEManager object.
174 virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() = 0;
176 // Switches the current input method (or keyboard layout) to the next one.
177 virtual bool SwitchToNextInputMethod() = 0;
179 // Switches the current input method (or keyboard layout) to the previous one.
180 virtual bool SwitchToPreviousInputMethod(
181 const ui::Accelerator& accelerator) = 0;
183 // Switches to an input method (or keyboard layout) which is associated with
184 // the |accelerator|.
185 virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) = 0;
187 // If keyboard layout can be uset at login screen
188 virtual bool IsLoginKeyboard(const std::string& layout) const = 0;
191 } // namespace input_method
192 } // namespace chromeos
194 #endif // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_