Commit cd8f50a4 authored by Bao-Duy Tran's avatar Bao-Duy Tran Committed by Commit Bot

input_method_util: Remove unused methods; Reduce unnecessary visibility.

Also, fix typo in a method name.

Bug: None
Change-Id: I53912102768cc98dcad18377859d2bb8664ddb21
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2437539
Commit-Queue: Bao-Duy Tran <tranbaoduy@chromium.org>
Reviewed-by: default avatarMy Nguyen <myy@chromium.org>
Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811906}
parent 58a681f2
......@@ -474,28 +474,6 @@ bool InputMethodUtil::IsKeyboardLayout(const std::string& input_method_id) {
extension_ime_util::IsKeyboardLayoutExtension(input_method_id);
}
std::string InputMethodUtil::GetKeyboardLayoutName(
const std::string& input_method_id) const {
auto iter = id_to_descriptor_.find(input_method_id);
return (iter == id_to_descriptor_.end()) ?
"" : iter->second.GetPreferredKeyboardLayout();
}
std::string InputMethodUtil::GetInputMethodDisplayNameFromId(
const std::string& input_method_id) const {
base::string16 display_name;
if (!extension_ime_util::IsExtensionIME(input_method_id) &&
TranslateStringInternal(input_method_id, &display_name)) {
return base::UTF16ToUTF8(display_name);
}
const InputMethodDescriptor* descriptor =
GetInputMethodDescriptorFromId(input_method_id);
if (descriptor)
return GetLocalizedDisplayName(*descriptor);
// Return an empty string if the input method is not found.
return "";
}
base::string16 InputMethodUtil::GetInputMethodShortName(
const InputMethodDescriptor& input_method) const {
// TODO(shuchen): remove this method, as the client can directly use
......@@ -806,7 +784,7 @@ void InputMethodUtil::InitXkbInputMethodsForTesting(
}
const InputMethodUtil::InputMethodIdToDescriptorMap&
InputMethodUtil::GetIdToDesciptorMapForTesting() {
InputMethodUtil::GetIdToDescriptorMapForTesting() {
return id_to_descriptor_;
}
......
......@@ -34,21 +34,6 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) InputMethodUtil {
explicit InputMethodUtil(InputMethodDelegate* delegate);
~InputMethodUtil();
// Converts a string sent from IBus IME engines, which is written in English,
// into Chrome's string ID, then pulls internationalized resource string from
// the resource bundle and returns it. These functions are not thread-safe.
// Non-UI threads are not allowed to call them.
// The english_string to should be a xkb id with "xkb:...:...:..." format.
// TODO(shuchen): this method should be removed when finish the wrapping of
// xkb to extension.
base::string16 TranslateString(const std::string& english_string) const;
// Converts an input method ID to a language code of the IME. Returns "Eng"
// when |input_method_id| is unknown.
// Example: "hangul" => "ko"
std::string GetLanguageCodeFromInputMethodId(
const std::string& input_method_id) const;
// Converts an input method ID to a display name of the IME. Returns
// an empty strng when |input_method_id| is unknown.
// Examples: "pinyin" => "Pinyin"
......@@ -162,9 +147,6 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) InputMethodUtil {
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
// keyboard). This function is mostly used for testing, but may be used
// as the fallback, when there is no other choice.
......@@ -178,19 +160,19 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) InputMethodUtil {
InputMethodType type,
std::vector<std::string>* out_input_method_ids) const;
// Gets the keyboard layout name from the given input method ID.
// If the ID is invalid, an empty string will be returned.
// This function only supports xkb layouts.
//
// Examples:
//
// "xkb:us::eng" => "us"
// "xkb:us:dvorak:eng" => "us(dvorak)"
// "xkb:gb::eng" => "gb"
// "pinyin" => "us" (because Pinyin uses US keyboard layout)
std::string GetKeyboardLayoutName(const std::string& input_method_id) const;
// Gets the id to descriptor map for testing.
const InputMethodIdToDescriptorMap& GetIdToDescriptorMapForTesting();
private:
// Converts a string sent from IBus IME engines, which is written in English,
// into Chrome's string ID, then pulls internationalized resource string from
// the resource bundle and returns it. These functions are not thread-safe.
// Non-UI threads are not allowed to call them.
// The english_string to should be a xkb id with "xkb:...:...:..." format.
// TODO(shuchen): this method should be removed when finish the wrapping of
// xkb to extension.
base::string16 TranslateString(const std::string& english_string) const;
bool TranslateStringInternal(const std::string& english_string,
base::string16 *out_string) const;
......
......@@ -40,7 +40,7 @@ class TestableInputMethodUtil : public InputMethodUtil {
}
// Change access rights.
using InputMethodUtil::GetInputMethodIdsFromLanguageCodeInternal;
using InputMethodUtil::GetKeyboardLayoutName;
using InputMethodUtil::GetIdToDescriptorMapForTesting;
};
} // namespace
......@@ -239,27 +239,6 @@ TEST_F(InputMethodUtilTest, TestIsKeyboardLayout) {
EXPECT_FALSE(InputMethodUtil::IsKeyboardLayout(Id(pinyin_ime_id)));
}
TEST_F(InputMethodUtilTest, TestGetKeyboardLayoutName) {
// Unsupported case.
EXPECT_EQ("", util_.GetKeyboardLayoutName("UNSUPPORTED_ID"));
// Supported cases (samples).
EXPECT_EQ("us", util_.GetKeyboardLayoutName(Id(pinyin_ime_id)));
EXPECT_EQ("es", util_.GetKeyboardLayoutName(Id("xkb:es::spa")));
EXPECT_EQ("es(cat)", util_.GetKeyboardLayoutName(Id("xkb:es:cat:cat")));
EXPECT_EQ("gb(extd)", util_.GetKeyboardLayoutName(Id("xkb:gb:extd:eng")));
EXPECT_EQ("us", util_.GetKeyboardLayoutName(Id("xkb:us::eng")));
EXPECT_EQ("us(dvorak)", util_.GetKeyboardLayoutName(Id("xkb:us:dvorak:eng")));
EXPECT_EQ("us(colemak)",
util_.GetKeyboardLayoutName(Id("xkb:us:colemak:eng")));
EXPECT_EQ("de(neo)", util_.GetKeyboardLayoutName(Id("xkb:de:neo:ger")));
}
TEST_F(InputMethodUtilTest, TestGetInputMethodDisplayNameFromId) {
EXPECT_EQ("US", util_.GetInputMethodDisplayNameFromId("xkb:us::eng"));
EXPECT_EQ("", util_.GetInputMethodDisplayNameFromId("nonexistent"));
}
TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) {
EXPECT_EQ(nullptr, util_.GetInputMethodDescriptorFromId("non_existent"));
......@@ -429,7 +408,7 @@ TEST_F(InputMethodUtilTest, TestGetLanguageCodesFromInputMethodIds) {
// Test all supported descriptors to detect a typo in input_methods.txt.
TEST_F(InputMethodUtilTest, TestIBusInputMethodText) {
const std::map<std::string, InputMethodDescriptor>& id_to_descriptor =
util_.GetIdToDesciptorMapForTesting();
util_.GetIdToDescriptorMapForTesting();
for (const auto& it : id_to_descriptor) {
const std::string language_code = it.second.language_codes().at(0);
const base::string16 display_name =
......
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