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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
// 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_IMPL_H_
#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_
#include <stddef.h>
#include <map>
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "base/threading/thread_checker.h"
#include "chrome/browser/chromeos/input_method/candidate_window_controller.h"
#include "chrome/browser/chromeos/input_method/input_method_util.h"
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "chrome/browser/profiles/profile.h"
#include "ui/base/ime/chromeos/input_method_manager.h"
#include "ui/base/ime/chromeos/input_method_whitelist.h"
#include "ui/base/ime/ime_engine_handler_interface.h"
namespace ui {
class IMEEngineHandlerInterface;
} // namespace ui
namespace chromeos {
class ComponentExtensionIMEManager;
class ComponentExtensionIMEManagerDelegate;
class InputMethodEngine;
namespace input_method {
class InputMethodDelegate;
class ImeKeyboard;
// The implementation of InputMethodManager.
class InputMethodManagerImpl : public InputMethodManager,
public CandidateWindowController::Observer,
public UserAddingScreen::Observer {
public:
class StateImpl : public InputMethodManager::State {
public:
StateImpl(InputMethodManagerImpl* manager, Profile* profile);
// Init new state as a copy of other.
void InitFrom(const StateImpl& other);
// Returns true if (manager_->state_ == this).
bool IsActive() const;
// Returns human-readable dump (for debug).
std::string Dump() const;
// Adds new input method to given list if possible
bool EnableInputMethodImpl(
const std::string& input_method_id,
std::vector<std::string>* new_active_input_method_ids) const;
// Returns true if |input_method_id| is in |active_input_method_ids|.
bool InputMethodIsActivated(const std::string& input_method_id) const;
// If |current_input_methodid_| is not in |input_method_ids|, switch to
// input_method_ids[0]. If the ID is equal to input_method_ids[N], switch to
// input_method_ids[N+1].
void SwitchToNextInputMethodInternal(
const std::vector<std::string>& input_method_ids,
const std::string& current_input_methodid);
// Returns the IDs of the subset of input methods which are active and are
// associated with |accelerator|. For example,
// { "mozc-hangul", "xkb:kr:kr104:kor" } is returned for
// ui::VKEY_DBE_SBCSCHAR if the two input methods are active.
void GetCandidateInputMethodsForAccelerator(
const ui::Accelerator& accelerator,
std::vector<std::string>* out_candidate_ids);
// Returns true if given input method requires pending extension.
bool MethodAwaitsExtensionLoad(const std::string& input_method_id) const;
// InputMethodManager::State overrides.
scoped_refptr<InputMethodManager::State> Clone() const override;
void AddInputMethodExtension(
const std::string& extension_id,
const InputMethodDescriptors& descriptors,
ui::IMEEngineHandlerInterface* instance) override;
void RemoveInputMethodExtension(const std::string& extension_id) override;
void ChangeInputMethod(const std::string& input_method_id,
bool show_message) override;
bool EnableInputMethod(
const std::string& new_active_input_method_id) override;
void EnableLoginLayouts(
const std::string& language_code,
const std::vector<std::string>& initial_layouts) override;
void EnableLockScreenLayouts() override;
void GetInputMethodExtensions(InputMethodDescriptors* result) override;
scoped_ptr<InputMethodDescriptors> GetActiveInputMethods() const override;
const std::vector<std::string>& GetActiveInputMethodIds() const override;
const InputMethodDescriptor* GetInputMethodFromId(
const std::string& input_method_id) const override;
size_t GetNumActiveInputMethods() const override;
void SetEnabledExtensionImes(std::vector<std::string>* ids) override;
void SetInputMethodLoginDefault() override;
void SetInputMethodLoginDefaultFromVPD(const std::string& locale,
const std::string& layout) override;
bool CanCycleInputMethod() override;
void SwitchToNextInputMethod() override;
void SwitchToPreviousInputMethod() override;
bool CanSwitchInputMethod(const ui::Accelerator& accelerator) override;
void SwitchInputMethod(const ui::Accelerator& accelerator) override;
InputMethodDescriptor GetCurrentInputMethod() const override;
bool ReplaceEnabledInputMethods(
const std::vector<std::string>& new_active_input_method_ids) override;
// ------------------------- Data members.
Profile* const profile;
// The input method which was/is selected.
InputMethodDescriptor previous_input_method;
InputMethodDescriptor current_input_method;
// The active input method ids cache.
std::vector<std::string> active_input_method_ids;
// The pending input method id for delayed 3rd party IME enabling.
std::string pending_input_method_id;
// The list of enabled extension IMEs.
std::vector<std::string> enabled_extension_imes;
// Extra input methods that have been explicitly added to the menu, such as
// those created by extension.
std::map<std::string, InputMethodDescriptor> extra_input_methods;
InputMethodManagerImpl* const manager_;
protected:
friend base::RefCounted<chromeos::input_method::InputMethodManager::State>;
~StateImpl() override;
};
// Constructs an InputMethodManager instance. The client is responsible for
// calling |SetUISessionState| in response to relevant changes in browser
// state.
InputMethodManagerImpl(scoped_ptr<InputMethodDelegate> delegate,
bool enable_extension_loading);
~InputMethodManagerImpl() override;
// Receives notification of an InputMethodManager::UISessionState transition.
void SetUISessionState(UISessionState new_ui_session);
// InputMethodManager override:
UISessionState GetUISessionState() override;
void AddObserver(InputMethodManager::Observer* observer) override;
void AddCandidateWindowObserver(
InputMethodManager::CandidateWindowObserver* observer) override;
void AddImeMenuObserver(
InputMethodManager::ImeMenuObserver* observer) override;
void RemoveObserver(InputMethodManager::Observer* observer) override;
void RemoveCandidateWindowObserver(
InputMethodManager::CandidateWindowObserver* observer) override;
void RemoveImeMenuObserver(
InputMethodManager::ImeMenuObserver* observer) override;
scoped_ptr<InputMethodDescriptors> GetSupportedInputMethods() const override;
void ActivateInputMethodMenuItem(const std::string& key) override;
bool IsISOLevel5ShiftUsedByCurrentInputMethod() const override;
bool IsAltGrUsedByCurrentInputMethod() const override;
void NotifyImeMenuItemsChanged(
const std::string& engine_id,
const std::vector<InputMethodManager::MenuItem>& items) override;
// chromeos::UserAddingScreen:
void OnUserAddingStarted() override;
void OnUserAddingFinished() override;
ImeKeyboard* GetImeKeyboard() override;
InputMethodUtil* GetInputMethodUtil() override;
ComponentExtensionIMEManager* GetComponentExtensionIMEManager() override;
bool IsLoginKeyboard(const std::string& layout) const override;
bool MigrateInputMethods(std::vector<std::string>* input_method_ids) override;
scoped_refptr<InputMethodManager::State> CreateNewState(
Profile* profile) override;
scoped_refptr<InputMethodManager::State> GetActiveIMEState() override;
void SetState(scoped_refptr<InputMethodManager::State> state) override;
void ImeMenuActivationChanged(bool is_active) override;
// Sets |candidate_window_controller_|.
void SetCandidateWindowControllerForTesting(
CandidateWindowController* candidate_window_controller);
// Sets |keyboard_|.
void SetImeKeyboardForTesting(ImeKeyboard* keyboard);
// Initialize |component_extension_manager_|.
void InitializeComponentExtensionForTesting(
scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate);
private:
friend class InputMethodManagerImplTest;
// CandidateWindowController::Observer overrides:
void CandidateClicked(int index) override;
void CandidateWindowOpened() override;
void CandidateWindowClosed() override;
// Temporarily deactivates all input methods (e.g. Chinese, Japanese, Arabic)
// since they are not necessary to input a login password. Users are still
// able to use/switch active keyboard layouts (e.g. US qwerty, US dvorak,
// French).
void OnScreenLocked();
// Resumes the original state by activating input methods and/or changing the
// current input method as needed.
void OnScreenUnlocked();
// Returns true if the given input method config value is a string list
// that only contains an input method ID of a keyboard layout.
bool ContainsOnlyKeyboardLayout(const std::vector<std::string>& value);
// Creates and initializes |candidate_window_controller_| if it hasn't been
// done.
void MaybeInitializeCandidateWindowController();
// Returns Input Method that best matches given id.
const InputMethodDescriptor* LookupInputMethod(
const std::string& input_method_id,
StateImpl* state);
// Change system input method.
void ChangeInputMethodInternal(const InputMethodDescriptor& descriptor,
Profile* profile,
bool show_message,
bool notify_menu);
// Loads necessary component extensions.
// TODO(nona): Support dynamical unloading.
void LoadNecessaryComponentExtensions(StateImpl* state);
// Starts or stops the system input method framework as needed.
// (after list of enabled input methods has been updated).
// If state is active, active input method is updated.
void ReconfigureIMFramework(StateImpl* state);
// Record input method usage histograms.
void RecordInputMethodUsage(const std::string& input_method_id);
// Notifies the current input method or the list of active input method IDs
// changed.
void NotifyImeMenuListChanged();
scoped_ptr<InputMethodDelegate> delegate_;
// The current UI session status.
UISessionState ui_session_;
// A list of objects that monitor the manager.
base::ObserverList<InputMethodManager::Observer> observers_;
base::ObserverList<CandidateWindowObserver> candidate_window_observers_;
base::ObserverList<ImeMenuObserver> ime_menu_observers_;
scoped_refptr<StateImpl> state_;
// The candidate window. This will be deleted when the APP_TERMINATING
// message is sent.
scoped_ptr<CandidateWindowController> candidate_window_controller_;
// An object which provides miscellaneous input method utility functions. Note
// that |util_| is required to initialize |keyboard_|.
InputMethodUtil util_;
// An object which provides component extension ime management functions.
scoped_ptr<ComponentExtensionIMEManager> component_extension_ime_manager_;
// An object for switching XKB layouts and keyboard status like caps lock and
// auto-repeat interval.
scoped_ptr<ImeKeyboard> keyboard_;
// Whether load IME extensions.
bool enable_extension_loading_;
// Whether the expanded IME menu is activated.
bool is_ime_menu_activated_;
// The engine map from extension_id to an engine.
typedef std::map<std::string, ui::IMEEngineHandlerInterface*> EngineMap;
typedef std::map<Profile*, EngineMap, ProfileCompare> ProfileEngineMap;
ProfileEngineMap engine_map_;
DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl);
};
} // namespace input_method
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_
|