Commit dcac15dc authored by shuchen@chromium.org's avatar shuchen@chromium.org

Adds whitelisted non-extension-based input methods if no component extensions...

Adds whitelisted non-extension-based input methods if no component extensions are at present (e.g. linux_chromeos).
And also clean up some useless code.

BUG=364712
TEST=Verified it works on linux_chromeos and no regression on Pixel device.

Review URL: https://codereview.chromium.org/306053005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274589 0039d316-1c4b-4281-b951-d872f2087c98
parent cd3f8a6d
...@@ -110,10 +110,8 @@ void InputMethodManagerImpl::SetState(State new_state) { ...@@ -110,10 +110,8 @@ void InputMethodManagerImpl::SetState(State new_state) {
scoped_ptr<InputMethodDescriptors> scoped_ptr<InputMethodDescriptors>
InputMethodManagerImpl::GetSupportedInputMethods() const { InputMethodManagerImpl::GetSupportedInputMethods() const {
scoped_ptr<InputMethodDescriptors> whitelist_imes = if (!IsXkbComponentExtensionAvailable())
whitelist_.GetSupportedInputMethods(); return whitelist_.GetSupportedInputMethods().Pass();
if (!component_extension_ime_manager_->IsInitialized())
return whitelist_imes.Pass();
return scoped_ptr<InputMethodDescriptors>(new InputMethodDescriptors).Pass(); return scoped_ptr<InputMethodDescriptors>(new InputMethodDescriptors).Pass();
} }
...@@ -325,9 +323,7 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal( ...@@ -325,9 +323,7 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal(
} }
if (!component_extension_ime_manager_->IsInitialized() && if (!component_extension_ime_manager_->IsInitialized() &&
(!InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch) || !InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) {
extension_ime_util::IsKeyboardLayoutExtension(
input_method_id_to_switch))) {
// We can't change input method before the initialization of // We can't change input method before the initialization of
// component extension ime manager. ChangeInputMethod will be // component extension ime manager. ChangeInputMethod will be
// called with |pending_input_method_| when the initialization is // called with |pending_input_method_| when the initialization is
...@@ -405,6 +401,18 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal( ...@@ -405,6 +401,18 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal(
return true; return true;
} }
bool InputMethodManagerImpl::IsXkbComponentExtensionAvailable() const {
if (!component_extension_ime_manager_->IsInitialized())
return false;
InputMethodDescriptors imes =
component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor();
for (size_t i = 0; i < imes.size(); ++i) {
if (StartsWithASCII(imes[i].id(), "xkb:", true))
return true;
}
return false;
}
void InputMethodManagerImpl::OnComponentExtensionInitialized( void InputMethodManagerImpl::OnComponentExtensionInitialized(
scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
...@@ -413,14 +421,7 @@ void InputMethodManagerImpl::OnComponentExtensionInitialized( ...@@ -413,14 +421,7 @@ void InputMethodManagerImpl::OnComponentExtensionInitialized(
component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor(); component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor();
// In case of XKB extension is not available (e.g. linux_chromeos), don't // In case of XKB extension is not available (e.g. linux_chromeos), don't
// reset the input methods in InputMethodUtil, Instead append input methods. // reset the input methods in InputMethodUtil, Instead append input methods.
bool xkb_found = false; if (IsXkbComponentExtensionAvailable())
for (size_t i = 0; i < imes.size(); ++i) {
if (StartsWithASCII(imes[i].id(), "xkb:", true)) {
xkb_found = true;
break;
}
}
if (xkb_found)
util_.ResetInputMethods(imes); util_.ResetInputMethods(imes);
else else
util_.AppendInputMethods(imes); util_.AppendInputMethods(imes);
......
...@@ -142,6 +142,10 @@ class InputMethodManagerImpl : public InputMethodManager, ...@@ -142,6 +142,10 @@ class InputMethodManagerImpl : public InputMethodManager,
bool ChangeInputMethodInternal(const std::string& input_method_id, bool ChangeInputMethodInternal(const std::string& input_method_id,
bool show_message); bool show_message);
// Gets whether the XKB extension is loaded successfully by checking the XKB
// input methods in input methods in |component_extension_ime_manager_|.
bool IsXkbComponentExtensionAvailable() const;
// Called when the ComponentExtensionIMEManagerDelegate is initialized. // Called when the ComponentExtensionIMEManagerDelegate is initialized.
void OnComponentExtensionInitialized( void OnComponentExtensionInitialized(
scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate); scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate);
......
...@@ -145,6 +145,13 @@ class InputMethodUtil { ...@@ -145,6 +145,13 @@ class InputMethodUtil {
// Initializes the extension based xkb IMEs for testing. // Initializes the extension based xkb IMEs for testing.
void InitXkbInputMethodsForTesting(); void InitXkbInputMethodsForTesting();
// Map from input method ID to associated input method descriptor.
typedef std::map<
std::string, InputMethodDescriptor> InputMethodIdToDescriptorMap;
// Gets the id to desctiptor map for testing.
const InputMethodIdToDescriptorMap& GetIdToDesciptorMapForTesting();
// Returns the fallback input method descriptor (the very basic US // Returns the fallback input method descriptor (the very basic US
// keyboard). This function is mostly used for testing, but may be used // keyboard). This function is mostly used for testing, but may be used
// as the fallback, when there is no other choice. // as the fallback, when there is no other choice.
...@@ -158,13 +165,6 @@ class InputMethodUtil { ...@@ -158,13 +165,6 @@ class InputMethodUtil {
InputMethodType type, InputMethodType type,
std::vector<std::string>* out_input_method_ids) const; std::vector<std::string>* out_input_method_ids) const;
// protected: for unit testing as well.
void ReloadInternalMaps();
// All input methods that are supported, including ones not active.
// protected: for testing.
scoped_ptr<InputMethodDescriptors> supported_input_methods_;
// Gets the keyboard layout name from the given input method ID. // Gets the keyboard layout name from the given input method ID.
// If the ID is invalid, an empty string will be returned. // If the ID is invalid, an empty string will be returned.
// This function only supports xkb layouts. // This function only supports xkb layouts.
...@@ -183,14 +183,8 @@ class InputMethodUtil { ...@@ -183,14 +183,8 @@ class InputMethodUtil {
// Map from language code to associated input method IDs, etc. // Map from language code to associated input method IDs, etc.
typedef std::multimap<std::string, std::string> LanguageCodeToIdsMap; typedef std::multimap<std::string, std::string> LanguageCodeToIdsMap;
// Map from input method ID to associated input method descriptor.
typedef std::map<
std::string, InputMethodDescriptor> InputMethodIdToDescriptorMap;
// Map from component extention IME id to associated input method descriptor.
typedef std::map<std::string, InputMethodDescriptor> ComponentExtIMEMap;
LanguageCodeToIdsMap language_code_to_ids_; LanguageCodeToIdsMap language_code_to_ids_;
std::map<std::string, std::string> id_to_language_code_;
InputMethodIdToDescriptorMap id_to_descriptor_; InputMethodIdToDescriptorMap id_to_descriptor_;
std::map<std::string, std::string> xkb_layout_to_indicator_; std::map<std::string, std::string> xkb_layout_to_indicator_;
......
...@@ -39,8 +39,6 @@ class TestableInputMethodUtil : public InputMethodUtil { ...@@ -39,8 +39,6 @@ class TestableInputMethodUtil : public InputMethodUtil {
// Change access rights. // Change access rights.
using InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal; using InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal;
using InputMethodUtil::GetKeyboardLayoutName; using InputMethodUtil::GetKeyboardLayoutName;
using InputMethodUtil::ReloadInternalMaps;
using InputMethodUtil::supported_input_methods_;
}; };
} // namespace } // namespace
...@@ -121,19 +119,7 @@ class InputMethodUtilTest : public testing::Test { ...@@ -121,19 +119,7 @@ class InputMethodUtilTest : public testing::Test {
}; };
TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) { TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) {
// Test normal cases. Two-letter language code should be returned. // Test invalid cases. Two-letter language code should be returned.
{
InputMethodDescriptor desc = GetDesc("vkd_fa", // input method id
"us", // keyboard layout name
"fa", // language name
""); // indicator
EXPECT_EQ(ASCIIToUTF16("FA"), util_.GetInputMethodShortName(desc));
}
{
InputMethodDescriptor desc = GetDesc("hangul_2set", "us", "ko", "");
EXPECT_EQ(base::UTF8ToUTF16("\xed\x95\x9c"),
util_.GetInputMethodShortName(desc));
}
{ {
InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", ""); InputMethodDescriptor desc = GetDesc("invalid-id", "us", "xx", "");
// Upper-case string of the unknown language code, "xx", should be returned. // Upper-case string of the unknown language code, "xx", should be returned.
...@@ -305,11 +291,6 @@ TEST_F(InputMethodUtilTest, TestGetKeyboardLayoutName) { ...@@ -305,11 +291,6 @@ TEST_F(InputMethodUtilTest, TestGetKeyboardLayoutName) {
EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName(Id("xkb:de:neo:ger"))); EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName(Id("xkb:de:neo:ger")));
} }
TEST_F(InputMethodUtilTest, TestGetLanguageCodeFromInputMethodId) {
// Make sure that the -CN is added properly.
EXPECT_EQ("zh-CN", util_.GetLanguageCodeFromInputMethodId(Id(pinyin_ime_id)));
}
TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) { TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) {
EXPECT_EQ("US", EXPECT_EQ("US",
util_.GetInputMethodDisplayNameFromId("xkb:us::eng")); util_.GetInputMethodDisplayNameFromId("xkb:us::eng"));
...@@ -448,9 +429,11 @@ TEST_F(InputMethodUtilTest, TestGetLanguageCodesFromInputMethodIds) { ...@@ -448,9 +429,11 @@ TEST_F(InputMethodUtilTest, TestGetLanguageCodesFromInputMethodIds) {
// Test all supported descriptors to detect a typo in input_methods.txt. // Test all supported descriptors to detect a typo in input_methods.txt.
TEST_F(InputMethodUtilTest, TestIBusInputMethodText) { TEST_F(InputMethodUtilTest, TestIBusInputMethodText) {
for (size_t i = 0; i < util_.supported_input_methods_->size(); ++i) { const std::map<std::string, InputMethodDescriptor>& id_to_descriptor =
const std::string language_code = util_.GetIdToDesciptorMapForTesting();
util_.supported_input_methods_->at(i).language_codes().at(0); for (std::map<std::string, InputMethodDescriptor>::const_iterator it =
id_to_descriptor.begin(); it != id_to_descriptor.end(); ++it) {
const std::string language_code = it->second.language_codes().at(0);
const base::string16 display_name = const base::string16 display_name =
l10n_util::GetDisplayNameForLocale(language_code, "en", false); l10n_util::GetDisplayNameForLocale(language_code, "en", false);
// Only two formats, like "fr" (lower case) and "en-US" (lower-upper), are // Only two formats, like "fr" (lower case) and "en-US" (lower-upper), are
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <vector> #include <vector>
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chromeos/ime/extension_ime_util.h"
#include "chromeos/ime/input_method_descriptor.h" #include "chromeos/ime/input_method_descriptor.h"
#include "chromeos/ime/input_methods.h" #include "chromeos/ime/input_methods.h"
...@@ -42,7 +43,8 @@ InputMethodWhitelist::GetSupportedInputMethods() const { ...@@ -42,7 +43,8 @@ InputMethodWhitelist::GetSupportedInputMethods() const {
DCHECK(!languages.empty()); DCHECK(!languages.empty());
input_methods->push_back(InputMethodDescriptor( input_methods->push_back(InputMethodDescriptor(
kInputMethods[i].input_method_id, extension_ime_util::GetInputMethodIDByEngineID(
kInputMethods[i].input_method_id),
"", "",
kInputMethods[i].indicator, kInputMethods[i].indicator,
layouts, layouts,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment