| 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" | |
| 10 #include "ash/ime/input_method_menu_manager.h" | |
| 11 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 12 #include "base/bind.h" | 10 #include "base/bind.h" |
| 13 #include "base/location.h" | 11 #include "base/location.h" |
| 14 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 16 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 18 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
| 19 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h" | 18 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 50 return util_.IsLoginKeyboard(layout); | 48 return util_.IsLoginKeyboard(layout); |
| 51 } | 49 } |
| 52 | 50 |
| 53 InputMethodManagerImpl::InputMethodManagerImpl( | 51 InputMethodManagerImpl::InputMethodManagerImpl( |
| 54 scoped_ptr<InputMethodDelegate> delegate) | 52 scoped_ptr<InputMethodDelegate> delegate) |
| 55 : delegate_(delegate.Pass()), | 53 : delegate_(delegate.Pass()), |
| 56 state_(STATE_LOGIN_SCREEN), | 54 state_(STATE_LOGIN_SCREEN), |
| 57 util_(delegate_.get(), GetSupportedInputMethods()), | 55 util_(delegate_.get(), GetSupportedInputMethods()), |
| 58 component_extension_ime_manager_(new ComponentExtensionIMEManager()), | 56 component_extension_ime_manager_(new ComponentExtensionIMEManager()), |
| 59 weak_ptr_factory_(this) { | 57 weak_ptr_factory_(this) { |
| 60 ash::ime::InputMethodMenuManager::Initialize(); | |
| 61 } | 58 } |
| 62 | 59 |
| 63 InputMethodManagerImpl::~InputMethodManagerImpl() { | 60 InputMethodManagerImpl::~InputMethodManagerImpl() { |
| 64 if (candidate_window_controller_.get()) | 61 if (candidate_window_controller_.get()) |
| 65 candidate_window_controller_->RemoveObserver(this); | 62 candidate_window_controller_->RemoveObserver(this); |
| 66 ash::ime::InputMethodMenuManager::Shutdown(); | |
| 67 } | 63 } |
| 68 | 64 |
| 69 void InputMethodManagerImpl::AddObserver( | 65 void InputMethodManagerImpl::AddObserver( |
| 70 InputMethodManager::Observer* observer) { | 66 InputMethodManager::Observer* observer) { |
| 71 observers_.AddObserver(observer); | 67 observers_.AddObserver(observer); |
| 72 } | 68 } |
| 73 | 69 |
| 74 void InputMethodManagerImpl::AddCandidateWindowObserver( | 70 void InputMethodManagerImpl::AddCandidateWindowObserver( |
| 75 InputMethodManager::CandidateWindowObserver* observer) { | 71 InputMethodManager::CandidateWindowObserver* observer) { |
| 76 candidate_window_observers_.AddObserver(observer); | 72 candidate_window_observers_.AddObserver(observer); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 next_engine->Enable(); | 343 next_engine->Enable(); |
| 348 } | 344 } |
| 349 | 345 |
| 350 // TODO(komatsu): Check if it is necessary to perform the above routine | 346 // TODO(komatsu): Check if it is necessary to perform the above routine |
| 351 // when the current input method is equal to |input_method_id_to_swich|. | 347 // when the current input method is equal to |input_method_id_to_swich|. |
| 352 if (current_input_method_.id() != input_method_id_to_switch) { | 348 if (current_input_method_.id() != input_method_id_to_switch) { |
| 353 // Clear property list. Property list would be updated by | 349 // Clear property list. Property list would be updated by |
| 354 // extension IMEs via InputMethodEngine::(Set|Update)MenuItems. | 350 // extension IMEs via InputMethodEngine::(Set|Update)MenuItems. |
| 355 // If the current input method is a keyboard layout, empty | 351 // If the current input method is a keyboard layout, empty |
| 356 // properties are sufficient. | 352 // properties are sufficient. |
| 357 const ash::ime::InputMethodMenuItemList empty_menu_item_list; | 353 const InputMethodPropertyList empty_property_list; |
| 358 ash::ime::InputMethodMenuManager* input_method_menu_manager = | 354 SetCurrentInputMethodProperties(empty_property_list); |
| 359 ash::ime::InputMethodMenuManager::Get(); | |
| 360 input_method_menu_manager->SetCurrentInputMethodMenuItemList( | |
| 361 empty_menu_item_list); | |
| 362 | 355 |
| 363 const InputMethodDescriptor* descriptor = NULL; | 356 const InputMethodDescriptor* descriptor = NULL; |
| 364 if (extension_ime_util::IsExtensionIME(input_method_id_to_switch)) { | 357 if (extension_ime_util::IsExtensionIME(input_method_id_to_switch)) { |
| 365 DCHECK(extra_input_methods_.find(input_method_id_to_switch) != | 358 DCHECK(extra_input_methods_.find(input_method_id_to_switch) != |
| 366 extra_input_methods_.end()); | 359 extra_input_methods_.end()); |
| 367 descriptor = &(extra_input_methods_[input_method_id_to_switch]); | 360 descriptor = &(extra_input_methods_[input_method_id_to_switch]); |
| 368 } else { | 361 } else { |
| 369 descriptor = | 362 descriptor = |
| 370 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); | 363 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); |
| 371 } | 364 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); | 412 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); |
| 420 } else if (component_extension_ime_manager_->IsWhitelisted( | 413 } else if (component_extension_ime_manager_->IsWhitelisted( |
| 421 unfiltered_input_method_ids[i])) { | 414 unfiltered_input_method_ids[i])) { |
| 422 component_extension_ime_manager_->LoadComponentExtensionIME( | 415 component_extension_ime_manager_->LoadComponentExtensionIME( |
| 423 unfiltered_input_method_ids[i]); | 416 unfiltered_input_method_ids[i]); |
| 424 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); | 417 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); |
| 425 } | 418 } |
| 426 } | 419 } |
| 427 } | 420 } |
| 428 | 421 |
| 429 void InputMethodManagerImpl::ActivateInputMethodMenuItem( | 422 void InputMethodManagerImpl::ActivateInputMethodProperty( |
| 430 const std::string& key) { | 423 const std::string& key) { |
| 431 DCHECK(!key.empty()); | 424 DCHECK(!key.empty()); |
| 432 | 425 |
| 433 if (ash::ime::InputMethodMenuManager::Get()-> | 426 for (size_t i = 0; i < property_list_.size(); ++i) { |
| 434 HasInputMethodMenuItemForKey(key)) { | 427 if (property_list_[i].key == key) { |
| 435 IMEEngineHandlerInterface* engine = | 428 IMEEngineHandlerInterface* engine = |
| 436 IMEBridge::Get()->GetCurrentEngineHandler(); | 429 IMEBridge::Get()->GetCurrentEngineHandler(); |
| 437 if (engine) | 430 if (engine) |
| 438 engine->PropertyActivate(key); | 431 engine->PropertyActivate(key); |
| 439 return; | 432 return; |
| 433 } |
| 440 } | 434 } |
| 441 | 435 |
| 442 DVLOG(1) << "ActivateInputMethodMenuItem: unknown key: " << key; | 436 DVLOG(1) << "ActivateInputMethodProperty: unknown key: " << key; |
| 443 } | 437 } |
| 444 | 438 |
| 445 void InputMethodManagerImpl::AddInputMethodExtension( | 439 void InputMethodManagerImpl::AddInputMethodExtension( |
| 446 const std::string& id, | 440 const std::string& id, |
| 447 InputMethodEngineInterface* engine) { | 441 InputMethodEngineInterface* engine) { |
| 448 if (state_ == STATE_TERMINATING) | 442 if (state_ == STATE_TERMINATING) |
| 449 return; | 443 return; |
| 450 | 444 |
| 451 if (!extension_ime_util::IsExtensionIME(id) && | 445 if (!extension_ime_util::IsExtensionIME(id) && |
| 452 !extension_ime_util::IsComponentExtensionIME(id)) { | 446 !extension_ime_util::IsComponentExtensionIME(id)) { |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 ChangeInputMethodInternal(*iter, true); | 680 ChangeInputMethodInternal(*iter, true); |
| 687 } | 681 } |
| 688 | 682 |
| 689 InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const { | 683 InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const { |
| 690 if (current_input_method_.id().empty()) | 684 if (current_input_method_.id().empty()) |
| 691 return InputMethodUtil::GetFallbackInputMethodDescriptor(); | 685 return InputMethodUtil::GetFallbackInputMethodDescriptor(); |
| 692 | 686 |
| 693 return current_input_method_; | 687 return current_input_method_; |
| 694 } | 688 } |
| 695 | 689 |
| 690 InputMethodPropertyList |
| 691 InputMethodManagerImpl::GetCurrentInputMethodProperties() const { |
| 692 // This check is necessary since an IME property (e.g. for Pinyin) might be |
| 693 // sent from ibus-daemon AFTER the current input method is switched to XKB. |
| 694 if (InputMethodUtil::IsKeyboardLayout(GetCurrentInputMethod().id())) |
| 695 return InputMethodPropertyList(); // Empty list. |
| 696 return property_list_; |
| 697 } |
| 698 |
| 699 void InputMethodManagerImpl::SetCurrentInputMethodProperties( |
| 700 const InputMethodPropertyList& property_list) { |
| 701 property_list_ = property_list; |
| 702 PropertyChanged(); |
| 703 } |
| 704 |
| 696 XKeyboard* InputMethodManagerImpl::GetXKeyboard() { | 705 XKeyboard* InputMethodManagerImpl::GetXKeyboard() { |
| 697 return xkeyboard_.get(); | 706 return xkeyboard_.get(); |
| 698 } | 707 } |
| 699 | 708 |
| 700 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() { | 709 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() { |
| 701 return &util_; | 710 return &util_; |
| 702 } | 711 } |
| 703 | 712 |
| 704 ComponentExtensionIMEManager* | 713 ComponentExtensionIMEManager* |
| 705 InputMethodManagerImpl::GetComponentExtensionIMEManager() { | 714 InputMethodManagerImpl::GetComponentExtensionIMEManager() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 | 750 |
| 742 void InputMethodManagerImpl::SetXKeyboardForTesting(XKeyboard* xkeyboard) { | 751 void InputMethodManagerImpl::SetXKeyboardForTesting(XKeyboard* xkeyboard) { |
| 743 xkeyboard_.reset(xkeyboard); | 752 xkeyboard_.reset(xkeyboard); |
| 744 } | 753 } |
| 745 | 754 |
| 746 void InputMethodManagerImpl::InitializeComponentExtensionForTesting( | 755 void InputMethodManagerImpl::InitializeComponentExtensionForTesting( |
| 747 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { | 756 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { |
| 748 OnComponentExtensionInitialized(delegate.Pass()); | 757 OnComponentExtensionInitialized(delegate.Pass()); |
| 749 } | 758 } |
| 750 | 759 |
| 760 void InputMethodManagerImpl::PropertyChanged() { |
| 761 FOR_EACH_OBSERVER(InputMethodManager::Observer, |
| 762 observers_, |
| 763 InputMethodPropertyChanged(this)); |
| 764 } |
| 765 |
| 751 void InputMethodManagerImpl::CandidateClicked(int index) { | 766 void InputMethodManagerImpl::CandidateClicked(int index) { |
| 752 IMEEngineHandlerInterface* engine = | 767 IMEEngineHandlerInterface* engine = |
| 753 IMEBridge::Get()->GetCurrentEngineHandler(); | 768 IMEBridge::Get()->GetCurrentEngineHandler(); |
| 754 if (engine) | 769 if (engine) |
| 755 engine->CandidateClicked(index); | 770 engine->CandidateClicked(index); |
| 756 } | 771 } |
| 757 | 772 |
| 758 void InputMethodManagerImpl::CandidateWindowOpened() { | 773 void InputMethodManagerImpl::CandidateWindowOpened() { |
| 759 FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver, | 774 FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver, |
| 760 candidate_window_observers_, | 775 candidate_window_observers_, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 if (candidate_window_controller_.get()) | 836 if (candidate_window_controller_.get()) |
| 822 return; | 837 return; |
| 823 | 838 |
| 824 candidate_window_controller_.reset( | 839 candidate_window_controller_.reset( |
| 825 CandidateWindowController::CreateCandidateWindowController()); | 840 CandidateWindowController::CreateCandidateWindowController()); |
| 826 candidate_window_controller_->AddObserver(this); | 841 candidate_window_controller_->AddObserver(this); |
| 827 } | 842 } |
| 828 | 843 |
| 829 } // namespace input_method | 844 } // namespace input_method |
| 830 } // namespace chromeos | 845 } // namespace chromeos |
| OLD | NEW |