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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 case STATE_TERMINATING: { | 103 case STATE_TERMINATING: { |
104 if (candidate_window_controller_.get()) | 104 if (candidate_window_controller_.get()) |
105 candidate_window_controller_.reset(); | 105 candidate_window_controller_.reset(); |
106 break; | 106 break; |
107 } | 107 } |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 scoped_ptr<InputMethodDescriptors> | 111 scoped_ptr<InputMethodDescriptors> |
112 InputMethodManagerImpl::GetSupportedInputMethods() const { | 112 InputMethodManagerImpl::GetSupportedInputMethods() const { |
113 scoped_ptr<InputMethodDescriptors> whitelist_imes = | 113 if (!IsXkbComponentExtensionAvailable()) |
114 whitelist_.GetSupportedInputMethods(); | 114 return whitelist_.GetSupportedInputMethods().Pass(); |
115 if (!component_extension_ime_manager_->IsInitialized()) | |
116 return whitelist_imes.Pass(); | |
117 return scoped_ptr<InputMethodDescriptors>(new InputMethodDescriptors).Pass(); | 115 return scoped_ptr<InputMethodDescriptors>(new InputMethodDescriptors).Pass(); |
118 } | 116 } |
119 | 117 |
120 scoped_ptr<InputMethodDescriptors> | 118 scoped_ptr<InputMethodDescriptors> |
121 InputMethodManagerImpl::GetActiveInputMethods() const { | 119 InputMethodManagerImpl::GetActiveInputMethods() const { |
122 scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors); | 120 scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors); |
123 // Build the active input method descriptors from the active input | 121 // Build the active input method descriptors from the active input |
124 // methods cache |active_input_method_ids_|. | 122 // methods cache |active_input_method_ids_|. |
125 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { | 123 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { |
126 const std::string& input_method_id = active_input_method_ids_[i]; | 124 const std::string& input_method_id = active_input_method_ids_[i]; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 DCHECK(!input_methods->empty()); | 316 DCHECK(!input_methods->empty()); |
319 input_method_id_to_switch = input_methods->at(0).id(); | 317 input_method_id_to_switch = input_methods->at(0).id(); |
320 if (!input_method_id.empty()) { | 318 if (!input_method_id.empty()) { |
321 DVLOG(1) << "Can't change the current input method to " | 319 DVLOG(1) << "Can't change the current input method to " |
322 << input_method_id << " since the engine is not enabled. " | 320 << input_method_id << " since the engine is not enabled. " |
323 << "Switch to " << input_method_id_to_switch << " instead."; | 321 << "Switch to " << input_method_id_to_switch << " instead."; |
324 } | 322 } |
325 } | 323 } |
326 | 324 |
327 if (!component_extension_ime_manager_->IsInitialized() && | 325 if (!component_extension_ime_manager_->IsInitialized() && |
328 (!InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch) || | 326 !InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) { |
329 extension_ime_util::IsKeyboardLayoutExtension( | |
330 input_method_id_to_switch))) { | |
331 // We can't change input method before the initialization of | 327 // We can't change input method before the initialization of |
332 // component extension ime manager. ChangeInputMethod will be | 328 // component extension ime manager. ChangeInputMethod will be |
333 // called with |pending_input_method_| when the initialization is | 329 // called with |pending_input_method_| when the initialization is |
334 // done. | 330 // done. |
335 pending_input_method_ = input_method_id_to_switch; | 331 pending_input_method_ = input_method_id_to_switch; |
336 return false; | 332 return false; |
337 } | 333 } |
338 pending_input_method_.clear(); | 334 pending_input_method_.clear(); |
339 | 335 |
340 // Hide candidate window and info list. | 336 // Hide candidate window and info list. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 << current_input_method_.GetPreferredKeyboardLayout(); | 394 << current_input_method_.GetPreferredKeyboardLayout(); |
399 } | 395 } |
400 | 396 |
401 // Update input method indicators (e.g. "US", "DV") in Chrome windows. | 397 // Update input method indicators (e.g. "US", "DV") in Chrome windows. |
402 FOR_EACH_OBSERVER(InputMethodManager::Observer, | 398 FOR_EACH_OBSERVER(InputMethodManager::Observer, |
403 observers_, | 399 observers_, |
404 InputMethodChanged(this, show_message)); | 400 InputMethodChanged(this, show_message)); |
405 return true; | 401 return true; |
406 } | 402 } |
407 | 403 |
| 404 bool InputMethodManagerImpl::IsXkbComponentExtensionAvailable() const { |
| 405 if (!component_extension_ime_manager_->IsInitialized()) |
| 406 return false; |
| 407 InputMethodDescriptors imes = |
| 408 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor(); |
| 409 for (size_t i = 0; i < imes.size(); ++i) { |
| 410 if (StartsWithASCII(imes[i].id(), "xkb:", true)) |
| 411 return true; |
| 412 } |
| 413 return false; |
| 414 } |
| 415 |
408 void InputMethodManagerImpl::OnComponentExtensionInitialized( | 416 void InputMethodManagerImpl::OnComponentExtensionInitialized( |
409 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { | 417 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { |
410 DCHECK(thread_checker_.CalledOnValidThread()); | 418 DCHECK(thread_checker_.CalledOnValidThread()); |
411 component_extension_ime_manager_->Initialize(delegate.Pass()); | 419 component_extension_ime_manager_->Initialize(delegate.Pass()); |
412 InputMethodDescriptors imes = | 420 InputMethodDescriptors imes = |
413 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor(); | 421 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor(); |
414 // In case of XKB extension is not available (e.g. linux_chromeos), don't | 422 // In case of XKB extension is not available (e.g. linux_chromeos), don't |
415 // reset the input methods in InputMethodUtil, Instead append input methods. | 423 // reset the input methods in InputMethodUtil, Instead append input methods. |
416 bool xkb_found = false; | 424 if (IsXkbComponentExtensionAvailable()) |
417 for (size_t i = 0; i < imes.size(); ++i) { | |
418 if (StartsWithASCII(imes[i].id(), "xkb:", true)) { | |
419 xkb_found = true; | |
420 break; | |
421 } | |
422 } | |
423 if (xkb_found) | |
424 util_.ResetInputMethods(imes); | 425 util_.ResetInputMethods(imes); |
425 else | 426 else |
426 util_.AppendInputMethods(imes); | 427 util_.AppendInputMethods(imes); |
427 | 428 |
428 LoadNecessaryComponentExtensions(); | 429 LoadNecessaryComponentExtensions(); |
429 | 430 |
430 if (!pending_input_method_.empty()) | 431 if (!pending_input_method_.empty()) |
431 ChangeInputMethodInternal(pending_input_method_, false); | 432 ChangeInputMethodInternal(pending_input_method_, false); |
432 } | 433 } |
433 | 434 |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 CandidateWindowController::CreateCandidateWindowController()); | 868 CandidateWindowController::CreateCandidateWindowController()); |
868 candidate_window_controller_->AddObserver(this); | 869 candidate_window_controller_->AddObserver(this); |
869 } | 870 } |
870 | 871 |
871 Profile* InputMethodManagerImpl::GetProfile() const { | 872 Profile* InputMethodManagerImpl::GetProfile() const { |
872 return ProfileManager::GetActiveUserProfile(); | 873 return ProfileManager::GetActiveUserProfile(); |
873 } | 874 } |
874 | 875 |
875 } // namespace input_method | 876 } // namespace input_method |
876 } // namespace chromeos | 877 } // namespace chromeos |
OLD | NEW |