diff options
Diffstat (limited to 'chrome/browser/chromeos')
25 files changed, 168 insertions, 744 deletions
diff --git a/chrome/browser/chromeos/cros/cros_library.cc b/chrome/browser/chromeos/cros/cros_library.cc index 7a0373a..c6609d2 100644 --- a/chrome/browser/chromeos/cros/cros_library.cc +++ b/chrome/browser/chromeos/cros/cros_library.cc @@ -10,7 +10,6 @@ #include "chrome/browser/chromeos/cros/cert_library.h" #include "chrome/browser/chromeos/cros/cros_library_loader.h" #include "chrome/browser/chromeos/cros/cryptohome_library.h" -#include "chrome/browser/chromeos/cros/input_method_library.h" #include "chrome/browser/chromeos/cros/libcros_service_library.h" #include "chrome/browser/chromeos/cros/login_library.h" #include "chrome/browser/chromeos/cros/mount_library.h" @@ -60,7 +59,6 @@ DEFINE_GET_LIBRARY_METHOD(Brightness, brightness); DEFINE_GET_LIBRARY_METHOD(Burn, burn); DEFINE_GET_LIBRARY_METHOD(Cert, cert); DEFINE_GET_LIBRARY_METHOD(Cryptohome, crypto); -DEFINE_GET_LIBRARY_METHOD(InputMethod, input_method); DEFINE_GET_LIBRARY_METHOD(LibCrosService, libcros_service); DEFINE_GET_LIBRARY_METHOD(Login, login); DEFINE_GET_LIBRARY_METHOD(Mount, mount); @@ -117,7 +115,6 @@ DEFINE_SET_LIBRARY_METHOD(Brightness, brightness); DEFINE_SET_LIBRARY_METHOD(Cert, cert); DEFINE_SET_LIBRARY_METHOD(Burn, burn); DEFINE_SET_LIBRARY_METHOD(Cryptohome, crypto); -DEFINE_SET_LIBRARY_METHOD(InputMethod, input_method); DEFINE_SET_LIBRARY_METHOD(LibCrosService, libcros_service); DEFINE_SET_LIBRARY_METHOD(Login, login); DEFINE_SET_LIBRARY_METHOD(Mount, mount); diff --git a/chrome/browser/chromeos/cros/cros_library.h b/chrome/browser/chromeos/cros/cros_library.h index 8148b3a..b42ed73 100644 --- a/chrome/browser/chromeos/cros/cros_library.h +++ b/chrome/browser/chromeos/cros/cros_library.h @@ -22,7 +22,6 @@ class BrightnessLibrary; class BurnLibrary; class CertLibrary; class CryptohomeLibrary; -class InputMethodLibrary; class LibCrosServiceLibrary; class LibraryLoader; class LoginLibrary; @@ -60,7 +59,6 @@ class CrosLibrary { void SetCertLibrary(CertLibrary* library, bool own); void SetBurnLibrary(BurnLibrary* library, bool own); void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own); - void SetInputMethodLibrary(InputMethodLibrary* library, bool own); void SetLibCrosServiceLibrary(LibCrosServiceLibrary* library, bool own); void SetLoginLibrary(LoginLibrary* library, bool own); void SetMountLibrary(MountLibrary* library, bool own); @@ -84,7 +82,6 @@ class CrosLibrary { BurnLibrary* GetBurnLibrary(); CertLibrary* GetCertLibrary(); CryptohomeLibrary* GetCryptohomeLibrary(); - InputMethodLibrary* GetInputMethodLibrary(); LibCrosServiceLibrary* GetLibCrosServiceLibrary(); LoginLibrary* GetLoginLibrary(); MountLibrary* GetMountLibrary(); @@ -159,7 +156,6 @@ class CrosLibrary { Library<BurnLibrary> burn_lib_; Library<CertLibrary> cert_lib_; Library<CryptohomeLibrary> crypto_lib_; - Library<InputMethodLibrary> input_method_lib_; Library<LibCrosServiceLibrary> libcros_service_lib_; Library<LoginLibrary> login_lib_; Library<MountLibrary> mount_lib_; diff --git a/chrome/browser/chromeos/cros/cros_mock.cc b/chrome/browser/chromeos/cros/cros_mock.cc index 73d9c5e..49f79da 100644 --- a/chrome/browser/chromeos/cros/cros_mock.cc +++ b/chrome/browser/chromeos/cros/cros_mock.cc @@ -8,14 +8,12 @@ #include "base/message_loop.h" #include "base/time.h" #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" -#include "chrome/browser/chromeos/cros/mock_input_method_library.h" #include "chrome/browser/chromeos/cros/mock_library_loader.h" #include "chrome/browser/chromeos/cros/mock_network_library.h" #include "chrome/browser/chromeos/cros/mock_power_library.h" #include "chrome/browser/chromeos/cros/mock_screen_lock_library.h" #include "chrome/browser/chromeos/cros/mock_speech_synthesis_library.h" #include "chrome/browser/chromeos/cros/mock_touchpad_library.h" -#include "chrome/browser/chromeos/input_method/input_method_util.h" #include "chrome/browser/chromeos/login/wizard_controller.h" #include "chrome/browser/chromeos/login/wizard_screen.h" #include "chrome/test/in_process_browser_test.h" @@ -37,14 +35,11 @@ using ::testing::_; CrosMock::CrosMock() : loader_(NULL), mock_cryptohome_library_(NULL), - mock_input_method_library_(NULL), mock_network_library_(NULL), mock_power_library_(NULL), mock_screen_lock_library_(NULL), mock_speech_synthesis_library_(NULL), mock_touchpad_library_(NULL) { - current_input_method_ = - input_method::GetFallbackInputMethodDescriptor(); } CrosMock::~CrosMock() { @@ -55,7 +50,6 @@ chromeos::CrosLibrary::TestApi* CrosMock::test_api() { } void CrosMock::InitStatusAreaMocks() { - InitMockInputMethodLibrary(); InitMockNetworkLibrary(); InitMockPowerLibrary(); InitMockTouchpadLibrary(); @@ -79,14 +73,6 @@ void CrosMock::InitMockCryptohomeLibrary() { test_api()->SetCryptohomeLibrary(mock_cryptohome_library_, true); } -void CrosMock::InitMockInputMethodLibrary() { - InitMockLibraryLoader(); - if (mock_input_method_library_) - return; - mock_input_method_library_ = new StrictMock<MockInputMethodLibrary>(); - test_api()->SetInputMethodLibrary(mock_input_method_library_, true); -} - void CrosMock::InitMockNetworkLibrary() { InitMockLibraryLoader(); if (mock_network_library_) @@ -133,10 +119,6 @@ MockCryptohomeLibrary* CrosMock::mock_cryptohome_library() { return mock_cryptohome_library_; } -MockInputMethodLibrary* CrosMock::mock_input_method_library() { - return mock_input_method_library_; -} - MockNetworkLibrary* CrosMock::mock_network_library() { return mock_network_library_; } @@ -158,63 +140,12 @@ MockTouchpadLibrary* CrosMock::mock_touchpad_library() { } void CrosMock::SetStatusAreaMocksExpectations() { - SetInputMethodLibraryStatusAreaExpectations(); SetNetworkLibraryStatusAreaExpectations(); SetPowerLibraryStatusAreaExpectations(); SetPowerLibraryExpectations(); SetTouchpadLibraryExpectations(); } -void CrosMock::SetInputMethodLibraryStatusAreaExpectations() { - EXPECT_CALL(*mock_input_method_library_, AddObserver(_)) - .Times(AnyNumber()) - .RetiresOnSaturation(); - EXPECT_CALL(*mock_input_method_library_, GetActiveInputMethods()) - .Times(AnyNumber()) - .WillRepeatedly(InvokeWithoutArgs(CreateInputMethodDescriptors)) - .RetiresOnSaturation(); - EXPECT_CALL(*mock_input_method_library_, GetSupportedInputMethods()) - .Times(AnyNumber()) - .WillRepeatedly(InvokeWithoutArgs(CreateInputMethodDescriptors)) - .RetiresOnSaturation(); - EXPECT_CALL(*mock_input_method_library_, GetKeyboardOverlayId(_)) - .Times(AnyNumber()) - .WillRepeatedly((Return("en_US"))) - .RetiresOnSaturation(); - EXPECT_CALL(*mock_input_method_library_, current_input_method()) - .Times(AnyNumber()) - .WillRepeatedly((Return(current_input_method_))) - .RetiresOnSaturation(); - EXPECT_CALL(*mock_input_method_library_, previous_input_method()) - .Times(AnyNumber()) - .WillRepeatedly((Return(previous_input_method_))) - .RetiresOnSaturation(); - EXPECT_CALL(*mock_input_method_library_, current_ime_properties()) - .Times(AnyNumber()) - .WillRepeatedly((ReturnRef(ime_properties_))) - .RetiresOnSaturation(); - EXPECT_CALL(*mock_input_method_library_, GetNumActiveInputMethods()) - .Times(AnyNumber()) - .WillRepeatedly((Return(1))) - .RetiresOnSaturation(); - EXPECT_CALL(*mock_input_method_library_, SetImeConfig(_, _, _)) - .Times(AnyNumber()) - .WillRepeatedly((Return(true))) - .RetiresOnSaturation(); - EXPECT_CALL(*mock_input_method_library_, RemoveObserver(_)) - .Times(AnyNumber()) - .RetiresOnSaturation(); - EXPECT_CALL(*mock_input_method_library_, SetDeferImeStartup(_)) - .Times(AnyNumber()) - .RetiresOnSaturation(); - EXPECT_CALL(*mock_input_method_library_, StopInputMethodDaemon()) - .Times(AnyNumber()) - .RetiresOnSaturation(); - EXPECT_CALL(*mock_input_method_library_, ChangeInputMethod(_)) - .Times(AnyNumber()) - .RetiresOnSaturation(); -} - void CrosMock::SetNetworkLibraryStatusAreaExpectations() { // We don't care how often these are called, just set their return values: EXPECT_CALL(*mock_network_library_, AddNetworkManagerObserver(_)) @@ -388,8 +319,6 @@ void CrosMock::TearDownMocks() { test_api()->SetLibraryLoader(NULL, false); if (mock_cryptohome_library_) test_api()->SetCryptohomeLibrary(NULL, false); - if (mock_input_method_library_) - test_api()->SetInputMethodLibrary(NULL, false); if (mock_network_library_) test_api()->SetNetworkLibrary(NULL, false); if (mock_power_library_) @@ -402,13 +331,4 @@ void CrosMock::TearDownMocks() { test_api()->SetTouchpadLibrary(NULL, false); } -input_method::InputMethodDescriptors* -CrosMock::CreateInputMethodDescriptors() { - input_method::InputMethodDescriptors* descriptors = - new input_method::InputMethodDescriptors; - descriptors->push_back( - input_method::GetFallbackInputMethodDescriptor()); - return descriptors; -} - } // namespace chromeos diff --git a/chrome/browser/chromeos/cros/cros_mock.h b/chrome/browser/chromeos/cros/cros_mock.h index 4cc2ecf..cfb61aa 100644 --- a/chrome/browser/chromeos/cros/cros_mock.h +++ b/chrome/browser/chromeos/cros/cros_mock.h @@ -7,14 +7,12 @@ #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/network_library.h" -#include "chrome/browser/chromeos/input_method/ibus_controller.h" #include "chrome/test/in_process_browser_test.h" namespace chromeos { class MockCryptohomeLibrary; class MockKeyboardLibrary; -class MockInputMethodLibrary; class MockLibraryLoader; class MockNetworkLibrary; class MockPowerLibrary; @@ -45,7 +43,6 @@ class CrosMock { // Initialization of mocks. void InitMockCryptohomeLibrary(); void InitMockKeyboardLibrary(); - void InitMockInputMethodLibrary(); void InitMockNetworkLibrary(); void InitMockPowerLibrary(); void InitMockScreenLockLibrary(); @@ -55,7 +52,6 @@ class CrosMock { // Get mocks. MockCryptohomeLibrary* mock_cryptohome_library(); MockKeyboardLibrary* mock_keyboard_library(); - MockInputMethodLibrary* mock_input_method_library(); MockNetworkLibrary* mock_network_library(); MockPowerLibrary* mock_power_library(); MockScreenLockLibrary* mock_screen_lock_library(); @@ -72,7 +68,6 @@ class CrosMock { // Methods to setup minimal mocks expectations for status area. void SetKeyboardLibraryStatusAreaExpectations(); - void SetInputMethodLibraryStatusAreaExpectations(); void SetNetworkLibraryStatusAreaExpectations(); void SetPowerLibraryStatusAreaExpectations(); void SetPowerLibraryExpectations(); @@ -81,10 +76,6 @@ class CrosMock { void TearDownMocks(); - // Creates input method descriptors. This is a helper function for - // SetInputMethodLibraryStatusAreaExpectations(). - static input_method::InputMethodDescriptors* CreateInputMethodDescriptors(); - // TestApi gives access to CrosLibrary private members. chromeos::CrosLibrary::TestApi* test_api(); @@ -93,16 +84,12 @@ class CrosMock { MockLibraryLoader* loader_; MockCryptohomeLibrary* mock_cryptohome_library_; MockKeyboardLibrary* mock_keyboard_library_; - MockInputMethodLibrary* mock_input_method_library_; MockNetworkLibrary* mock_network_library_; MockPowerLibrary* mock_power_library_; MockScreenLockLibrary* mock_screen_lock_library_; MockSpeechSynthesisLibrary* mock_speech_synthesis_library_; MockTouchpadLibrary* mock_touchpad_library_; - input_method::ImePropertyList ime_properties_; - input_method::InputMethodDescriptor current_input_method_; - input_method::InputMethodDescriptor previous_input_method_; WifiNetworkVector wifi_networks_; CellularNetworkVector cellular_networks_; VirtualNetworkVector virtual_networks_; diff --git a/chrome/browser/chromeos/cros/mock_input_method_library.cc b/chrome/browser/chromeos/cros/mock_input_method_library.cc deleted file mode 100644 index ec61f6d..0000000 --- a/chrome/browser/chromeos/cros/mock_input_method_library.cc +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/cros/mock_input_method_library.h" - -namespace chromeos { - -MockInputMethodLibrary::MockInputMethodLibrary() {} - -MockInputMethodLibrary::~MockInputMethodLibrary() {} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/cros/mock_input_method_library.h b/chrome/browser/chromeos/cros/mock_input_method_library.h deleted file mode 100644 index 2077818..0000000 --- a/chrome/browser/chromeos/cros/mock_input_method_library.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_CROS_MOCK_INPUT_METHOD_LIBRARY_H_ -#define CHROME_BROWSER_CHROMEOS_CROS_MOCK_INPUT_METHOD_LIBRARY_H_ -#pragma once - -#include <set> -#include <string> - -#include "chrome/browser/chromeos/cros/input_method_library.h" -#include "googleurl/src/gurl.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace chromeos { - -class MockInputMethodLibrary : public InputMethodLibrary { - public: - MockInputMethodLibrary(); - virtual ~MockInputMethodLibrary(); - - MOCK_METHOD1(AddObserver, void(Observer*)); - MOCK_METHOD1(AddVirtualKeyboardObserver, void(VirtualKeyboardObserver*)); - MOCK_METHOD1(RemoveObserver, void(Observer*)); - MOCK_METHOD1(RemoveVirtualKeyboardObserver, void(VirtualKeyboardObserver*)); - - MOCK_METHOD0(GetActiveInputMethods, - input_method::InputMethodDescriptors*(void)); - MOCK_METHOD0(GetNumActiveInputMethods, size_t(void)); - MOCK_METHOD0(GetSupportedInputMethods, - input_method::InputMethodDescriptors*(void)); - MOCK_METHOD1(ChangeInputMethod, void(const std::string&)); - MOCK_METHOD2(SetImePropertyActivated, void(const std::string&, bool)); - MOCK_METHOD1(InputMethodIsActivated, bool(const std::string&)); - MOCK_METHOD3(SetImeConfig, bool(const std::string&, const std::string&, - const input_method::ImeConfigValue&)); - MOCK_CONST_METHOD0(previous_input_method, - input_method::InputMethodDescriptor(void)); - MOCK_CONST_METHOD0(current_input_method, - input_method::InputMethodDescriptor(void)); - MOCK_CONST_METHOD0(current_ime_properties, - const input_method::ImePropertyList&(void)); - MOCK_METHOD1(GetKeyboardOverlayId, std::string(const std::string&)); - MOCK_METHOD0(StartInputMethodDaemon, bool(void)); - MOCK_METHOD0(StopInputMethodDaemon, void(void)); - MOCK_METHOD1(SetDeferImeStartup, void(bool)); - MOCK_METHOD1(SetEnableAutoImeShutdown, void(bool)); - MOCK_METHOD1(SendHandwritingStroke, - void(const input_method::HandwritingStroke&)); - MOCK_METHOD1(CancelHandwritingStrokes, void(int)); - MOCK_METHOD3(RegisterVirtualKeyboard, void(const GURL&, - const std::set<std::string>&, - bool)); -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_INPUT_METHOD_LIBRARY_H_ diff --git a/chrome/browser/chromeos/input_method/ibus_controller.cc b/chrome/browser/chromeos/input_method/ibus_controller.cc index 668e82e..c06b8d3 100644 --- a/chrome/browser/chromeos/input_method/ibus_controller.cc +++ b/chrome/browser/chromeos/input_method/ibus_controller.cc @@ -73,23 +73,6 @@ ImeConfigValue::ImeConfigValue() ImeConfigValue::~ImeConfigValue() { } -// TODO(satorux): The function is used via -// InputMethodLibrary::GetSupportedInputMethodDescriptors(). The -// indirection is unnecessary once we get rid of libcros. We should -// refactor the two functions. -InputMethodDescriptors* GetSupportedInputMethodDescriptors() { - InputMethodDescriptors* input_methods = new InputMethodDescriptors; - for (size_t i = 0; i < arraysize(kIBusEngines); ++i) { - if (InputMethodIdIsWhitelisted(kIBusEngines[i].id)) { - input_methods->push_back(CreateInputMethodDescriptor( - kIBusEngines[i].id, - kIBusEngines[i].layout, - kIBusEngines[i].language)); - } - } - return input_methods; -} - // Returns true if |input_method_id| is whitelisted. bool InputMethodIdIsWhitelisted(const std::string& input_method_id) { static std::set<std::string>* g_supported_input_methods = NULL; diff --git a/chrome/browser/chromeos/input_method/ibus_controller.h b/chrome/browser/chromeos/input_method/ibus_controller.h index bcbd4fb..677a309 100644 --- a/chrome/browser/chromeos/input_method/ibus_controller.h +++ b/chrome/browser/chromeos/input_method/ibus_controller.h @@ -280,11 +280,6 @@ class IBusController { virtual void CancelHandwriting(int n_strokes) = 0; }; -// Gets all input method engines that are supported, including ones not -// active. Caller has to delete the returned list. This function never -// returns NULL. -InputMethodDescriptors* GetSupportedInputMethodDescriptors(); - // // FUNCTIONS BELOW ARE ONLY FOR UNIT TESTS. DO NOT USE THEM. // diff --git a/chrome/browser/chromeos/cros/input_method_library.cc b/chrome/browser/chromeos/input_method/input_method_manager.cc index bea87a4..a98a147 100644 --- a/chrome/browser/chromeos/cros/input_method_library.cc +++ b/chrome/browser/chromeos/input_method/input_method_manager.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/cros/input_method_library.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" #include <algorithm> @@ -11,6 +11,7 @@ #include "unicode/uloc.h" #include "base/basictypes.h" +#include "base/memory/singleton.h" #include "base/message_loop.h" #include "base/process_util.h" #include "base/string_split.h" @@ -57,25 +58,23 @@ bool FindAndUpdateProperty( } // namespace namespace chromeos { +namespace input_method { -// The production implementation of InputMethodLibrary. -class InputMethodLibraryImpl : public InputMethodLibrary, +// The implementation of InputMethodManager. +class InputMethodManagerImpl : public InputMethodManager, public NotificationObserver, public input_method::IBusController::Observer { public: - InputMethodLibraryImpl() + InputMethodManagerImpl() : ibus_controller_(NULL), should_launch_ime_(false), ime_connected_(false), defer_ime_startup_(false), enable_auto_ime_shutdown_(true), - ibus_daemon_process_handle_(base::kNullProcessHandle), #if !defined(TOUCH_UI) - initialized_successfully_(false), - candidate_window_controller_(NULL) { -#else - initialized_successfully_(false) { + candidate_window_controller_(NULL), #endif + ibus_daemon_process_handle_(base::kNullProcessHandle) { // Observe APP_TERMINATING to stop input method daemon gracefully. // We should not use APP_EXITING here since logout might be canceled by // JavaScript after APP_EXITING is sent (crosbug.com/11055). @@ -85,40 +84,26 @@ class InputMethodLibraryImpl : public InputMethodLibrary, // details. notification_registrar_.Add(this, NotificationType::APP_TERMINATING, NotificationService::AllSources()); - } - - // Initializes the object. On success, returns true on and sets - // initialized_successfully_ to true. - // - // Note that we start monitoring input method status in here in Init() - // to avoid a potential race. If we start the monitoring right after - // starting ibus-daemon, there is a higher chance of a race between - // Chrome and ibus-daemon to occur. - bool Init() { - DCHECK(!initialized_successfully_) << "Already initialized"; ibus_controller_ = input_method::IBusController::Create(); // The observer should be added before Connect() so we can capture the // initial connection change. ibus_controller_->AddObserver(this); ibus_controller_->Connect(); - - initialized_successfully_ = true; - return true; } - virtual ~InputMethodLibraryImpl() { + virtual ~InputMethodManagerImpl() { ibus_controller_->RemoveObserver(this); } - virtual void AddObserver(InputMethodLibrary::Observer* observer) { + virtual void AddObserver(InputMethodManager::Observer* observer) { if (!observers_.size()) { observer->FirstObserverIsAdded(this); } observers_.AddObserver(observer); } - virtual void RemoveObserver(InputMethodLibrary::Observer* observer) { + virtual void RemoveObserver(InputMethodManager::Observer* observer) { observers_.RemoveObserver(observer); } @@ -162,20 +147,6 @@ class InputMethodLibraryImpl : public InputMethodLibrary, return input_methods->size(); } - virtual input_method::InputMethodDescriptors* GetSupportedInputMethods() { - if (!initialized_successfully_) { - // If initialization was failed, return the fallback input method, - // as this function is guaranteed to return at least one descriptor. - input_method::InputMethodDescriptors* result = - new input_method::InputMethodDescriptors; - result->push_back(input_method::GetFallbackInputMethodDescriptor()); - return result; - } - - // This never returns NULL. - return input_method::GetSupportedInputMethodDescriptors(); - } - virtual void ChangeInputMethod(const std::string& input_method_id) { // Changing the input method isn't guaranteed to succeed here, but we // should remember the last one regardless. See comments in @@ -204,9 +175,6 @@ class InputMethodLibraryImpl : public InputMethodLibrary, virtual void SetImePropertyActivated(const std::string& key, bool activated) { - if (!initialized_successfully_) - return; - DCHECK(!key.empty()); ibus_controller_->SetImePropertyActivated(key, activated); } @@ -274,23 +242,12 @@ class InputMethodLibraryImpl : public InputMethodLibrary, return current_ime_properties_; } - virtual std::string GetKeyboardOverlayId(const std::string& input_method_id) { - if (!initialized_successfully_) - return ""; - - return input_method::GetKeyboardOverlayId(input_method_id); - } - virtual void SendHandwritingStroke( const input_method::HandwritingStroke& stroke) { - if (!initialized_successfully_) - return; ibus_controller_->SendHandwritingStroke(stroke); } virtual void CancelHandwritingStrokes(int stroke_count) { - if (!initialized_successfully_) - return; // TODO(yusukes): Rename the libcros function to CancelHandwritingStrokes. ibus_controller_->CancelHandwriting(stroke_count); } @@ -298,14 +255,19 @@ class InputMethodLibraryImpl : public InputMethodLibrary, virtual void RegisterVirtualKeyboard(const GURL& launch_url, const std::set<std::string>& layouts, bool is_system) { - if (!initialized_successfully_) - return; virtual_keyboard_selector_.AddVirtualKeyboard(launch_url, layouts, is_system); } + static InputMethodManagerImpl* GetInstance() { + return Singleton<InputMethodManagerImpl, + DefaultSingletonTraits<InputMethodManagerImpl> >::get(); + } + private: + friend struct DefaultSingletonTraits<InputMethodManagerImpl>; + // Returns true if the given input method config value is a single // element string list that contains an input method ID of a keyboard // layout. @@ -415,9 +377,6 @@ class InputMethodLibraryImpl : public InputMethodLibrary, // true if the current engine is switched to |input_method_id| or the // first one. bool ChangeInputMethodViaIBus(const std::string& input_method_id) { - if (!initialized_successfully_) - return false; - std::string input_method_id_to_switch = input_method_id; if (!InputMethodIsActivated(input_method_id)) { @@ -449,9 +408,6 @@ class InputMethodLibraryImpl : public InputMethodLibrary, // |pending_config_requests_| until the config backend (ibus-memconf) // starts. void FlushImeConfig() { - if (!initialized_successfully_) - return; - bool active_input_methods_are_changed = false; InputMethodConfigRequests::iterator iter = pending_config_requests_.begin(); @@ -534,7 +490,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary, // ibus-daemon, and observers are notified. See // InputMethodChangedHandler() for details. const size_t num_active_input_methods = GetNumActiveInputMethods(); - FOR_EACH_OBSERVER(InputMethodLibrary::Observer, observers_, + FOR_EACH_OBSERVER(InputMethodManager::Observer, observers_, ActiveInputMethodsChanged(this, current_input_method_, num_active_input_methods)); @@ -623,8 +579,8 @@ class InputMethodLibraryImpl : public InputMethodLibrary, // observer to do so. Otherwise, we'll end up updating preferences many // times when many observers are attached (ex. many windows are opened), // which is unnecessary and expensive. - ObserverListBase<InputMethodLibrary::Observer>::Iterator it(observers_); - InputMethodLibrary::Observer* first_observer = it.GetNext(); + ObserverListBase<InputMethodManager::Observer>::Iterator it(observers_); + InputMethodManager::Observer* first_observer = it.GetNext(); if (first_observer) { first_observer->PreferenceUpdateNeeded(this, previous_input_method_, @@ -636,7 +592,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary, // For now, we have to do this every time to keep indicators updated. See // comments near the FOR_EACH_OBSERVER call in FlushImeConfig() for details. const size_t num_active_input_methods = GetNumActiveInputMethods(); - FOR_EACH_OBSERVER(InputMethodLibrary::Observer, observers_, + FOR_EACH_OBSERVER(InputMethodManager::Observer, observers_, InputMethodChanged(this, current_input_method_, num_active_input_methods)); @@ -731,7 +687,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary, current_ime_properties_ = prop_list; // Update input method menu - FOR_EACH_OBSERVER(InputMethodLibrary::Observer, observers_, + FOR_EACH_OBSERVER(InputMethodManager::Observer, observers_, PropertyListChanged(this, current_ime_properties_)); } @@ -751,7 +707,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary, } // Update input method menu - FOR_EACH_OBSERVER(InputMethodLibrary::Observer, observers_, + FOR_EACH_OBSERVER(InputMethodManager::Observer, observers_, PropertyListChanged(this, current_ime_properties_)); } @@ -797,9 +753,6 @@ class InputMethodLibraryImpl : public InputMethodLibrary, bool MaybeLaunchInputMethodDaemon() { // CandidateWindowController requires libcros to be loaded. Besides, // launching ibus-daemon without libcros loaded doesn't make sense. - if (!initialized_successfully_) - return false; - if (!should_launch_ime_) { return false; } @@ -833,7 +786,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary, // Called when the input method process is shut down. static void OnImeShutdown(GPid pid, gint status, - InputMethodLibraryImpl* library) { + InputMethodManagerImpl* library) { if (library->ibus_daemon_process_handle_ != base::kNullProcessHandle && base::GetProcId(library->ibus_daemon_process_handle_) == pid) { library->ibus_daemon_process_handle_ = base::kNullProcessHandle; @@ -847,9 +800,6 @@ class InputMethodLibraryImpl : public InputMethodLibrary, // called from MaybeStopInputMethodDaemon(), except one case where we // stop the input method daemon at Chrome shutdown in Observe(). void StopInputMethodDaemon() { - if (!initialized_successfully_) - return; - should_launch_ime_ = false; if (ibus_daemon_process_handle_ != base::kNullProcessHandle) { const base::ProcessId pid = base::GetProcId(ibus_daemon_process_handle_); @@ -889,7 +839,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary, // A reference to the language api, to allow callbacks when the input method // status changes. input_method::IBusController* ibus_controller_; - ObserverList<InputMethodLibrary::Observer> observers_; + ObserverList<InputMethodManager::Observer> observers_; ObserverList<VirtualKeyboardObserver> virtual_keyboard_observers_; // The input method which was/is selected. @@ -933,15 +883,6 @@ class InputMethodLibraryImpl : public InputMethodLibrary, // TODO(yusukes): clear this variable when a user logs in. std::string tentative_current_input_method_id_; - // The process handle of the IBus daemon. kNullProcessHandle if it's not - // running. - base::ProcessHandle ibus_daemon_process_handle_; - - // True if initialization is successfully done, meaning that libcros is - // loaded and input method status monitoring is started. This value - // should be checked where we call libcros functions. - bool initialized_successfully_; - // The candidate window. This will be deleted when the APP_TERMINATING // message is sent. #if !defined(TOUCH_UI) @@ -949,342 +890,28 @@ class InputMethodLibraryImpl : public InputMethodLibrary, candidate_window_controller_; #endif + // The process handle of the IBus daemon. kNullProcessHandle if it's not + // running. + base::ProcessHandle ibus_daemon_process_handle_; + // An object which keeps a list of available virtual keyboards. input_method::VirtualKeyboardSelector virtual_keyboard_selector_; // The active input method ids cache. std::vector<std::string> active_input_method_ids_; - DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryImpl); -}; - -// The stub implementation of InputMethodLibrary. Used for testing. -class InputMethodLibraryStubImpl : public InputMethodLibrary { - public: - InputMethodLibraryStubImpl() - : keyboard_overlay_map_(GetKeyboardOverlayMapForTesting()) { - current_input_method_ = input_method::GetFallbackInputMethodDescriptor(); - } - - virtual ~InputMethodLibraryStubImpl() {} - virtual void AddObserver(Observer* observer) {} - virtual void AddVirtualKeyboardObserver(VirtualKeyboardObserver* observer) {} - virtual void RemoveObserver(Observer* observer) {} - virtual void RemoveVirtualKeyboardObserver( - VirtualKeyboardObserver* observer) {} - - virtual input_method::InputMethodDescriptors* GetActiveInputMethods() { - return GetInputMethodDescriptorsForTesting(); - } - - - virtual size_t GetNumActiveInputMethods() { - scoped_ptr<input_method::InputMethodDescriptors> descriptors( - GetActiveInputMethods()); - return descriptors->size(); - } - - virtual input_method::InputMethodDescriptors* GetSupportedInputMethods() { - return GetInputMethodDescriptorsForTesting(); - } - - virtual void ChangeInputMethod(const std::string& input_method_id) {} - virtual void SetImePropertyActivated(const std::string& key, - bool activated) {} - - virtual bool InputMethodIsActivated(const std::string& input_method_id) { - return true; - } - - virtual bool SetImeConfig(const std::string& section, - const std::string& config_name, - const input_method::ImeConfigValue& value) { - return false; - } - - virtual input_method::InputMethodDescriptor previous_input_method() const { - return previous_input_method_; - } - - virtual input_method::InputMethodDescriptor current_input_method() const { - return current_input_method_; - } - - virtual const input_method::ImePropertyList& current_ime_properties() const { - return current_ime_properties_; - } - - virtual bool StartInputMethodDaemon() { - return true; - } - virtual void StopInputMethodDaemon() {} - virtual void SetDeferImeStartup(bool defer) {} - virtual void SetEnableAutoImeShutdown(bool enable) {} - - virtual std::string GetKeyboardOverlayId(const std::string& input_method_id) { - KeyboardOverlayMap::const_iterator iter = - keyboard_overlay_map_->find(input_method_id); - return (iter != keyboard_overlay_map_->end()) ? - iter->second : ""; - } - - virtual void SendHandwritingStroke( - const input_method::HandwritingStroke& stroke) {} - virtual void CancelHandwritingStrokes(int stroke_count) {} - virtual void RegisterVirtualKeyboard(const GURL& launch_url, - const std::set<std::string>& layouts, - bool is_system) {} - - private: - typedef std::map<std::string, std::string> KeyboardOverlayMap; - - // Gets input method descriptors for testing. Shouldn't be used for - // production. - input_method::InputMethodDescriptors* GetInputMethodDescriptorsForTesting() { - input_method::InputMethodDescriptors* descriptions = - new input_method::InputMethodDescriptors; - // The list is created from output of gen_engines.py in libcros. - // % SHARE=/build/x86-generic/usr/share python gen_engines.py - // $SHARE/chromeos-assets/input_methods/whitelist.txt - // $SHARE/ibus/component/{chewing,hangul,m17n,mozc,pinyin,xkb-layouts}.xml - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:nl::nld", "nl", "nl", "nld")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:be::nld", "be", "be", "nld")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:fr::fra", "fr", "fr", "fra")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:be::fra", "be", "be", "fra")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:ca::fra", "ca", "ca", "fra")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:ch:fr:fra", "ch(fr)", "ch(fr)", "fra")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:de::ger", "de", "de", "ger")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:de:neo:ger", "de(neo)", "de(neo)", "ger")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:be::ger", "be", "be", "ger")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:ch::ger", "ch", "ch", "ger")); - descriptions->push_back(input_method::InputMethodDescriptor( - "mozc", "us", "us", "ja")); - descriptions->push_back(input_method::InputMethodDescriptor( - "mozc-jp", "jp", "jp", "ja")); - descriptions->push_back(input_method::InputMethodDescriptor( - "mozc-dv", "us(dvorak)", "us(dvorak)", "ja")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:jp::jpn", "jp", "jp", "jpn")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:ru::rus", "ru", "ru", "rus")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:ru:phonetic:rus", "ru(phonetic)", "ru(phonetic)", "rus")); - descriptions->push_back(input_method::InputMethodDescriptor( - "m17n:th:kesmanee", "us", "us", "th")); - descriptions->push_back(input_method::InputMethodDescriptor( - "m17n:th:pattachote", "us", "us", "th")); - descriptions->push_back(input_method::InputMethodDescriptor( - "m17n:th:tis820", "us", "us", "th")); - descriptions->push_back(input_method::InputMethodDescriptor( - "mozc-chewing", "us", "us", "zh_TW")); - descriptions->push_back(input_method::InputMethodDescriptor( - "m17n:zh:cangjie", "us", "us", "zh")); - descriptions->push_back(input_method::InputMethodDescriptor( - "m17n:zh:quick", "us", "us", "zh")); - descriptions->push_back(input_method::InputMethodDescriptor( - "m17n:vi:tcvn", "us", "us", "vi")); - descriptions->push_back(input_method::InputMethodDescriptor( - "m17n:vi:telex", "us", "us", "vi")); - descriptions->push_back(input_method::InputMethodDescriptor( - "m17n:vi:viqr", "us", "us", "vi")); - descriptions->push_back(input_method::InputMethodDescriptor( - "m17n:vi:vni", "us", "us", "vi")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:us::eng", "us", "us", "eng")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:us:intl:eng", "us(intl)", "us(intl)", "eng")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:us:altgr-intl:eng", "us(altgr-intl)", "us(altgr-intl)", "eng")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:us:dvorak:eng", "us(dvorak)", "us(dvorak)", "eng")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:us:colemak:eng", "us(colemak)", "us(colemak)", "eng")); - descriptions->push_back(input_method::InputMethodDescriptor( - "hangul", "kr(kr104)", "kr(kr104)", "ko")); - descriptions->push_back(input_method::InputMethodDescriptor( - "pinyin", "us", "us", "zh")); - descriptions->push_back(input_method::InputMethodDescriptor( - "pinyin-dv", "us(dvorak)", "us(dvorak)", "zh")); - descriptions->push_back(input_method::InputMethodDescriptor( - "m17n:ar:kbd", "us", "us", "ar")); - descriptions->push_back(input_method::InputMethodDescriptor( - "m17n:hi:itrans", "us", "us", "hi")); - descriptions->push_back(input_method::InputMethodDescriptor( - "m17n:fa:isiri", "us", "us", "fa")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:br::por", "br", "br", "por")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:bg::bul", "bg", "bg", "bul")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:bg:phonetic:bul", "bg(phonetic)", "bg(phonetic)", "bul")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:ca:eng:eng", "ca(eng)", "ca(eng)", "eng")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:cz::cze", "cz", "cz", "cze")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:ee::est", "ee", "ee", "est")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:es::spa", "es", "es", "spa")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:es:cat:cat", "es(cat)", "es(cat)", "cat")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:dk::dan", "dk", "dk", "dan")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:gr::gre", "gr", "gr", "gre")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:il::heb", "il", "il", "heb")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:kr:kr104:kor", "kr(kr104)", "kr(kr104)", "kor")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:latam::spa", "latam", "latam", "spa")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:lt::lit", "lt", "lt", "lit")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:lv:apostrophe:lav", "lv(apostrophe)", "lv(apostrophe)", "lav")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:hr::scr", "hr", "hr", "scr")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:gb:extd:eng", "gb(extd)", "gb(extd)", "eng")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:gb:dvorak:eng", "gb(dvorak)", "gb(dvorak)", "eng")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:fi::fin", "fi", "fi", "fin")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:hu::hun", "hu", "hu", "hun")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:it::ita", "it", "it", "ita")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:no::nob", "no", "no", "nob")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:pl::pol", "pl", "pl", "pol")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:pt::por", "pt", "pt", "por")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:ro::rum", "ro", "ro", "rum")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:se::swe", "se", "se", "swe")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:sk::slo", "sk", "sk", "slo")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:si::slv", "si", "si", "slv")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:rs::srp", "rs", "rs", "srp")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:tr::tur", "tr", "tr", "tur")); - descriptions->push_back(input_method::InputMethodDescriptor( - "xkb:ua::ukr", "ua", "ua", "ukr")); - return descriptions; - } - - // Gets keyboard overlay map for testing. Shouldn't be used for - // production. - std::map<std::string, std::string>* GetKeyboardOverlayMapForTesting() { - KeyboardOverlayMap* keyboard_overlay_map = - new KeyboardOverlayMap; - (*keyboard_overlay_map)["xkb:nl::nld"] = "nl"; - (*keyboard_overlay_map)["xkb:be::nld"] = "nl"; - (*keyboard_overlay_map)["xkb:fr::fra"] = "fr"; - (*keyboard_overlay_map)["xkb:be::fra"] = "fr"; - (*keyboard_overlay_map)["xkb:ca::fra"] = "fr_CA"; - (*keyboard_overlay_map)["xkb:ch:fr:fra"] = "fr"; - (*keyboard_overlay_map)["xkb:de::ger"] = "de"; - (*keyboard_overlay_map)["xkb:be::ger"] = "de"; - (*keyboard_overlay_map)["xkb:ch::ger"] = "de"; - (*keyboard_overlay_map)["mozc"] = "en_US"; - (*keyboard_overlay_map)["mozc-jp"] = "ja"; - (*keyboard_overlay_map)["mozc-dv"] = "en_US_dvorak"; - (*keyboard_overlay_map)["xkb:jp::jpn"] = "ja"; - (*keyboard_overlay_map)["xkb:ru::rus"] = "ru"; - (*keyboard_overlay_map)["xkb:ru:phonetic:rus"] = "ru"; - (*keyboard_overlay_map)["m17n:th:kesmanee"] = "th"; - (*keyboard_overlay_map)["m17n:th:pattachote"] = "th"; - (*keyboard_overlay_map)["m17n:th:tis820"] = "th"; - (*keyboard_overlay_map)["mozc-chewing"] = "zh_TW"; - (*keyboard_overlay_map)["m17n:zh:cangjie"] = "zh_TW"; - (*keyboard_overlay_map)["m17n:zh:quick"] = "zh_TW"; - (*keyboard_overlay_map)["m17n:vi:tcvn"] = "vi"; - (*keyboard_overlay_map)["m17n:vi:telex"] = "vi"; - (*keyboard_overlay_map)["m17n:vi:viqr"] = "vi"; - (*keyboard_overlay_map)["m17n:vi:vni"] = "vi"; - (*keyboard_overlay_map)["xkb:us::eng"] = "en_US"; - (*keyboard_overlay_map)["xkb:us:intl:eng"] = "en_US"; - (*keyboard_overlay_map)["xkb:us:altgr-intl:eng"] = "en_US"; - (*keyboard_overlay_map)["xkb:us:dvorak:eng"] = - "en_US_dvorak"; - (*keyboard_overlay_map)["xkb:us:colemak:eng"] = - "en_US"; - (*keyboard_overlay_map)["hangul"] = "ko"; - (*keyboard_overlay_map)["pinyin"] = "zh_CN"; - (*keyboard_overlay_map)["m17n:ar:kbd"] = "ar"; - (*keyboard_overlay_map)["m17n:hi:itrans"] = "hi"; - (*keyboard_overlay_map)["m17n:fa:isiri"] = "ar"; - (*keyboard_overlay_map)["xkb:br::por"] = "pt_BR"; - (*keyboard_overlay_map)["xkb:bg::bul"] = "bg"; - (*keyboard_overlay_map)["xkb:bg:phonetic:bul"] = "bg"; - (*keyboard_overlay_map)["xkb:ca:eng:eng"] = "ca"; - (*keyboard_overlay_map)["xkb:cz::cze"] = "cs"; - (*keyboard_overlay_map)["xkb:ee::est"] = "et"; - (*keyboard_overlay_map)["xkb:es::spa"] = "es"; - (*keyboard_overlay_map)["xkb:es:cat:cat"] = "ca"; - (*keyboard_overlay_map)["xkb:dk::dan"] = "da"; - (*keyboard_overlay_map)["xkb:gr::gre"] = "el"; - (*keyboard_overlay_map)["xkb:il::heb"] = "iw"; - (*keyboard_overlay_map)["xkb:kr:kr104:kor"] = "ko"; - (*keyboard_overlay_map)["xkb:latam::spa"] = "es_419"; - (*keyboard_overlay_map)["xkb:lt::lit"] = "lt"; - (*keyboard_overlay_map)["xkb:lv:apostrophe:lav"] = "lv"; - (*keyboard_overlay_map)["xkb:hr::scr"] = "hr"; - (*keyboard_overlay_map)["xkb:gb:extd:eng"] = "en_GB"; - (*keyboard_overlay_map)["xkb:gb:dvorak:eng"] = "en_GB_dvorak"; - (*keyboard_overlay_map)["xkb:fi::fin"] = "fi"; - (*keyboard_overlay_map)["xkb:hu::hun"] = "hu"; - (*keyboard_overlay_map)["xkb:it::ita"] = "it"; - (*keyboard_overlay_map)["xkb:no::nob"] = "no"; - (*keyboard_overlay_map)["xkb:pl::pol"] = "pl"; - (*keyboard_overlay_map)["xkb:pt::por"] = "pt_PT"; - (*keyboard_overlay_map)["xkb:ro::rum"] = "ro"; - (*keyboard_overlay_map)["xkb:se::swe"] = "sv"; - (*keyboard_overlay_map)["xkb:sk::slo"] = "sk"; - (*keyboard_overlay_map)["xkb:si::slv"] = "sl"; - (*keyboard_overlay_map)["xkb:rs::srp"] = "sr"; - (*keyboard_overlay_map)["xkb:tr::tur"] = "tr"; - (*keyboard_overlay_map)["xkb:ua::ukr"] = "uk"; - return keyboard_overlay_map; - } - - input_method::InputMethodDescriptor previous_input_method_; - input_method::InputMethodDescriptor current_input_method_; - input_method::ImePropertyList current_ime_properties_; - scoped_ptr<KeyboardOverlayMap> keyboard_overlay_map_; - - DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryStubImpl); + DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl); }; // static -InputMethodLibrary* InputMethodLibrary::GetImpl(bool stub) { - if (stub) { - return new InputMethodLibraryStubImpl(); - } else { - InputMethodLibraryImpl* impl = new InputMethodLibraryImpl(); - if (!impl->Init()) { - LOG(ERROR) << "Failed to initialize InputMethodLibraryImpl"; - } - return impl; - } +InputMethodManager* InputMethodManager::GetInstance() { + return InputMethodManagerImpl::GetInstance(); } +} // namespace input_method } // namespace chromeos // Allows InvokeLater without adding refcounting. This class is a Singleton and // won't be deleted until it's last InvokeLater is run. -DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl); +DISABLE_RUNNABLE_METHOD_REFCOUNT( + chromeos::input_method::InputMethodManagerImpl); diff --git a/chrome/browser/chromeos/cros/input_method_library.h b/chrome/browser/chromeos/input_method/input_method_manager.h index fb3bb11..0ea7f5e 100644 --- a/chrome/browser/chromeos/cros/input_method_library.h +++ b/chrome/browser/chromeos/input_method/input_method_manager.h @@ -5,8 +5,8 @@ // TODO(satorux): Move this from 'cros' directory to 'input_method' // directory. -#ifndef CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_ -#define CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_ +#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_ +#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_ #pragma once #include <set> @@ -21,16 +21,15 @@ class GURL; namespace chromeos { - namespace input_method { + class VirtualKeyboard; -} // namespace input_method -// This class handles the interaction with the ChromeOS language library APIs. -// Classes can add themselves as observers. Users can get an instance of this -// library class like this: -// chromeos::CrosLibrary::Get()->GetInputMethodLibrary() -class InputMethodLibrary { + +// This class manages input methodshandles. Classes can add themselves as +// observers. Clients can get an instance of this library class by: +// InputMethodManager::GetInstance(). +class InputMethodManager { public: class Observer { public: @@ -38,29 +37,29 @@ class InputMethodLibrary { // Called when the current input method is changed. virtual void InputMethodChanged( - InputMethodLibrary* obj, + InputMethodManager* manager, const input_method::InputMethodDescriptor& current_input_method, size_t num_active_input_methods) = 0; // Called when the active input methods are changed. virtual void ActiveInputMethodsChanged( - InputMethodLibrary* obj, + InputMethodManager* manager, const input_method::InputMethodDescriptor& current_input_method, size_t num_active_input_methods) = 0; // Called when the preferences have to be updated. virtual void PreferenceUpdateNeeded( - InputMethodLibrary* obj, + InputMethodManager* manager, const input_method::InputMethodDescriptor& previous_input_method, const input_method::InputMethodDescriptor& current_input_method) = 0; // Called when the list of properties is changed. virtual void PropertyListChanged( - InputMethodLibrary* obj, + InputMethodManager* manager, const input_method::ImePropertyList& current_ime_properties) = 0; // Called by AddObserver() when the first observer is added. - virtual void FirstObserverIsAdded(InputMethodLibrary* obj) = 0; + virtual void FirstObserverIsAdded(InputMethodManager* obj) = 0; }; class VirtualKeyboardObserver { @@ -68,12 +67,14 @@ class InputMethodLibrary { virtual ~VirtualKeyboardObserver() {} // Called when the current virtual keyboard is changed. virtual void VirtualKeyboardChanged( - InputMethodLibrary* obj, + InputMethodManager* manager, const input_method::VirtualKeyboard& virtual_keyboard, const std::string& virtual_keyboard_layout) = 0; }; - virtual ~InputMethodLibrary() {} + virtual ~InputMethodManager() {} + + static InputMethodManager* GetInstance(); // Adds an observer to receive notifications of input method related // changes as desribed in the Observer class above. @@ -92,11 +93,6 @@ class InputMethodLibrary { // Returns the number of active input methods. virtual size_t GetNumActiveInputMethods() = 0; - // Returns the list of input methods we support, including ones not active. - // If the cros library is not found or IBus/DBus daemon is not alive, this - // function returns a fallback input method list (and never returns NULL). - virtual input_method::InputMethodDescriptors* GetSupportedInputMethods() = 0; - // Changes the current input method to |input_method_id|. virtual void ChangeInputMethod(const std::string& input_method_id) = 0; @@ -126,11 +122,6 @@ class InputMethodLibrary { const std::string& config_name, const input_method::ImeConfigValue& value) = 0; - // Returns the keyboard overlay ID corresponding to |input_method_id|. - // Returns an empty string if there is no corresponding keyboard overlay ID. - virtual std::string GetKeyboardOverlayId( - const std::string& input_method_id) = 0; - // Sets the IME state to enabled, and launches input method daemon if needed. // Returns true if the daemon is started. Otherwise, e.g. the daemon is // already started, returns false. @@ -170,12 +161,9 @@ class InputMethodLibrary { virtual const input_method::ImePropertyList& current_ime_properties() const = 0; - - // Factory function, creates a new instance and returns ownership. - // For normal usage, access the singleton via CrosLibrary::Get(). - static InputMethodLibrary* GetImpl(bool stub); }; +} // namespace input_method } // namespace chromeos -#endif // CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_ +#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_H_ diff --git a/chrome/browser/chromeos/input_method/input_method_util.cc b/chrome/browser/chromeos/input_method/input_method_util.cc index f0e1e83..f1e6fbf 100644 --- a/chrome/browser/chromeos/input_method/input_method_util.cc +++ b/chrome/browser/chromeos/input_method/input_method_util.cc @@ -19,7 +19,8 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/input_method/ibus_input_methods.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" #include "chrome/browser/chromeos/input_method/keyboard_overlay_map.h" #include "chrome/browser/chromeos/language_preferences.h" #include "chrome/browser/prefs/pref_service.h" @@ -53,10 +54,8 @@ struct IdMaps { } void ReloadMaps() { - InputMethodLibrary* library = - CrosLibrary::Get()->GetInputMethodLibrary(); scoped_ptr<InputMethodDescriptors> supported_input_methods( - library->GetSupportedInputMethods()); + GetSupportedInputMethods()); if (supported_input_methods->size() <= 1) { LOG(ERROR) << "GetSupportedInputMethods returned a fallback ID"; // TODO(yusukes): Handle this error in nicer way. @@ -691,13 +690,13 @@ void EnableInputMethods(const std::string& language_code, InputMethodType type, ImeConfigValue value; value.type = ImeConfigValue::kValueTypeStringList; value.string_list_value = input_method_ids; - InputMethodLibrary* library = CrosLibrary::Get()->GetInputMethodLibrary(); - library->SetImeConfig(language_prefs::kGeneralSectionName, + InputMethodManager* manager = InputMethodManager::GetInstance(); + manager->SetImeConfig(language_prefs::kGeneralSectionName, language_prefs::kPreloadEnginesConfigName, value); // Finaly, change to the initial input method, as needed. if (!initial_input_method_id.empty()) { - library->ChangeInputMethod(initial_input_method_id); + manager->ChangeInputMethod(initial_input_method_id); } } @@ -732,6 +731,19 @@ InputMethodDescriptor GetFallbackInputMethodDescriptor() { return InputMethodDescriptor("xkb:us::eng", "us", "us", "eng"); } +InputMethodDescriptors* GetSupportedInputMethods() { + InputMethodDescriptors* input_methods = new InputMethodDescriptors; + for (size_t i = 0; i < arraysize(kIBusEngines); ++i) { + if (InputMethodIdIsWhitelisted(kIBusEngines[i].id)) { + input_methods->push_back(CreateInputMethodDescriptor( + kIBusEngines[i].id, + kIBusEngines[i].layout, + kIBusEngines[i].language)); + } + } + return input_methods; +} + void ReloadInternalMaps() { IdMaps::GetInstance()->ReloadMaps(); } diff --git a/chrome/browser/chromeos/input_method/input_method_util.h b/chrome/browser/chromeos/input_method/input_method_util.h index a9c63b6..fa68b73 100644 --- a/chrome/browser/chromeos/input_method/input_method_util.h +++ b/chrome/browser/chromeos/input_method/input_method_util.h @@ -11,7 +11,7 @@ #include <vector> #include "base/string16.h" -#include "chrome/browser/chromeos/cros/input_method_library.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" namespace chromeos { namespace input_method { @@ -139,10 +139,7 @@ enum InputMethodType { // Note that the function might return false or |language_code| is unknown. // // The retured input method IDs are sorted by populalirty per -// chromeos/platform/assets/input_methods/whitelist.txt in production. -// For testing with the stub libcros, the list in -// GetInputMethodDescriptorsForTesting() in input_method_library.cc will -// be used. +// chromeos/platform/assets/input_methods/whitelist.txt. bool GetInputMethodIdsFromLanguageCode( const std::string& language_code, InputMethodType type, @@ -187,6 +184,11 @@ std::string GetHardwareInputMethodId(); // as the fallback, when there is no other choice. InputMethodDescriptor GetFallbackInputMethodDescriptor(); +// Gets all input method engines that are supported, including ones not +// active. Caller has to delete the returned list. This function never +// returns NULL. +InputMethodDescriptors* GetSupportedInputMethods(); + // This function should be called when Chrome's application locale is // changed, so that the internal maps of this library is reloaded. void OnLocaleChanged(); diff --git a/chrome/browser/chromeos/input_method/input_method_util_unittest.cc b/chrome/browser/chromeos/input_method/input_method_util_unittest.cc index 6e889c5d..669ae75 100644 --- a/chrome/browser/chromeos/input_method/input_method_util_unittest.cc +++ b/chrome/browser/chromeos/input_method/input_method_util_unittest.cc @@ -133,10 +133,9 @@ TEST_F(InputMethodUtilTest, GetInputMethodDescriptorFromId) { ASSERT_TRUE(NULL != descriptor); // ASSERT_NE doesn't compile. EXPECT_EQ("pinyin", descriptor->id); EXPECT_EQ("us", descriptor->keyboard_layout); - // This is not zh-CN as the language code in InputMethodDescriptor is - // not normalized to our format. The normalization is done in - // GetLanguageCodeFromDescriptor(). - EXPECT_EQ("zh", descriptor->language_code); + // This used to be "zh" but now we have "zh-CN" in ibus_input_methods.h, + // hence this should be zh-CN now. + EXPECT_EQ("zh-CN", descriptor->language_code); } TEST_F(InputMethodUtilTest, GetLanguageNativeDisplayNameFromCode) { diff --git a/chrome/browser/chromeos/login/base_login_display_host.cc b/chrome/browser/chromeos/login/base_login_display_host.cc index bfab826..0338e19 100644 --- a/chrome/browser/chromeos/login/base_login_display_host.cc +++ b/chrome/browser/chromeos/login/base_login_display_host.cc @@ -10,9 +10,9 @@ #include "base/threading/thread_restrictions.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/cros/input_method_library.h" #include "chrome/browser/chromeos/cros/login_library.h" #include "chrome/browser/chromeos/customization_document.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" #include "chrome/browser/chromeos/input_method/input_method_util.h" #include "chrome/browser/chromeos/language_preferences.h" #include "chrome/browser/chromeos/login/existing_user_controller.h" @@ -218,7 +218,7 @@ void ShowLoginWizard(const std::string& first_screen_name, // The login screen will enable alternate keyboard layouts, but we don't want // to start the IME process unless one is selected. - chromeos::CrosLibrary::Get()->GetInputMethodLibrary()-> + chromeos::input_method::InputMethodManager::GetInstance()-> SetDeferImeStartup(true); // Tell the window manager that the user isn't logged in. chromeos::WmIpc::instance()->SetLoggedInProperty(false); diff --git a/chrome/browser/chromeos/login/keyboard_switch_menu.cc b/chrome/browser/chromeos/login/keyboard_switch_menu.cc index 4cb30b6..e419021 100644 --- a/chrome/browser/chromeos/login/keyboard_switch_menu.cc +++ b/chrome/browser/chromeos/login/keyboard_switch_menu.cc @@ -6,7 +6,7 @@ #include "base/i18n/rtl.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" #include "chrome/browser/chromeos/input_method/input_method_util.h" #include "chrome/browser/chromeos/status/status_area_host.h" #include "grit/generated_resources.h" @@ -64,9 +64,10 @@ string16 KeyboardSwitchMenu::GetCurrentKeyboardName() const { } VLOG(1) << "The input method menu is not ready yet. Show the display " << "name of the current input method"; - InputMethodLibrary* library = CrosLibrary::Get()->GetInputMethodLibrary(); + input_method::InputMethodManager* manager = + input_method::InputMethodManager::GetInstance(); return UTF8ToUTF16(input_method::GetInputMethodDisplayNameFromId( - library->current_input_method().id)); + manager->current_input_method().id)); } } // namespace chromeos diff --git a/chrome/browser/chromeos/login/login_browsertest.cc b/chrome/browser/chromeos/login/login_browsertest.cc index ac9dcef..cc3a590 100644 --- a/chrome/browser/chromeos/login/login_browsertest.cc +++ b/chrome/browser/chromeos/login/login_browsertest.cc @@ -6,7 +6,6 @@ #include "base/time.h" #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" -#include "chrome/browser/chromeos/cros/mock_input_method_library.h" #include "chrome/browser/chromeos/cros/mock_library_loader.h" #include "chrome/browser/chromeos/cros/mock_network_library.h" #include "chrome/browser/chromeos/cros/mock_power_library.h" diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index 7cc6cf1..5755648 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -22,6 +22,7 @@ #include "chrome/browser/chromeos/boot_times_loader.h" #include "chrome/browser/chromeos/cros/login_library.h" #include "chrome/browser/chromeos/cros/network_library.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" #include "chrome/browser/chromeos/input_method/input_method_util.h" #include "chrome/browser/chromeos/login/background_view.h" #include "chrome/browser/chromeos/login/cookie_fetcher.h" @@ -486,10 +487,11 @@ void LoginUtilsImpl::SetFirstLoginPrefs(PrefService* prefs) { std::string locale = g_browser_process->GetApplicationLocale(); // First, we'll set kLanguagePreloadEngines. - InputMethodLibrary* library = CrosLibrary::Get()->GetInputMethodLibrary(); + input_method::InputMethodManager* manager = + input_method::InputMethodManager::GetInstance(); std::vector<std::string> input_method_ids; input_method::GetFirstLoginInputMethodIds(locale, - library->current_input_method(), + manager->current_input_method(), &input_method_ids); // Save the input methods in the user's preferences. StringPrefMember language_preload_engines; diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc index 78e6543..15c7d09 100644 --- a/chrome/browser/chromeos/login/screen_locker.cc +++ b/chrome/browser/chromeos/login/screen_locker.cc @@ -20,9 +20,9 @@ #include "base/string_util.h" #include "base/timer.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/cros/input_method_library.h" #include "chrome/browser/chromeos/cros/login_library.h" #include "chrome/browser/chromeos/cros/screen_lock_library.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" #include "chrome/browser/chromeos/input_method/input_method_util.h" #include "chrome/browser/chromeos/language_preferences.h" #include "chrome/browser/chromeos/login/authenticator.h" @@ -111,17 +111,16 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, // able to use/switch active keyboard layouts (e.g. US qwerty, US dvorak, // French). void SetupInputMethodsForScreenLocker() { - if (chromeos::CrosLibrary::Get()->EnsureLoaded() && - // The LockScreen function is also called when the OS is suspended, and + if (// The LockScreen function is also called when the OS is suspended, and // in that case |saved_active_input_method_list_| might be non-empty. saved_active_input_method_list_.empty()) { - chromeos::InputMethodLibrary* library = - chromeos::CrosLibrary::Get()->GetInputMethodLibrary(); + chromeos::input_method::InputMethodManager* manager = + chromeos::input_method::InputMethodManager::GetInstance(); - saved_previous_input_method_id_ = library->previous_input_method().id; - saved_current_input_method_id_ = library->current_input_method().id; + saved_previous_input_method_id_ = manager->previous_input_method().id; + saved_current_input_method_id_ = manager->current_input_method().id; scoped_ptr<chromeos::input_method::InputMethodDescriptors> - active_input_method_list(library->GetActiveInputMethods()); + active_input_method_list(manager->GetActiveInputMethods()); const std::string hardware_keyboard_id = chromeos::input_method::GetHardwareInputMethodId(); @@ -148,8 +147,8 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, } // We don't want to shut down the IME, even if the hardware layout is the // only IME left. - library->SetEnableAutoImeShutdown(false); - library->SetImeConfig( + manager->SetEnableAutoImeShutdown(false); + manager->SetImeConfig( chromeos::language_prefs::kGeneralSectionName, chromeos::language_prefs::kPreloadEnginesConfigName, value); @@ -157,24 +156,23 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, } void RestoreInputMethods() { - if (chromeos::CrosLibrary::Get()->EnsureLoaded() && - !saved_active_input_method_list_.empty()) { - chromeos::InputMethodLibrary* library = - chromeos::CrosLibrary::Get()->GetInputMethodLibrary(); + if (!saved_active_input_method_list_.empty()) { + chromeos::input_method::InputMethodManager* manager = + chromeos::input_method::InputMethodManager::GetInstance(); chromeos::input_method::ImeConfigValue value; value.type = chromeos::input_method::ImeConfigValue::kValueTypeStringList; value.string_list_value = saved_active_input_method_list_; - library->SetEnableAutoImeShutdown(true); - library->SetImeConfig( + manager->SetEnableAutoImeShutdown(true); + manager->SetImeConfig( chromeos::language_prefs::kGeneralSectionName, chromeos::language_prefs::kPreloadEnginesConfigName, value); // Send previous input method id first so Ctrl+space would work fine. if (!saved_previous_input_method_id_.empty()) - library->ChangeInputMethod(saved_previous_input_method_id_); + manager->ChangeInputMethod(saved_previous_input_method_id_); if (!saved_current_input_method_id_.empty()) - library->ChangeInputMethod(saved_current_input_method_id_); + manager->ChangeInputMethod(saved_current_input_method_id_); saved_previous_input_method_id_.clear(); saved_current_input_method_id_.clear(); @@ -841,9 +839,9 @@ void ScreenLocker::OnLoginFailure(const LoginFailure& error) { if (!error_text.empty()) msg += ASCIIToUTF16("\n") + ASCIIToUTF16(error_text); - InputMethodLibrary* input_method_library = - CrosLibrary::Get()->GetInputMethodLibrary(); - if (input_method_library->GetNumActiveInputMethods() > 1) + input_method::InputMethodManager* input_method_manager = + input_method::InputMethodManager::GetInstance(); + if (input_method_manager->GetNumActiveInputMethods() > 1) msg += ASCIIToUTF16("\n") + l10n_util::GetStringUTF16(IDS_LOGIN_ERROR_KEYBOARD_SWITCH_HINT); diff --git a/chrome/browser/chromeos/login/screen_locker_browsertest.cc b/chrome/browser/chromeos/login/screen_locker_browsertest.cc index f143511..c2d22cc 100644 --- a/chrome/browser/chromeos/login/screen_locker_browsertest.cc +++ b/chrome/browser/chromeos/login/screen_locker_browsertest.cc @@ -7,7 +7,6 @@ #include "base/message_loop.h" #include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" -#include "chrome/browser/chromeos/cros/mock_input_method_library.h" #include "chrome/browser/chromeos/cros/mock_screen_lock_library.h" #include "chrome/browser/chromeos/login/mock_authenticator.h" #include "chrome/browser/chromeos/login/screen_locker.h" @@ -97,13 +96,11 @@ namespace chromeos { class ScreenLockerTest : public CrosInProcessBrowserTest { public: - ScreenLockerTest() : mock_screen_lock_library_(NULL), - mock_input_method_library_(NULL) { + ScreenLockerTest() : mock_screen_lock_library_(NULL) { } protected: MockScreenLockLibrary *mock_screen_lock_library_; - MockInputMethodLibrary *mock_input_method_library_; // Test the no password mode with different unlock scheme given by // |unlock| function. @@ -152,7 +149,6 @@ class ScreenLockerTest : public CrosInProcessBrowserTest { cros_mock_->InitStatusAreaMocks(); cros_mock_->InitMockScreenLockLibrary(); mock_screen_lock_library_ = cros_mock_->mock_screen_lock_library(); - mock_input_method_library_ = cros_mock_->mock_input_method_library(); EXPECT_CALL(*mock_screen_lock_library_, AddObserver(testing::_)) .Times(1) .RetiresOnSaturation(); @@ -176,10 +172,6 @@ class ScreenLockerTest : public CrosInProcessBrowserTest { // Temporarily disabling all screen locker tests while investigating the // issue crbug.com/78764. IN_PROC_BROWSER_TEST_F(ScreenLockerTest, DISABLED_TestBasic) { - EXPECT_CALL(*mock_input_method_library_, GetNumActiveInputMethods()) - .Times(1) - .WillRepeatedly((testing::Return(0))) - .RetiresOnSaturation(); EXPECT_CALL(*mock_screen_lock_library_, NotifyScreenUnlockRequested()) .Times(1) .RetiresOnSaturation(); diff --git a/chrome/browser/chromeos/login/user_manager.cc b/chrome/browser/chromeos/login/user_manager.cc index d2e9d52..56ad2c4 100644 --- a/chrome/browser/chromeos/login/user_manager.cc +++ b/chrome/browser/chromeos/login/user_manager.cc @@ -20,7 +20,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/cryptohome_library.h" -#include "chrome/browser/chromeos/cros/input_method_library.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" #include "chrome/browser/chromeos/login/default_user_images.h" #include "chrome/browser/chromeos/login/login_display.h" #include "chrome/browser/chromeos/login/ownership_service.h" @@ -606,10 +606,10 @@ void UserManager::NotifyOnLogin() { Source<UserManager>(this), Details<const User>(&logged_in_user_)); - chromeos::CrosLibrary::Get()->GetInputMethodLibrary()-> + chromeos::input_method::InputMethodManager::GetInstance()-> SetDeferImeStartup(false); // Shut down the IME so that it will reload the user's settings. - chromeos::CrosLibrary::Get()->GetInputMethodLibrary()-> + chromeos::input_method::InputMethodManager::GetInstance()-> StopInputMethodDaemon(); // Let the window manager know that we're logged in now. WmIpc::instance()->SetLoggedInProperty(true); diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc index 8a4ae82..b2c9e70 100644 --- a/chrome/browser/chromeos/preferences.cc +++ b/chrome/browser/chromeos/preferences.cc @@ -10,9 +10,9 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/cros/input_method_library.h" #include "chrome/browser/chromeos/cros/power_library.h" #include "chrome/browser/chromeos/cros/touchpad_library.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" #include "chrome/browser/chromeos/input_method/input_method_util.h" #include "chrome/browser/chromeos/input_method/xkeyboard.h" #include "chrome/browser/chromeos/login/login_utils.h" @@ -448,7 +448,7 @@ void Preferences::SetLanguageConfigBoolean(const char* section, input_method::ImeConfigValue config; config.type = input_method::ImeConfigValue::kValueTypeBool; config.bool_value = value; - CrosLibrary::Get()->GetInputMethodLibrary()-> + input_method::InputMethodManager::GetInstance()-> SetImeConfig(section, name, config); } @@ -458,7 +458,7 @@ void Preferences::SetLanguageConfigInteger(const char* section, input_method::ImeConfigValue config; config.type = input_method::ImeConfigValue::kValueTypeInt; config.int_value = value; - CrosLibrary::Get()->GetInputMethodLibrary()-> + input_method::InputMethodManager::GetInstance()-> SetImeConfig(section, name, config); } @@ -468,7 +468,7 @@ void Preferences::SetLanguageConfigString(const char* section, input_method::ImeConfigValue config; config.type = input_method::ImeConfigValue::kValueTypeString; config.string_value = value; - CrosLibrary::Get()->GetInputMethodLibrary()-> + input_method::InputMethodManager::GetInstance()-> SetImeConfig(section, name, config); } @@ -481,7 +481,7 @@ void Preferences::SetLanguageConfigStringList( for (size_t i = 0; i < values.size(); ++i) config.string_list_value.push_back(values[i]); - CrosLibrary::Get()->GetInputMethodLibrary()-> + input_method::InputMethodManager::GetInstance()-> SetImeConfig(section, name, config); } diff --git a/chrome/browser/chromeos/status/input_method_menu.cc b/chrome/browser/chromeos/status/input_method_menu.cc index fb76f7f..41947dd 100644 --- a/chrome/browser/chromeos/status/input_method_menu.cc +++ b/chrome/browser/chromeos/status/input_method_menu.cc @@ -12,7 +12,6 @@ #include "base/time.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/input_method/input_method_util.h" #include "chrome/browser/chromeos/language_preferences.h" #include "chrome/browser/prefs/pref_service.h" @@ -126,13 +125,15 @@ std::wstring GetLanguageName(const std::string& language_code) { namespace chromeos { +using input_method::InputMethodManager; + //////////////////////////////////////////////////////////////////////////////// // InputMethodMenu InputMethodMenu::InputMethodMenu(PrefService* pref_service, StatusAreaHost::ScreenMode screen_mode, bool for_out_of_box_experience_dialog) - : input_method_descriptors_(CrosLibrary::Get()->GetInputMethodLibrary()-> + : input_method_descriptors_(InputMethodManager::GetInstance()-> GetActiveInputMethods()), model_(new ui::SimpleMenuModel(NULL)), ALLOW_THIS_IN_INITIALIZER_LIST(input_method_menu_delegate_( @@ -155,8 +156,8 @@ InputMethodMenu::InputMethodMenu(PrefService* pref_service, prefs::kLanguageCurrentInputMethod, pref_service, this); } - InputMethodLibrary* library = CrosLibrary::Get()->GetInputMethodLibrary(); - library->AddObserver(this); // FirstObserverIsAdded() might be called back. + InputMethodManager* manager = InputMethodManager::GetInstance(); + manager->AddObserver(this); // FirstObserverIsAdded() might be called back. if (screen_mode_ == StatusAreaHost::kLoginMode) { // This button is for the login screen. @@ -169,7 +170,7 @@ InputMethodMenu::InputMethodMenu(PrefService* pref_service, InputMethodMenu::~InputMethodMenu() { // RemoveObserver() is no-op if |this| object is already removed from the // observer list. - CrosLibrary::Get()->GetInputMethodLibrary()->RemoveObserver(this); + InputMethodManager::GetInstance()->RemoveObserver(this); } //////////////////////////////////////////////////////////////////////////////// @@ -197,13 +198,13 @@ bool InputMethodMenu::IsItemCheckedAt(int index) const { if (IndexIsInInputMethodList(index)) { const input_method::InputMethodDescriptor& input_method = input_method_descriptors_->at(index); - return input_method == CrosLibrary::Get()->GetInputMethodLibrary()-> + return input_method == InputMethodManager::GetInstance()-> current_input_method(); } if (GetPropertyIndex(index, &index)) { const input_method::ImePropertyList& property_list - = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); + = InputMethodManager::GetInstance()->current_ime_properties(); return property_list.at(index).is_selection_item_checked; } @@ -221,7 +222,7 @@ int InputMethodMenu::GetGroupIdAt(int index) const { if (GetPropertyIndex(index, &index)) { const input_method::ImePropertyList& property_list - = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); + = InputMethodManager::GetInstance()->current_ime_properties(); return property_list.at(index).selection_item_id; } @@ -288,7 +289,7 @@ ui::MenuModel::ItemType InputMethodMenu::GetTypeAt(int index) const { if (GetPropertyIndex(index, &index)) { const input_method::ImePropertyList& property_list - = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); + = InputMethodManager::GetInstance()->current_ime_properties(); if (property_list.at(index).is_selection_item) { return ui::MenuModel::TYPE_RADIO; } @@ -312,10 +313,10 @@ string16 InputMethodMenu::GetLabelAt(int index) const { if (IndexIsInInputMethodList(index)) { name = GetTextForMenu(input_method_descriptors_->at(index)); } else if (GetPropertyIndex(index, &index)) { - InputMethodLibrary* library = CrosLibrary::Get()->GetInputMethodLibrary(); + InputMethodManager* manager = InputMethodManager::GetInstance(); const input_method::ImePropertyList& property_list = - library->current_ime_properties(); - const std::string& input_method_id = library->current_input_method().id; + manager->current_ime_properties(); + const std::string& input_method_id = manager->current_input_method().id; return input_method::GetStringUTF16( property_list.at(index).label, input_method_id); } @@ -336,7 +337,7 @@ void InputMethodMenu::ActivatedAt(int index) { // Inter-IME switching. const input_method::InputMethodDescriptor& input_method = input_method_descriptors_->at(index); - CrosLibrary::Get()->GetInputMethodLibrary()->ChangeInputMethod( + InputMethodManager::GetInstance()->ChangeInputMethod( input_method.id); UserMetrics::RecordAction( UserMetricsAction("LanguageMenuButton_InputMethodChanged")); @@ -346,7 +347,7 @@ void InputMethodMenu::ActivatedAt(int index) { if (GetPropertyIndex(index, &index)) { // Intra-IME switching (e.g. Japanese-Hiragana to Japanese-Katakana). const input_method::ImePropertyList& property_list - = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); + = InputMethodManager::GetInstance()->current_ime_properties(); const std::string key = property_list.at(index).key; if (property_list.at(index).is_selection_item) { // Radio button is clicked. @@ -354,17 +355,17 @@ void InputMethodMenu::ActivatedAt(int index) { // First, deactivate all other properties in the same radio group. for (int i = 0; i < static_cast<int>(property_list.size()); ++i) { if (i != index && id == property_list.at(i).selection_item_id) { - CrosLibrary::Get()->GetInputMethodLibrary()->SetImePropertyActivated( + InputMethodManager::GetInstance()->SetImePropertyActivated( property_list.at(i).key, false); } } // Then, activate the property clicked. - CrosLibrary::Get()->GetInputMethodLibrary()->SetImePropertyActivated( + InputMethodManager::GetInstance()->SetImePropertyActivated( key, true); } else { // Command button like "Switch to half punctuation mode" is clicked. // We can always use "Deactivate" for command buttons. - CrosLibrary::Get()->GetInputMethodLibrary()->SetImePropertyActivated( + InputMethodManager::GetInstance()->SetImePropertyActivated( key, false); } return; @@ -399,17 +400,17 @@ void InputMethodMenu::RunMenu(views::View* source, const gfx::Point& pt) { } //////////////////////////////////////////////////////////////////////////////// -// InputMethodLibrary::Observer implementation: +// InputMethodManager::Observer implementation: void InputMethodMenu::InputMethodChanged( - InputMethodLibrary* obj, + InputMethodManager* manager, const input_method::InputMethodDescriptor& current_input_method, size_t num_active_input_methods) { UpdateUIFromInputMethod(current_input_method, num_active_input_methods); } void InputMethodMenu::PreferenceUpdateNeeded( - InputMethodLibrary* obj, + InputMethodManager* manager, const input_method::InputMethodDescriptor& previous_input_method, const input_method::InputMethodDescriptor& current_input_method) { if (screen_mode_ == StatusAreaHost::kBrowserMode) { @@ -429,7 +430,7 @@ void InputMethodMenu::PreferenceUpdateNeeded( } void InputMethodMenu::PropertyListChanged( - InputMethodLibrary* obj, + InputMethodManager* manager, const input_method::ImePropertyList& current_ime_properties) { // Usual order of notifications of input method change is: // 1. RegisterProperties(empty) @@ -444,15 +445,14 @@ void InputMethodMenu::PropertyListChanged( // it is better to be avoided. Otherwise users can sometimes observe the // awkward clear-then-register behavior. if (!current_ime_properties.empty()) { - InputMethodLibrary* library = CrosLibrary::Get()->GetInputMethodLibrary(); const input_method::InputMethodDescriptor& input_method = - library->current_input_method(); - size_t num_active_input_methods = library->GetNumActiveInputMethods(); + manager->current_input_method(); + size_t num_active_input_methods = manager->GetNumActiveInputMethods(); UpdateUIFromInputMethod(input_method, num_active_input_methods); } } -void InputMethodMenu::FirstObserverIsAdded(InputMethodLibrary* obj) { +void InputMethodMenu::FirstObserverIsAdded(InputMethodManager* manager) { // NOTICE: Since this function might be called from the constructor of this // class, it's better to avoid calling virtual functions. @@ -462,16 +462,15 @@ void InputMethodMenu::FirstObserverIsAdded(InputMethodLibrary* obj) { // preference so that the Control+space hot-key could work fine from the // beginning. InputMethodChanged() will be called soon and the indicator // will be updated. - InputMethodLibrary* library = CrosLibrary::Get()->GetInputMethodLibrary(); const std::string previous_input_method_id = previous_input_method_pref_.GetValue(); if (!previous_input_method_id.empty()) { - library->ChangeInputMethod(previous_input_method_id); + manager->ChangeInputMethod(previous_input_method_id); } const std::string current_input_method_id = current_input_method_pref_.GetValue(); if (!current_input_method_id.empty()) { - library->ChangeInputMethod(current_input_method_id); + manager->ChangeInputMethod(current_input_method_id); } } } @@ -482,13 +481,13 @@ void InputMethodMenu::PrepareForMenuOpen() { } void InputMethodMenu::PrepareMenuModel() { - input_method_descriptors_.reset(CrosLibrary::Get()->GetInputMethodLibrary()-> + input_method_descriptors_.reset(InputMethodManager::GetInstance()-> GetActiveInputMethods()); RebuildModel(); } void InputMethodMenu::ActiveInputMethodsChanged( - InputMethodLibrary* obj, + InputMethodManager* manager, const input_method::InputMethodDescriptor& current_input_method, size_t num_active_input_methods) { // Update the icon if active input methods are changed. See also @@ -522,7 +521,7 @@ void InputMethodMenu::RebuildModel() { } const input_method::ImePropertyList& property_list - = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); + = InputMethodManager::GetInstance()->current_ime_properties(); if (!property_list.empty()) { if (need_separator) { model_->AddSeparator(); @@ -572,7 +571,7 @@ bool InputMethodMenu::GetPropertyIndex(int index, int* property_index) const { (model_->GetCommandIdAt(index) == COMMAND_ID_IME_PROPERTIES)) { const int tmp_property_index = model_->GetGroupIdAt(index); const input_method::ImePropertyList& property_list - = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); + = InputMethodManager::GetInstance()->current_ime_properties(); if (tmp_property_index < static_cast<int>(property_list.size())) { *property_index = tmp_property_index; return true; @@ -685,7 +684,7 @@ void InputMethodMenu::Observe(NotificationType type, // When a user logs in, we should remove |this| object from the observer // list so that PreferenceUpdateNeeded() does not update the local state // anymore. - CrosLibrary::Get()->GetInputMethodLibrary()->RemoveObserver(this); + InputMethodManager::GetInstance()->RemoveObserver(this); } } diff --git a/chrome/browser/chromeos/status/input_method_menu.h b/chrome/browser/chromeos/status/input_method_menu.h index 60d3d88..22dbb15 100644 --- a/chrome/browser/chromeos/status/input_method_menu.h +++ b/chrome/browser/chromeos/status/input_method_menu.h @@ -8,7 +8,7 @@ #include <string> -#include "chrome/browser/chromeos/cros/input_method_library.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" #include "chrome/browser/chromeos/status/status_area_host.h" #include "chrome/browser/prefs/pref_member.h" #include "content/common/notification_observer.h" @@ -38,7 +38,7 @@ namespace chromeos { // which shows the dropdown menu on click. class InputMethodMenu : public views::ViewMenuDelegate, public ui::MenuModel, - public InputMethodLibrary::Observer, + public input_method::InputMethodManager::Observer, public NotificationObserver { public: InputMethodMenu(PrefService* pref_service, @@ -70,23 +70,23 @@ class InputMethodMenu : public views::ViewMenuDelegate, // to adjust the position of the menu. virtual void RunMenu(views::View* source, const gfx::Point& pt); - // InputMethodLibrary::Observer implementation. + // InputMethodManager::Observer implementation. virtual void InputMethodChanged( - InputMethodLibrary* obj, + input_method::InputMethodManager* manager, const input_method::InputMethodDescriptor& current_input_method, size_t num_active_input_methods); virtual void ActiveInputMethodsChanged( - InputMethodLibrary* obj, + input_method::InputMethodManager* manager, const input_method::InputMethodDescriptor& current_input_method, size_t num_active_input_methods); virtual void PreferenceUpdateNeeded( - InputMethodLibrary* obj, + input_method::InputMethodManager* manager, const input_method::InputMethodDescriptor& previous_input_method, const input_method::InputMethodDescriptor& current_input_method); virtual void PropertyListChanged( - InputMethodLibrary* obj, + input_method::InputMethodManager* manager, const input_method::ImePropertyList& current_ime_properties); - virtual void FirstObserverIsAdded(InputMethodLibrary* obj); + virtual void FirstObserverIsAdded(input_method::InputMethodManager* manager); // NotificationObserver implementation. virtual void Observe(NotificationType type, diff --git a/chrome/browser/chromeos/status/input_method_menu_button.cc b/chrome/browser/chromeos/status/input_method_menu_button.cc index 5e82ba3..1ab01de 100644 --- a/chrome/browser/chromeos/status/input_method_menu_button.cc +++ b/chrome/browser/chromeos/status/input_method_menu_button.cc @@ -7,7 +7,7 @@ #include <string> #include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" #include "chrome/browser/chromeos/input_method/input_method_util.h" #include "chrome/browser/chromeos/status/status_area_host.h" #include "chrome/browser/prefs/pref_service.h" @@ -158,14 +158,14 @@ bool InputMethodMenuButton::ShouldSupportConfigUI() { } void InputMethodMenuButton::UpdateUIFromCurrentInputMethod() { - chromeos::InputMethodLibrary* input_method_library = - chromeos::CrosLibrary::Get()->GetInputMethodLibrary(); + input_method::InputMethodManager* input_method_manager = + input_method::InputMethodManager::GetInstance(); const input_method::InputMethodDescriptor& input_method = - input_method_library->current_input_method(); + input_method_manager->current_input_method(); const std::wstring name = InputMethodMenu::GetTextForIndicator(input_method); const std::wstring tooltip = InputMethodMenu::GetTextForMenu(input_method); const size_t num_active_input_methods = - input_method_library->GetNumActiveInputMethods(); + input_method_manager->GetNumActiveInputMethods(); UpdateUI(input_method.id, name, tooltip, num_active_input_methods); } diff --git a/chrome/browser/chromeos/status/input_method_menu_button_browsertest.cc b/chrome/browser/chromeos/status/input_method_menu_button_browsertest.cc index b2db7fc..4b85fcd 100644 --- a/chrome/browser/chromeos/status/input_method_menu_button_browsertest.cc +++ b/chrome/browser/chromeos/status/input_method_menu_button_browsertest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,7 +6,6 @@ #include "base/string_util.h" #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" -#include "chrome/browser/chromeos/cros/mock_input_method_library.h" #include "chrome/browser/chromeos/frame/browser_view.h" #include "chrome/browser/chromeos/status/status_area_view.h" #include "chrome/browser/chromeos/view_ids.h" |