summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/status/language_menu_button.cc
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-11 02:31:05 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-11 02:31:05 +0000
commit181022e70bd2e711f1ed6d126a1058d48640ee27 (patch)
treed880883a00f1c9f482a0485677cbc522748a6610 /chrome/browser/chromeos/status/language_menu_button.cc
parent897b2627d88109e5280e20b6658d702b43468617 (diff)
downloadchromium_src-181022e70bd2e711f1ed6d126a1058d48640ee27.zip
chromium_src-181022e70bd2e711f1ed6d126a1058d48640ee27.tar.gz
chromium_src-181022e70bd2e711f1ed6d126a1058d48640ee27.tar.bz2
Hide the input language menu if there is only one input method and it's a XKB keyboard layout.
For instance, if English USA keyboard layout is the only input method enabled, we don't show the input language menu on the right upper corner. On the other hand, if Japanese input method is the only input method enabled, we still show the input language menu so users can change the intra input method modes, like Hiragana and Katakana modes. Note that this is a retry of r49375 that was reverted in r49393 http://src.chromium.org/viewvc/chrome?view=rev&revision=49375 http://src.chromium.org/viewvc/chrome?view=rev&revision=49393 The new fix is in chrome/browser/chromeos/login/login_browsertest.cc - .WillRepeatedly(Return(CreateFallbackInputMethodDescriptors())); + .WillRepeatedly( + InvokeWithoutArgs(CreateFallbackInputMethodDescriptors)); BUG=chromium-os:2275 TEST=manually on the netbook; try bots Review URL: http://codereview.chromium.org/2787007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49494 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/status/language_menu_button.cc')
-rw-r--r--chrome/browser/chromeos/status/language_menu_button.cc44
1 files changed, 34 insertions, 10 deletions
diff --git a/chrome/browser/chromeos/status/language_menu_button.cc b/chrome/browser/chromeos/status/language_menu_button.cc
index ead895e6..156bb66 100644
--- a/chrome/browser/chromeos/status/language_menu_button.cc
+++ b/chrome/browser/chromeos/status/language_menu_button.cc
@@ -149,6 +149,7 @@ LanguageMenuButton::LanguageMenuButton(StatusAreaHost* host)
SetFont(ResourceBundle::GetSharedInstance().GetFont(
ResourceBundle::BaseFont).DeriveFont(1, gfx::Font::BOLD));
SetEnabledColor(0xB3FFFFFF); // White with 70% Alpha
+ SetDisabledColor(0x00FFFFFF); // White with 00% Alpha (invisible)
SetShowHighlighted(false);
// Update the model
RebuildModel();
@@ -316,7 +317,7 @@ string16 LanguageMenuButton::GetLabelAt(int index) const {
std::wstring name;
if (IndexIsInInputMethodList(index)) {
const std::string language_code =
- chromeos::LanguageLibrary::GetLanguageCodeFromDescriptor(
+ LanguageLibrary::GetLanguageCodeFromDescriptor(
input_method_descriptors_->at(index));
bool need_method_name = (need_method_name_.count(language_code) > 0);
name = FormatInputLanguage(input_method_descriptors_->at(index), true,
@@ -395,11 +396,9 @@ void LanguageMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
// LanguageLibrary::Observer implementation:
void LanguageMenuButton::InputMethodChanged(LanguageLibrary* obj) {
- const chromeos::InputMethodDescriptor& input_method =
+ const InputMethodDescriptor& input_method =
obj->current_input_method();
- const std::wstring name = FormatInputLanguage(input_method, false, false);
- const std::wstring tooltip = FormatInputLanguage(input_method, true, true);
- UpdateIcon(name, tooltip);
+ UpdateIconFromInputMethod(input_method);
// Update Chrome prefs as well.
if (GetPrefService(host_)) {
const std::wstring& previous_input_method_id =
@@ -411,6 +410,12 @@ void LanguageMenuButton::InputMethodChanged(LanguageLibrary* obj) {
}
}
+void LanguageMenuButton::ActiveInputMethodsChanged(LanguageLibrary* obj) {
+ // Update the icon if active input methods are changed. See also
+ // comments in UpdateIcon()
+ UpdateIconFromInputMethod(obj->current_input_method());
+}
+
void LanguageMenuButton::ImePropertiesChanged(LanguageLibrary* obj) {
}
@@ -418,11 +423,9 @@ void LanguageMenuButton::ImePropertiesChanged(LanguageLibrary* obj) {
// views::View implementation:
void LanguageMenuButton::LocaleChanged() {
- const chromeos::InputMethodDescriptor& input_method =
+ const InputMethodDescriptor& input_method =
CrosLibrary::Get()->GetLanguageLibrary()->current_input_method();
- const std::wstring name = FormatInputLanguage(input_method, false, false);
- const std::wstring tooltip = FormatInputLanguage(input_method, true, true);
- UpdateIcon(name, tooltip);
+ UpdateIconFromInputMethod(input_method);
Layout();
SchedulePaint();
}
@@ -432,11 +435,32 @@ void LanguageMenuButton::UpdateIcon(
if (!tooltip.empty()) {
SetTooltipText(tooltip);
}
+ // Hide the button only if there is only one input method, and the input
+ // method is a XKB keyboard layout. We don't hide the button for other
+ // types of input methods as these might have intra input method modes,
+ // like Hiragana and Katakana modes in Japanese input methods.
+ scoped_ptr<InputMethodDescriptors> active_input_methods(
+ CrosLibrary::Get()->GetLanguageLibrary()->GetActiveInputMethods());
+ if (active_input_methods->size() == 1 &&
+ LanguageLibrary::IsKeyboardLayout(active_input_methods->at(0).id)) {
+ // As the disabled color is set to invisible, disabling makes the
+ // button disappear.
+ SetEnabled(false);
+ } else {
+ SetEnabled(true);
+ }
SetText(name);
set_alignment(TextButton::ALIGN_RIGHT);
SchedulePaint();
}
+void LanguageMenuButton::UpdateIconFromInputMethod(
+ const InputMethodDescriptor& input_method) {
+ const std::wstring name = FormatInputLanguage(input_method, false, false);
+ const std::wstring tooltip = FormatInputLanguage(input_method, true, true);
+ UpdateIcon(name, tooltip);
+}
+
void LanguageMenuButton::RebuildModel() {
model_.reset(new menus::SimpleMenuModel(NULL));
string16 dummy_label = UTF8ToUTF16("");
@@ -453,7 +477,7 @@ void LanguageMenuButton::RebuildModel() {
model_->AddRadioItem(COMMAND_ID_INPUT_METHODS, dummy_label, i);
const std::string language_code
- = chromeos::LanguageLibrary::GetLanguageCodeFromDescriptor(
+ = LanguageLibrary::GetLanguageCodeFromDescriptor(
input_method_descriptors_->at(i));
// If there is more than one input method for this language, then we need
// to display the method name.