OLD | NEW |
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 Loading... |
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 explicit InputMethodManagerImpl(scoped_ptr<InputMethodDelegate> delegate); | 134 explicit InputMethodManagerImpl(scoped_ptr<InputMethodDelegate> delegate); |
36 virtual ~InputMethodManagerImpl(); | 135 virtual ~InputMethodManagerImpl(); |
37 | 136 |
38 // Receives notification of an InputMethodManager::State transition. | 137 // Receives notification of an InputMethodManager::UISessionState transition. |
39 void SetState(State new_state); | 138 void SetUISessionState(UISessionState new_ui_session); |
40 | 139 |
41 // InputMethodManager override: | 140 // InputMethodManager override: |
42 virtual State GetState() OVERRIDE; | 141 virtual UISessionState GetUISessionState() OVERRIDE; |
43 virtual void AddObserver(InputMethodManager::Observer* observer) OVERRIDE; | 142 virtual void AddObserver(InputMethodManager::Observer* observer) OVERRIDE; |
44 virtual void AddCandidateWindowObserver( | 143 virtual void AddCandidateWindowObserver( |
45 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE; | 144 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE; |
46 virtual void RemoveObserver(InputMethodManager::Observer* observer) OVERRIDE; | 145 virtual void RemoveObserver(InputMethodManager::Observer* observer) OVERRIDE; |
47 virtual void RemoveCandidateWindowObserver( | 146 virtual void RemoveCandidateWindowObserver( |
48 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE; | 147 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE; |
49 virtual scoped_ptr<InputMethodDescriptors> | 148 virtual scoped_ptr<InputMethodDescriptors> |
50 GetSupportedInputMethods() const OVERRIDE; | 149 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; | 150 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; | 151 virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const OVERRIDE; |
85 virtual bool IsAltGrUsedByCurrentInputMethod() const OVERRIDE; | 152 virtual bool IsAltGrUsedByCurrentInputMethod() const OVERRIDE; |
86 | 153 |
87 virtual ImeKeyboard* GetImeKeyboard() OVERRIDE; | 154 virtual ImeKeyboard* GetImeKeyboard() OVERRIDE; |
88 virtual InputMethodUtil* GetInputMethodUtil() OVERRIDE; | 155 virtual InputMethodUtil* GetInputMethodUtil() OVERRIDE; |
89 virtual ComponentExtensionIMEManager* | 156 virtual ComponentExtensionIMEManager* |
90 GetComponentExtensionIMEManager() OVERRIDE; | 157 GetComponentExtensionIMEManager() OVERRIDE; |
91 virtual bool IsLoginKeyboard(const std::string& layout) const OVERRIDE; | 158 virtual bool IsLoginKeyboard(const std::string& layout) const OVERRIDE; |
92 | 159 |
93 virtual bool MigrateInputMethods( | 160 virtual bool MigrateInputMethods( |
94 std::vector<std::string>* input_method_ids) OVERRIDE; | 161 std::vector<std::string>* input_method_ids) OVERRIDE; |
95 | 162 |
| 163 virtual scoped_refptr<InputMethodManager::State> CreateNewState( |
| 164 Profile* profile) OVERRIDE; |
| 165 |
| 166 virtual scoped_refptr<InputMethodManager::State> GetActiveIMEState() OVERRIDE; |
| 167 virtual void SetState( |
| 168 scoped_refptr<InputMethodManager::State> state) OVERRIDE; |
| 169 |
96 // Sets |candidate_window_controller_|. | 170 // Sets |candidate_window_controller_|. |
97 void SetCandidateWindowControllerForTesting( | 171 void SetCandidateWindowControllerForTesting( |
98 CandidateWindowController* candidate_window_controller); | 172 CandidateWindowController* candidate_window_controller); |
99 // Sets |keyboard_|. | 173 // Sets |keyboard_|. |
100 void SetImeKeyboardForTesting(ImeKeyboard* keyboard); | 174 void SetImeKeyboardForTesting(ImeKeyboard* keyboard); |
101 // Initialize |component_extension_manager_|. | 175 // Initialize |component_extension_manager_|. |
102 void InitializeComponentExtensionForTesting( | 176 void InitializeComponentExtensionForTesting( |
103 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate); | 177 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate); |
104 | 178 |
105 private: | 179 private: |
106 friend class InputMethodManagerImplTest; | 180 friend class InputMethodManagerImplTest; |
107 | 181 |
108 // CandidateWindowController::Observer overrides: | 182 // CandidateWindowController::Observer overrides: |
109 virtual void CandidateClicked(int index) OVERRIDE; | 183 virtual void CandidateClicked(int index) OVERRIDE; |
110 virtual void CandidateWindowOpened() OVERRIDE; | 184 virtual void CandidateWindowOpened() OVERRIDE; |
111 virtual void CandidateWindowClosed() OVERRIDE; | 185 virtual void CandidateWindowClosed() OVERRIDE; |
112 | 186 |
113 // Temporarily deactivates all input methods (e.g. Chinese, Japanese, Arabic) | 187 // Temporarily deactivates all input methods (e.g. Chinese, Japanese, Arabic) |
114 // since they are not necessary to input a login password. Users are still | 188 // 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, | 189 // able to use/switch active keyboard layouts (e.g. US qwerty, US dvorak, |
116 // French). | 190 // French). |
117 void OnScreenLocked(); | 191 void OnScreenLocked(); |
118 | 192 |
119 // Resumes the original state by activating input methods and/or changing the | 193 // Resumes the original state by activating input methods and/or changing the |
120 // current input method as needed. | 194 // current input method as needed. |
121 void OnScreenUnlocked(); | 195 void OnScreenUnlocked(); |
122 | 196 |
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 | 197 // 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. | 198 // that only contains an input method ID of a keyboard layout. |
128 bool ContainsOnlyKeyboardLayout(const std::vector<std::string>& value); | 199 bool ContainsOnlyKeyboardLayout(const std::vector<std::string>& value); |
129 | 200 |
130 // Creates and initializes |candidate_window_controller_| if it hasn't been | 201 // Creates and initializes |candidate_window_controller_| if it hasn't been |
131 // done. | 202 // done. |
132 void MaybeInitializeCandidateWindowController(); | 203 void MaybeInitializeCandidateWindowController(); |
133 | 204 |
134 // If |current_input_method_id_| is not in |input_method_ids|, switch to | 205 // 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 | 206 const InputMethodDescriptor* LookupInputMethod( |
136 // input_method_ids[N+1]. | 207 const std::string& input_method_id, |
137 void SwitchToNextInputMethodInternal( | 208 StateImpl* state); |
138 const std::vector<std::string>& input_method_ids, | |
139 const std::string& current_input_method_id); | |
140 | 209 |
141 // Change system input method. | 210 // Change system input method. |
142 // Returns true if the system input method is changed. | 211 void ChangeInputMethodInternal(const InputMethodDescriptor& descriptor, |
143 bool ChangeInputMethodInternal(const std::string& input_method_id, | 212 bool show_message, |
144 bool show_message); | 213 bool notify_menu); |
145 | 214 |
146 // Loads necessary component extensions. | 215 // Loads necessary component extensions. |
147 // TODO(nona): Support dynamical unloading. | 216 // TODO(nona): Support dynamical unloading. |
148 void LoadNecessaryComponentExtensions(); | 217 void LoadNecessaryComponentExtensions(StateImpl* 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 | 218 |
155 // Starts or stops the system input method framework as needed. | 219 // Starts or stops the system input method framework as needed. |
156 // (after list of enabled input methods has been updated) | 220 // (after list of enabled input methods has been updated). |
157 void ReconfigureIMFramework(); | 221 // If state is active, active input method is updated. |
| 222 void ReconfigureIMFramework(StateImpl* state); |
158 | 223 |
159 scoped_ptr<InputMethodDelegate> delegate_; | 224 scoped_ptr<InputMethodDelegate> delegate_; |
160 | 225 |
161 // The current browser status. | 226 // The current UI session status. |
162 State state_; | 227 UISessionState ui_session_; |
163 | 228 |
164 // A list of objects that monitor the manager. | 229 // A list of objects that monitor the manager. |
165 ObserverList<InputMethodManager::Observer> observers_; | 230 ObserverList<InputMethodManager::Observer> observers_; |
166 ObserverList<CandidateWindowObserver> candidate_window_observers_; | 231 ObserverList<CandidateWindowObserver> candidate_window_observers_; |
167 | 232 |
168 // The input method which was/is selected. | 233 scoped_refptr<StateImpl> 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 | |
188 // The pending input method id for delayed 3rd party IME enabling. | |
189 std::string pending_input_method_id_; | |
190 | 234 |
191 // The candidate window. This will be deleted when the APP_TERMINATING | 235 // The candidate window. This will be deleted when the APP_TERMINATING |
192 // message is sent. | 236 // message is sent. |
193 scoped_ptr<CandidateWindowController> candidate_window_controller_; | 237 scoped_ptr<CandidateWindowController> candidate_window_controller_; |
194 | 238 |
195 // An object which provides miscellaneous input method utility functions. Note | 239 // An object which provides miscellaneous input method utility functions. Note |
196 // that |util_| is required to initialize |keyboard_|. | 240 // that |util_| is required to initialize |keyboard_|. |
197 InputMethodUtil util_; | 241 InputMethodUtil util_; |
198 | 242 |
199 // An object which provides component extension ime management functions. | 243 // An object which provides component extension ime management functions. |
200 scoped_ptr<ComponentExtensionIMEManager> component_extension_ime_manager_; | 244 scoped_ptr<ComponentExtensionIMEManager> component_extension_ime_manager_; |
201 | 245 |
202 // An object for switching XKB layouts and keyboard status like caps lock and | 246 // An object for switching XKB layouts and keyboard status like caps lock and |
203 // auto-repeat interval. | 247 // auto-repeat interval. |
204 scoped_ptr<ImeKeyboard> keyboard_; | 248 scoped_ptr<ImeKeyboard> keyboard_; |
205 | 249 |
206 // The engine map from extension_id to an engine. | 250 // The engine map from extension_id to an engine. |
207 std::map<std::string, InputMethodEngineInterface*> engine_map_; | 251 typedef std::map<std::string, InputMethodEngineInterface*> EngineMap; |
| 252 EngineMap engine_map_; |
208 | 253 |
209 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl); | 254 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl); |
210 }; | 255 }; |
211 | 256 |
212 } // namespace input_method | 257 } // namespace input_method |
213 } // namespace chromeos | 258 } // namespace chromeos |
214 | 259 |
215 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_ | 260 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_ |
OLD | NEW |