Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_manager_impl.cc

Issue 150203015: Split out InputMethodMenuManager from InputMethodManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h" 19 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h"
18 #include "chrome/browser/chromeos/input_method/component_extension_ime_manager_i mpl.h" 20 #include "chrome/browser/chromeos/input_method/component_extension_ime_manager_i mpl.h"
(...skipping 27 matching lines...) Expand all
46 return util_.IsLoginKeyboard(layout); 48 return util_.IsLoginKeyboard(layout);
47 } 49 }
48 50
49 InputMethodManagerImpl::InputMethodManagerImpl( 51 InputMethodManagerImpl::InputMethodManagerImpl(
50 scoped_ptr<InputMethodDelegate> delegate) 52 scoped_ptr<InputMethodDelegate> delegate)
51 : delegate_(delegate.Pass()), 53 : delegate_(delegate.Pass()),
52 state_(STATE_LOGIN_SCREEN), 54 state_(STATE_LOGIN_SCREEN),
53 util_(delegate_.get(), GetSupportedInputMethods()), 55 util_(delegate_.get(), GetSupportedInputMethods()),
54 component_extension_ime_manager_(new ComponentExtensionIMEManager()), 56 component_extension_ime_manager_(new ComponentExtensionIMEManager()),
55 weak_ptr_factory_(this) { 57 weak_ptr_factory_(this) {
58 ash::ime::InputMethodMenuManager::Initialize();
56 } 59 }
57 60
58 InputMethodManagerImpl::~InputMethodManagerImpl() { 61 InputMethodManagerImpl::~InputMethodManagerImpl() {
59 if (candidate_window_controller_.get()) 62 if (candidate_window_controller_.get())
60 candidate_window_controller_->RemoveObserver(this); 63 candidate_window_controller_->RemoveObserver(this);
64 ash::ime::InputMethodMenuManager::Shutdown();
61 } 65 }
62 66
63 void InputMethodManagerImpl::AddObserver( 67 void InputMethodManagerImpl::AddObserver(
64 InputMethodManager::Observer* observer) { 68 InputMethodManager::Observer* observer) {
65 observers_.AddObserver(observer); 69 observers_.AddObserver(observer);
66 } 70 }
67 71
68 void InputMethodManagerImpl::AddCandidateWindowObserver( 72 void InputMethodManagerImpl::AddCandidateWindowObserver(
69 InputMethodManager::CandidateWindowObserver* observer) { 73 InputMethodManager::CandidateWindowObserver* observer) {
70 candidate_window_observers_.AddObserver(observer); 74 candidate_window_observers_.AddObserver(observer);
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 next_engine->Enable(); 345 next_engine->Enable();
342 } 346 }
343 347
344 // TODO(komatsu): Check if it is necessary to perform the above routine 348 // TODO(komatsu): Check if it is necessary to perform the above routine
345 // when the current input method is equal to |input_method_id_to_swich|. 349 // when the current input method is equal to |input_method_id_to_swich|.
346 if (current_input_method_.id() != input_method_id_to_switch) { 350 if (current_input_method_.id() != input_method_id_to_switch) {
347 // Clear property list. Property list would be updated by 351 // Clear property list. Property list would be updated by
348 // extension IMEs via InputMethodEngine::(Set|Update)MenuItems. 352 // extension IMEs via InputMethodEngine::(Set|Update)MenuItems.
349 // If the current input method is a keyboard layout, empty 353 // If the current input method is a keyboard layout, empty
350 // properties are sufficient. 354 // properties are sufficient.
351 const InputMethodPropertyList empty_property_list; 355 const ash::ime::InputMethodMenuItemList empty_menu_item_list;
352 SetCurrentInputMethodProperties(empty_property_list); 356 ash::ime::InputMethodMenuManager* input_method_menu_manager =
357 ash::ime::InputMethodMenuManager::Get();
358 input_method_menu_manager->SetCurrentInputMethodMenuItemList(
359 empty_menu_item_list);
353 360
354 const InputMethodDescriptor* descriptor = NULL; 361 const InputMethodDescriptor* descriptor = NULL;
355 if (extension_ime_util::IsExtensionIME(input_method_id_to_switch)) { 362 if (extension_ime_util::IsExtensionIME(input_method_id_to_switch)) {
356 DCHECK(extra_input_methods_.find(input_method_id_to_switch) != 363 DCHECK(extra_input_methods_.find(input_method_id_to_switch) !=
357 extra_input_methods_.end()); 364 extra_input_methods_.end());
358 descriptor = &(extra_input_methods_[input_method_id_to_switch]); 365 descriptor = &(extra_input_methods_[input_method_id_to_switch]);
359 } else { 366 } else {
360 descriptor = 367 descriptor =
361 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); 368 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch);
362 } 369 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); 417 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]);
411 } else if (component_extension_ime_manager_->IsWhitelisted( 418 } else if (component_extension_ime_manager_->IsWhitelisted(
412 unfiltered_input_method_ids[i])) { 419 unfiltered_input_method_ids[i])) {
413 component_extension_ime_manager_->LoadComponentExtensionIME( 420 component_extension_ime_manager_->LoadComponentExtensionIME(
414 unfiltered_input_method_ids[i]); 421 unfiltered_input_method_ids[i]);
415 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); 422 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]);
416 } 423 }
417 } 424 }
418 } 425 }
419 426
420 void InputMethodManagerImpl::ActivateInputMethodProperty( 427 void InputMethodManagerImpl::ActivateInputMethodMenuItem(
421 const std::string& key) { 428 const std::string& key) {
422 DCHECK(!key.empty()); 429 DCHECK(!key.empty());
423 430
424 for (size_t i = 0; i < property_list_.size(); ++i) { 431 if (ash::ime::InputMethodMenuManager::Get()->
425 if (property_list_[i].key == key) { 432 HasInputMethodMenuItemForKey(key)) {
426 IMEEngineHandlerInterface* engine = 433 IMEEngineHandlerInterface* engine =
427 IMEBridge::Get()->GetCurrentEngineHandler(); 434 IMEBridge::Get()->GetCurrentEngineHandler();
428 if (engine) 435 if (engine)
429 engine->PropertyActivate(key); 436 engine->PropertyActivate(key);
430 return; 437 return;
431 }
432 } 438 }
433 439
434 DVLOG(1) << "ActivateInputMethodProperty: unknown key: " << key; 440 DVLOG(1) << "ActivateInputMethodMenuItem: unknown key: " << key;
435 } 441 }
436 442
437 void InputMethodManagerImpl::AddInputMethodExtension( 443 void InputMethodManagerImpl::AddInputMethodExtension(
438 const std::string& id, 444 const std::string& id,
439 InputMethodEngineInterface* engine) { 445 InputMethodEngineInterface* engine) {
440 if (state_ == STATE_TERMINATING) 446 if (state_ == STATE_TERMINATING)
441 return; 447 return;
442 448
443 if (!extension_ime_util::IsExtensionIME(id) && 449 if (!extension_ime_util::IsExtensionIME(id) &&
444 !extension_ime_util::IsComponentExtensionIME(id)) { 450 !extension_ime_util::IsComponentExtensionIME(id)) {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 ChangeInputMethodInternal(*iter, true); 684 ChangeInputMethodInternal(*iter, true);
679 } 685 }
680 686
681 InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const { 687 InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const {
682 if (current_input_method_.id().empty()) 688 if (current_input_method_.id().empty())
683 return InputMethodUtil::GetFallbackInputMethodDescriptor(); 689 return InputMethodUtil::GetFallbackInputMethodDescriptor();
684 690
685 return current_input_method_; 691 return current_input_method_;
686 } 692 }
687 693
688 InputMethodPropertyList
689 InputMethodManagerImpl::GetCurrentInputMethodProperties() const {
690 // This check is necessary since an IME property (e.g. for Pinyin) might be
691 // sent from ibus-daemon AFTER the current input method is switched to XKB.
692 if (InputMethodUtil::IsKeyboardLayout(GetCurrentInputMethod().id()))
693 return InputMethodPropertyList(); // Empty list.
694 return property_list_;
695 }
696
697 void InputMethodManagerImpl::SetCurrentInputMethodProperties(
698 const InputMethodPropertyList& property_list) {
699 property_list_ = property_list;
700 PropertyChanged();
701 }
702
703 XKeyboard* InputMethodManagerImpl::GetXKeyboard() { 694 XKeyboard* InputMethodManagerImpl::GetXKeyboard() {
704 return xkeyboard_.get(); 695 return xkeyboard_.get();
705 } 696 }
706 697
707 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() { 698 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() {
708 return &util_; 699 return &util_;
709 } 700 }
710 701
711 ComponentExtensionIMEManager* 702 ComponentExtensionIMEManager*
712 InputMethodManagerImpl::GetComponentExtensionIMEManager() { 703 InputMethodManagerImpl::GetComponentExtensionIMEManager() {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 736
746 void InputMethodManagerImpl::SetXKeyboardForTesting(XKeyboard* xkeyboard) { 737 void InputMethodManagerImpl::SetXKeyboardForTesting(XKeyboard* xkeyboard) {
747 xkeyboard_.reset(xkeyboard); 738 xkeyboard_.reset(xkeyboard);
748 } 739 }
749 740
750 void InputMethodManagerImpl::InitializeComponentExtensionForTesting( 741 void InputMethodManagerImpl::InitializeComponentExtensionForTesting(
751 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { 742 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) {
752 OnComponentExtensionInitialized(delegate.Pass()); 743 OnComponentExtensionInitialized(delegate.Pass());
753 } 744 }
754 745
755 void InputMethodManagerImpl::PropertyChanged() {
756 FOR_EACH_OBSERVER(InputMethodManager::Observer,
757 observers_,
758 InputMethodPropertyChanged(this));
759 }
760
761 void InputMethodManagerImpl::CandidateClicked(int index) { 746 void InputMethodManagerImpl::CandidateClicked(int index) {
762 IMEEngineHandlerInterface* engine = 747 IMEEngineHandlerInterface* engine =
763 IMEBridge::Get()->GetCurrentEngineHandler(); 748 IMEBridge::Get()->GetCurrentEngineHandler();
764 if (engine) 749 if (engine)
765 engine->CandidateClicked(index); 750 engine->CandidateClicked(index);
766 } 751 }
767 752
768 void InputMethodManagerImpl::CandidateWindowOpened() { 753 void InputMethodManagerImpl::CandidateWindowOpened() {
769 FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver, 754 FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver,
770 candidate_window_observers_, 755 candidate_window_observers_,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 if (candidate_window_controller_.get()) 816 if (candidate_window_controller_.get())
832 return; 817 return;
833 818
834 candidate_window_controller_.reset( 819 candidate_window_controller_.reset(
835 CandidateWindowController::CreateCandidateWindowController()); 820 CandidateWindowController::CreateCandidateWindowController());
836 candidate_window_controller_->AddObserver(this); 821 candidate_window_controller_->AddObserver(this);
837 } 822 }
838 823
839 } // namespace input_method 824 } // namespace input_method
840 } // namespace chromeos 825 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698