Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_manager_impl.h

Issue 419293002: IME refactoring: ChromeOS introduce input methods State. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit test fixed. Re-sorted methods of StateImpl and IMM. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_ 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 12 matching lines...) Expand all
23 class ComponentExtensionIMEManagerDelegate; 23 class ComponentExtensionIMEManagerDelegate;
24 class InputMethodEngine; 24 class InputMethodEngine;
25 namespace input_method { 25 namespace input_method {
26 class InputMethodDelegate; 26 class InputMethodDelegate;
27 class ImeKeyboard; 27 class ImeKeyboard;
28 28
29 // The implementation of InputMethodManager. 29 // The implementation of InputMethodManager.
30 class InputMethodManagerImpl : public InputMethodManager, 30 class InputMethodManagerImpl : public InputMethodManager,
31 public CandidateWindowController::Observer { 31 public CandidateWindowController::Observer {
32 public: 32 public:
33 class StateImpl : public InputMethodManager::State {
34 public:
35 StateImpl(InputMethodManagerImpl* manager, Profile* profile);
36
37 // Init new state as a copy of other.
38 void InitFrom(const StateImpl& other);
39
40 // Returns true if (manager_->state_ == this).
41 bool IsActive() const;
42
43 // Returns human-readable dump (for debug).
44 std::string Dump() const;
45
46 // Adds new input method to given list if possible
47 bool EnableInputMethodImpl(
48 const std::string& input_method_id,
49 std::vector<std::string>* new_active_input_method_ids) const;
50
51 // Returns true if |input_method_id| is in |active_input_method_ids|.
52 bool InputMethodIsActivated(const std::string& input_method_id) const;
53
54 // If |current_input_methodid_| is not in |input_method_ids|, switch to
55 // input_method_ids[0]. If the ID is equal to input_method_ids[N], switch to
56 // input_method_ids[N+1].
57 void SwitchToNextInputMethodInternal(
58 const std::vector<std::string>& input_method_ids,
59 const std::string& current_input_methodid);
60
61 // Returns true if given input method requires pending extension.
62 bool MethodAwaitsExtensionLoad(const std::string& input_method_id) const;
63
64 // InputMethodManager::State overrides.
65 virtual scoped_refptr<InputMethodManager::State> Clone() const OVERRIDE;
66 virtual void AddInputMethodExtension(
67 const std::string& extension_id,
68 const InputMethodDescriptors& descriptors,
69 InputMethodEngineInterface* instance) OVERRIDE;
70 virtual void RemoveInputMethodExtension(
71 const std::string& extension_id) OVERRIDE;
72 virtual void ChangeInputMethod(const std::string& input_method_id,
73 bool show_message) OVERRIDE;
74 virtual bool EnableInputMethod(
75 const std::string& new_active_input_method_id) OVERRIDE;
76 virtual void EnableLoginLayouts(
77 const std::string& language_code,
78 const std::vector<std::string>& initial_layouts) OVERRIDE;
79 virtual void EnableLockScreenLayouts() OVERRIDE;
80 virtual void GetInputMethodExtensions(
81 InputMethodDescriptors* result) OVERRIDE;
82 virtual scoped_ptr<InputMethodDescriptors> GetActiveInputMethods()
83 const OVERRIDE;
84 virtual const std::vector<std::string>& GetActiveInputMethodIds()
85 const OVERRIDE;
86 virtual const InputMethodDescriptor* GetInputMethodFromId(
87 const std::string& input_method_id) const OVERRIDE;
88 virtual size_t GetNumActiveInputMethods() const OVERRIDE;
89 virtual void SetEnabledExtensionImes(
90 std::vector<std::string>* ids) OVERRIDE;
91 virtual void SetInputMethodLoginDefault() OVERRIDE;
92 virtual void SetInputMethodLoginDefaultFromVPD(
93 const std::string& locale,
94 const std::string& layout) OVERRIDE;
95 virtual bool SwitchToNextInputMethod() OVERRIDE;
96 virtual bool SwitchToPreviousInputMethod(
97 const ui::Accelerator& accelerator) OVERRIDE;
98 virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) OVERRIDE;
99 virtual InputMethodDescriptor GetCurrentInputMethod() const OVERRIDE;
100 virtual bool ReplaceEnabledInputMethods(
101 const std::vector<std::string>& new_active_input_method_ids) OVERRIDE;
102
103 // ------------------------- Data members.
104 Profile* const profile;
105
106 // The input method which was/is selected.
107 InputMethodDescriptor previous_input_method;
108 InputMethodDescriptor current_input_method;
109
110 // The active input method ids cache.
111 std::vector<std::string> active_input_method_ids;
112
113 // The pending input method id for delayed 3rd party IME enabling.
114 std::string pending_input_method_id;
115
116 // The list of enabled extension IMEs.
117 std::vector<std::string> enabled_extension_imes;
118
119 // Extra input methods that have been explicitly added to the menu, such as
120 // those created by extension.
121 std::map<std::string, InputMethodDescriptor> extra_input_methods;
122
123 private:
124 InputMethodManagerImpl* const manager_;
125
126 protected:
127 friend base::RefCounted<chromeos::input_method::InputMethodManager::State>;
128 virtual ~StateImpl();
129 };
130
33 // Constructs an InputMethodManager instance. The client is responsible for 131 // Constructs an InputMethodManager instance. The client is responsible for
34 // calling |SetState| in response to relevant changes in browser state. 132 // calling |SetUISessionState| in response to relevant changes in browser
133 // state.
35 InputMethodManagerImpl(scoped_ptr<InputMethodDelegate> delegate, 134 InputMethodManagerImpl(scoped_ptr<InputMethodDelegate> delegate,
36 bool enable_extension_loading); 135 bool enable_extension_loading);
37 virtual ~InputMethodManagerImpl(); 136 virtual ~InputMethodManagerImpl();
38 137
39 // Receives notification of an InputMethodManager::State transition. 138 // Receives notification of an InputMethodManager::UISessionState transition.
40 void SetState(State new_state); 139 void SetUISessionState(UISessionState new_ui_session);
41 140
42 // InputMethodManager override: 141 // InputMethodManager override:
43 virtual State GetState() OVERRIDE; 142 virtual UISessionState GetUISessionState() OVERRIDE;
44 virtual void AddObserver(InputMethodManager::Observer* observer) OVERRIDE; 143 virtual void AddObserver(InputMethodManager::Observer* observer) OVERRIDE;
45 virtual void AddCandidateWindowObserver( 144 virtual void AddCandidateWindowObserver(
46 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE; 145 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE;
47 virtual void RemoveObserver(InputMethodManager::Observer* observer) OVERRIDE; 146 virtual void RemoveObserver(InputMethodManager::Observer* observer) OVERRIDE;
48 virtual void RemoveCandidateWindowObserver( 147 virtual void RemoveCandidateWindowObserver(
49 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE; 148 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE;
50 virtual scoped_ptr<InputMethodDescriptors> 149 virtual scoped_ptr<InputMethodDescriptors>
51 GetSupportedInputMethods() const OVERRIDE; 150 GetSupportedInputMethods() const OVERRIDE;
52 virtual scoped_ptr<InputMethodDescriptors>
53 GetActiveInputMethods() const OVERRIDE;
54 virtual const std::vector<std::string>& GetActiveInputMethodIds() const
55 OVERRIDE;
56 virtual size_t GetNumActiveInputMethods() const OVERRIDE;
57 virtual const InputMethodDescriptor* GetInputMethodFromId(
58 const std::string& input_method_id) const OVERRIDE;
59 virtual void EnableLoginLayouts(
60 const std::string& language_code,
61 const std::vector<std::string>& initial_layouts) OVERRIDE;
62 virtual bool ReplaceEnabledInputMethods(
63 const std::vector<std::string>& new_active_input_method_ids) OVERRIDE;
64 virtual bool EnableInputMethod(const std::string& new_active_input_method_id)
65 OVERRIDE;
66 virtual void ChangeInputMethod(const std::string& input_method_id) OVERRIDE;
67 virtual void ActivateInputMethodMenuItem(const std::string& key) OVERRIDE; 151 virtual void ActivateInputMethodMenuItem(const std::string& key) OVERRIDE;
68 virtual void AddInputMethodExtension(
69 const std::string& extension_id,
70 const InputMethodDescriptors& descriptors,
71 InputMethodEngineInterface* instance) OVERRIDE;
72 virtual void RemoveInputMethodExtension(
73 const std::string& extension_id) OVERRIDE;
74 virtual void GetInputMethodExtensions(
75 InputMethodDescriptors* result) OVERRIDE;
76 virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) OVERRIDE;
77 virtual void SetInputMethodLoginDefault() OVERRIDE;
78 virtual void SetInputMethodLoginDefaultFromVPD(
79 const std::string& locale, const std::string& layout) OVERRIDE;
80 virtual bool SwitchToNextInputMethod() OVERRIDE;
81 virtual bool SwitchToPreviousInputMethod(
82 const ui::Accelerator& accelerator) OVERRIDE;
83 virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) OVERRIDE;
84 virtual InputMethodDescriptor GetCurrentInputMethod() const OVERRIDE;
85 virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const OVERRIDE; 152 virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const OVERRIDE;
86 virtual bool IsAltGrUsedByCurrentInputMethod() const OVERRIDE; 153 virtual bool IsAltGrUsedByCurrentInputMethod() const OVERRIDE;
87 154
88 virtual ImeKeyboard* GetImeKeyboard() OVERRIDE; 155 virtual ImeKeyboard* GetImeKeyboard() OVERRIDE;
89 virtual InputMethodUtil* GetInputMethodUtil() OVERRIDE; 156 virtual InputMethodUtil* GetInputMethodUtil() OVERRIDE;
90 virtual ComponentExtensionIMEManager* 157 virtual ComponentExtensionIMEManager*
91 GetComponentExtensionIMEManager() OVERRIDE; 158 GetComponentExtensionIMEManager() OVERRIDE;
92 virtual bool IsLoginKeyboard(const std::string& layout) const OVERRIDE; 159 virtual bool IsLoginKeyboard(const std::string& layout) const OVERRIDE;
93 160
94 virtual bool MigrateInputMethods( 161 virtual bool MigrateInputMethods(
95 std::vector<std::string>* input_method_ids) OVERRIDE; 162 std::vector<std::string>* input_method_ids) OVERRIDE;
96 163
164 virtual scoped_refptr<InputMethodManager::State> CreateNewState(
165 Profile* profile) OVERRIDE;
166
167 virtual scoped_refptr<InputMethodManager::State> GetActiveIMEState() OVERRIDE;
168 virtual void SetState(
169 scoped_refptr<InputMethodManager::State> state) OVERRIDE;
170
97 // Sets |candidate_window_controller_|. 171 // Sets |candidate_window_controller_|.
98 void SetCandidateWindowControllerForTesting( 172 void SetCandidateWindowControllerForTesting(
99 CandidateWindowController* candidate_window_controller); 173 CandidateWindowController* candidate_window_controller);
100 // Sets |keyboard_|. 174 // Sets |keyboard_|.
101 void SetImeKeyboardForTesting(ImeKeyboard* keyboard); 175 void SetImeKeyboardForTesting(ImeKeyboard* keyboard);
102 // Initialize |component_extension_manager_|. 176 // Initialize |component_extension_manager_|.
103 void InitializeComponentExtensionForTesting( 177 void InitializeComponentExtensionForTesting(
104 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate); 178 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate);
105 179
106 private: 180 private:
107 friend class InputMethodManagerImplTest; 181 friend class InputMethodManagerImplTest;
108 182
109 // CandidateWindowController::Observer overrides: 183 // CandidateWindowController::Observer overrides:
110 virtual void CandidateClicked(int index) OVERRIDE; 184 virtual void CandidateClicked(int index) OVERRIDE;
111 virtual void CandidateWindowOpened() OVERRIDE; 185 virtual void CandidateWindowOpened() OVERRIDE;
112 virtual void CandidateWindowClosed() OVERRIDE; 186 virtual void CandidateWindowClosed() OVERRIDE;
113 187
114 // Temporarily deactivates all input methods (e.g. Chinese, Japanese, Arabic) 188 // Temporarily deactivates all input methods (e.g. Chinese, Japanese, Arabic)
115 // since they are not necessary to input a login password. Users are still 189 // since they are not necessary to input a login password. Users are still
116 // able to use/switch active keyboard layouts (e.g. US qwerty, US dvorak, 190 // able to use/switch active keyboard layouts (e.g. US qwerty, US dvorak,
117 // French). 191 // French).
118 void OnScreenLocked(); 192 void OnScreenLocked();
119 193
120 // Resumes the original state by activating input methods and/or changing the 194 // Resumes the original state by activating input methods and/or changing the
121 // current input method as needed. 195 // current input method as needed.
122 void OnScreenUnlocked(); 196 void OnScreenUnlocked();
123 197
124 // Returns true if |input_method_id| is in |active_input_method_ids_|.
125 bool InputMethodIsActivated(const std::string& input_method_id);
126
127 // Returns true if the given input method config value is a string list 198 // Returns true if the given input method config value is a string list
128 // that only contains an input method ID of a keyboard layout. 199 // that only contains an input method ID of a keyboard layout.
129 bool ContainsOnlyKeyboardLayout(const std::vector<std::string>& value); 200 bool ContainsOnlyKeyboardLayout(const std::vector<std::string>& value);
130 201
131 // Creates and initializes |candidate_window_controller_| if it hasn't been 202 // Creates and initializes |candidate_window_controller_| if it hasn't been
132 // done. 203 // done.
133 void MaybeInitializeCandidateWindowController(); 204 void MaybeInitializeCandidateWindowController();
134 205
135 // If |current_input_method_id_| is not in |input_method_ids|, switch to 206 // Returns Input Method that best matches given id.
136 // input_method_ids[0]. If the ID is equal to input_method_ids[N], switch to 207 const InputMethodDescriptor* LookupInputMethod(
137 // input_method_ids[N+1]. 208 const std::string& input_method_id,
138 void SwitchToNextInputMethodInternal( 209 StateImpl* state);
139 const std::vector<std::string>& input_method_ids,
140 const std::string& current_input_method_id);
141 210
142 // Change system input method. 211 // Change system input method.
143 // Returns true if the system input method is changed. 212 void ChangeInputMethodInternal(const InputMethodDescriptor& descriptor,
144 bool ChangeInputMethodInternal(const std::string& input_method_id, 213 bool show_message,
145 bool show_message); 214 bool notify_menu);
146 215
147 // Loads necessary component extensions. 216 // Loads necessary component extensions.
148 // TODO(nona): Support dynamical unloading. 217 // TODO(nona): Support dynamical unloading.
149 void LoadNecessaryComponentExtensions(); 218 void LoadNecessaryComponentExtensions(StateImpl* state);
150
151 // Adds new input method to given list if possible
152 bool EnableInputMethodImpl(
153 const std::string& input_method_id,
154 std::vector<std::string>* new_active_input_method_ids) const;
155 219
156 // Starts or stops the system input method framework as needed. 220 // Starts or stops the system input method framework as needed.
157 // (after list of enabled input methods has been updated) 221 // (after list of enabled input methods has been updated).
158 void ReconfigureIMFramework(); 222 // If state is active, active input method is updated.
223 void ReconfigureIMFramework(StateImpl* state);
159 224
160 scoped_ptr<InputMethodDelegate> delegate_; 225 scoped_ptr<InputMethodDelegate> delegate_;
161 226
162 // The current browser status. 227 // The current UI session status.
163 State state_; 228 UISessionState ui_session_;
164 229
165 // A list of objects that monitor the manager. 230 // A list of objects that monitor the manager.
166 ObserverList<InputMethodManager::Observer> observers_; 231 ObserverList<InputMethodManager::Observer> observers_;
167 ObserverList<CandidateWindowObserver> candidate_window_observers_; 232 ObserverList<CandidateWindowObserver> candidate_window_observers_;
168 233
169 // The input method which was/is selected. 234 scoped_refptr<StateImpl> state_;
170 InputMethodDescriptor previous_input_method_;
171 InputMethodDescriptor current_input_method_;
172 // The active input method ids cache.
173 std::vector<std::string> active_input_method_ids_;
174
175 // The list of enabled extension IMEs.
176 std::vector<std::string> enabled_extension_imes_;
177
178 // For screen locker. When the screen is locked, |previous_input_method_|,
179 // |current_input_method_|, and |active_input_method_ids_| above are copied
180 // to these "saved" variables.
181 InputMethodDescriptor saved_previous_input_method_;
182 InputMethodDescriptor saved_current_input_method_;
183 std::vector<std::string> saved_active_input_method_ids_;
184
185 // Extra input methods that have been explicitly added to the menu, such as
186 // those created by extension.
187 std::map<std::string, InputMethodDescriptor> extra_input_methods_;
188
189 // The pending input method id for delayed 3rd party IME enabling.
190 std::string pending_input_method_id_;
191 235
192 // The candidate window. This will be deleted when the APP_TERMINATING 236 // The candidate window. This will be deleted when the APP_TERMINATING
193 // message is sent. 237 // message is sent.
194 scoped_ptr<CandidateWindowController> candidate_window_controller_; 238 scoped_ptr<CandidateWindowController> candidate_window_controller_;
195 239
196 // An object which provides miscellaneous input method utility functions. Note 240 // An object which provides miscellaneous input method utility functions. Note
197 // that |util_| is required to initialize |keyboard_|. 241 // that |util_| is required to initialize |keyboard_|.
198 InputMethodUtil util_; 242 InputMethodUtil util_;
199 243
200 // An object which provides component extension ime management functions. 244 // An object which provides component extension ime management functions.
201 scoped_ptr<ComponentExtensionIMEManager> component_extension_ime_manager_; 245 scoped_ptr<ComponentExtensionIMEManager> component_extension_ime_manager_;
202 246
203 // An object for switching XKB layouts and keyboard status like caps lock and 247 // An object for switching XKB layouts and keyboard status like caps lock and
204 // auto-repeat interval. 248 // auto-repeat interval.
205 scoped_ptr<ImeKeyboard> keyboard_; 249 scoped_ptr<ImeKeyboard> keyboard_;
206 250
207 // The engine map from extension_id to an engine.
208 std::map<std::string, InputMethodEngineInterface*> engine_map_;
209 251
210 // Whether load IME extensions. 252 // Whether load IME extensions.
211 bool enable_extension_loading_; 253 bool enable_extension_loading_;
212 254
255 // The engine map from extension_id to an engine.
256 typedef std::map<std::string, InputMethodEngineInterface*> EngineMap;
257 EngineMap engine_map_;
258
213 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl); 259 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl);
214 }; 260 };
215 261
216 } // namespace input_method 262 } // namespace input_method
217 } // namespace chromeos 263 } // namespace chromeos
218 264
219 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_ 265 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698