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 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" |
6 | 6 |
7 #include <algorithm> // std::find | 7 #include <algorithm> // std::find |
8 | 8 |
9 #include "ash/ime/input_method_menu_item.h" | 9 #include "ash/ime/input_method_menu_item.h" |
10 #include "ash/ime/input_method_menu_manager.h" | 10 #include "ash/ime/input_method_menu_manager.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 container.end(); | 43 container.end(); |
44 } | 44 } |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 bool InputMethodManagerImpl::IsLoginKeyboard( | 48 bool InputMethodManagerImpl::IsLoginKeyboard( |
49 const std::string& layout) const { | 49 const std::string& layout) const { |
50 return util_.IsLoginKeyboard(layout); | 50 return util_.IsLoginKeyboard(layout); |
51 } | 51 } |
52 | 52 |
| 53 bool InputMethodManagerImpl::MigrateXkbInputMethods( |
| 54 std::vector<std::string>* input_method_ids) { |
| 55 return util_.MigrateXkbInputMethods(input_method_ids); |
| 56 } |
| 57 |
53 InputMethodManagerImpl::InputMethodManagerImpl( | 58 InputMethodManagerImpl::InputMethodManagerImpl( |
54 scoped_ptr<InputMethodDelegate> delegate) | 59 scoped_ptr<InputMethodDelegate> delegate) |
55 : delegate_(delegate.Pass()), | 60 : delegate_(delegate.Pass()), |
56 state_(STATE_LOGIN_SCREEN), | 61 state_(STATE_LOGIN_SCREEN), |
57 util_(delegate_.get(), GetSupportedInputMethods()), | 62 util_(delegate_.get(), GetSupportedInputMethods()), |
58 component_extension_ime_manager_(new ComponentExtensionIMEManager()), | 63 component_extension_ime_manager_(new ComponentExtensionIMEManager()), |
59 weak_ptr_factory_(this) { | 64 weak_ptr_factory_(this) { |
60 } | 65 } |
61 | 66 |
62 InputMethodManagerImpl::~InputMethodManagerImpl() { | 67 InputMethodManagerImpl::~InputMethodManagerImpl() { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 206 |
202 // Add candidates to layouts, while skipping duplicates. | 207 // Add candidates to layouts, while skipping duplicates. |
203 for (size_t i = 0; i < candidates.size(); ++i) { | 208 for (size_t i = 0; i < candidates.size(); ++i) { |
204 const std::string& candidate = candidates[i]; | 209 const std::string& candidate = candidates[i]; |
205 // Not efficient, but should be fine, as the two vectors are very | 210 // Not efficient, but should be fine, as the two vectors are very |
206 // short (2-5 items). | 211 // short (2-5 items). |
207 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate)) | 212 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate)) |
208 layouts.push_back(candidate); | 213 layouts.push_back(candidate); |
209 } | 214 } |
210 | 215 |
| 216 MigrateXkbInputMethods(&layouts); |
211 active_input_method_ids_.swap(layouts); | 217 active_input_method_ids_.swap(layouts); |
212 | 218 |
213 // Initialize candidate window controller and widgets such as | 219 // Initialize candidate window controller and widgets such as |
214 // candidate window, infolist and mode indicator. Note, mode | 220 // candidate window, infolist and mode indicator. Note, mode |
215 // indicator is used by only keyboard layout input methods. | 221 // indicator is used by only keyboard layout input methods. |
216 if (active_input_method_ids_.size() > 1) | 222 if (active_input_method_ids_.size() > 1) |
217 MaybeInitializeCandidateWindowController(); | 223 MaybeInitializeCandidateWindowController(); |
218 | 224 |
219 // you can pass empty |initial_layout|. | 225 // you can pass empty |initial_layout|. |
220 ChangeInputMethod(initial_layouts.empty() ? "" : initial_layouts[0]); | 226 ChangeInputMethod(initial_layouts.empty() ? "" : |
| 227 extension_ime_util::GetInputMethodIDByKeyboardLayout( |
| 228 initial_layouts[0])); |
221 } | 229 } |
222 | 230 |
223 // Adds new input method to given list. | 231 // Adds new input method to given list. |
224 bool InputMethodManagerImpl::EnableInputMethodImpl( | 232 bool InputMethodManagerImpl::EnableInputMethodImpl( |
225 const std::string& input_method_id, | 233 const std::string& input_method_id, |
226 std::vector<std::string>* new_active_input_method_ids) const { | 234 std::vector<std::string>* new_active_input_method_ids) const { |
227 DCHECK(new_active_input_method_ids); | 235 DCHECK(new_active_input_method_ids); |
228 if (!util_.IsValidInputMethodId(input_method_id)) { | 236 if (!util_.IsValidInputMethodId(input_method_id)) { |
229 DVLOG(1) << "EnableInputMethod: Invalid ID: " << input_method_id; | 237 DVLOG(1) << "EnableInputMethod: Invalid ID: " << input_method_id; |
230 return false; | 238 return false; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 } | 286 } |
279 | 287 |
280 // Copy extension IDs to |new_active_input_method_ids_filtered|. We have to | 288 // Copy extension IDs to |new_active_input_method_ids_filtered|. We have to |
281 // keep relative order of the extension input method IDs. | 289 // keep relative order of the extension input method IDs. |
282 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { | 290 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { |
283 const std::string& input_method_id = active_input_method_ids_[i]; | 291 const std::string& input_method_id = active_input_method_ids_[i]; |
284 if (extension_ime_util::IsExtensionIME(input_method_id)) | 292 if (extension_ime_util::IsExtensionIME(input_method_id)) |
285 new_active_input_method_ids_filtered.push_back(input_method_id); | 293 new_active_input_method_ids_filtered.push_back(input_method_id); |
286 } | 294 } |
287 active_input_method_ids_.swap(new_active_input_method_ids_filtered); | 295 active_input_method_ids_.swap(new_active_input_method_ids_filtered); |
| 296 MigrateXkbInputMethods(&active_input_method_ids_); |
288 | 297 |
289 ReconfigureIMFramework(); | 298 ReconfigureIMFramework(); |
290 | 299 |
291 // If |current_input_method| is no longer in |active_input_method_ids_|, | 300 // If |current_input_method| is no longer in |active_input_method_ids_|, |
292 // ChangeInputMethod() picks the first one in |active_input_method_ids_|. | 301 // ChangeInputMethod() picks the first one in |active_input_method_ids_|. |
293 ChangeInputMethod(current_input_method_.id()); | 302 ChangeInputMethod(current_input_method_.id()); |
294 return true; | 303 return true; |
295 } | 304 } |
296 | 305 |
297 void InputMethodManagerImpl::ChangeInputMethod( | 306 void InputMethodManagerImpl::ChangeInputMethod( |
(...skipping 14 matching lines...) Expand all Loading... |
312 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods()); | 321 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods()); |
313 DCHECK(!input_methods->empty()); | 322 DCHECK(!input_methods->empty()); |
314 input_method_id_to_switch = input_methods->at(0).id(); | 323 input_method_id_to_switch = input_methods->at(0).id(); |
315 if (!input_method_id.empty()) { | 324 if (!input_method_id.empty()) { |
316 DVLOG(1) << "Can't change the current input method to " | 325 DVLOG(1) << "Can't change the current input method to " |
317 << input_method_id << " since the engine is not enabled. " | 326 << input_method_id << " since the engine is not enabled. " |
318 << "Switch to " << input_method_id_to_switch << " instead."; | 327 << "Switch to " << input_method_id_to_switch << " instead."; |
319 } | 328 } |
320 } | 329 } |
321 | 330 |
322 if (!component_extension_ime_manager_->IsInitialized() && | 331 if (!component_extension_ime_manager_->IsInitialized() && ( |
323 !InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) { | 332 !InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch) || |
| 333 extension_ime_util::IsKeyboardLayoutExtension( |
| 334 input_method_id_to_switch))) { |
324 // We can't change input method before the initialization of | 335 // We can't change input method before the initialization of |
325 // component extension ime manager. ChangeInputMethod will be | 336 // component extension ime manager. ChangeInputMethod will be |
326 // called with |pending_input_method_| when the initialization is | 337 // called with |pending_input_method_| when the initialization is |
327 // done. | 338 // done. |
328 pending_input_method_ = input_method_id_to_switch; | 339 pending_input_method_ = input_method_id_to_switch; |
329 return false; | 340 return false; |
330 } | 341 } |
331 pending_input_method_.clear(); | 342 pending_input_method_.clear(); |
332 | 343 |
333 // Hide candidate window and info list. | 344 // Hide candidate window and info list. |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 break; | 664 break; |
654 default: | 665 default: |
655 NOTREACHED(); | 666 NOTREACHED(); |
656 break; | 667 break; |
657 } | 668 } |
658 if (input_method_ids_to_switch.empty()) { | 669 if (input_method_ids_to_switch.empty()) { |
659 DVLOG(1) << "Unexpected VKEY: " << accelerator.key_code(); | 670 DVLOG(1) << "Unexpected VKEY: " << accelerator.key_code(); |
660 return false; | 671 return false; |
661 } | 672 } |
662 | 673 |
| 674 MigrateXkbInputMethods(&input_method_ids_to_switch); |
| 675 |
663 // Obtain the intersection of input_method_ids_to_switch and | 676 // Obtain the intersection of input_method_ids_to_switch and |
664 // active_input_method_ids_. The order of IDs in active_input_method_ids_ is | 677 // active_input_method_ids_. The order of IDs in active_input_method_ids_ is |
665 // preserved. | 678 // preserved. |
666 std::vector<std::string> ids; | 679 std::vector<std::string> ids; |
667 for (size_t i = 0; i < input_method_ids_to_switch.size(); ++i) { | 680 for (size_t i = 0; i < input_method_ids_to_switch.size(); ++i) { |
668 const std::string& id = input_method_ids_to_switch[i]; | 681 const std::string& id = input_method_ids_to_switch[i]; |
669 if (Contains(active_input_method_ids_, id)) | 682 if (Contains(active_input_method_ids_, id)) |
670 ids.push_back(id); | 683 ids.push_back(id); |
671 } | 684 } |
672 if (ids.empty()) { | 685 if (ids.empty()) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 if (candidate_window_controller_.get()) | 848 if (candidate_window_controller_.get()) |
836 return; | 849 return; |
837 | 850 |
838 candidate_window_controller_.reset( | 851 candidate_window_controller_.reset( |
839 CandidateWindowController::CreateCandidateWindowController()); | 852 CandidateWindowController::CreateCandidateWindowController()); |
840 candidate_window_controller_->AddObserver(this); | 853 candidate_window_controller_->AddObserver(this); |
841 } | 854 } |
842 | 855 |
843 } // namespace input_method | 856 } // namespace input_method |
844 } // namespace chromeos | 857 } // namespace chromeos |
OLD | NEW |