diff options
author | shuchen <shuchen@chromium.org> | 2014-11-13 08:38:19 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-13 16:38:39 +0000 |
commit | 09194f83919025a67a0eaf3b610fa91f6e14e480 (patch) | |
tree | a1415ab1b1248804fc94b4a8af5d493a4bc03c19 /chromeos/ime | |
parent | 10318845b6eaca2658d96df562c34579df5a08f2 (diff) | |
download | chromium_src-09194f83919025a67a0eaf3b610fa91f6e14e480.zip chromium_src-09194f83919025a67a0eaf3b610fa91f6e14e480.tar.gz chromium_src-09194f83919025a67a0eaf3b610fa91f6e14e480.tar.bz2 |
Sort input method list as the sequence as XKB, M17n, T13, CJK.
BUG=432662
TEST=Verified on linux_chromeos.
Review URL: https://codereview.chromium.org/722183002
Cr-Commit-Position: refs/heads/master@{#304033}
Diffstat (limited to 'chromeos/ime')
-rw-r--r-- | chromeos/ime/component_extension_ime_manager.cc | 22 | ||||
-rw-r--r-- | chromeos/ime/component_extension_ime_manager_unittest.cc | 36 |
2 files changed, 45 insertions, 13 deletions
diff --git a/chromeos/ime/component_extension_ime_manager.cc b/chromeos/ime/component_extension_ime_manager.cc index 9a8cce1..6c7f068 100644 --- a/chromeos/ime/component_extension_ime_manager.cc +++ b/chromeos/ime/component_extension_ime_manager.cc @@ -59,6 +59,27 @@ const char* kLoginLayoutWhitelist[] = { "us(intl)" }; +// Gets the input method category according to the given input method id. +// This is used for sorting a list of input methods. +int GetInputMethodCategory(const std::string& id) { + const std::string engine_id = + chromeos::extension_ime_util::GetComponentIDByInputMethodID(id); + if (StartsWithASCII(engine_id, "xkb:", true)) + return 0; + if (StartsWithASCII(engine_id, "vkd_", true)) + return 1; + if (engine_id.find("-t-i0-") != std::string::npos && + !StartsWithASCII(engine_id, "zh-", true)) { + return 2; + } + return 3; +} + +bool InputMethodCompare(const input_method::InputMethodDescriptor& im1, + const input_method::InputMethodDescriptor& im2) { + return GetInputMethodCategory(im1.id()) < GetInputMethodCategory(im2.id()); +} + } // namespace ComponentExtensionEngine::ComponentExtensionEngine() { @@ -173,6 +194,7 @@ input_method::InputMethodDescriptors ime.input_view_url)); } } + std::stable_sort(result.begin(), result.end(), InputMethodCompare); return result; } diff --git a/chromeos/ime/component_extension_ime_manager_unittest.cc b/chromeos/ime/component_extension_ime_manager_unittest.cc index 9e8bdb3..840f3c4 100644 --- a/chromeos/ime/component_extension_ime_manager_unittest.cc +++ b/chromeos/ime/component_extension_ime_manager_unittest.cc @@ -28,24 +28,24 @@ class ComponentExtensionIMEManagerTest : public testing::Test { ext1.path = base::FilePath("ext1_file_path"); ComponentExtensionEngine ext1_engine1; - ext1_engine1.engine_id = "ext1_engine1_engine_id"; + ext1_engine1.engine_id = "zh-t-i0-pinyin"; ext1_engine1.display_name = "ext1_engine_1_display_name"; - ext1_engine1.language_codes.push_back("en"); + ext1_engine1.language_codes.push_back("zh-CN"); ext1_engine1.layouts.push_back("us"); ext1.engines.push_back(ext1_engine1); ComponentExtensionEngine ext1_engine2; - ext1_engine2.engine_id = "ext1_engine2_engine_id"; + ext1_engine2.engine_id = "mozc_us"; ext1_engine2.display_name = "ext1_engine2_display_name"; - ext1_engine2.language_codes.push_back("en"); + ext1_engine2.language_codes.push_back("jp"); ext1_engine2.layouts.push_back("us"); ext1.engines.push_back(ext1_engine2); ComponentExtensionEngine ext1_engine3; - ext1_engine3.engine_id = "ext1_engine3_engine_id"; + ext1_engine3.engine_id = "xkb:ru::rus"; ext1_engine3.display_name = "ext1_engine3_display_name"; - ext1_engine3.language_codes.push_back("ja"); - ext1_engine3.layouts.push_back("us"); + ext1_engine3.language_codes.push_back("ru"); + ext1_engine3.layouts.push_back("ru"); ext1.engines.push_back(ext1_engine3); ime_list_.push_back(ext1); @@ -56,24 +56,24 @@ class ComponentExtensionIMEManagerTest : public testing::Test { ext2.path = base::FilePath("ext2_file_path"); ComponentExtensionEngine ext2_engine1; - ext2_engine1.engine_id = "ext2_engine1_engine_id"; + ext2_engine1.engine_id = "vkd_ru_phone_aatseel"; ext2_engine1.display_name = "ext2_engine_1_display_name"; - ext2_engine1.language_codes.push_back("en"); + ext2_engine1.language_codes.push_back("ru"); ext2_engine1.layouts.push_back("us"); ext2.engines.push_back(ext2_engine1); ComponentExtensionEngine ext2_engine2; - ext2_engine2.engine_id = "ext2_engine2_engine_id"; + ext2_engine2.engine_id = "vkd_vi_telex"; ext2_engine2.display_name = "ext2_engine2_display_name"; ext2_engine2.language_codes.push_back("hi"); ext2_engine2.layouts.push_back("us"); ext2.engines.push_back(ext2_engine2); ComponentExtensionEngine ext2_engine3; - ext2_engine3.engine_id = "ext2_engine3_engine_id"; + ext2_engine3.engine_id = "xkb:us::eng"; ext2_engine3.display_name = "ext2_engine3_display_name"; - ext2_engine3.language_codes.push_back("ja"); - ext2_engine3.layouts.push_back("jp"); + ext2_engine3.language_codes.push_back("us"); + ext2_engine3.layouts.push_back("us"); ext2.engines.push_back(ext2_engine3); ime_list_.push_back(ext2); @@ -191,6 +191,16 @@ TEST_F(ComponentExtensionIMEManagerTest, GetAllIMEAsInputMethodDescriptor) { total_ime_size += ime_list_[i].engines.size(); } EXPECT_EQ(total_ime_size, descriptors.size()); + + // Verify order + for (size_t i = 0; i < descriptors.size(); ++i) { + const input_method::InputMethodDescriptor& d = descriptors[i]; + if (i < 2) { + EXPECT_TRUE(d.id().find("xkb:") != std::string::npos); + } else if (i >= 2 && i < 4) { + EXPECT_TRUE(d.id().find("vkd_") != std::string::npos); + } + } } } // namespace |