summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-03 13:14:23 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-03 13:14:23 +0000
commitd18893ee6559342bfc97ba0432fbdaf1b3222712 (patch)
tree9ee18073cbdf2da518d3bffc4150b04400b3df55 /chrome/browser/chromeos
parentdc6cc4791a83ce08a03ff103c6932d4d6e22cae3 (diff)
downloadchromium_src-d18893ee6559342bfc97ba0432fbdaf1b3222712.zip
chromium_src-d18893ee6559342bfc97ba0432fbdaf1b3222712.tar.gz
chromium_src-d18893ee6559342bfc97ba0432fbdaf1b3222712.tar.bz2
Add a function that returns the descriptor of the hardware keyboard.
Along the way, remove call sites of CreateFallbackInputMethodDescriptors() and GetHardwareKeyboardLayoutName(). Those functions are no longer used in Chrome tree. BUG=chromium-os:11528 TEST=manually confirmed that input methods worked as before Review URL: http://codereview.chromium.org/6312116 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r--chrome/browser/chromeos/cros/cros_mock.cc18
-rw-r--r--chrome/browser/chromeos/cros/cros_mock.h4
-rw-r--r--chrome/browser/chromeos/cros/input_method_library.cc18
-rw-r--r--chrome/browser/chromeos/cros/input_method_library.h7
-rw-r--r--chrome/browser/chromeos/cros/keyboard_library.cc9
-rw-r--r--chrome/browser/chromeos/cros/keyboard_library.h5
-rw-r--r--chrome/browser/chromeos/input_method/input_method_util.cc14
-rw-r--r--chrome/browser/chromeos/input_method/input_method_util.h7
-rw-r--r--chrome/browser/chromeos/login/language_switch_menu.cc6
-rw-r--r--chrome/browser/chromeos/login/screen_locker.cc33
-rw-r--r--chrome/browser/chromeos/preferences.cc6
11 files changed, 65 insertions, 62 deletions
diff --git a/chrome/browser/chromeos/cros/cros_mock.cc b/chrome/browser/chromeos/cros/cros_mock.cc
index e136d5e..fd6ffdb 100644
--- a/chrome/browser/chromeos/cros/cros_mock.cc
+++ b/chrome/browser/chromeos/cros/cros_mock.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/chromeos/cros/mock_speech_synthesis_library.h"
#include "chrome/browser/chromeos/cros/mock_system_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"
@@ -49,7 +50,7 @@ CrosMock::CrosMock()
current_input_method_("", "", "", ""),
previous_input_method_("", "", "", "") {
current_input_method_ =
- InputMethodLibrary::GetFallbackInputMethodDescriptor();
+ input_method::GetFallbackInputMethodDescriptor();
}
CrosMock::~CrosMock() {
@@ -199,10 +200,6 @@ void CrosMock::SetStatusAreaMocksExpectations() {
}
void CrosMock::SetKeyboardLibraryStatusAreaExpectations() {
- EXPECT_CALL(*mock_keyboard_library_, GetHardwareKeyboardLayoutName())
- .Times(AnyNumber())
- .WillRepeatedly((Return("xkb:us::eng")))
- .RetiresOnSaturation();
EXPECT_CALL(*mock_keyboard_library_, GetCurrentKeyboardLayoutName())
.Times(AnyNumber())
.WillRepeatedly((Return("us")))
@@ -239,11 +236,11 @@ void CrosMock::SetInputMethodLibraryStatusAreaExpectations() {
.RetiresOnSaturation();
EXPECT_CALL(*mock_input_method_library_, GetActiveInputMethods())
.Times(AnyNumber())
- .WillRepeatedly(InvokeWithoutArgs(CreateFallbackInputMethodDescriptors))
+ .WillRepeatedly(InvokeWithoutArgs(CreateInputMethodDescriptors))
.RetiresOnSaturation();
EXPECT_CALL(*mock_input_method_library_, GetSupportedInputMethods())
.Times(AnyNumber())
- .WillRepeatedly(InvokeWithoutArgs(CreateFallbackInputMethodDescriptors))
+ .WillRepeatedly(InvokeWithoutArgs(CreateInputMethodDescriptors))
.RetiresOnSaturation();
EXPECT_CALL(*mock_input_method_library_, current_input_method())
.Times(AnyNumber())
@@ -463,4 +460,11 @@ void CrosMock::TearDownMocks() {
test_api()->SetTouchpadLibrary(NULL, false);
}
+InputMethodDescriptors* CrosMock::CreateInputMethodDescriptors() {
+ InputMethodDescriptors* descriptors = new 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 e5fa39b..1e8c577 100644
--- a/chrome/browser/chromeos/cros/cros_mock.h
+++ b/chrome/browser/chromeos/cros/cros_mock.h
@@ -86,6 +86,10 @@ class CrosMock {
void TearDownMocks();
+ // Creates input method descriptors. This is a helper function for
+ // SetInputMethodLibraryStatusAreaExpectations().
+ static InputMethodDescriptors* CreateInputMethodDescriptors();
+
// TestApi gives access to CrosLibrary private members.
chromeos::CrosLibrary::TestApi* test_api();
diff --git a/chrome/browser/chromeos/cros/input_method_library.cc b/chrome/browser/chromeos/cros/input_method_library.cc
index 0da36fc..3c0924b 100644
--- a/chrome/browser/chromeos/cros/input_method_library.cc
+++ b/chrome/browser/chromeos/cros/input_method_library.cc
@@ -63,12 +63,9 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
should_change_input_method_(false),
ibus_daemon_process_id_(0),
candidate_window_controller_(NULL) {
- // TODO(yusukes): Using both CreateFallbackInputMethodDescriptors and
- // chromeos::GetHardwareKeyboardLayoutName doesn't look clean. Probably
- // we should unify these APIs.
- scoped_ptr<InputMethodDescriptors> input_method_descriptors(
- CreateFallbackInputMethodDescriptors());
- current_input_method_ = input_method_descriptors->at(0);
+ current_input_method_ =
+ input_method::GetHardwareInputMethodDescriptor();
+ active_input_method_ids_.push_back(current_input_method_.id);
// 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).
@@ -109,8 +106,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
}
}
if (result->empty()) {
- delete result;
- result = CreateFallbackInputMethodDescriptors();
+ result->push_back(input_method::GetHardwareInputMethodDescriptor());
}
return result;
}
@@ -128,7 +124,9 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
input_method_status_connection_);
}
if (!result || result->empty()) {
- result = CreateFallbackInputMethodDescriptors();
+ delete result;
+ result = new InputMethodDescriptors;
+ result->push_back(input_method::GetHardwareInputMethodDescriptor());
}
return result;
}
@@ -739,7 +737,7 @@ class InputMethodLibraryStubImpl : public InputMethodLibrary {
current_input_method_("", "", "", ""),
keyboard_overlay_map_(
CreateRealisticKeyboardOverlayMap()) {
- current_input_method_ = GetFallbackInputMethodDescriptor();
+ current_input_method_ = input_method::GetFallbackInputMethodDescriptor();
}
~InputMethodLibraryStubImpl() {}
diff --git a/chrome/browser/chromeos/cros/input_method_library.h b/chrome/browser/chromeos/cros/input_method_library.h
index e29870e..07b07ef 100644
--- a/chrome/browser/chromeos/cros/input_method_library.h
+++ b/chrome/browser/chromeos/cros/input_method_library.h
@@ -126,13 +126,6 @@ class InputMethodLibrary {
virtual const ImePropertyList& current_ime_properties() const = 0;
- // Returns the fallback input method descriptor (the very basic US
- // keyboard). This function is mostly used for testing, but may be used
- // as the fallback, when there is no other choice.
- static InputMethodDescriptor GetFallbackInputMethodDescriptor() {
- return InputMethodDescriptor("xkb:us::eng", "USA", "us", "eng");
- }
-
// Factory function, creates a new instance and returns ownership.
// For normal usage, access the singleton via CrosLibrary::Get().
static InputMethodLibrary* GetImpl(bool stub);
diff --git a/chrome/browser/chromeos/cros/keyboard_library.cc b/chrome/browser/chromeos/cros/keyboard_library.cc
index 7d0d4f4..ef27426 100644
--- a/chrome/browser/chromeos/cros/keyboard_library.cc
+++ b/chrome/browser/chromeos/cros/keyboard_library.cc
@@ -14,11 +14,6 @@ class KeyboardLibraryImpl : public KeyboardLibrary {
KeyboardLibraryImpl() {}
virtual ~KeyboardLibraryImpl() {}
- std::string GetHardwareKeyboardLayoutName() const {
- // TODO(satorux): Rework this function. crosbug.com/11528.
- return "xkb:us::eng";
- }
-
std::string GetCurrentKeyboardLayoutName() const {
if (CrosLibrary::Get()->EnsureLoaded()) {
return chromeos::GetCurrentKeyboardLayoutName();
@@ -77,10 +72,6 @@ class KeyboardLibraryStubImpl : public KeyboardLibrary {
KeyboardLibraryStubImpl() {}
virtual ~KeyboardLibraryStubImpl() {}
- std::string GetHardwareKeyboardLayoutName() const {
- return "xkb:us::eng";
- }
-
std::string GetCurrentKeyboardLayoutName() const {
return "";
}
diff --git a/chrome/browser/chromeos/cros/keyboard_library.h b/chrome/browser/chromeos/cros/keyboard_library.h
index b3ab35c..21d539d 100644
--- a/chrome/browser/chromeos/cros/keyboard_library.h
+++ b/chrome/browser/chromeos/cros/keyboard_library.h
@@ -18,11 +18,6 @@ class KeyboardLibrary {
public:
virtual ~KeyboardLibrary() {}
- // Returns the input method ID of the hardware layout like
- // "xkb:us::eng". On error, returns "". TODO(satorux): Rename this
- // function and rework the implementation. crosbug.com/11528.
- virtual std::string GetHardwareKeyboardLayoutName() const = 0;
-
// Returns the current layout name as XKB layout like "us" and
// "us(dvorak)". On error, returns "". This function is very expensive
// as it calls a libcros function that gets the layout information from
diff --git a/chrome/browser/chromeos/input_method/input_method_util.cc b/chrome/browser/chromeos/input_method/input_method_util.cc
index cb579fb..ffe76e7 100644
--- a/chrome/browser/chromeos/input_method/input_method_util.cc
+++ b/chrome/browser/chromeos/input_method/input_method_util.cc
@@ -575,8 +575,9 @@ void EnableInputMethods(const std::string& language_code, InputMethodType type,
std::vector<std::string> input_method_ids;
GetInputMethodIdsFromLanguageCode(language_code, type, &input_method_ids);
- std::string keyboard = CrosLibrary::Get()->GetKeyboardLibrary()->
- GetHardwareKeyboardLayoutName();
+ // Add the hardware keyboard.
+ const std::string keyboard =
+ input_method::GetHardwareInputMethodDescriptor().id;
if (std::count(input_method_ids.begin(), input_method_ids.end(),
keyboard) == 0) {
input_method_ids.push_back(keyboard);
@@ -597,6 +598,15 @@ void EnableInputMethods(const std::string& language_code, InputMethodType type,
}
}
+InputMethodDescriptor GetHardwareInputMethodDescriptor() {
+ // TODO(satorux): Rework this function. crosbug.com/11528.
+ return GetFallbackInputMethodDescriptor();
+}
+
+InputMethodDescriptor GetFallbackInputMethodDescriptor() {
+ return InputMethodDescriptor("xkb:us::eng", "USA", "us", "eng");
+}
+
void OnLocaleChanged() {
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 5818c6c..7b6b6da 100644
--- a/chrome/browser/chromeos/input_method/input_method_util.h
+++ b/chrome/browser/chromeos/input_method/input_method_util.h
@@ -156,6 +156,13 @@ bool GetInputMethodIdsFromLanguageCode(
void EnableInputMethods(const std::string& language_code, InputMethodType type,
const std::string& initial_input_method_id);
+// Returns the input method descriptor of the hardware keyboard.
+InputMethodDescriptor GetHardwareInputMethodDescriptor();
+
+// Returns the fallback input method descriptor (the very basic US
+// keyboard). This function is mostly used for testing, but may be used
+// as the fallback, when there is no other choice.
+InputMethodDescriptor GetFallbackInputMethodDescriptor();
// DO NOT USE Functions below. These are only exported for unit tests.
void SortInputMethodIdsByNamesInternal(
diff --git a/chrome/browser/chromeos/login/language_switch_menu.cc b/chrome/browser/chromeos/login/language_switch_menu.cc
index 18df166..a731f9e 100644
--- a/chrome/browser/chromeos/login/language_switch_menu.cc
+++ b/chrome/browser/chromeos/login/language_switch_menu.cc
@@ -103,10 +103,12 @@ void LanguageSwitchMenu::SwitchLanguage(const std::string& locale) {
CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale;
// Enable the keyboard layouts that are necessary for the new locale.
+ // Change the current input method to the hardware keyboard layout
+ // since the input method currently in use may not be supported by the
+ // new locale.
input_method::EnableInputMethods(
locale, input_method::kKeyboardLayoutsOnly,
- CrosLibrary::Get()->GetKeyboardLibrary()->
- GetHardwareKeyboardLayoutName());
+ input_method::GetHardwareInputMethodDescriptor().id);
// The following line does not seem to affect locale anyhow. Maybe in
// future..
diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc
index c2bc45d..3223ac6 100644
--- a/chrome/browser/chromeos/login/screen_locker.cc
+++ b/chrome/browser/chromeos/login/screen_locker.cc
@@ -27,6 +27,7 @@
#include "chrome/browser/chromeos/cros/keyboard_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_util.h"
#include "chrome/browser/chromeos/language_preferences.h"
#include "chrome/browser/chromeos/login/authenticator.h"
#include "chrome/browser/chromeos/login/background_view.h"
@@ -122,18 +123,16 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer,
// 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* language =
+ chromeos::InputMethodLibrary* library =
chromeos::CrosLibrary::Get()->GetInputMethodLibrary();
- chromeos::KeyboardLibrary* keyboard =
- chromeos::CrosLibrary::Get()->GetKeyboardLibrary();
- saved_previous_input_method_id_ = language->previous_input_method().id;
- saved_current_input_method_id_ = language->current_input_method().id;
+ saved_previous_input_method_id_ = library->previous_input_method().id;
+ saved_current_input_method_id_ = library->current_input_method().id;
scoped_ptr<chromeos::InputMethodDescriptors> active_input_method_list(
- language->GetActiveInputMethods());
+ library->GetActiveInputMethods());
- const std::string hardware_keyboard =
- keyboard->GetHardwareKeyboardLayoutName(); // e.g. "xkb:us::eng"
+ const std::string hardware_keyboard_id =
+ chromeos::input_method::GetHardwareInputMethodDescriptor().id;
// We'll add the hardware keyboard if it's not included in
// |active_input_method_list| so that the user can always use the hardware
// keyboard on the screen locker.
@@ -149,17 +148,17 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer,
if (!StartsWithASCII(input_method_id, kValidInputMethodPrefix, true))
continue;
value.string_list_value.push_back(input_method_id);
- if (input_method_id == hardware_keyboard) {
+ if (input_method_id == hardware_keyboard_id) {
should_add_hardware_keyboard = false;
}
}
if (should_add_hardware_keyboard) {
- value.string_list_value.push_back(hardware_keyboard);
+ value.string_list_value.push_back(hardware_keyboard_id);
}
// We don't want to shut down the IME, even if the hardware layout is the
// only IME left.
- language->SetEnableAutoImeShutdown(false);
- language->SetImeConfig(
+ library->SetEnableAutoImeShutdown(false);
+ library->SetImeConfig(
chromeos::language_prefs::kGeneralSectionName,
chromeos::language_prefs::kPreloadEnginesConfigName,
value);
@@ -169,22 +168,22 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer,
void RestoreInputMethods() {
if (chromeos::CrosLibrary::Get()->EnsureLoaded() &&
!saved_active_input_method_list_.empty()) {
- chromeos::InputMethodLibrary* language =
+ chromeos::InputMethodLibrary* library =
chromeos::CrosLibrary::Get()->GetInputMethodLibrary();
chromeos::ImeConfigValue value;
value.type = chromeos::ImeConfigValue::kValueTypeStringList;
value.string_list_value = saved_active_input_method_list_;
- language->SetEnableAutoImeShutdown(true);
- language->SetImeConfig(
+ library->SetEnableAutoImeShutdown(true);
+ library->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())
- language->ChangeInputMethod(saved_previous_input_method_id_);
+ library->ChangeInputMethod(saved_previous_input_method_id_);
if (!saved_current_input_method_id_.empty())
- language->ChangeInputMethod(saved_current_input_method_id_);
+ library->ChangeInputMethod(saved_current_input_method_id_);
saved_previous_input_method_id_.clear();
saved_current_input_method_id_.clear();
diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc
index 0f57dae..e887d05 100644
--- a/chrome/browser/chromeos/preferences.cc
+++ b/chrome/browser/chromeos/preferences.cc
@@ -50,9 +50,9 @@ void Preferences::RegisterUserPrefs(PrefService* prefs) {
language_prefs::kHotkeyPreviousEngine);
prefs->RegisterStringPref(prefs::kLanguagePreferredLanguages,
kFallbackInputMethodLocale);
- KeyboardLibrary* keyboard_library = CrosLibrary::Get()->GetKeyboardLibrary();
- prefs->RegisterStringPref(prefs::kLanguagePreloadEngines,
- keyboard_library->GetHardwareKeyboardLayoutName());
+ prefs->RegisterStringPref(
+ prefs::kLanguagePreloadEngines,
+ input_method::GetHardwareInputMethodDescriptor().id);
for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
prefs->RegisterBooleanPref(
language_prefs::kChewingBooleanPrefs[i].pref_name,