diff options
author | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-13 02:05:07 +0000 |
---|---|---|
committer | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-13 02:05:07 +0000 |
commit | 2309775146992010901f711af529a2523706a208 (patch) | |
tree | 55f6f2f458730cd937391f9d00735cf12c23a331 | |
parent | 505d8e85e2f2383703d1932e0e4bc722a531c47f (diff) | |
download | chromium_src-2309775146992010901f711af529a2523706a208.zip chromium_src-2309775146992010901f711af529a2523706a208.tar.gz chromium_src-2309775146992010901f711af529a2523706a208.tar.bz2 |
Switch to preferred XKB layout when current input method is changed.
libcros part: http://codereview.chromium.org/2051009
BUG=chromium-os:3226
TEST=manual
Review URL: http://codereview.chromium.org/2003014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47107 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/cros/language_library.cc | 35 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/language_library_test.cc | 9 |
2 files changed, 7 insertions, 37 deletions
diff --git a/chrome/browser/chromeos/cros/language_library.cc b/chrome/browser/chromeos/cros/language_library.cc index 3f5ba68..d294efe 100644 --- a/chrome/browser/chromeos/cros/language_library.cc +++ b/chrome/browser/chromeos/cros/language_library.cc @@ -103,8 +103,7 @@ std::string LanguageLibrary::NormalizeLanguageCode( return two_letter_code; } -bool LanguageLibrary::IsKeyboardLayout( - const std::string& input_method_id) { +bool LanguageLibrary::IsKeyboardLayout(const std::string& input_method_id) { const bool kCaseInsensitive = false; return StartsWithASCII(input_method_id, "xkb:", kCaseInsensitive); } @@ -112,6 +111,7 @@ bool LanguageLibrary::IsKeyboardLayout( std::string LanguageLibrary::GetLanguageCodeFromDescriptor( const InputMethodDescriptor& descriptor) { // Special-case Chewing. Handle this as zh-TW, rather than zh. + // TODO: we should fix this issue in chewing engine rather than here. if (descriptor.id == "chewing" && descriptor.language_code == "zh") { return "zh-TW"; @@ -123,6 +123,8 @@ std::string LanguageLibrary::GetLanguageCodeFromDescriptor( // Add country codes to language codes of some XKB input methods to make // these compatible with Chrome's application locale codes like "en-US". // TODO(satorux): Maybe we need to handle "es" for "es-419". + // TODO: We should not rely on the format of the engine name. Should we add + // |country_code| in InputMethodDescriptor? if (IsKeyboardLayout(descriptor.id) && (language_code == "en" || language_code == "zh" || @@ -137,22 +139,6 @@ std::string LanguageLibrary::GetLanguageCodeFromDescriptor( return language_code; } -std::string LanguageLibrary::GetKeyboardLayoutName( - const std::string& input_method_id) { - std::vector<std::string> portions; - SplitString(input_method_id, ':', &portions); - if (portions.size() > 1 && !portions[1].empty()) { - std::string keyboard_layout = portions[1]; - if (portions.size() > 2 && !portions[2].empty()) { - keyboard_layout.append("("); - keyboard_layout.append(portions[2]); - keyboard_layout.append(")"); - } - return keyboard_layout; - } - return kDefaultKeyboardLayout; -} - LanguageLibraryImpl::LanguageLibraryImpl() : input_method_status_connection_(NULL), current_input_method_("", "", "", ""), @@ -351,16 +337,9 @@ void LanguageLibraryImpl::UpdateCurrentInputMethod( } DLOG(INFO) << "UpdateCurrentInputMethod (UI thread)"; - if (IsKeyboardLayout(current_input_method.id)) { - // If the new input method is a keyboard layout, switch the keyboard. - chromeos::SetCurrentKeyboardLayoutByName( - GetKeyboardLayoutName(current_input_method.id)); - } else { - // If the new input method is an IME, change the keyboard back to the - // default layout (US). TODO(satorux): What if the user is using a non-US - // keyboard, such as a Japanese keyboard? We need to rework this. - chromeos::SetCurrentKeyboardLayoutByName(kDefaultKeyboardLayout); - } + // Change the keyboard layout to a preferred layout for the input method. + chromeos::SetCurrentKeyboardLayoutByName( + current_input_method.keyboard_layout); current_input_method_ = current_input_method; FOR_EACH_OBSERVER(Observer, observers_, InputMethodChanged(this)); diff --git a/chrome/browser/chromeos/cros/language_library_test.cc b/chrome/browser/chromeos/cros/language_library_test.cc index 1f044cb..cd77898 100644 --- a/chrome/browser/chromeos/cros/language_library_test.cc +++ b/chrome/browser/chromeos/cros/language_library_test.cc @@ -44,13 +44,4 @@ TEST(LanguageLibraryTest, GetLanguageCodeFromDescriptor) { InputMethodDescriptor("xkb:uk::eng", "United Kingdom", "us", "eng"))); } -TEST(LanguageLibraryTest, GetKeyboardLayoutName) { - EXPECT_EQ("us", LanguageLibrary::GetKeyboardLayoutName("xkb:us::eng")); - EXPECT_EQ("gb", LanguageLibrary::GetKeyboardLayoutName("xkb:gb::eng")); - EXPECT_EQ("us(dvorak)", - LanguageLibrary::GetKeyboardLayoutName("xkb:us:dvorak:eng")); - EXPECT_EQ("us", LanguageLibrary::GetKeyboardLayoutName("")); - EXPECT_EQ("us", LanguageLibrary::GetKeyboardLayoutName("bogus")); -} - } // namespace chromeos |