summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/cros/cros_in_process_browser_test.cc4
-rw-r--r--chrome/browser/chromeos/cros/language_library.cc9
-rw-r--r--chrome/browser/chromeos/cros/language_library.h1
-rw-r--r--chrome/browser/chromeos/login/login_browsertest.cc4
-rw-r--r--chrome/browser/chromeos/status/language_menu_button.cc44
-rw-r--r--chrome/browser/chromeos/status/language_menu_button.h5
6 files changed, 54 insertions, 13 deletions
diff --git a/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc b/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc
index 7128a9b..4a73ceb 100644
--- a/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc
+++ b/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc
@@ -123,8 +123,8 @@ void CrosInProcessBrowserTest::SetLanguageLibraryStatusAreaExpectations() {
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*mock_language_library_, GetActiveInputMethods())
- .Times(1)
- .WillOnce(Return(CreateFallbackInputMethodDescriptors()))
+ .Times(AnyNumber())
+ .WillRepeatedly(InvokeWithoutArgs(CreateFallbackInputMethodDescriptors))
.RetiresOnSaturation();
EXPECT_CALL(*mock_language_library_, current_ime_properties())
.Times(1)
diff --git a/chrome/browser/chromeos/cros/language_library.cc b/chrome/browser/chromeos/cros/language_library.cc
index d1dc57c..91446b5 100644
--- a/chrome/browser/chromeos/cros/language_library.cc
+++ b/chrome/browser/chromeos/cros/language_library.cc
@@ -9,6 +9,7 @@
#include "base/string_util.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/language_preferences.h"
#include "third_party/cros/chromeos_keyboard.h"
#include "third_party/icu/public/common/unicode/uloc.h"
@@ -243,6 +244,7 @@ bool LanguageLibraryImpl::SetImeConfig(
}
void LanguageLibraryImpl::FlushImeConfig() {
+ bool active_input_methods_are_changed = false;
if (EnsureLoadedAndStarted()) {
LOG(INFO) << "Sending " << pending_config_requests_.size()
<< " set config command(s)";
@@ -255,6 +257,10 @@ void LanguageLibraryImpl::FlushImeConfig() {
section.c_str(), config_name.c_str(), value)) {
// Successfully sent. Remove the command and proceed to the next one.
pending_config_requests_.erase(iter++);
+ // Check if it's a change in active input methods.
+ if (config_name == kPreloadEnginesConfigName) {
+ active_input_methods_are_changed = true;
+ }
} else {
LOG(ERROR) << "chromeos::SetImeConfig failed. Will retry later: "
<< section << "/" << config_name;
@@ -271,6 +277,9 @@ void LanguageLibraryImpl::FlushImeConfig() {
&LanguageLibraryImpl::FlushImeConfig);
}
}
+ if (active_input_methods_are_changed) {
+ FOR_EACH_OBSERVER(Observer, observers_, ActiveInputMethodsChanged(this));
+ }
}
// static
diff --git a/chrome/browser/chromeos/cros/language_library.h b/chrome/browser/chromeos/cros/language_library.h
index 4d90df5..53a94b3 100644
--- a/chrome/browser/chromeos/cros/language_library.h
+++ b/chrome/browser/chromeos/cros/language_library.h
@@ -26,6 +26,7 @@ class LanguageLibrary {
virtual ~Observer() = 0;
virtual void InputMethodChanged(LanguageLibrary* obj) = 0;
virtual void ImePropertiesChanged(LanguageLibrary* obj) = 0;
+ virtual void ActiveInputMethodsChanged(LanguageLibrary* obj) = 0;
};
virtual ~LanguageLibrary() {}
diff --git a/chrome/browser/chromeos/login/login_browsertest.cc b/chrome/browser/chromeos/login/login_browsertest.cc
index 4c1800f..6c3a94c 100644
--- a/chrome/browser/chromeos/login/login_browsertest.cc
+++ b/chrome/browser/chromeos/login/login_browsertest.cc
@@ -22,6 +22,7 @@
namespace chromeos {
using ::testing::_;
+using ::testing::InvokeWithoutArgs;
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::NiceMock;
@@ -36,7 +37,8 @@ class LoginTestBase : public InProcessBrowserTest {
testApi_->SetLanguageLibrary(&mock_language_library_, false);
EXPECT_CALL(mock_language_library_, GetActiveInputMethods())
- .WillRepeatedly(Return(CreateFallbackInputMethodDescriptors()));
+ .WillRepeatedly(
+ InvokeWithoutArgs(CreateFallbackInputMethodDescriptors));
EXPECT_CALL(mock_language_library_, current_ime_properties())
.WillOnce((ReturnRef(ime_properties_)));
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.
diff --git a/chrome/browser/chromeos/status/language_menu_button.h b/chrome/browser/chromeos/status/language_menu_button.h
index a74d5c6..78fe470 100644
--- a/chrome/browser/chromeos/status/language_menu_button.h
+++ b/chrome/browser/chromeos/status/language_menu_button.h
@@ -52,6 +52,7 @@ class LanguageMenuButton : public views::MenuButton,
// LanguageLibrary::Observer implementation.
virtual void InputMethodChanged(LanguageLibrary* obj);
virtual void ImePropertiesChanged(LanguageLibrary* obj);
+ virtual void ActiveInputMethodsChanged(LanguageLibrary* obj);
// NotificationObserver implementation.
virtual void Observe(NotificationType type,
@@ -69,6 +70,10 @@ class LanguageMenuButton : public views::MenuButton,
// Updates the status area with |name| and tooltip with |tooltip|.
void UpdateIcon(const std::wstring& name, const std::wstring& tooltip);
+ // Updates the status area from the given input method.
+ void UpdateIconFromInputMethod(
+ const InputMethodDescriptor& input_method);
+
// Rebuilds |model_|. This function should be called whenever
// |input_method_descriptors_| is updated, or ImePropertiesChanged() is
// called.