OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 111 } |
112 | 112 |
113 } // namespace | 113 } // namespace |
114 | 114 |
115 namespace chromeos { | 115 namespace chromeos { |
116 | 116 |
117 //////////////////////////////////////////////////////////////////////////////// | 117 //////////////////////////////////////////////////////////////////////////////// |
118 // InputMethodMenu | 118 // InputMethodMenu |
119 | 119 |
120 InputMethodMenu::InputMethodMenu(PrefService* pref_service, | 120 InputMethodMenu::InputMethodMenu(PrefService* pref_service, |
121 bool is_browser_mode, | 121 StatusAreaHost::ScreenMode screen_mode, |
122 bool is_screen_locker_mode, | 122 bool for_out_of_box_experience_dialog) |
123 bool is_out_of_box_experience_mode) | |
124 : input_method_descriptors_(CrosLibrary::Get()->GetInputMethodLibrary()-> | 123 : input_method_descriptors_(CrosLibrary::Get()->GetInputMethodLibrary()-> |
125 GetActiveInputMethods()), | 124 GetActiveInputMethods()), |
126 model_(NULL), | 125 model_(NULL), |
127 // Be aware that the constructor of |input_method_menu_| calls | 126 // Be aware that the constructor of |input_method_menu_| calls |
128 // GetItemCount() in this class. Therefore, GetItemCount() have to return | 127 // GetItemCount() in this class. Therefore, GetItemCount() have to return |
129 // 0 when |model_| is NULL. | 128 // 0 when |model_| is NULL. |
130 ALLOW_THIS_IN_INITIALIZER_LIST(input_method_menu_(this)), | 129 ALLOW_THIS_IN_INITIALIZER_LIST(input_method_menu_(this)), |
131 minimum_input_method_menu_width_(0), | 130 minimum_input_method_menu_width_(0), |
132 pref_service_(pref_service), | 131 pref_service_(pref_service), |
133 is_browser_mode_(is_browser_mode), | 132 screen_mode_(screen_mode), |
134 is_screen_locker_mode_(is_screen_locker_mode), | 133 for_out_of_box_experience_dialog_(for_out_of_box_experience_dialog) { |
135 is_out_of_box_experience_mode_(is_out_of_box_experience_mode) { | |
136 DCHECK(input_method_descriptors_.get() && | 134 DCHECK(input_method_descriptors_.get() && |
137 !input_method_descriptors_->empty()); | 135 !input_method_descriptors_->empty()); |
138 | 136 |
139 // Sync current and previous input methods on Chrome prefs with ibus-daemon. | 137 // Sync current and previous input methods on Chrome prefs with ibus-daemon. |
140 // InputMethodChanged() will be called soon and the indicator will be updated. | 138 // InputMethodChanged() will be called soon and the indicator will be updated. |
141 InputMethodLibrary* library = CrosLibrary::Get()->GetInputMethodLibrary(); | 139 InputMethodLibrary* library = CrosLibrary::Get()->GetInputMethodLibrary(); |
142 if (pref_service && is_browser_mode_) { | 140 if (pref_service && (screen_mode_ == StatusAreaHost::kBrowserMode)) { |
143 previous_input_method_pref_.Init( | 141 previous_input_method_pref_.Init( |
144 prefs::kLanguagePreviousInputMethod, pref_service, this); | 142 prefs::kLanguagePreviousInputMethod, pref_service, this); |
145 const std::string previous_input_method_id = | 143 const std::string previous_input_method_id = |
146 previous_input_method_pref_.GetValue(); | 144 previous_input_method_pref_.GetValue(); |
147 if (!previous_input_method_id.empty()) { | 145 if (!previous_input_method_id.empty()) { |
148 library->ChangeInputMethod(previous_input_method_id); | 146 library->ChangeInputMethod(previous_input_method_id); |
149 } | 147 } |
150 | 148 |
151 current_input_method_pref_.Init( | 149 current_input_method_pref_.Init( |
152 prefs::kLanguageCurrentInputMethod, pref_service, this); | 150 prefs::kLanguageCurrentInputMethod, pref_service, this); |
153 const std::string current_input_method_id = | 151 const std::string current_input_method_id = |
154 current_input_method_pref_.GetValue(); | 152 current_input_method_pref_.GetValue(); |
155 if (!current_input_method_id.empty()) { | 153 if (!current_input_method_id.empty()) { |
156 library->ChangeInputMethod(current_input_method_id); | 154 library->ChangeInputMethod(current_input_method_id); |
157 } | 155 } |
158 } | 156 } |
159 library->AddObserver(this); | 157 library->AddObserver(this); |
160 | 158 |
161 if (!is_browser_mode_ && !is_screen_locker_mode_) { | 159 if (screen_mode_ == StatusAreaHost::kLoginMode) { |
162 // This button is for the login screen. | 160 // This button is for the login screen. |
163 registrar_.Add(this, | 161 registrar_.Add(this, |
164 NotificationType::LOGIN_USER_CHANGED, | 162 NotificationType::LOGIN_USER_CHANGED, |
165 NotificationService::AllSources()); | 163 NotificationService::AllSources()); |
166 } | 164 } |
167 } | 165 } |
168 | 166 |
169 InputMethodMenu::~InputMethodMenu() { | 167 InputMethodMenu::~InputMethodMenu() { |
170 // RemoveObserver() is no-op if |this| object is already removed from the | 168 // RemoveObserver() is no-op if |this| object is already removed from the |
171 // observer list. | 169 // observer list. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 206 } |
209 | 207 |
210 // Separator(s) or the "Customize language and input..." button. | 208 // Separator(s) or the "Customize language and input..." button. |
211 return false; | 209 return false; |
212 } | 210 } |
213 | 211 |
214 int InputMethodMenu::GetGroupIdAt(int index) const { | 212 int InputMethodMenu::GetGroupIdAt(int index) const { |
215 DCHECK_GE(index, 0); | 213 DCHECK_GE(index, 0); |
216 | 214 |
217 if (IndexIsInInputMethodList(index)) { | 215 if (IndexIsInInputMethodList(index)) { |
218 return is_out_of_box_experience_mode_ ? | 216 return for_out_of_box_experience_dialog_ ? |
219 kRadioGroupNone : kRadioGroupLanguage; | 217 kRadioGroupNone : kRadioGroupLanguage; |
220 } | 218 } |
221 | 219 |
222 if (GetPropertyIndex(index, &index)) { | 220 if (GetPropertyIndex(index, &index)) { |
223 const ImePropertyList& property_list | 221 const ImePropertyList& property_list |
224 = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); | 222 = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); |
225 return property_list.at(index).selection_item_id; | 223 return property_list.at(index).selection_item_id; |
226 } | 224 } |
227 | 225 |
228 return kRadioGroupNone; | 226 return kRadioGroupNone; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 269 } |
272 | 270 |
273 ui::MenuModel::ItemType InputMethodMenu::GetTypeAt(int index) const { | 271 ui::MenuModel::ItemType InputMethodMenu::GetTypeAt(int index) const { |
274 DCHECK_GE(index, 0); | 272 DCHECK_GE(index, 0); |
275 | 273 |
276 if (IndexPointsToConfigureImeMenuItem(index)) { | 274 if (IndexPointsToConfigureImeMenuItem(index)) { |
277 return ui::MenuModel::TYPE_COMMAND; // "Customize language and input" | 275 return ui::MenuModel::TYPE_COMMAND; // "Customize language and input" |
278 } | 276 } |
279 | 277 |
280 if (IndexIsInInputMethodList(index)) { | 278 if (IndexIsInInputMethodList(index)) { |
281 return is_out_of_box_experience_mode_ ? | 279 return for_out_of_box_experience_dialog_ ? |
282 ui::MenuModel::TYPE_COMMAND : ui::MenuModel::TYPE_RADIO; | 280 ui::MenuModel::TYPE_COMMAND : ui::MenuModel::TYPE_RADIO; |
283 } | 281 } |
284 | 282 |
285 if (GetPropertyIndex(index, &index)) { | 283 if (GetPropertyIndex(index, &index)) { |
286 const ImePropertyList& property_list | 284 const ImePropertyList& property_list |
287 = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); | 285 = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); |
288 if (property_list.at(index).is_selection_item) { | 286 if (property_list.at(index).is_selection_item) { |
289 return ui::MenuModel::TYPE_RADIO; | 287 return ui::MenuModel::TYPE_RADIO; |
290 } | 288 } |
291 return ui::MenuModel::TYPE_COMMAND; | 289 return ui::MenuModel::TYPE_COMMAND; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 size_t num_active_input_methods) { | 381 size_t num_active_input_methods) { |
384 UserMetrics::RecordAction( | 382 UserMetrics::RecordAction( |
385 UserMetricsAction("LanguageMenuButton_InputMethodChanged")); | 383 UserMetricsAction("LanguageMenuButton_InputMethodChanged")); |
386 UpdateUIFromInputMethod(current_input_method, num_active_input_methods); | 384 UpdateUIFromInputMethod(current_input_method, num_active_input_methods); |
387 } | 385 } |
388 | 386 |
389 void InputMethodMenu::PreferenceUpdateNeeded( | 387 void InputMethodMenu::PreferenceUpdateNeeded( |
390 InputMethodLibrary* obj, | 388 InputMethodLibrary* obj, |
391 const InputMethodDescriptor& previous_input_method, | 389 const InputMethodDescriptor& previous_input_method, |
392 const InputMethodDescriptor& current_input_method) { | 390 const InputMethodDescriptor& current_input_method) { |
393 if (is_browser_mode_) { | 391 if (screen_mode_ == StatusAreaHost::kBrowserMode) { |
394 if (pref_service_) { // make sure we're not in unit tests. | 392 if (pref_service_) { // make sure we're not in unit tests. |
395 // Sometimes (e.g. initial boot) |previous_input_method.id| is empty. | 393 // Sometimes (e.g. initial boot) |previous_input_method.id| is empty. |
396 previous_input_method_pref_.SetValue(previous_input_method.id); | 394 previous_input_method_pref_.SetValue(previous_input_method.id); |
397 current_input_method_pref_.SetValue(current_input_method.id); | 395 current_input_method_pref_.SetValue(current_input_method.id); |
398 } | 396 } |
399 } else { | 397 } else if (screen_mode_ == StatusAreaHost::kLoginMode) { |
400 // We're in the login screen (i.e. not in the normal browser mode nor screen | |
401 // locker mode). | |
402 if (g_browser_process && g_browser_process->local_state()) { | 398 if (g_browser_process && g_browser_process->local_state()) { |
403 g_browser_process->local_state()->SetString( | 399 g_browser_process->local_state()->SetString( |
404 language_prefs::kPreferredKeyboardLayout, current_input_method.id); | 400 language_prefs::kPreferredKeyboardLayout, current_input_method.id); |
405 g_browser_process->local_state()->SavePersistentPrefs(); | 401 g_browser_process->local_state()->SavePersistentPrefs(); |
406 } | 402 } |
407 } | 403 } |
408 } | 404 } |
409 | 405 |
410 void InputMethodMenu::PrepareForMenuOpen() { | 406 void InputMethodMenu::PrepareForMenuOpen() { |
411 UserMetrics::RecordAction(UserMetricsAction("LanguageMenuButton_Open")); | 407 UserMetrics::RecordAction(UserMetricsAction("LanguageMenuButton_Open")); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 CrosLibrary::Get()->GetInputMethodLibrary()->RemoveObserver(this); | 606 CrosLibrary::Get()->GetInputMethodLibrary()->RemoveObserver(this); |
611 } | 607 } |
612 } | 608 } |
613 | 609 |
614 void InputMethodMenu::SetMinimumWidth(int width) { | 610 void InputMethodMenu::SetMinimumWidth(int width) { |
615 // On the OOBE network selection screen, fixed width menu would be preferable. | 611 // On the OOBE network selection screen, fixed width menu would be preferable. |
616 minimum_input_method_menu_width_ = width; | 612 minimum_input_method_menu_width_ = width; |
617 } | 613 } |
618 | 614 |
619 } // namespace chromeos | 615 } // namespace chromeos |
OLD | NEW |