| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/status/input_method_menu.h" | 5 #include "chrome/browser/chromeos/status/input_method_menu.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } // namespace | 125 } // namespace |
| 126 | 126 |
| 127 namespace chromeos { | 127 namespace chromeos { |
| 128 | 128 |
| 129 using input_method::InputMethodManager; | 129 using input_method::InputMethodManager; |
| 130 | 130 |
| 131 //////////////////////////////////////////////////////////////////////////////// | 131 //////////////////////////////////////////////////////////////////////////////// |
| 132 // InputMethodMenu | 132 // InputMethodMenu |
| 133 | 133 |
| 134 InputMethodMenu::InputMethodMenu(PrefService* pref_service, | 134 InputMethodMenu::InputMethodMenu(PrefService* pref_service, |
| 135 StatusAreaHost::ScreenMode screen_mode, | 135 StatusAreaViewChromeos::ScreenMode screen_mode, |
| 136 bool for_out_of_box_experience_dialog) | 136 bool for_out_of_box_experience_dialog) |
| 137 : input_method_descriptors_(InputMethodManager::GetInstance()-> | 137 : input_method_descriptors_(InputMethodManager::GetInstance()-> |
| 138 GetActiveInputMethods()), | 138 GetActiveInputMethods()), |
| 139 model_(new ui::SimpleMenuModel(NULL)), | 139 model_(new ui::SimpleMenuModel(NULL)), |
| 140 ALLOW_THIS_IN_INITIALIZER_LIST(input_method_menu_delegate_( | 140 ALLOW_THIS_IN_INITIALIZER_LIST(input_method_menu_delegate_( |
| 141 new views::MenuModelAdapter(this))), | 141 new views::MenuModelAdapter(this))), |
| 142 input_method_menu_( | 142 input_method_menu_( |
| 143 new views::MenuItemView(input_method_menu_delegate_.get())), | 143 new views::MenuItemView(input_method_menu_delegate_.get())), |
| 144 input_method_menu_runner_(new views::MenuRunner(input_method_menu_)), | 144 input_method_menu_runner_(new views::MenuRunner(input_method_menu_)), |
| 145 minimum_input_method_menu_width_(0), | 145 minimum_input_method_menu_width_(0), |
| 146 menu_alignment_(views::MenuItemView::TOPRIGHT), | 146 menu_alignment_(views::MenuItemView::TOPRIGHT), |
| 147 pref_service_(pref_service), | 147 pref_service_(pref_service), |
| 148 screen_mode_(screen_mode), | 148 screen_mode_(screen_mode), |
| 149 for_out_of_box_experience_dialog_(for_out_of_box_experience_dialog) { | 149 for_out_of_box_experience_dialog_(for_out_of_box_experience_dialog) { |
| 150 DCHECK(input_method_descriptors_.get() && | 150 DCHECK(input_method_descriptors_.get() && |
| 151 !input_method_descriptors_->empty()); | 151 !input_method_descriptors_->empty()); |
| 152 | 152 |
| 153 // Sync current and previous input methods on Chrome prefs with ibus-daemon. | 153 // Sync current and previous input methods on Chrome prefs with ibus-daemon. |
| 154 if (pref_service_ && (screen_mode_ == StatusAreaHost::kBrowserMode)) { | 154 if (pref_service_ && (screen_mode_ == StatusAreaViewChromeos::BROWSER_MODE)) { |
| 155 previous_input_method_pref_.Init( | 155 previous_input_method_pref_.Init( |
| 156 prefs::kLanguagePreviousInputMethod, pref_service, this); | 156 prefs::kLanguagePreviousInputMethod, pref_service, this); |
| 157 current_input_method_pref_.Init( | 157 current_input_method_pref_.Init( |
| 158 prefs::kLanguageCurrentInputMethod, pref_service, this); | 158 prefs::kLanguageCurrentInputMethod, pref_service, this); |
| 159 } | 159 } |
| 160 | 160 |
| 161 InputMethodManager* manager = InputMethodManager::GetInstance(); | 161 InputMethodManager* manager = InputMethodManager::GetInstance(); |
| 162 if (screen_mode_ == StatusAreaHost::kViewsLoginMode || | 162 if (screen_mode_ == StatusAreaViewChromeos::LOGIN_MODE_VIEWS || |
| 163 screen_mode_ == StatusAreaHost::kWebUILoginMode) { | 163 screen_mode_ == StatusAreaViewChromeos::LOGIN_MODE_WEBUI) { |
| 164 // This button is for the login screen. | 164 // This button is for the login screen. |
| 165 manager->AddPreLoginPreferenceObserver(this); | 165 manager->AddPreLoginPreferenceObserver(this); |
| 166 registrar_.Add(this, | 166 registrar_.Add(this, |
| 167 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 167 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 168 content::NotificationService::AllSources()); | 168 content::NotificationService::AllSources()); |
| 169 } else if (screen_mode_ == StatusAreaHost::kBrowserMode) { | 169 } else if (screen_mode_ == StatusAreaViewChromeos::BROWSER_MODE) { |
| 170 manager->AddPostLoginPreferenceObserver(this); | 170 manager->AddPostLoginPreferenceObserver(this); |
| 171 } | 171 } |
| 172 | 172 |
| 173 // AddObserver() should be called after AddXXXLoginPreferenceObserver. This is | 173 // AddObserver() should be called after AddXXXLoginPreferenceObserver. This is |
| 174 // because when the function is called FirstObserverIsAdded might be called | 174 // because when the function is called FirstObserverIsAdded might be called |
| 175 // back, and FirstObserverIsAdded might then might call ChangeInputMethod() in | 175 // back, and FirstObserverIsAdded might then might call ChangeInputMethod() in |
| 176 // InputMethodManager. We have to prevent the manager function from calling | 176 // InputMethodManager. We have to prevent the manager function from calling |
| 177 // callback functions like InputMethodChanged since they touch (yet | 177 // callback functions like InputMethodChanged since they touch (yet |
| 178 // uninitialized) UI elements. | 178 // uninitialized) UI elements. |
| 179 manager->AddObserver(this); | 179 manager->AddObserver(this); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 InputMethodManager* manager, | 414 InputMethodManager* manager, |
| 415 const input_method::InputMethodDescriptor& current_input_method, | 415 const input_method::InputMethodDescriptor& current_input_method, |
| 416 size_t num_active_input_methods) { | 416 size_t num_active_input_methods) { |
| 417 UpdateUIFromInputMethod(current_input_method, num_active_input_methods); | 417 UpdateUIFromInputMethod(current_input_method, num_active_input_methods); |
| 418 } | 418 } |
| 419 | 419 |
| 420 void InputMethodMenu::PreferenceUpdateNeeded( | 420 void InputMethodMenu::PreferenceUpdateNeeded( |
| 421 InputMethodManager* manager, | 421 InputMethodManager* manager, |
| 422 const input_method::InputMethodDescriptor& previous_input_method, | 422 const input_method::InputMethodDescriptor& previous_input_method, |
| 423 const input_method::InputMethodDescriptor& current_input_method) { | 423 const input_method::InputMethodDescriptor& current_input_method) { |
| 424 if (screen_mode_ == StatusAreaHost::kBrowserMode) { | 424 if (screen_mode_ == StatusAreaViewChromeos::BROWSER_MODE) { |
| 425 if (pref_service_) { // make sure we're not in unit tests. | 425 if (pref_service_) { // make sure we're not in unit tests. |
| 426 // Sometimes (e.g. initial boot) |previous_input_method.id()| is empty. | 426 // Sometimes (e.g. initial boot) |previous_input_method.id()| is empty. |
| 427 previous_input_method_pref_.SetValue(previous_input_method.id()); | 427 previous_input_method_pref_.SetValue(previous_input_method.id()); |
| 428 current_input_method_pref_.SetValue(current_input_method.id()); | 428 current_input_method_pref_.SetValue(current_input_method.id()); |
| 429 pref_service_->ScheduleSavePersistentPrefs(); | 429 pref_service_->ScheduleSavePersistentPrefs(); |
| 430 } | 430 } |
| 431 } else if (screen_mode_ == StatusAreaHost::kViewsLoginMode || | 431 } else if (screen_mode_ == StatusAreaViewChromeos::LOGIN_MODE_VIEWS || |
| 432 screen_mode_ == StatusAreaHost::kWebUILoginMode) { | 432 screen_mode_ == StatusAreaViewChromeos::LOGIN_MODE_WEBUI) { |
| 433 if (g_browser_process && g_browser_process->local_state()) { | 433 if (g_browser_process && g_browser_process->local_state()) { |
| 434 g_browser_process->local_state()->SetString( | 434 g_browser_process->local_state()->SetString( |
| 435 language_prefs::kPreferredKeyboardLayout, current_input_method.id()); | 435 language_prefs::kPreferredKeyboardLayout, current_input_method.id()); |
| 436 g_browser_process->local_state()->ScheduleSavePersistentPrefs(); | 436 g_browser_process->local_state()->ScheduleSavePersistentPrefs(); |
| 437 } | 437 } |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 | 440 |
| 441 void InputMethodMenu::PropertyListChanged( | 441 void InputMethodMenu::PropertyListChanged( |
| 442 InputMethodManager* manager, | 442 InputMethodManager* manager, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 458 manager->current_input_method(); | 458 manager->current_input_method(); |
| 459 size_t num_active_input_methods = manager->GetNumActiveInputMethods(); | 459 size_t num_active_input_methods = manager->GetNumActiveInputMethods(); |
| 460 UpdateUIFromInputMethod(input_method, num_active_input_methods); | 460 UpdateUIFromInputMethod(input_method, num_active_input_methods); |
| 461 } | 461 } |
| 462 } | 462 } |
| 463 | 463 |
| 464 void InputMethodMenu::FirstObserverIsAdded(InputMethodManager* manager) { | 464 void InputMethodMenu::FirstObserverIsAdded(InputMethodManager* manager) { |
| 465 // NOTICE: Since this function might be called from the constructor of this | 465 // NOTICE: Since this function might be called from the constructor of this |
| 466 // class, it's better to avoid calling virtual functions. | 466 // class, it's better to avoid calling virtual functions. |
| 467 | 467 |
| 468 if (pref_service_ && (screen_mode_ == StatusAreaHost::kBrowserMode)) { | 468 if (pref_service_ && (screen_mode_ == StatusAreaViewChromeos::BROWSER_MODE)) { |
| 469 // Get the input method name in the Preferences file which was in use last | 469 // Get the input method name in the Preferences file which was in use last |
| 470 // time, and switch to the method. We remember two input method names in the | 470 // time, and switch to the method. We remember two input method names in the |
| 471 // preference so that the Control+space hot-key could work fine from the | 471 // preference so that the Control+space hot-key could work fine from the |
| 472 // beginning. InputMethodChanged() will be called soon and the indicator | 472 // beginning. InputMethodChanged() will be called soon and the indicator |
| 473 // will be updated. | 473 // will be updated. |
| 474 const std::string previous_input_method_id = | 474 const std::string previous_input_method_id = |
| 475 previous_input_method_pref_.GetValue(); | 475 previous_input_method_pref_.GetValue(); |
| 476 if (!previous_input_method_id.empty()) { | 476 if (!previous_input_method_id.empty()) { |
| 477 manager->ChangeInputMethod(previous_input_method_id); | 477 manager->ChangeInputMethod(previous_input_method_id); |
| 478 } | 478 } |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 } | 714 } |
| 715 } | 715 } |
| 716 | 716 |
| 717 void InputMethodMenu::SetMinimumWidth(int width) { | 717 void InputMethodMenu::SetMinimumWidth(int width) { |
| 718 // On the OOBE network selection screen, fixed width menu would be preferable. | 718 // On the OOBE network selection screen, fixed width menu would be preferable. |
| 719 minimum_input_method_menu_width_ = width; | 719 minimum_input_method_menu_width_ = width; |
| 720 } | 720 } |
| 721 | 721 |
| 722 void InputMethodMenu::RemoveObservers() { | 722 void InputMethodMenu::RemoveObservers() { |
| 723 InputMethodManager* manager = InputMethodManager::GetInstance(); | 723 InputMethodManager* manager = InputMethodManager::GetInstance(); |
| 724 if (screen_mode_ == StatusAreaHost::kViewsLoginMode || | 724 if (screen_mode_ == StatusAreaViewChromeos::LOGIN_MODE_VIEWS || |
| 725 screen_mode_ == StatusAreaHost::kWebUILoginMode) { | 725 screen_mode_ == StatusAreaViewChromeos::LOGIN_MODE_WEBUI) { |
| 726 manager->RemovePreLoginPreferenceObserver(this); | 726 manager->RemovePreLoginPreferenceObserver(this); |
| 727 } else if (screen_mode_ == StatusAreaHost::kBrowserMode) { | 727 } else if (screen_mode_ == StatusAreaViewChromeos::BROWSER_MODE) { |
| 728 manager->RemovePostLoginPreferenceObserver(this); | 728 manager->RemovePostLoginPreferenceObserver(this); |
| 729 } | 729 } |
| 730 manager->RemoveObserver(this); | 730 manager->RemoveObserver(this); |
| 731 } | 731 } |
| 732 | 732 |
| 733 } // namespace chromeos | 733 } // namespace chromeos |
| OLD | NEW |