summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 23:00:38 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 23:00:38 +0000
commitd5e28a3e5402329a9f50075ed8d6417feeea7c71 (patch)
tree8f902ea56c5460eefb1b878bb50bc9edd762fd36 /chrome
parent82114f59366794a020af471abc3c83ddfd34cde3 (diff)
downloadchromium_src-d5e28a3e5402329a9f50075ed8d6417feeea7c71.zip
chromium_src-d5e28a3e5402329a9f50075ed8d6417feeea7c71.tar.gz
chromium_src-d5e28a3e5402329a9f50075ed8d6417feeea7c71.tar.bz2
ash: Add an entry for IME in the tray.
BUG=118862 TEST=none Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=127748 Review URL: https://chromiumcodereview.appspot.com/9751005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/input_method/input_method_manager.h3
-rw-r--r--chrome/browser/chromeos/input_method/input_method_util.cc80
-rw-r--r--chrome/browser/chromeos/input_method/input_method_util.h3
-rw-r--r--chrome/browser/chromeos/input_method/input_method_util_unittest.cc112
-rw-r--r--chrome/browser/chromeos/status/input_method_menu.cc84
-rw-r--r--chrome/browser/chromeos/status/input_method_menu.h5
-rw-r--r--chrome/browser/chromeos/status/input_method_menu_button.cc3
-rw-r--r--chrome/browser/chromeos/status/input_method_menu_unittest.cc104
-rw-r--r--chrome/browser/chromeos/system/ash_system_tray_delegate.cc55
9 files changed, 257 insertions, 192 deletions
diff --git a/chrome/browser/chromeos/input_method/input_method_manager.h b/chrome/browser/chromeos/input_method/input_method_manager.h
index a7ff166..5aa3114 100644
--- a/chrome/browser/chromeos/input_method/input_method_manager.h
+++ b/chrome/browser/chromeos/input_method/input_method_manager.h
@@ -129,7 +129,8 @@ class InputMethodManager {
// Returns the list of input methods we can select (i.e. active). If the cros
// library is not found or IBus/DBus daemon is not alive, this function
- // returns a fallback input method list (and never returns NULL).
+ // returns a fallback input method list (and never returns NULL). Caller has
+ // to delete the returned list.
virtual InputMethodDescriptors* GetActiveInputMethods() = 0;
// Returns the number of active input methods.
diff --git a/chrome/browser/chromeos/input_method/input_method_util.cc b/chrome/browser/chromeos/input_method/input_method_util.cc
index 8006a31..72c4655 100644
--- a/chrome/browser/chromeos/input_method/input_method_util.cc
+++ b/chrome/browser/chromeos/input_method/input_method_util.cc
@@ -24,6 +24,46 @@
#include "ui/base/l10n/l10n_util_collator.h"
#include "unicode/uloc.h"
+namespace {
+
+// A mapping from an input method id to a string for the language indicator. The
+// mapping is necessary since some input methods belong to the same language.
+// For example, both "xkb:us::eng" and "xkb:us:dvorak:eng" are for US English.
+const struct {
+ const char* input_method_id;
+ const char* indicator_text;
+} kMappingFromIdToIndicatorText[] = {
+ // To distinguish from "xkb:us::eng"
+ { "xkb:us:altgr-intl:eng", "EXTD" },
+ { "xkb:us:dvorak:eng", "DV" },
+ { "xkb:us:intl:eng", "INTL" },
+ { "xkb:us:colemak:eng", "CO" },
+ { "english-m", "??" },
+ { "xkb:de:neo:ger", "NEO" },
+ // To distinguish from "xkb:es::spa"
+ { "xkb:es:cat:cat", "CAS" },
+ // To distinguish from "xkb:gb::eng"
+ { "xkb:gb:dvorak:eng", "DV" },
+ // To distinguish from "xkb:jp::jpn"
+ { "mozc", "\xe3\x81\x82" }, // U+3042, Japanese Hiragana letter A in UTF-8.
+ { "mozc-dv", "\xe3\x81\x82" },
+ { "mozc-jp", "\xe3\x81\x82" },
+ { "zinnia-japanese", "\xe6\x89\x8b" }, // U+624B, "hand"
+ // For simplified Chinese input methods
+ { "pinyin", "\xe6\x8b\xbc" }, // U+62FC
+ { "pinyin-dv", "\xe6\x8b\xbc" },
+ // For traditional Chinese input methods
+ { "mozc-chewing", "\xe9\x85\xb7" }, // U+9177
+ { "m17n:zh:cangjie", "\xe5\x80\x89" }, // U+5009
+ { "m17n:zh:quick", "\xe9\x80\x9f" }, // U+901F
+ // For Hangul input method.
+ { "mozc-hangul", "\xed\x95\x9c" }, // U+D55C
+};
+
+const size_t kMappingFromIdToIndicatorTextLen =
+ ARRAYSIZE_UNSAFE(kMappingFromIdToIndicatorText);
+}
+
namespace chromeos {
namespace input_method {
@@ -319,6 +359,46 @@ std::string InputMethodUtil::GetInputMethodDisplayNameFromId(
return "";
}
+string16 InputMethodUtil::GetInputMethodShortName(
+ const InputMethodDescriptor& input_method) const {
+ // For the status area, we use two-letter, upper-case language code like
+ // "US" and "JP".
+ string16 text;
+
+ // Check special cases first.
+ for (size_t i = 0; i < kMappingFromIdToIndicatorTextLen; ++i) {
+ if (kMappingFromIdToIndicatorText[i].input_method_id == input_method.id()) {
+ text = UTF8ToUTF16(kMappingFromIdToIndicatorText[i].indicator_text);
+ break;
+ }
+ }
+
+ // Display the keyboard layout name when using a keyboard layout.
+ if (text.empty() &&
+ IsKeyboardLayout(input_method.id())) {
+ const size_t kMaxKeyboardLayoutNameLen = 2;
+ const string16 keyboard_layout =
+ UTF8ToUTF16(GetKeyboardLayoutName(input_method.id()));
+ text = StringToUpperASCII(keyboard_layout).substr(
+ 0, kMaxKeyboardLayoutNameLen);
+ }
+
+ // TODO(yusukes): Some languages have two or more input methods. For example,
+ // Thai has 3, Vietnamese has 4. If these input methods could be activated at
+ // the same time, we should do either of the following:
+ // (1) Add mappings to |kMappingFromIdToIndicatorText|
+ // (2) Add suffix (1, 2, ...) to |text| when ambiguous.
+
+ if (text.empty()) {
+ const size_t kMaxLanguageNameLen = 2;
+ const std::string language_code = input_method.language_code();
+ text = StringToUpperASCII(UTF8ToUTF16(language_code)).substr(
+ 0, kMaxLanguageNameLen);
+ }
+ DCHECK(!text.empty());
+ return text;
+}
+
const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromId(
const std::string& input_method_id) const {
InputMethodIdToDescriptorMap::const_iterator iter
diff --git a/chrome/browser/chromeos/input_method/input_method_util.h b/chrome/browser/chromeos/input_method/input_method_util.h
index 8f260ab..f99bb08 100644
--- a/chrome/browser/chromeos/input_method/input_method_util.h
+++ b/chrome/browser/chromeos/input_method/input_method_util.h
@@ -72,6 +72,9 @@ class InputMethodUtil {
std::string GetInputMethodDisplayNameFromId(
const std::string& input_method_id) const;
+ string16 GetInputMethodShortName(
+ const InputMethodDescriptor& input_method) const;
+
// Converts an input method ID to an input method descriptor. Returns NULL
// when |input_method_id| is unknown.
// Example: "pinyin" => { id: "pinyin", display_name: "Pinyin",
diff --git a/chrome/browser/chromeos/input_method/input_method_util_unittest.cc b/chrome/browser/chromeos/input_method/input_method_util_unittest.cc
index 7a3f82f..aae6745 100644
--- a/chrome/browser/chromeos/input_method/input_method_util_unittest.cc
+++ b/chrome/browser/chromeos/input_method/input_method_util_unittest.cc
@@ -34,6 +34,14 @@ namespace input_method {
namespace {
+InputMethodDescriptor GetDesc(IBusController* controller,
+ const std::string& id,
+ const std::string& raw_layout,
+ const std::string& language_code) {
+ return controller->CreateInputMethodDescriptor(id, "", raw_layout,
+ language_code);
+}
+
class TestableInputMethodUtil : public InputMethodUtil {
public:
explicit TestableInputMethodUtil(InputMethodDescriptors* methods)
@@ -58,6 +66,110 @@ class InputMethodUtilTest : public testing::Test {
TestableInputMethodUtil util_;
};
+TEST_F(InputMethodUtilTest, GetInputMethodShortNameTest) {
+ scoped_ptr<IBusController> controller(IBusController::Create());
+
+ // Test normal cases. Two-letter language code should be returned.
+ {
+ InputMethodDescriptor desc = GetDesc(controller.get(),
+ "m17n:fa:isiri", // input method id
+ "us", // keyboard layout name
+ "fa"); // language name
+ EXPECT_EQ(ASCIIToUTF16("FA"), util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "mozc-hangul", "us", "ko");
+ EXPECT_EQ(UTF8ToUTF16("\xed\x95\x9c"),
+ util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "invalid-id", "us", "xx");
+ // Upper-case string of the unknown language code, "xx", should be returned.
+ EXPECT_EQ(ASCIIToUTF16("XX"), util_.GetInputMethodShortName(desc));
+ }
+
+ // Test special cases.
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "xkb:us:dvorak:eng", "us", "en-US");
+ EXPECT_EQ(ASCIIToUTF16("DV"), util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "xkb:us:colemak:eng", "us", "en-US");
+ EXPECT_EQ(ASCIIToUTF16("CO"), util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "xkb:us:altgr-intl:eng", "us", "en-US");
+ EXPECT_EQ(ASCIIToUTF16("EXTD"), util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "xkb:us:intl:eng", "us", "en-US");
+ EXPECT_EQ(ASCIIToUTF16("INTL"), util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "xkb:de:neo:ger", "de(neo)", "de");
+ EXPECT_EQ(ASCIIToUTF16("NEO"), util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "xkb:es:cat:cat", "es(cat)", "ca");
+ EXPECT_EQ(ASCIIToUTF16("CAS"), util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc = GetDesc(controller.get(), "mozc", "us", "ja");
+ EXPECT_EQ(UTF8ToUTF16("\xe3\x81\x82"),
+ util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "mozc-jp", "jp", "ja");
+ EXPECT_EQ(UTF8ToUTF16("\xe3\x81\x82"),
+ util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "zinnia-japanese", "us", "ja");
+ EXPECT_EQ(UTF8ToUTF16("\xe6\x89\x8b"),
+ util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "pinyin", "us", "zh-CN");
+ EXPECT_EQ(UTF8ToUTF16("\xe6\x8b\xbc"),
+ util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "pinyin-dv", "us(dvorak)", "zh-CN");
+ EXPECT_EQ(UTF8ToUTF16("\xe6\x8b\xbc"),
+ util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "mozc-chewing", "us", "zh-TW");
+ EXPECT_EQ(UTF8ToUTF16("\xe9\x85\xb7"),
+ util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "m17n:zh:cangjie", "us", "zh-TW");
+ EXPECT_EQ(UTF8ToUTF16("\xe5\x80\x89"),
+ util_.GetInputMethodShortName(desc));
+ }
+ {
+ InputMethodDescriptor desc =
+ GetDesc(controller.get(), "m17n:zh:quick", "us", "zh-TW");
+ EXPECT_EQ(UTF8ToUTF16("\xe9\x80\x9f"),
+ util_.GetInputMethodShortName(desc));
+ }
+}
+
TEST_F(InputMethodUtilTest, TestGetStringUTF8) {
EXPECT_EQ(UTF8ToUTF16("Pinyin input method"),
util_.TranslateString("pinyin"));
diff --git a/chrome/browser/chromeos/status/input_method_menu.cc b/chrome/browser/chromeos/status/input_method_menu.cc
index 3771ce0..8fe6ae8 100644
--- a/chrome/browser/chromeos/status/input_method_menu.cc
+++ b/chrome/browser/chromeos/status/input_method_menu.cc
@@ -84,42 +84,6 @@ enum {
const int kRadioGroupLanguage = 1 << 16;
const int kRadioGroupNone = -1;
-// A mapping from an input method id to a string for the language indicator. The
-// mapping is necessary since some input methods belong to the same language.
-// For example, both "xkb:us::eng" and "xkb:us:dvorak:eng" are for US English.
-const struct {
- const char* input_method_id;
- const char* indicator_text;
-} kMappingFromIdToIndicatorText[] = {
- // To distinguish from "xkb:us::eng"
- { "xkb:us:altgr-intl:eng", "EXTD" },
- { "xkb:us:dvorak:eng", "DV" },
- { "xkb:us:intl:eng", "INTL" },
- { "xkb:us:colemak:eng", "CO" },
- { "english-m", "??" },
- { "xkb:de:neo:ger", "NEO" },
- // To distinguish from "xkb:es::spa"
- { "xkb:es:cat:cat", "CAS" },
- // To distinguish from "xkb:gb::eng"
- { "xkb:gb:dvorak:eng", "DV" },
- // To distinguish from "xkb:jp::jpn"
- { "mozc", "\xe3\x81\x82" }, // U+3042, Japanese Hiragana letter A in UTF-8.
- { "mozc-dv", "\xe3\x81\x82" },
- { "mozc-jp", "\xe3\x81\x82" },
- { "zinnia-japanese", "\xe6\x89\x8b" }, // U+624B, "hand"
- // For simplified Chinese input methods
- { "pinyin", "\xe6\x8b\xbc" }, // U+62FC
- { "pinyin-dv", "\xe6\x8b\xbc" },
- // For traditional Chinese input methods
- { "mozc-chewing", "\xe9\x85\xb7" }, // U+9177
- { "m17n:zh:cangjie", "\xe5\x80\x89" }, // U+5009
- { "m17n:zh:quick", "\xe9\x80\x9f" }, // U+901F
- // For Hangul input method.
- { "mozc-hangul", "\xed\x95\x9c" }, // U+D55C
-};
-const size_t kMappingFromIdToIndicatorTextLen =
- ARRAYSIZE_UNSAFE(kMappingFromIdToIndicatorText);
-
// Returns the language name for the given |language_code|.
string16 GetLanguageName(const std::string& language_code) {
const string16 language_name = l10n_util::GetDisplayNameForLocale(
@@ -506,7 +470,9 @@ void InputMethodMenu::ActiveInputMethodsChanged(
void InputMethodMenu::UpdateUIFromInputMethod(
const input_method::InputMethodDescriptor& input_method,
size_t num_active_input_methods) {
- const string16 name = GetTextForIndicator(input_method);
+ InputMethodManager* manager = InputMethodManager::GetInstance();
+ const string16 name = manager->GetInputMethodUtil()->
+ GetInputMethodShortName(input_method);
const string16 tooltip = GetTextForMenu(input_method);
UpdateUI(input_method.id(), name, tooltip, num_active_input_methods);
}
@@ -599,50 +565,6 @@ bool InputMethodMenu::IndexPointsToConfigureImeMenuItem(int index) const {
(model_->GetCommandIdAt(index) == COMMAND_ID_CUSTOMIZE_LANGUAGE));
}
-string16 InputMethodMenu::GetTextForIndicator(
- const input_method::InputMethodDescriptor& input_method) {
- input_method::InputMethodManager* manager =
- input_method::InputMethodManager::GetInstance();
-
- // For the status area, we use two-letter, upper-case language code like
- // "US" and "JP".
- string16 text;
-
- // Check special cases first.
- for (size_t i = 0; i < kMappingFromIdToIndicatorTextLen; ++i) {
- if (kMappingFromIdToIndicatorText[i].input_method_id == input_method.id()) {
- text = UTF8ToUTF16(kMappingFromIdToIndicatorText[i].indicator_text);
- break;
- }
- }
-
- // Display the keyboard layout name when using a keyboard layout.
- if (text.empty() &&
- input_method::InputMethodUtil::IsKeyboardLayout(input_method.id())) {
- const size_t kMaxKeyboardLayoutNameLen = 2;
- const string16 keyboard_layout =
- UTF8ToUTF16(manager->GetInputMethodUtil()->GetKeyboardLayoutName(
- input_method.id()));
- text = StringToUpperASCII(keyboard_layout).substr(
- 0, kMaxKeyboardLayoutNameLen);
- }
-
- // TODO(yusukes): Some languages have two or more input methods. For example,
- // Thai has 3, Vietnamese has 4. If these input methods could be activated at
- // the same time, we should do either of the following:
- // (1) Add mappings to |kMappingFromIdToIndicatorText|
- // (2) Add suffix (1, 2, ...) to |text| when ambiguous.
-
- if (text.empty()) {
- const size_t kMaxLanguageNameLen = 2;
- const std::string language_code = input_method.language_code();
- text = StringToUpperASCII(UTF8ToUTF16(language_code)).substr(
- 0, kMaxLanguageNameLen);
- }
- DCHECK(!text.empty());
- return text;
-}
-
string16 InputMethodMenu::GetTextForMenu(
const input_method::InputMethodDescriptor& input_method) {
if (!input_method.name().empty()) {
diff --git a/chrome/browser/chromeos/status/input_method_menu.h b/chrome/browser/chromeos/status/input_method_menu.h
index 23083aa..93c789b 100644
--- a/chrome/browser/chromeos/status/input_method_menu.h
+++ b/chrome/browser/chromeos/status/input_method_menu.h
@@ -112,11 +112,6 @@ class InputMethodMenu
// Registers input method preferences for the login screen.
static void RegisterPrefs(PrefService* local_state);
- // Returns a string for the indicator on top right corner of the Chrome
- // window. The method is public for unit tests.
- static string16 GetTextForIndicator(
- const input_method::InputMethodDescriptor& input_method);
-
// Returns a string for the drop-down menu and the tooltip for the indicator.
// The method is public for unit tests.
static string16 GetTextForMenu(
diff --git a/chrome/browser/chromeos/status/input_method_menu_button.cc b/chrome/browser/chromeos/status/input_method_menu_button.cc
index 1fb19f3..6b2f027 100644
--- a/chrome/browser/chromeos/status/input_method_menu_button.cc
+++ b/chrome/browser/chromeos/status/input_method_menu_button.cc
@@ -147,7 +147,8 @@ void InputMethodMenuButton::UpdateUIFromCurrentInputMethod() {
input_method::InputMethodManager::GetInstance();
const input_method::InputMethodDescriptor& input_method =
input_method_manager->GetCurrentInputMethod();
- const string16 name = InputMethodMenu::GetTextForIndicator(input_method);
+ const string16 name = input_method_manager->GetInputMethodUtil()->
+ GetInputMethodShortName(input_method);
const string16 tooltip = InputMethodMenu::GetTextForMenu(input_method);
const size_t num_active_input_methods =
input_method_manager->GetNumActiveInputMethods();
diff --git a/chrome/browser/chromeos/status/input_method_menu_unittest.cc b/chrome/browser/chromeos/status/input_method_menu_unittest.cc
index 387db05..9361c74 100644
--- a/chrome/browser/chromeos/status/input_method_menu_unittest.cc
+++ b/chrome/browser/chromeos/status/input_method_menu_unittest.cc
@@ -27,110 +27,6 @@ InputMethodDescriptor GetDesc(IBusController* controller,
} // namespace
-TEST(InputMethodMenuTest, GetTextForIndicatorTest) {
- scoped_ptr<IBusController> controller(IBusController::Create());
-
- // Test normal cases. Two-letter language code should be returned.
- {
- InputMethodDescriptor desc = GetDesc(controller.get(),
- "m17n:fa:isiri", // input method id
- "us", // keyboard layout name
- "fa"); // language name
- EXPECT_EQ(ASCIIToUTF16("FA"), InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "mozc-hangul", "us", "ko");
- EXPECT_EQ(UTF8ToUTF16("\xed\x95\x9c"),
- InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "invalid-id", "us", "xx");
- // Upper-case string of the unknown language code, "xx", should be returned.
- EXPECT_EQ(ASCIIToUTF16("XX"), InputMethodMenu::GetTextForIndicator(desc));
- }
-
- // Test special cases.
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "xkb:us:dvorak:eng", "us", "en-US");
- EXPECT_EQ(ASCIIToUTF16("DV"), InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "xkb:us:colemak:eng", "us", "en-US");
- EXPECT_EQ(ASCIIToUTF16("CO"), InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "xkb:us:altgr-intl:eng", "us", "en-US");
- EXPECT_EQ(ASCIIToUTF16("EXTD"), InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "xkb:us:intl:eng", "us", "en-US");
- EXPECT_EQ(ASCIIToUTF16("INTL"), InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "xkb:de:neo:ger", "de(neo)", "de");
- EXPECT_EQ(ASCIIToUTF16("NEO"), InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "xkb:es:cat:cat", "es(cat)", "ca");
- EXPECT_EQ(ASCIIToUTF16("CAS"), InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc = GetDesc(controller.get(), "mozc", "us", "ja");
- EXPECT_EQ(UTF8ToUTF16("\xe3\x81\x82"),
- InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "mozc-jp", "jp", "ja");
- EXPECT_EQ(UTF8ToUTF16("\xe3\x81\x82"),
- InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "zinnia-japanese", "us", "ja");
- EXPECT_EQ(UTF8ToUTF16("\xe6\x89\x8b"),
- InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "pinyin", "us", "zh-CN");
- EXPECT_EQ(UTF8ToUTF16("\xe6\x8b\xbc"),
- InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "pinyin-dv", "us(dvorak)", "zh-CN");
- EXPECT_EQ(UTF8ToUTF16("\xe6\x8b\xbc"),
- InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "mozc-chewing", "us", "zh-TW");
- EXPECT_EQ(UTF8ToUTF16("\xe9\x85\xb7"),
- InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "m17n:zh:cangjie", "us", "zh-TW");
- EXPECT_EQ(UTF8ToUTF16("\xe5\x80\x89"),
- InputMethodMenu::GetTextForIndicator(desc));
- }
- {
- InputMethodDescriptor desc =
- GetDesc(controller.get(), "m17n:zh:quick", "us", "zh-TW");
- EXPECT_EQ(UTF8ToUTF16("\xe9\x80\x9f"),
- InputMethodMenu::GetTextForIndicator(desc));
- }
-}
-
// Test whether the function returns language name for non-ambiguous languages.
TEST(InputMethodMenuTest, GetTextForMenuTest) {
scoped_ptr<IBusController> controller(IBusController::Create());
diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc
index 4eff0dc..b538e30 100644
--- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc
+++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc
@@ -8,6 +8,7 @@
#include "ash/shell_window_ids.h"
#include "ash/system/audio/audio_observer.h"
#include "ash/system/brightness/brightness_observer.h"
+#include "ash/system/ime/ime_observer.h"
#include "ash/system/network/network_observer.h"
#include "ash/system/power/clock_observer.h"
#include "ash/system/power/power_status_observer.h"
@@ -26,6 +27,8 @@
#include "chrome/browser/chromeos/dbus/dbus_thread_manager.h"
#include "chrome/browser/chromeos/dbus/power_manager_client.h"
#include "chrome/browser/chromeos/input_method/input_method_manager.h"
+#include "chrome/browser/chromeos/input_method/input_method_util.h"
+#include "chrome/browser/chromeos/input_method/input_method_whitelist.h"
#include "chrome/browser/chromeos/input_method/xkeyboard.h"
#include "chrome/browser/chromeos/login/base_login_display_host.h"
#include "chrome/browser/chromeos/login/login_display_host.h"
@@ -71,6 +74,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
public NetworkLibrary::NetworkObserver,
public NetworkLibrary::CellularDataPlanObserver,
public content::NotificationObserver,
+ public input_method::InputMethodManager::Observer,
public system::TimezoneSettings::Observer,
public SystemKeyEventListener::CapsLockObserver {
public:
@@ -92,6 +96,8 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
OnNetworkManagerChanged(crosnet);
crosnet->AddCellularDataPlanObserver(this);
+ input_method::InputMethodManager::GetInstance()->AddObserver(this);
+
system::TimezoneSettings::GetInstance()->AddObserver(this);
if (SystemKeyEventListener::GetInstance())
@@ -123,6 +129,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
if (audiohandler)
audiohandler->RemoveVolumeObserver(this);
DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
+ input_method::InputMethodManager::GetInstance()->RemoveObserver(this);
system::TimezoneSettings::GetInstance()->RemoveObserver(this);
if (SystemKeyEventListener::GetInstance())
SystemKeyEventListener::GetInstance()->RemoveCapsLockObserver(this);
@@ -229,6 +236,26 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
NotifyScreenLockRequested();
}
+ virtual ash::IMEInfoList GetAvailableIMEList() OVERRIDE {
+ ash::IMEInfoList list;
+ input_method::InputMethodManager* manager =
+ input_method::InputMethodManager::GetInstance();
+ input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
+ scoped_ptr<input_method::InputMethodDescriptors> ime_descriptors(
+ manager->GetActiveInputMethods());
+ std::string current = manager->GetCurrentInputMethod().id();
+ for (size_t i = 0; i < ime_descriptors->size(); i++) {
+ input_method::InputMethodDescriptor& ime = ime_descriptors->at(i);
+ ash::IMEInfo info;
+ info.id = ime.id();
+ info.name = UTF8ToUTF16(util->GetInputMethodDisplayNameFromId(info.id));
+ info.short_name = util->GetInputMethodShortName(ime);
+ info.selected = ime.id() == current;
+ list.push_back(info);
+ }
+ return list;
+ }
+
virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon(bool large) OVERRIDE {
ash::NetworkIconInfo info;
info.image = !large ? network_icon_->GetIconAndText(&info.description) :
@@ -379,6 +406,13 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
}
}
+ void NotifyRefreshIME() {
+ ash::IMEObserver* observer =
+ ash::Shell::GetInstance()->tray()->ime_observer();
+ if (observer)
+ observer->OnIMERefresh();
+ }
+
void RefreshNetworkObserver(NetworkLibrary* crosnet) {
const Network* network = crosnet->active_network();
std::string new_path = network ? network->service_path() : std::string();
@@ -530,6 +564,27 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
}
}
+ // Overridden from InputMethodManager::Observer.
+ virtual void InputMethodChanged(
+ input_method::InputMethodManager* manager,
+ const input_method::InputMethodDescriptor& current_method,
+ size_t num_active_input_methods) OVERRIDE {
+ NotifyRefreshIME();
+ }
+
+ virtual void ActiveInputMethodsChanged(
+ input_method::InputMethodManager* manager,
+ const input_method::InputMethodDescriptor& current_input_method,
+ size_t num_active_input_methods) OVERRIDE {
+ NotifyRefreshIME();
+ }
+
+ virtual void PropertyListChanged(
+ input_method::InputMethodManager* manager,
+ const input_method::InputMethodPropertyList& properties) OVERRIDE {
+ NotifyRefreshIME();
+ }
+
// Overridden from system::TimezoneSettings::Observer.
virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE {
NotifyRefreshClock();