Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / chromeos / ime / input_method_manager.h
blob075804e7600bd936b6a521bf26359aedb15116e8
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_
8 #include <map>
9 #include <string>
10 #include <vector>
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"
18 namespace ui {
19 class Accelerator;
20 } // namespace ui
22 namespace chromeos {
23 class ComponentExtensionIMEManager;
24 class InputMethodEngine;
25 namespace input_method {
27 class InputMethodUtil;
28 class XKeyboard;
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 {
34 public:
35 enum State {
36 STATE_LOGIN_SCREEN = 0,
37 STATE_BROWSER_SCREEN,
38 STATE_LOCK_SCREEN,
39 STATE_TERMINATING,
42 class Observer {
43 public:
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 {
59 public:
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
70 // first.
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 number of active input methods including extension input
102 // methods.
103 virtual size_t GetNumActiveInputMethods() const = 0;
105 // Changes the current input method to |input_method_id|. If |input_method_id|
106 // is not active, switch to the first one in the active input method list.
107 virtual void ChangeInputMethod(const std::string& input_method_id) = 0;
109 // Enables keyboard layouts (e.g. US Qwerty, US Dvorak, French Azerty) that
110 // are necessary for the |language_code| and then switches to |initial_layout|
111 // if the string is not empty. For example, if |language_code| is "en-US", US
112 // Qwerty, US International, US Extended, US Dvorak, and US Colemak layouts
113 // would be enabled. Likewise, for Germany locale, US Qwerty which corresponds
114 // to the hardware keyboard layout and several keyboard layouts for Germany
115 // would be enabled.
116 // This method is for setting up i18n keyboard layouts for the login screen.
117 virtual void EnableLayouts(const std::string& language_code,
118 const std::string& initial_layout) = 0;
120 // Activates the input method property specified by the |key|.
121 virtual void ActivateInputMethodProperty(const std::string& key) = 0;
123 // Updates the list of active input method IDs, and then starts or stops the
124 // system input method framework as needed.
125 virtual bool EnableInputMethods(
126 const std::vector<std::string>& new_active_input_method_ids) = 0;
128 // Remaps old input methods like "mozc" to new input methods. Return true if
129 // at least one IME is migrated.
130 // TODO(nona): Remove this function after few milestones are passed.
131 // (http://crbug.com/236747)
132 virtual bool MigrateOldInputMethods(
133 std::vector<std::string>* input_method_ids) = 0;
135 // Updates a configuration of a system input method engine with |value|.
136 // Returns true if the configuration is correctly set.
137 virtual bool SetInputMethodConfig(const std::string& section,
138 const std::string& config_name,
139 const InputMethodConfigValue& value) = 0;
141 // Adds an input method extension. This function does not takes ownership of
142 // |instance|.
143 virtual void AddInputMethodExtension(
144 const std::string& id,
145 const std::string& name,
146 const std::vector<std::string>& layouts,
147 const std::vector<std::string>& languages,
148 const GURL& options_url,
149 InputMethodEngine* instance) = 0;
151 // Removes an input method extension.
152 virtual void RemoveInputMethodExtension(const std::string& 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 // 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() = 0;
182 // Switches to an input method (or keyboard layout) which is associated with
183 // the |accelerator|.
184 virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) = 0;
187 } // namespace input_method
188 } // namespace chromeos
190 #endif // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_