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" |
9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
10 #include "base/bind.h" | 12 #include "base/bind.h" |
11 #include "base/location.h" | 13 #include "base/location.h" |
12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
13 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
14 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
16 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
17 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h" | 20 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h" |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 next_engine->Enable(); | 352 next_engine->Enable(); |
351 } | 353 } |
352 | 354 |
353 // TODO(komatsu): Check if it is necessary to perform the above routine | 355 // TODO(komatsu): Check if it is necessary to perform the above routine |
354 // when the current input method is equal to |input_method_id_to_swich|. | 356 // when the current input method is equal to |input_method_id_to_swich|. |
355 if (current_input_method_.id() != input_method_id_to_switch) { | 357 if (current_input_method_.id() != input_method_id_to_switch) { |
356 // Clear property list. Property list would be updated by | 358 // Clear property list. Property list would be updated by |
357 // extension IMEs via InputMethodEngine::(Set|Update)MenuItems. | 359 // extension IMEs via InputMethodEngine::(Set|Update)MenuItems. |
358 // If the current input method is a keyboard layout, empty | 360 // If the current input method is a keyboard layout, empty |
359 // properties are sufficient. | 361 // properties are sufficient. |
360 const InputMethodPropertyList empty_property_list; | 362 const ash::ime::InputMethodMenuItemList empty_menu_item_list; |
361 SetCurrentInputMethodProperties(empty_property_list); | 363 ash::ime::InputMethodMenuManager* input_method_menu_manager = |
| 364 ash::ime::InputMethodMenuManager::GetInstance(); |
| 365 input_method_menu_manager->SetCurrentInputMethodMenuItemList( |
| 366 empty_menu_item_list); |
362 | 367 |
363 const InputMethodDescriptor* descriptor = NULL; | 368 const InputMethodDescriptor* descriptor = NULL; |
364 if (extension_ime_util::IsExtensionIME(input_method_id_to_switch)) { | 369 if (extension_ime_util::IsExtensionIME(input_method_id_to_switch)) { |
365 DCHECK(extra_input_methods_.find(input_method_id_to_switch) != | 370 DCHECK(extra_input_methods_.find(input_method_id_to_switch) != |
366 extra_input_methods_.end()); | 371 extra_input_methods_.end()); |
367 descriptor = &(extra_input_methods_[input_method_id_to_switch]); | 372 descriptor = &(extra_input_methods_[input_method_id_to_switch]); |
368 } else { | 373 } else { |
369 descriptor = | 374 descriptor = |
370 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); | 375 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); |
371 } | 376 } |
(...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]); | 424 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); |
420 } else if (component_extension_ime_manager_->IsWhitelisted( | 425 } else if (component_extension_ime_manager_->IsWhitelisted( |
421 unfiltered_input_method_ids[i])) { | 426 unfiltered_input_method_ids[i])) { |
422 component_extension_ime_manager_->LoadComponentExtensionIME( | 427 component_extension_ime_manager_->LoadComponentExtensionIME( |
423 unfiltered_input_method_ids[i]); | 428 unfiltered_input_method_ids[i]); |
424 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); | 429 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); |
425 } | 430 } |
426 } | 431 } |
427 } | 432 } |
428 | 433 |
429 void InputMethodManagerImpl::ActivateInputMethodProperty( | 434 void InputMethodManagerImpl::ActivateInputMethodMenuItem( |
430 const std::string& key) { | 435 const std::string& key) { |
431 DCHECK(!key.empty()); | 436 DCHECK(!key.empty()); |
432 | 437 |
433 for (size_t i = 0; i < property_list_.size(); ++i) { | 438 if (ash::ime::InputMethodMenuManager::GetInstance()-> |
434 if (property_list_[i].key == key) { | 439 HasInputMethodMenuItemForKey(key)) { |
435 IMEEngineHandlerInterface* engine = | 440 IMEEngineHandlerInterface* engine = |
436 IMEBridge::Get()->GetCurrentEngineHandler(); | 441 IMEBridge::Get()->GetCurrentEngineHandler(); |
437 if (engine) | 442 if (engine) |
438 engine->PropertyActivate(key); | 443 engine->PropertyActivate(key); |
439 return; | 444 return; |
440 } | |
441 } | 445 } |
442 | 446 |
443 DVLOG(1) << "ActivateInputMethodProperty: unknown key: " << key; | 447 DVLOG(1) << "ActivateInputMethodMenuItem: unknown key: " << key; |
444 } | 448 } |
445 | 449 |
446 void InputMethodManagerImpl::AddInputMethodExtension( | 450 void InputMethodManagerImpl::AddInputMethodExtension( |
447 const std::string& id, | 451 const std::string& id, |
448 InputMethodEngineInterface* engine) { | 452 InputMethodEngineInterface* engine) { |
449 if (state_ == STATE_TERMINATING) | 453 if (state_ == STATE_TERMINATING) |
450 return; | 454 return; |
451 | 455 |
452 if (!extension_ime_util::IsExtensionIME(id) && | 456 if (!extension_ime_util::IsExtensionIME(id) && |
453 !extension_ime_util::IsComponentExtensionIME(id)) { | 457 !extension_ime_util::IsComponentExtensionIME(id)) { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 ChangeInputMethodInternal(*iter, true); | 693 ChangeInputMethodInternal(*iter, true); |
690 } | 694 } |
691 | 695 |
692 InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const { | 696 InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const { |
693 if (current_input_method_.id().empty()) | 697 if (current_input_method_.id().empty()) |
694 return InputMethodUtil::GetFallbackInputMethodDescriptor(); | 698 return InputMethodUtil::GetFallbackInputMethodDescriptor(); |
695 | 699 |
696 return current_input_method_; | 700 return current_input_method_; |
697 } | 701 } |
698 | 702 |
699 InputMethodPropertyList | |
700 InputMethodManagerImpl::GetCurrentInputMethodProperties() const { | |
701 // This check is necessary since an IME property (e.g. for Pinyin) might be | |
702 // sent from ibus-daemon AFTER the current input method is switched to XKB. | |
703 if (InputMethodUtil::IsKeyboardLayout(GetCurrentInputMethod().id())) | |
704 return InputMethodPropertyList(); // Empty list. | |
705 return property_list_; | |
706 } | |
707 | |
708 void InputMethodManagerImpl::SetCurrentInputMethodProperties( | |
709 const InputMethodPropertyList& property_list) { | |
710 property_list_ = property_list; | |
711 PropertyChanged(); | |
712 } | |
713 | |
714 XKeyboard* InputMethodManagerImpl::GetXKeyboard() { | 703 XKeyboard* InputMethodManagerImpl::GetXKeyboard() { |
715 return xkeyboard_.get(); | 704 return xkeyboard_.get(); |
716 } | 705 } |
717 | 706 |
718 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() { | 707 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() { |
719 return &util_; | 708 return &util_; |
720 } | 709 } |
721 | 710 |
722 ComponentExtensionIMEManager* | 711 ComponentExtensionIMEManager* |
723 InputMethodManagerImpl::GetComponentExtensionIMEManager() { | 712 InputMethodManagerImpl::GetComponentExtensionIMEManager() { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 | 748 |
760 void InputMethodManagerImpl::SetXKeyboardForTesting(XKeyboard* xkeyboard) { | 749 void InputMethodManagerImpl::SetXKeyboardForTesting(XKeyboard* xkeyboard) { |
761 xkeyboard_.reset(xkeyboard); | 750 xkeyboard_.reset(xkeyboard); |
762 } | 751 } |
763 | 752 |
764 void InputMethodManagerImpl::InitializeComponentExtensionForTesting( | 753 void InputMethodManagerImpl::InitializeComponentExtensionForTesting( |
765 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { | 754 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { |
766 OnComponentExtensionInitialized(delegate.Pass()); | 755 OnComponentExtensionInitialized(delegate.Pass()); |
767 } | 756 } |
768 | 757 |
769 void InputMethodManagerImpl::PropertyChanged() { | |
770 FOR_EACH_OBSERVER(InputMethodManager::Observer, | |
771 observers_, | |
772 InputMethodPropertyChanged(this)); | |
773 } | |
774 | |
775 void InputMethodManagerImpl::CandidateClicked(int index) { | 758 void InputMethodManagerImpl::CandidateClicked(int index) { |
776 IMEEngineHandlerInterface* engine = | 759 IMEEngineHandlerInterface* engine = |
777 IMEBridge::Get()->GetCurrentEngineHandler(); | 760 IMEBridge::Get()->GetCurrentEngineHandler(); |
778 if (engine) | 761 if (engine) |
779 engine->CandidateClicked(index); | 762 engine->CandidateClicked(index); |
780 } | 763 } |
781 | 764 |
782 void InputMethodManagerImpl::CandidateWindowOpened() { | 765 void InputMethodManagerImpl::CandidateWindowOpened() { |
783 FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver, | 766 FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver, |
784 candidate_window_observers_, | 767 candidate_window_observers_, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 if (candidate_window_controller_.get()) | 835 if (candidate_window_controller_.get()) |
853 return; | 836 return; |
854 | 837 |
855 candidate_window_controller_.reset( | 838 candidate_window_controller_.reset( |
856 CandidateWindowController::CreateCandidateWindowController()); | 839 CandidateWindowController::CreateCandidateWindowController()); |
857 candidate_window_controller_->AddObserver(this); | 840 candidate_window_controller_->AddObserver(this); |
858 } | 841 } |
859 | 842 |
860 } // namespace input_method | 843 } // namespace input_method |
861 } // namespace chromeos | 844 } // namespace chromeos |
OLD | NEW |