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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 empty_menu_item_list); | 379 empty_menu_item_list); |
380 | 380 |
381 const InputMethodDescriptor* descriptor = NULL; | 381 const InputMethodDescriptor* descriptor = NULL; |
382 if (extension_ime_util::IsExtensionIME(input_method_id_to_switch)) { | 382 if (extension_ime_util::IsExtensionIME(input_method_id_to_switch)) { |
383 DCHECK(extra_input_methods_.find(input_method_id_to_switch) != | 383 DCHECK(extra_input_methods_.find(input_method_id_to_switch) != |
384 extra_input_methods_.end()); | 384 extra_input_methods_.end()); |
385 descriptor = &(extra_input_methods_[input_method_id_to_switch]); | 385 descriptor = &(extra_input_methods_[input_method_id_to_switch]); |
386 } else { | 386 } else { |
387 descriptor = | 387 descriptor = |
388 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); | 388 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); |
| 389 if (!descriptor) |
| 390 LOG(ERROR) << "Unknown input method id: " << input_method_id_to_switch; |
389 } | 391 } |
390 DCHECK(descriptor); | 392 DCHECK(descriptor); |
391 | 393 |
392 previous_input_method_ = current_input_method_; | 394 previous_input_method_ = current_input_method_; |
393 current_input_method_ = *descriptor; | 395 current_input_method_ = *descriptor; |
394 } | 396 } |
395 | 397 |
396 // Change the keyboard layout to a preferred layout for the input method. | 398 // Change the keyboard layout to a preferred layout for the input method. |
397 if (!keyboard_->SetCurrentKeyboardLayoutByName( | 399 if (!keyboard_->SetCurrentKeyboardLayoutByName( |
398 current_input_method_.GetPreferredKeyboardLayout())) { | 400 current_input_method_.GetPreferredKeyboardLayout())) { |
399 LOG(ERROR) << "Failed to change keyboard layout to " | 401 LOG(ERROR) << "Failed to change keyboard layout to " |
400 << current_input_method_.GetPreferredKeyboardLayout(); | 402 << current_input_method_.GetPreferredKeyboardLayout(); |
401 } | 403 } |
402 | 404 |
403 // Update input method indicators (e.g. "US", "DV") in Chrome windows. | 405 // Update input method indicators (e.g. "US", "DV") in Chrome windows. |
404 FOR_EACH_OBSERVER(InputMethodManager::Observer, | 406 FOR_EACH_OBSERVER(InputMethodManager::Observer, |
405 observers_, | 407 observers_, |
406 InputMethodChanged(this, show_message)); | 408 InputMethodChanged(this, show_message)); |
407 return true; | 409 return true; |
408 } | 410 } |
409 | 411 |
410 void InputMethodManagerImpl::OnComponentExtensionInitialized( | 412 void InputMethodManagerImpl::OnComponentExtensionInitialized( |
411 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { | 413 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { |
412 DCHECK(thread_checker_.CalledOnValidThread()); | 414 DCHECK(thread_checker_.CalledOnValidThread()); |
413 component_extension_ime_manager_->Initialize(delegate.Pass()); | 415 component_extension_ime_manager_->Initialize(delegate.Pass()); |
414 util_.SetComponentExtensions( | 416 InputMethodDescriptors imes = |
415 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor()); | 417 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor(); |
| 418 // In case of XKB extension is not available (e.g. linux_chromeos), don't |
| 419 // reset the input methods in InputMethodUtil, Instead append input methods. |
| 420 bool xkb_found = false; |
| 421 for (size_t i = 0; i < imes.size(); ++i) { |
| 422 if (StartsWithASCII(imes[i].id(), "xkb:", true)) { |
| 423 xkb_found = true; |
| 424 break; |
| 425 } |
| 426 } |
| 427 if (xkb_found) |
| 428 util_.ResetInputMethods(imes); |
| 429 else |
| 430 util_.AppendInputMethods(imes); |
416 | 431 |
417 LoadNecessaryComponentExtensions(); | 432 LoadNecessaryComponentExtensions(); |
418 | 433 |
419 if (!pending_input_method_.empty()) | 434 if (!pending_input_method_.empty()) |
420 ChangeInputMethodInternal(pending_input_method_, false); | 435 ChangeInputMethodInternal(pending_input_method_, false); |
421 } | 436 } |
422 | 437 |
423 void InputMethodManagerImpl::LoadNecessaryComponentExtensions() { | 438 void InputMethodManagerImpl::LoadNecessaryComponentExtensions() { |
424 if (!component_extension_ime_manager_->IsInitialized()) | 439 if (!component_extension_ime_manager_->IsInitialized()) |
425 return; | 440 return; |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 CandidateWindowController::CreateCandidateWindowController()); | 869 CandidateWindowController::CreateCandidateWindowController()); |
855 candidate_window_controller_->AddObserver(this); | 870 candidate_window_controller_->AddObserver(this); |
856 } | 871 } |
857 | 872 |
858 Profile* InputMethodManagerImpl::GetProfile() const { | 873 Profile* InputMethodManagerImpl::GetProfile() const { |
859 return ProfileManager::GetActiveUserProfile(); | 874 return ProfileManager::GetActiveUserProfile(); |
860 } | 875 } |
861 | 876 |
862 } // namespace input_method | 877 } // namespace input_method |
863 } // namespace chromeos | 878 } // namespace chromeos |
OLD | NEW |