1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_
#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_
#pragma once
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/observer_list.h"
#include "base/time.h"
#include "base/timer.h"
#include "chrome/browser/chromeos/input_method/input_method_config.h"
#include "chrome/browser/chromeos/input_method/input_method_descriptor.h"
#include "chrome/browser/chromeos/input_method/input_method_property.h"
#include "chrome/browser/chromeos/input_method/input_method_util.h"
class GURL;
namespace ui {
class Accelerator;
} // namespace ui
namespace chromeos {
namespace input_method {
class HotkeyManager;
class VirtualKeyboard;
class XKeyboard;
// This class manages input methodshandles. Classes can add themselves as
// observers. Clients can get an instance of this library class by:
// InputMethodManager::GetInstance().
class InputMethodManager {
public:
enum State {
STATE_LOGIN_SCREEN = 0,
// The user entered the correct password (= NOTIFICATION_LOGIN_USER_CHANGED
// has been sent), but NOTIFICATION_SESSION_STARTED has not.
STATE_LOGGING_IN,
// The browser window for user session is ready.
STATE_BROWSER_SCREEN,
STATE_LOCK_SCREEN,
STATE_TERMINATING,
};
class Observer {
public:
virtual ~Observer() {}
// Called when the current input method is changed.
virtual void InputMethodChanged(
InputMethodManager* manager,
const InputMethodDescriptor& current_input_method,
size_t num_active_input_methods) = 0;
// Called when the active input methods are changed.
// TODO(yusukes): Remove this method in R20.
virtual void ActiveInputMethodsChanged(
InputMethodManager* manager,
const InputMethodDescriptor& current_input_method,
size_t num_active_input_methods) = 0;
// Called when the list of properties is changed.
// TODO(yusukes): Remove this method in R20.
virtual void PropertyListChanged(
InputMethodManager* manager,
const InputMethodPropertyList& current_ime_properties) = 0;
};
// CandidateWindowObserver is notified of events related to the candidate
// window. The "suggestion window" used by IMEs such as ibus-mozc does not
// count as the candidate window (this may change if we later want suggestion
// window events as well). These events also won't occur when the virtual
// keyboard is used, since it controls its own candidate window.
class CandidateWindowObserver {
public:
virtual ~CandidateWindowObserver() {}
// Called when the candidate window is opened.
virtual void CandidateWindowOpened(InputMethodManager* manager) = 0;
// Called when the candidate window is closed.
virtual void CandidateWindowClosed(InputMethodManager* manager) = 0;
};
class VirtualKeyboardObserver {
public:
virtual ~VirtualKeyboardObserver() {}
// Called when the current virtual keyboard is changed.
virtual void VirtualKeyboardChanged(
InputMethodManager* manager,
const VirtualKeyboard& virtual_keyboard,
const std::string& virtual_keyboard_layout) = 0;
};
virtual ~InputMethodManager() {}
static InputMethodManager* GetInstance();
// Adds an observer to receive notifications of input method related
// changes as desribed in the Observer class above.
virtual void AddObserver(Observer* observer) = 0;
virtual void AddCandidateWindowObserver(
CandidateWindowObserver* observer) = 0;
virtual void AddVirtualKeyboardObserver(
VirtualKeyboardObserver* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
virtual void RemoveCandidateWindowObserver(
CandidateWindowObserver* observer) = 0;
virtual void RemoveVirtualKeyboardObserver(
VirtualKeyboardObserver* observer) = 0;
// Returns all input methods that are supported, including ones not active.
// Caller has to delete the returned list. This function never returns NULL.
virtual InputMethodDescriptors* GetSupportedInputMethods() = 0;
// Returns the list of input methods we can select (i.e. active). If the cros
// library is not found or IBus/DBus daemon is not alive, this function
// returns a fallback input method list (and never returns NULL). Caller has
// to delete the returned list.
virtual InputMethodDescriptors* GetActiveInputMethods() = 0;
// Returns the number of active input methods.
virtual size_t GetNumActiveInputMethods() = 0;
// Changes the current input method to |input_method_id|.
virtual void ChangeInputMethod(const std::string& input_method_id) = 0;
// Enables input methods (e.g. Chinese, Japanese) and keyboard layouts (e.g.
// US qwerty, US dvorak, French azerty) that are necessary for the language
// code and then switches to |initial_input_method_id| if the string is not
// empty. For example, if |language_code| is "en-US", US qwerty and US dvorak
// layouts would be enabled. Likewise, for Germany locale, US qwerty layout
// and several keyboard layouts for Germany would be enabled.
//
// Note that this function does not save the input methods in the user's
// preferences, as this function is designed for the login screen and the
// screen locker, where we shouldn't change the user's preferences.
virtual void EnableLayouts(
const std::string& language_code,
const std::string& initial_input_method_id) = 0;
// Sets whether the input method property specified by |key| is activated. If
// |activated| is true, activates the property. If |activate| is false,
// deactivates the property. Examples of keys:
// - "InputMode.Katakana"
// - "InputMode.HalfWidthKatakana"
// - "TypingMode.Romaji"
// - "TypingMode.Kana"
virtual void SetImePropertyActivated(const std::string& key,
bool activated) = 0;
// Returns true if the input method specified by |input_method_id| is active.
virtual bool InputMethodIsActivated(const std::string& input_method_id) = 0;
// Updates a configuration of ibus-daemon or IBus engines with |value|.
// Returns true if the configuration (and all pending configurations, if any)
// are processed. If ibus-daemon is not running, this function just queues
// the request and returns false.
// When you would like to set 'panel/custom_font', |section| should
// be "panel", and |config_name| should be "custom_font".
// Notice: This function might call the Observer::ActiveInputMethodsChanged()
// callback function immediately, before returning from the
// SetInputMethodConfig function. See also http://crosbug.com/5217.
virtual bool SetInputMethodConfig(const std::string& section,
const std::string& config_name,
const InputMethodConfigValue& value) = 0;
// Add an input method to insert into the language menu.
virtual void AddActiveIme(const std::string& id,
const std::string& name,
const std::vector<std::string>& layouts,
const std::string& language) = 0;
// Remove an input method from the language menu.
virtual void RemoveActiveIme(const std::string& id) = 0;
virtual bool GetExtraDescriptor(const std::string& id,
InputMethodDescriptor* descriptor) = 0;
// Sets the IME state to enabled, and launches input method daemon if needed.
// Returns true if the daemon is started. Otherwise, e.g. the daemon is
// already started, returns false.
virtual bool StartInputMethodDaemon() = 0;
// Disables the IME, and kills the daemon process if they are running.
// Returns true if the daemon is stopped. Otherwise, e.g. the daemon is
// already stopped, returns false.
virtual bool StopInputMethodDaemon() = 0;
// Controls whether the IME process is stopped when all non-default preload
// engines are removed.
virtual void SetEnableAutoImeShutdown(bool enable) = 0;
// Controls whether extension IME are displayed in the language menu, and can
// be selected.
virtual void SetEnableExtensionIMEs(bool enable) = 0;
// Sends a handwriting stroke to libcros. See chromeos::SendHandwritingStroke
// for details.
virtual void SendHandwritingStroke(
const HandwritingStroke& stroke) = 0;
// Clears last N handwriting strokes in libcros. See
// chromeos::CancelHandwriting for details.
virtual void CancelHandwritingStrokes(int stroke_count) = 0;
// Registers a new virtual keyboard for |layouts|. Set |is_system| true when
// the keyboard is provided as a content extension. System virtual keyboards
// have lower priority than non-system ones. See virtual_keyboard_selector.h
// for details.
// TODO(yusukes): Add UnregisterVirtualKeyboard function as well.
virtual void RegisterVirtualKeyboard(const GURL& launch_url,
const std::string& name,
const std::set<std::string>& layouts,
bool is_system) = 0;
// Sets user preference on virtual keyboard selection.
// See virtual_keyboard_selector.h for details.
virtual bool SetVirtualKeyboardPreference(const std::string& input_method_id,
const GURL& extention_url) = 0;
// Clears all preferences on virtual keyboard selection.
// See virtual_keyboard_selector.h for details.
virtual void ClearAllVirtualKeyboardPreferences() = 0;
// Returns a map from extension URL to virtual keyboard extension.
virtual const std::map<GURL, const VirtualKeyboard*>&
GetUrlToKeyboardMapping() const = 0;
// Returns a multi map from layout name to virtual keyboard extension.
virtual const std::multimap<std::string, const VirtualKeyboard*>&
GetLayoutNameToKeyboardMapping() const = 0;
// Returns an X keyboard object which could be used to change the current XKB
// layout, change the caps lock status, and set the auto repeat rate/interval.
virtual XKeyboard* GetXKeyboard() = 0;
// Returns a InputMethodUtil object.
virtual InputMethodUtil* GetInputMethodUtil() = 0;
// Enable all input method hotkeys.
virtual void EnableHotkeys() = 0;
// Disable all input method hotkeys.
virtual void DisableHotkeys() = 0;
// Switches the current input method (or keyboard layout) to the next one.
virtual bool SwitchToNextInputMethod() = 0;
// Switches the current input method (or keyboard layout) to the previous one.
virtual bool SwitchToPreviousInputMethod() = 0;
// Switches to an input method (or keyboard layout) which is associated with
// the |accelerator|.
virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) = 0;
virtual InputMethodDescriptor GetPreviousInputMethod() const = 0;
virtual InputMethodDescriptor GetCurrentInputMethod() const = 0;
virtual InputMethodPropertyList GetCurrentInputMethodProperties() const = 0;
};
} // namespace input_method
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_
|