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" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h" | 20 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h" |
21 #include "chrome/browser/chromeos/input_method/component_extension_ime_manager_i
mpl.h" | 21 #include "chrome/browser/chromeos/input_method/component_extension_ime_manager_i
mpl.h" |
22 #include "chrome/browser/chromeos/input_method/input_method_engine.h" | 22 #include "chrome/browser/chromeos/input_method/input_method_engine.h" |
23 #include "chrome/browser/chromeos/language_preferences.h" | 23 #include "chrome/browser/chromeos/language_preferences.h" |
24 #include "chromeos/ime/component_extension_ime_manager.h" | 24 #include "chromeos/ime/component_extension_ime_manager.h" |
25 #include "chromeos/ime/extension_ime_util.h" | 25 #include "chromeos/ime/extension_ime_util.h" |
26 #include "chromeos/ime/fake_xkeyboard.h" | 26 #include "chromeos/ime/fake_ime_keyboard.h" |
| 27 #include "chromeos/ime/ime_keyboard.h" |
27 #include "chromeos/ime/input_method_delegate.h" | 28 #include "chromeos/ime/input_method_delegate.h" |
28 #include "chromeos/ime/xkeyboard.h" | |
29 #include "third_party/icu/source/common/unicode/uloc.h" | 29 #include "third_party/icu/source/common/unicode/uloc.h" |
30 #include "ui/base/accelerators/accelerator.h" | 30 #include "ui/base/accelerators/accelerator.h" |
31 | 31 |
32 namespace chromeos { | 32 namespace chromeos { |
33 namespace input_method { | 33 namespace input_method { |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 const char nacl_mozc_jp_id[] = | 37 const char nacl_mozc_jp_id[] = |
38 "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_jp"; | 38 "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_jp"; |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 descriptor = | 386 descriptor = |
387 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); | 387 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); |
388 } | 388 } |
389 DCHECK(descriptor); | 389 DCHECK(descriptor); |
390 | 390 |
391 previous_input_method_ = current_input_method_; | 391 previous_input_method_ = current_input_method_; |
392 current_input_method_ = *descriptor; | 392 current_input_method_ = *descriptor; |
393 } | 393 } |
394 | 394 |
395 // Change the keyboard layout to a preferred layout for the input method. | 395 // Change the keyboard layout to a preferred layout for the input method. |
396 if (!xkeyboard_->SetCurrentKeyboardLayoutByName( | 396 if (!keyboard_->SetCurrentKeyboardLayoutByName( |
397 current_input_method_.GetPreferredKeyboardLayout())) { | 397 current_input_method_.GetPreferredKeyboardLayout())) { |
398 LOG(ERROR) << "Failed to change keyboard layout to " | 398 LOG(ERROR) << "Failed to change keyboard layout to " |
399 << current_input_method_.GetPreferredKeyboardLayout(); | 399 << current_input_method_.GetPreferredKeyboardLayout(); |
400 } | 400 } |
401 | 401 |
402 // Update input method indicators (e.g. "US", "DV") in Chrome windows. | 402 // Update input method indicators (e.g. "US", "DV") in Chrome windows. |
403 FOR_EACH_OBSERVER(InputMethodManager::Observer, | 403 FOR_EACH_OBSERVER(InputMethodManager::Observer, |
404 observers_, | 404 observers_, |
405 InputMethodChanged(this, show_message)); | 405 InputMethodChanged(this, show_message)); |
406 return true; | 406 return true; |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 } | 709 } |
710 | 710 |
711 InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const { | 711 InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const { |
712 if (current_input_method_.id().empty()) | 712 if (current_input_method_.id().empty()) |
713 return InputMethodUtil::GetFallbackInputMethodDescriptor(); | 713 return InputMethodUtil::GetFallbackInputMethodDescriptor(); |
714 | 714 |
715 return current_input_method_; | 715 return current_input_method_; |
716 } | 716 } |
717 | 717 |
718 bool InputMethodManagerImpl::IsISOLevel5ShiftUsedByCurrentInputMethod() const { | 718 bool InputMethodManagerImpl::IsISOLevel5ShiftUsedByCurrentInputMethod() const { |
719 return xkeyboard_->IsISOLevel5ShiftAvailable(); | 719 return keyboard_->IsISOLevel5ShiftAvailable(); |
720 } | 720 } |
721 | 721 |
722 bool InputMethodManagerImpl::IsAltGrUsedByCurrentInputMethod() const { | 722 bool InputMethodManagerImpl::IsAltGrUsedByCurrentInputMethod() const { |
723 return xkeyboard_->IsAltGrAvailable(); | 723 return keyboard_->IsAltGrAvailable(); |
724 } | 724 } |
725 | 725 |
726 XKeyboard* InputMethodManagerImpl::GetXKeyboard() { | 726 ImeKeyboard* InputMethodManagerImpl::GetImeKeyboard() { |
727 return xkeyboard_.get(); | 727 return keyboard_.get(); |
728 } | 728 } |
729 | 729 |
730 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() { | 730 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() { |
731 return &util_; | 731 return &util_; |
732 } | 732 } |
733 | 733 |
734 ComponentExtensionIMEManager* | 734 ComponentExtensionIMEManager* |
735 InputMethodManagerImpl::GetComponentExtensionIMEManager() { | 735 InputMethodManagerImpl::GetComponentExtensionIMEManager() { |
736 DCHECK(thread_checker_.CalledOnValidThread()); | 736 DCHECK(thread_checker_.CalledOnValidThread()); |
737 return component_extension_ime_manager_.get(); | 737 return component_extension_ime_manager_.get(); |
738 } | 738 } |
739 | 739 |
740 void InputMethodManagerImpl::InitializeComponentExtension() { | 740 void InputMethodManagerImpl::InitializeComponentExtension() { |
741 ComponentExtensionIMEManagerImpl* impl = | 741 ComponentExtensionIMEManagerImpl* impl = |
742 new ComponentExtensionIMEManagerImpl(); | 742 new ComponentExtensionIMEManagerImpl(); |
743 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(impl); | 743 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(impl); |
744 impl->InitializeAsync(base::Bind( | 744 impl->InitializeAsync(base::Bind( |
745 &InputMethodManagerImpl::OnComponentExtensionInitialized, | 745 &InputMethodManagerImpl::OnComponentExtensionInitialized, |
746 weak_ptr_factory_.GetWeakPtr(), | 746 weak_ptr_factory_.GetWeakPtr(), |
747 base::Passed(&delegate))); | 747 base::Passed(&delegate))); |
748 } | 748 } |
749 | 749 |
750 void InputMethodManagerImpl::Init(base::SequencedTaskRunner* ui_task_runner) { | 750 void InputMethodManagerImpl::Init(base::SequencedTaskRunner* ui_task_runner) { |
751 DCHECK(thread_checker_.CalledOnValidThread()); | 751 DCHECK(thread_checker_.CalledOnValidThread()); |
752 | 752 |
753 if (base::SysInfo::IsRunningOnChromeOS()) | 753 if (base::SysInfo::IsRunningOnChromeOS()) |
754 xkeyboard_.reset(XKeyboard::Create()); | 754 keyboard_.reset(ImeKeyboard::Create()); |
755 else | 755 else |
756 xkeyboard_.reset(new FakeXKeyboard()); | 756 keyboard_.reset(new FakeImeKeyboard()); |
757 | 757 |
758 // We can't call impl->Initialize here, because file thread is not available | 758 // We can't call impl->Initialize here, because file thread is not available |
759 // at this moment. | 759 // at this moment. |
760 ui_task_runner->PostTask( | 760 ui_task_runner->PostTask( |
761 FROM_HERE, | 761 FROM_HERE, |
762 base::Bind(&InputMethodManagerImpl::InitializeComponentExtension, | 762 base::Bind(&InputMethodManagerImpl::InitializeComponentExtension, |
763 weak_ptr_factory_.GetWeakPtr())); | 763 weak_ptr_factory_.GetWeakPtr())); |
764 } | 764 } |
765 | 765 |
766 void InputMethodManagerImpl::SetCandidateWindowControllerForTesting( | 766 void InputMethodManagerImpl::SetCandidateWindowControllerForTesting( |
767 CandidateWindowController* candidate_window_controller) { | 767 CandidateWindowController* candidate_window_controller) { |
768 candidate_window_controller_.reset(candidate_window_controller); | 768 candidate_window_controller_.reset(candidate_window_controller); |
769 candidate_window_controller_->AddObserver(this); | 769 candidate_window_controller_->AddObserver(this); |
770 } | 770 } |
771 | 771 |
772 void InputMethodManagerImpl::SetXKeyboardForTesting(XKeyboard* xkeyboard) { | 772 void InputMethodManagerImpl::SetImeKeyboardForTesting(ImeKeyboard* keyboard) { |
773 xkeyboard_.reset(xkeyboard); | 773 keyboard_.reset(keyboard); |
774 } | 774 } |
775 | 775 |
776 void InputMethodManagerImpl::InitializeComponentExtensionForTesting( | 776 void InputMethodManagerImpl::InitializeComponentExtensionForTesting( |
777 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { | 777 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { |
778 OnComponentExtensionInitialized(delegate.Pass()); | 778 OnComponentExtensionInitialized(delegate.Pass()); |
779 } | 779 } |
780 | 780 |
781 void InputMethodManagerImpl::CandidateClicked(int index) { | 781 void InputMethodManagerImpl::CandidateClicked(int index) { |
782 IMEEngineHandlerInterface* engine = | 782 IMEEngineHandlerInterface* engine = |
783 IMEBridge::Get()->GetCurrentEngineHandler(); | 783 IMEBridge::Get()->GetCurrentEngineHandler(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 if (candidate_window_controller_.get()) | 849 if (candidate_window_controller_.get()) |
850 return; | 850 return; |
851 | 851 |
852 candidate_window_controller_.reset( | 852 candidate_window_controller_.reset( |
853 CandidateWindowController::CreateCandidateWindowController()); | 853 CandidateWindowController::CreateCandidateWindowController()); |
854 candidate_window_controller_->AddObserver(this); | 854 candidate_window_controller_->AddObserver(this); |
855 } | 855 } |
856 | 856 |
857 } // namespace input_method | 857 } // namespace input_method |
858 } // namespace chromeos | 858 } // namespace chromeos |
OLD | NEW |