| 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 "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "chrome/browser/chromeos/input_method/browser_state_monitor.h" | 13 #include "chrome/browser/chromeos/input_method/browser_state_monitor.h" |
| 14 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h" | 14 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h" |
| 15 #include "chrome/browser/chromeos/input_method/input_method_delegate.h" |
| 15 #include "chrome/browser/chromeos/input_method/input_method_engine_ibus.h" | 16 #include "chrome/browser/chromeos/input_method/input_method_engine_ibus.h" |
| 16 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 17 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 17 #include "chrome/browser/chromeos/input_method/xkeyboard.h" | 18 #include "chrome/browser/chromeos/input_method/xkeyboard.h" |
| 18 #include "chrome/browser/chromeos/language_preferences.h" | 19 #include "chrome/browser/chromeos/language_preferences.h" |
| 19 #include "ui/base/accelerators/accelerator.h" | 20 #include "ui/base/accelerators/accelerator.h" |
| 20 #include "unicode/uloc.h" | 21 #include "unicode/uloc.h" |
| 21 | 22 |
| 22 namespace chromeos { | 23 namespace chromeos { |
| 23 namespace input_method { | 24 namespace input_method { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 bool Contains(const std::vector<std::string>& container, | 28 bool Contains(const std::vector<std::string>& container, |
| 28 const std::string& value) { | 29 const std::string& value) { |
| 29 return std::find(container.begin(), container.end(), value) != | 30 return std::find(container.begin(), container.end(), value) != |
| 30 container.end(); | 31 container.end(); |
| 31 } | 32 } |
| 32 | 33 |
| 33 } // namespace | 34 } // namespace |
| 34 | 35 |
| 35 InputMethodManagerImpl::InputMethodManagerImpl() | 36 InputMethodManagerImpl::InputMethodManagerImpl( |
| 36 : state_(STATE_LOGIN_SCREEN), | 37 scoped_ptr<InputMethodDelegate> delegate) |
| 37 util_(GetSupportedInputMethods()) { | 38 : delegate_(delegate.Pass()), |
| 39 state_(STATE_LOGIN_SCREEN), |
| 40 util_(delegate_.get(), GetSupportedInputMethods()) { |
| 38 } | 41 } |
| 39 | 42 |
| 40 InputMethodManagerImpl::~InputMethodManagerImpl() { | 43 InputMethodManagerImpl::~InputMethodManagerImpl() { |
| 41 if (ibus_controller_.get()) | 44 if (ibus_controller_.get()) |
| 42 ibus_controller_->RemoveObserver(this); | 45 ibus_controller_->RemoveObserver(this); |
| 43 if (candidate_window_controller_.get()) { | 46 if (candidate_window_controller_.get()) { |
| 44 candidate_window_controller_->RemoveObserver(this); | 47 candidate_window_controller_->RemoveObserver(this); |
| 45 candidate_window_controller_->Shutdown(ibus_controller_.get()); | 48 candidate_window_controller_->Shutdown(ibus_controller_.get()); |
| 46 } | 49 } |
| 47 } | 50 } |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 ite != extra_input_method_instances_.end(); | 575 ite != extra_input_method_instances_.end(); |
| 573 ite++) { | 576 ite++) { |
| 574 if (!Contains(filtered_extension_imes_, ite->first)) | 577 if (!Contains(filtered_extension_imes_, ite->first)) |
| 575 ite->second->OnDisconnected(); | 578 ite->second->OnDisconnected(); |
| 576 } | 579 } |
| 577 } | 580 } |
| 578 | 581 |
| 579 void InputMethodManagerImpl::Init() { | 582 void InputMethodManagerImpl::Init() { |
| 580 DCHECK(!ibus_controller_.get()); | 583 DCHECK(!ibus_controller_.get()); |
| 581 | 584 |
| 582 browser_state_monitor_.reset(new BrowserStateMonitor(this)); | 585 browser_state_monitor_.reset(new BrowserStateMonitor(this, delegate_.get())); |
| 583 ibus_controller_.reset(IBusController::Create()); | 586 ibus_controller_.reset(IBusController::Create()); |
| 584 xkeyboard_.reset(XKeyboard::Create(util_)); | 587 xkeyboard_.reset(XKeyboard::Create(util_)); |
| 585 ibus_controller_->AddObserver(this); | 588 ibus_controller_->AddObserver(this); |
| 586 } | 589 } |
| 587 | 590 |
| 588 void InputMethodManagerImpl::SetIBusControllerForTesting( | 591 void InputMethodManagerImpl::SetIBusControllerForTesting( |
| 589 IBusController* ibus_controller) { | 592 IBusController* ibus_controller) { |
| 590 ibus_controller_.reset(ibus_controller); | 593 ibus_controller_.reset(ibus_controller); |
| 591 ibus_controller_->AddObserver(this); | 594 ibus_controller_->AddObserver(this); |
| 592 } | 595 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 return; | 678 return; |
| 676 | 679 |
| 677 candidate_window_controller_.reset( | 680 candidate_window_controller_.reset( |
| 678 CandidateWindowController::CreateCandidateWindowController()); | 681 CandidateWindowController::CreateCandidateWindowController()); |
| 679 if (candidate_window_controller_->Init(ibus_controller_.get())) | 682 if (candidate_window_controller_->Init(ibus_controller_.get())) |
| 680 candidate_window_controller_->AddObserver(this); | 683 candidate_window_controller_->AddObserver(this); |
| 681 else | 684 else |
| 682 DVLOG(1) << "Failed to initialize the candidate window controller"; | 685 DVLOG(1) << "Failed to initialize the candidate window controller"; |
| 683 } | 686 } |
| 684 | 687 |
| 685 // static | |
| 686 InputMethodManagerImpl* InputMethodManagerImpl::GetInstanceForTesting() { | |
| 687 return new InputMethodManagerImpl; | |
| 688 } | |
| 689 | |
| 690 } // namespace input_method | 688 } // namespace input_method |
| 691 } // namespace chromeos | 689 } // namespace chromeos |
| OLD | NEW |