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

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: Cleanup. 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 State : public InputMethodManager::State {
Nikita (slow) 2014/08/13 10:56:41 As discussed, makes sense to rename as StateImpl.
Alexander Alekseev 2014/08/13 23:29:32 Done.
34 public:
35 State(InputMethodManagerImpl* manager, Profile* profile);
36
37 // Init new state as a copy of other.
38 void InitFrom(const State& 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);
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 // InputMethodManager::State overrides.
62 virtual void AddInputMethodExtension(
63 const std::string& extension_id,
64 const InputMethodDescriptors& descriptors,
65 InputMethodEngineInterface* instance) OVERRIDE;
66 virtual void RemoveInputMethodExtension(
67 const std::string& extension_id) OVERRIDE;
68 virtual void ChangeInputMethod(const std::string& input_method_id,
69 bool show_message) OVERRIDE;
70 virtual bool EnableInputMethod(
71 const std::string& new_active_input_method_id) OVERRIDE;
72 virtual void EnableLoginLayouts(
73 const std::string& language_code,
74 const std::vector<std::string>& initial_layouts) OVERRIDE;
75 virtual void EnableLockScreenLayouts() OVERRIDE;
76 virtual void GetInputMethodExtensions(
77 InputMethodDescriptors* result) OVERRIDE;
78 virtual scoped_ptr<InputMethodDescriptors> GetActiveInputMethods()
79 const OVERRIDE;
80 virtual const std::vector<std::string>& GetActiveInputMethodIds()
81 const OVERRIDE;
82 virtual const InputMethodDescriptor* GetInputMethodFromId(
83 const std::string& input_method_id) const OVERRIDE;
84 virtual size_t GetNumActiveInputMethods() const OVERRIDE;
85 virtual void SetEnabledExtensionImes(
86 std::vector<std::string>* ids) OVERRIDE;
87 virtual void SetInputMethodLoginDefault() OVERRIDE;
88 virtual void SetInputMethodLoginDefaultFromVPD(
89 const std::string& locale,
90 const std::string& layout) OVERRIDE;
91 virtual bool SwitchToNextInputMethod() OVERRIDE;
92 virtual bool SwitchToPreviousInputMethod(
93 const ui::Accelerator& accelerator) OVERRIDE;
94 virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) OVERRIDE;
95 virtual InputMethodDescriptor GetCurrentInputMethod() const OVERRIDE;
96 virtual bool ReplaceEnabledInputMethods(
97 const std::vector<std::string>& new_active_input_method_ids) OVERRIDE;
98
99 // ------------------------- Data members.
100 Profile* const profile;
101
102 // The input method which was/is selected.
103 InputMethodDescriptor previous_input_method;
104 InputMethodDescriptor current_input_method;
105
106 // The active input method ids cache.
107 std::vector<std::string> active_input_method_ids;
108
109 // The list of enabled extension IMEs.
110 std::vector<std::string> enabled_extension_imes;
111
112 // Extra input methods that have been explicitly added to the menu, such as
113 // those created by extension.
114 std::map<std::string, InputMethodDescriptor> extra_input_methods;
115
116 private:
117 InputMethodManagerImpl* const manager_;
118
119 protected:
120 friend base::RefCounted<chromeos::input_method::InputMethodManager::State>;
121 virtual ~State();
122 };
123
33 // Constructs an InputMethodManager instance. The client is responsible for 124 // Constructs an InputMethodManager instance. The client is responsible for
34 // calling |SetState| in response to relevant changes in browser state. 125 // calling |SetUISessionState| in response to relevant changes in browser
126 // state.
35 explicit InputMethodManagerImpl(scoped_ptr<InputMethodDelegate> delegate); 127 explicit InputMethodManagerImpl(scoped_ptr<InputMethodDelegate> delegate);
36 virtual ~InputMethodManagerImpl(); 128 virtual ~InputMethodManagerImpl();
37 129
38 // Receives notification of an InputMethodManager::State transition. 130 // Receives notification of an InputMethodManager::UISessionState transition.
39 void SetState(State new_state); 131 void SetUISessionState(UISessionState new_ui_session);
40 132
41 // InputMethodManager override: 133 // InputMethodManager override:
42 virtual void InitializeComponentExtension() OVERRIDE; 134 virtual void InitializeComponentExtension(Profile* profile) OVERRIDE;
43 virtual void AddObserver(InputMethodManager::Observer* observer) OVERRIDE; 135 virtual void AddObserver(InputMethodManager::Observer* observer) OVERRIDE;
44 virtual void AddCandidateWindowObserver( 136 virtual void AddCandidateWindowObserver(
45 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE; 137 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE;
46 virtual void RemoveObserver(InputMethodManager::Observer* observer) OVERRIDE; 138 virtual void RemoveObserver(InputMethodManager::Observer* observer) OVERRIDE;
47 virtual void RemoveCandidateWindowObserver( 139 virtual void RemoveCandidateWindowObserver(
48 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE; 140 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE;
49 virtual scoped_ptr<InputMethodDescriptors> 141 virtual scoped_ptr<InputMethodDescriptors>
50 GetSupportedInputMethods() const OVERRIDE; 142 GetSupportedInputMethods() const OVERRIDE;
51 virtual scoped_ptr<InputMethodDescriptors>
52 GetActiveInputMethods() const OVERRIDE;
53 virtual const std::vector<std::string>& GetActiveInputMethodIds() const
54 OVERRIDE;
55 virtual size_t GetNumActiveInputMethods() const OVERRIDE;
56 virtual const InputMethodDescriptor* GetInputMethodFromId(
57 const std::string& input_method_id) const OVERRIDE;
58 virtual void EnableLoginLayouts(
59 const std::string& language_code,
60 const std::vector<std::string>& initial_layouts) OVERRIDE;
61 virtual bool ReplaceEnabledInputMethods(
62 const std::vector<std::string>& new_active_input_method_ids) OVERRIDE;
63 virtual bool EnableInputMethod(const std::string& new_active_input_method_id)
64 OVERRIDE;
65 virtual void ChangeInputMethod(const std::string& input_method_id) OVERRIDE;
66 virtual void ActivateInputMethodMenuItem(const std::string& key) OVERRIDE; 143 virtual void ActivateInputMethodMenuItem(const std::string& key) OVERRIDE;
67 virtual void AddInputMethodExtension(
68 const std::string& extension_id,
69 const InputMethodDescriptors& descriptors,
70 InputMethodEngineInterface* instance) OVERRIDE;
71 virtual void RemoveInputMethodExtension(
72 const std::string& extension_id) OVERRIDE;
73 virtual void GetInputMethodExtensions(
74 InputMethodDescriptors* result) OVERRIDE;
75 virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) OVERRIDE;
76 virtual void SetInputMethodLoginDefault() OVERRIDE;
77 virtual void SetInputMethodLoginDefaultFromVPD(
78 const std::string& locale, const std::string& layout) OVERRIDE;
79 virtual bool SwitchToNextInputMethod() OVERRIDE;
80 virtual bool SwitchToPreviousInputMethod(
81 const ui::Accelerator& accelerator) OVERRIDE;
82 virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) OVERRIDE;
83 virtual InputMethodDescriptor GetCurrentInputMethod() const OVERRIDE;
84 virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const OVERRIDE; 144 virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const OVERRIDE;
85 virtual bool IsAltGrUsedByCurrentInputMethod() const OVERRIDE; 145 virtual bool IsAltGrUsedByCurrentInputMethod() const OVERRIDE;
86 146
87 virtual ImeKeyboard* GetImeKeyboard() OVERRIDE; 147 virtual ImeKeyboard* GetImeKeyboard() OVERRIDE;
88 virtual InputMethodUtil* GetInputMethodUtil() OVERRIDE; 148 virtual InputMethodUtil* GetInputMethodUtil() OVERRIDE;
89 virtual ComponentExtensionIMEManager* 149 virtual ComponentExtensionIMEManager*
90 GetComponentExtensionIMEManager() OVERRIDE; 150 GetComponentExtensionIMEManager() OVERRIDE;
91 virtual bool IsLoginKeyboard(const std::string& layout) const OVERRIDE; 151 virtual bool IsLoginKeyboard(const std::string& layout) const OVERRIDE;
92 152
93 virtual bool MigrateInputMethods( 153 virtual bool MigrateInputMethods(
94 std::vector<std::string>* input_method_ids) OVERRIDE; 154 std::vector<std::string>* input_method_ids) OVERRIDE;
95 155
156 virtual scoped_refptr<InputMethodManager::State> GetDefaultState(
157 Profile* profile) OVERRIDE;
158
159 virtual scoped_refptr<InputMethodManager::State> GetActiveIMEState() OVERRIDE;
160 virtual scoped_refptr<InputMethodManager::State> CloneState(
161 const InputMethodManager::State* state) OVERRIDE;
162 virtual void SetState(
163 scoped_refptr<InputMethodManager::State> state) OVERRIDE;
164
96 // Sets |candidate_window_controller_|. 165 // Sets |candidate_window_controller_|.
97 void SetCandidateWindowControllerForTesting( 166 void SetCandidateWindowControllerForTesting(
98 CandidateWindowController* candidate_window_controller); 167 CandidateWindowController* candidate_window_controller);
99 // Sets |keyboard_|. 168 // Sets |keyboard_|.
100 void SetImeKeyboardForTesting(ImeKeyboard* keyboard); 169 void SetImeKeyboardForTesting(ImeKeyboard* keyboard);
101 // Initialize |component_extension_manager_|. 170 // Initialize |component_extension_manager_|.
102 void InitializeComponentExtensionForTesting( 171 void InitializeComponentExtensionForTesting(
103 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate); 172 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate);
104 173
105 private: 174 private:
106 friend class InputMethodManagerImplTest; 175 friend class InputMethodManagerImplTest;
107 176
108 // CandidateWindowController::Observer overrides: 177 // CandidateWindowController::Observer overrides:
109 virtual void CandidateClicked(int index) OVERRIDE; 178 virtual void CandidateClicked(int index) OVERRIDE;
110 virtual void CandidateWindowOpened() OVERRIDE; 179 virtual void CandidateWindowOpened() OVERRIDE;
111 virtual void CandidateWindowClosed() OVERRIDE; 180 virtual void CandidateWindowClosed() OVERRIDE;
112 181
113 // Temporarily deactivates all input methods (e.g. Chinese, Japanese, Arabic) 182 // Temporarily deactivates all input methods (e.g. Chinese, Japanese, Arabic)
114 // since they are not necessary to input a login password. Users are still 183 // since they are not necessary to input a login password. Users are still
115 // able to use/switch active keyboard layouts (e.g. US qwerty, US dvorak, 184 // able to use/switch active keyboard layouts (e.g. US qwerty, US dvorak,
116 // French). 185 // French).
117 void OnScreenLocked(); 186 void OnScreenLocked();
118 187
119 // Resumes the original state by activating input methods and/or changing the 188 // Resumes the original state by activating input methods and/or changing the
120 // current input method as needed. 189 // current input method as needed.
121 void OnScreenUnlocked(); 190 void OnScreenUnlocked();
122 191
123 // Returns true if |input_method_id| is in |active_input_method_ids_|.
124 bool InputMethodIsActivated(const std::string& input_method_id);
125
126 // Returns true if the given input method config value is a string list 192 // Returns true if the given input method config value is a string list
127 // that only contains an input method ID of a keyboard layout. 193 // that only contains an input method ID of a keyboard layout.
128 bool ContainsOnlyKeyboardLayout(const std::vector<std::string>& value); 194 bool ContainsOnlyKeyboardLayout(const std::vector<std::string>& value);
129 195
130 // Creates and initializes |candidate_window_controller_| if it hasn't been 196 // Creates and initializes |candidate_window_controller_| if it hasn't been
131 // done. 197 // done.
132 void MaybeInitializeCandidateWindowController(); 198 void MaybeInitializeCandidateWindowController();
133 199
134 // If |current_input_method_id_| is not in |input_method_ids|, switch to 200 // Returns Input Method that best matches given id.
135 // input_method_ids[0]. If the ID is equal to input_method_ids[N], switch to 201 const InputMethodDescriptor* LookupInputMethod(
136 // input_method_ids[N+1]. 202 const std::string& input_method_id,
137 void SwitchToNextInputMethodInternal( 203 State* state);
138 const std::vector<std::string>& input_method_ids,
139 const std::string& current_input_method_id);
140 204
141 // Change system input method. 205 // Change system input method.
142 // Returns true if the system input method is changed. 206 void ChangeInputMethodInternal(const InputMethodDescriptor& descriptor,
143 bool ChangeInputMethodInternal(const std::string& input_method_id, 207 bool show_message,
144 bool show_message); 208 bool notify_menu);
145 209
146 // Loads necessary component extensions. 210 // Loads necessary component extensions.
147 // TODO(nona): Support dynamical unloading. 211 // TODO(nona): Support dynamical unloading.
148 void LoadNecessaryComponentExtensions(); 212 void LoadNecessaryComponentExtensions(State*);
149
150 // Adds new input method to given list if possible
151 bool EnableInputMethodImpl(
152 const std::string& input_method_id,
153 std::vector<std::string>* new_active_input_method_ids) const;
154 213
155 // Starts or stops the system input method framework as needed. 214 // Starts or stops the system input method framework as needed.
156 // (after list of enabled input methods has been updated) 215 // (after list of enabled input methods has been updated).
157 void ReconfigureIMFramework(); 216 // If state is active, active input method is updated.
217 void ReconfigureIMFramework(State* state);
158 218
159 scoped_ptr<InputMethodDelegate> delegate_; 219 scoped_ptr<InputMethodDelegate> delegate_;
160 220
161 // The current browser status. 221 // The current browser status.
162 State state_; 222 UISessionState ui_session_;
Shu Chen 2014/08/13 16:15:34 pls update the comment.
Alexander Alekseev 2014/08/13 23:29:32 Done.
163 223
164 // A list of objects that monitor the manager. 224 // A list of objects that monitor the manager.
165 ObserverList<InputMethodManager::Observer> observers_; 225 ObserverList<InputMethodManager::Observer> observers_;
166 ObserverList<CandidateWindowObserver> candidate_window_observers_; 226 ObserverList<CandidateWindowObserver> candidate_window_observers_;
167 227
168 // The input method which was/is selected. 228 scoped_refptr<State> state_;
169 InputMethodDescriptor previous_input_method_;
170 InputMethodDescriptor current_input_method_;
171 // The active input method ids cache.
172 std::vector<std::string> active_input_method_ids_;
173
174 // The list of enabled extension IMEs.
175 std::vector<std::string> enabled_extension_imes_;
176
177 // For screen locker. When the screen is locked, |previous_input_method_|,
178 // |current_input_method_|, and |active_input_method_ids_| above are copied
179 // to these "saved" variables.
180 InputMethodDescriptor saved_previous_input_method_;
181 InputMethodDescriptor saved_current_input_method_;
182 std::vector<std::string> saved_active_input_method_ids_;
183
184 // Extra input methods that have been explicitly added to the menu, such as
185 // those created by extension.
186 std::map<std::string, InputMethodDescriptor> extra_input_methods_;
187 229
188 // The candidate window. This will be deleted when the APP_TERMINATING 230 // The candidate window. This will be deleted when the APP_TERMINATING
189 // message is sent. 231 // message is sent.
190 scoped_ptr<CandidateWindowController> candidate_window_controller_; 232 scoped_ptr<CandidateWindowController> candidate_window_controller_;
191 233
192 // An object which provides miscellaneous input method utility functions. Note 234 // An object which provides miscellaneous input method utility functions. Note
193 // that |util_| is required to initialize |keyboard_|. 235 // that |util_| is required to initialize |keyboard_|.
194 InputMethodUtil util_; 236 InputMethodUtil util_;
195 237
196 // An object which provides component extension ime management functions. 238 // An object which provides component extension ime management functions.
197 scoped_ptr<ComponentExtensionIMEManager> component_extension_ime_manager_; 239 scoped_ptr<ComponentExtensionIMEManager> component_extension_ime_manager_;
198 240
199 // An object for switching XKB layouts and keyboard status like caps lock and 241 // An object for switching XKB layouts and keyboard status like caps lock and
200 // auto-repeat interval. 242 // auto-repeat interval.
201 scoped_ptr<ImeKeyboard> keyboard_; 243 scoped_ptr<ImeKeyboard> keyboard_;
202 244
203 base::ThreadChecker thread_checker_; 245 base::ThreadChecker thread_checker_;
204 246
205 base::WeakPtrFactory<InputMethodManagerImpl> weak_ptr_factory_; 247 base::WeakPtrFactory<InputMethodManagerImpl> weak_ptr_factory_;
Shu Chen 2014/08/13 16:15:33 add a blank line.
Alexander Alekseev 2014/08/13 23:29:32 Done.
248 // The engine map from extension_id to an engine.
249 typedef std::map<std::string, InputMethodEngineInterface*> EngineMap;
250 EngineMap engine_map_;
206 251
207 // The engine map from extension_id to an engine. 252 // Default profile states.
208 std::map<std::string, InputMethodEngineInterface*> engine_map_; 253 std::map<Profile*, scoped_refptr<State> > default_states_;
Shu Chen 2014/08/13 16:15:34 Can you please add comments to explain for what do
Alexander Alekseev 2014/08/13 23:29:32 Before your recent CL, there were two independant
209 254
210 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl); 255 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl);
211 }; 256 };
212 257
213 } // namespace input_method 258 } // namespace input_method
214 } // namespace chromeos 259 } // namespace chromeos
215 260
216 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_ 261 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698