OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 203 } |
204 | 204 |
205 bool InputMethodMenu::IsItemCheckedAt(int index) const { | 205 bool InputMethodMenu::IsItemCheckedAt(int index) const { |
206 DCHECK_GE(index, 0); | 206 DCHECK_GE(index, 0); |
207 DCHECK(input_method_descriptors_.get()); | 207 DCHECK(input_method_descriptors_.get()); |
208 | 208 |
209 if (IndexIsInInputMethodList(index)) { | 209 if (IndexIsInInputMethodList(index)) { |
210 const input_method::InputMethodDescriptor& input_method | 210 const input_method::InputMethodDescriptor& input_method |
211 = input_method_descriptors_->at(index); | 211 = input_method_descriptors_->at(index); |
212 return input_method == InputMethodManager::GetInstance()-> | 212 return input_method == InputMethodManager::GetInstance()-> |
213 current_input_method(); | 213 GetCurrentInputMethod(); |
214 } | 214 } |
215 | 215 |
216 if (GetPropertyIndex(index, &index)) { | 216 if (GetPropertyIndex(index, &index)) { |
217 const input_method::ImePropertyList& property_list | 217 const input_method::InputMethodPropertyList& property_list |
218 = InputMethodManager::GetInstance()->current_ime_properties(); | 218 = InputMethodManager::GetInstance()->GetCurrentInputMethodProperties(); |
219 return property_list.at(index).is_selection_item_checked; | 219 return property_list.at(index).is_selection_item_checked; |
220 } | 220 } |
221 | 221 |
222 // Separator(s) or the "Customize language and input..." button. | 222 // Separator(s) or the "Customize language and input..." button. |
223 return false; | 223 return false; |
224 } | 224 } |
225 | 225 |
226 int InputMethodMenu::GetGroupIdAt(int index) const { | 226 int InputMethodMenu::GetGroupIdAt(int index) const { |
227 DCHECK_GE(index, 0); | 227 DCHECK_GE(index, 0); |
228 | 228 |
229 if (IndexIsInInputMethodList(index)) { | 229 if (IndexIsInInputMethodList(index)) { |
230 return for_out_of_box_experience_dialog_ ? | 230 return for_out_of_box_experience_dialog_ ? |
231 kRadioGroupNone : kRadioGroupLanguage; | 231 kRadioGroupNone : kRadioGroupLanguage; |
232 } | 232 } |
233 | 233 |
234 if (GetPropertyIndex(index, &index)) { | 234 if (GetPropertyIndex(index, &index)) { |
235 const input_method::ImePropertyList& property_list | 235 const input_method::InputMethodPropertyList& property_list |
236 = InputMethodManager::GetInstance()->current_ime_properties(); | 236 = InputMethodManager::GetInstance()->GetCurrentInputMethodProperties(); |
237 return property_list.at(index).selection_item_id; | 237 return property_list.at(index).selection_item_id; |
238 } | 238 } |
239 | 239 |
240 return kRadioGroupNone; | 240 return kRadioGroupNone; |
241 } | 241 } |
242 | 242 |
243 bool InputMethodMenu::HasIcons() const { | 243 bool InputMethodMenu::HasIcons() const { |
244 // We don't support icons on Chrome OS. | 244 // We don't support icons on Chrome OS. |
245 return false; | 245 return false; |
246 } | 246 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 if (IndexPointsToConfigureImeMenuItem(index)) { | 292 if (IndexPointsToConfigureImeMenuItem(index)) { |
293 return ui::MenuModel::TYPE_COMMAND; // "Customize language and input" | 293 return ui::MenuModel::TYPE_COMMAND; // "Customize language and input" |
294 } | 294 } |
295 | 295 |
296 if (IndexIsInInputMethodList(index)) { | 296 if (IndexIsInInputMethodList(index)) { |
297 return for_out_of_box_experience_dialog_ ? | 297 return for_out_of_box_experience_dialog_ ? |
298 ui::MenuModel::TYPE_COMMAND : ui::MenuModel::TYPE_RADIO; | 298 ui::MenuModel::TYPE_COMMAND : ui::MenuModel::TYPE_RADIO; |
299 } | 299 } |
300 | 300 |
301 if (GetPropertyIndex(index, &index)) { | 301 if (GetPropertyIndex(index, &index)) { |
302 const input_method::ImePropertyList& property_list | 302 const input_method::InputMethodPropertyList& property_list |
303 = InputMethodManager::GetInstance()->current_ime_properties(); | 303 = InputMethodManager::GetInstance()->GetCurrentInputMethodProperties(); |
304 if (property_list.at(index).is_selection_item) { | 304 if (property_list.at(index).is_selection_item) { |
305 return ui::MenuModel::TYPE_RADIO; | 305 return ui::MenuModel::TYPE_RADIO; |
306 } | 306 } |
307 return ui::MenuModel::TYPE_COMMAND; | 307 return ui::MenuModel::TYPE_COMMAND; |
308 } | 308 } |
309 | 309 |
310 return ui::MenuModel::TYPE_SEPARATOR; | 310 return ui::MenuModel::TYPE_SEPARATOR; |
311 } | 311 } |
312 | 312 |
313 string16 InputMethodMenu::GetLabelAt(int index) const { | 313 string16 InputMethodMenu::GetLabelAt(int index) const { |
314 DCHECK_GE(index, 0); | 314 DCHECK_GE(index, 0); |
315 DCHECK(input_method_descriptors_.get()); | 315 DCHECK(input_method_descriptors_.get()); |
316 | 316 |
317 // We use IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE here as the button | 317 // We use IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE here as the button |
318 // opens the same dialog that is opened from the main options dialog. | 318 // opens the same dialog that is opened from the main options dialog. |
319 if (IndexPointsToConfigureImeMenuItem(index)) { | 319 if (IndexPointsToConfigureImeMenuItem(index)) { |
320 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE); | 320 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE); |
321 } | 321 } |
322 | 322 |
323 string16 name; | 323 string16 name; |
324 if (IndexIsInInputMethodList(index)) { | 324 if (IndexIsInInputMethodList(index)) { |
325 name = GetTextForMenu(input_method_descriptors_->at(index)); | 325 name = GetTextForMenu(input_method_descriptors_->at(index)); |
326 } else if (GetPropertyIndex(index, &index)) { | 326 } else if (GetPropertyIndex(index, &index)) { |
327 InputMethodManager* manager = InputMethodManager::GetInstance(); | 327 InputMethodManager* manager = InputMethodManager::GetInstance(); |
328 const input_method::ImePropertyList& property_list = | 328 const input_method::InputMethodPropertyList& property_list = |
329 manager->current_ime_properties(); | 329 manager->GetCurrentInputMethodProperties(); |
330 return manager->GetInputMethodUtil()->TranslateString( | 330 return manager->GetInputMethodUtil()->TranslateString( |
331 property_list.at(index).label); | 331 property_list.at(index).label); |
332 } | 332 } |
333 | 333 |
334 return name; | 334 return name; |
335 } | 335 } |
336 | 336 |
337 void InputMethodMenu::ActivatedAt(int index) { | 337 void InputMethodMenu::ActivatedAt(int index) { |
338 DCHECK_GE(index, 0); | 338 DCHECK_GE(index, 0); |
339 DCHECK(input_method_descriptors_.get()); | 339 DCHECK(input_method_descriptors_.get()); |
340 | 340 |
341 if (IndexPointsToConfigureImeMenuItem(index)) { | 341 if (IndexPointsToConfigureImeMenuItem(index)) { |
342 OpenConfigUI(); | 342 OpenConfigUI(); |
343 return; | 343 return; |
344 } | 344 } |
345 | 345 |
346 if (IndexIsInInputMethodList(index)) { | 346 if (IndexIsInInputMethodList(index)) { |
347 // Inter-IME switching. | 347 // Inter-IME switching. |
348 const input_method::InputMethodDescriptor& input_method | 348 const input_method::InputMethodDescriptor& input_method |
349 = input_method_descriptors_->at(index); | 349 = input_method_descriptors_->at(index); |
350 InputMethodManager::GetInstance()->ChangeInputMethod( | 350 InputMethodManager::GetInstance()->ChangeInputMethod( |
351 input_method.id()); | 351 input_method.id()); |
352 content::RecordAction( | 352 content::RecordAction( |
353 UserMetricsAction("LanguageMenuButton_InputMethodChanged")); | 353 UserMetricsAction("LanguageMenuButton_InputMethodChanged")); |
354 return; | 354 return; |
355 } | 355 } |
356 | 356 |
357 if (GetPropertyIndex(index, &index)) { | 357 if (GetPropertyIndex(index, &index)) { |
358 // Intra-IME switching (e.g. Japanese-Hiragana to Japanese-Katakana). | 358 // Intra-IME switching (e.g. Japanese-Hiragana to Japanese-Katakana). |
359 const input_method::ImePropertyList& property_list | 359 const input_method::InputMethodPropertyList& property_list |
360 = InputMethodManager::GetInstance()->current_ime_properties(); | 360 = InputMethodManager::GetInstance()->GetCurrentInputMethodProperties(); |
361 const std::string key = property_list.at(index).key; | 361 const std::string key = property_list.at(index).key; |
362 if (property_list.at(index).is_selection_item) { | 362 if (property_list.at(index).is_selection_item) { |
363 // Radio button is clicked. | 363 // Radio button is clicked. |
364 const int id = property_list.at(index).selection_item_id; | 364 const int id = property_list.at(index).selection_item_id; |
365 // First, deactivate all other properties in the same radio group. | 365 // First, deactivate all other properties in the same radio group. |
366 for (int i = 0; i < static_cast<int>(property_list.size()); ++i) { | 366 for (int i = 0; i < static_cast<int>(property_list.size()); ++i) { |
367 if (i != index && id == property_list.at(i).selection_item_id) { | 367 if (i != index && id == property_list.at(i).selection_item_id) { |
368 InputMethodManager::GetInstance()->SetImePropertyActivated( | 368 InputMethodManager::GetInstance()->SetImePropertyActivated( |
369 property_list.at(i).key, false); | 369 property_list.at(i).key, false); |
370 } | 370 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 } else if (StatusAreaViewChromeos::IsLoginMode()) { | 430 } else if (StatusAreaViewChromeos::IsLoginMode()) { |
431 if (g_browser_process && g_browser_process->local_state()) { | 431 if (g_browser_process && g_browser_process->local_state()) { |
432 g_browser_process->local_state()->SetString( | 432 g_browser_process->local_state()->SetString( |
433 language_prefs::kPreferredKeyboardLayout, current_input_method.id()); | 433 language_prefs::kPreferredKeyboardLayout, current_input_method.id()); |
434 } | 434 } |
435 } | 435 } |
436 } | 436 } |
437 | 437 |
438 void InputMethodMenu::PropertyListChanged( | 438 void InputMethodMenu::PropertyListChanged( |
439 InputMethodManager* manager, | 439 InputMethodManager* manager, |
440 const input_method::ImePropertyList& current_ime_properties) { | 440 const input_method::InputMethodPropertyList& current_ime_properties) { |
441 // Usual order of notifications of input method change is: | 441 // Usual order of notifications of input method change is: |
442 // 1. RegisterProperties(empty) | 442 // 1. RegisterProperties(empty) |
443 // 2. RegisterProperties(list-of-new-properties) | 443 // 2. RegisterProperties(list-of-new-properties) |
444 // 3. GlobalInputMethodChanged | 444 // 3. GlobalInputMethodChanged |
445 // However, due to the asynchronicity, we occasionally (but rarely) face to | 445 // However, due to the asynchronicity, we occasionally (but rarely) face to |
446 // 1. RegisterProperties(empty) | 446 // 1. RegisterProperties(empty) |
447 // 2. GlobalInputMethodChanged | 447 // 2. GlobalInputMethodChanged |
448 // 3. RegisterProperties(list-of-new-properties) | 448 // 3. RegisterProperties(list-of-new-properties) |
449 // this order. On this unusual case, we must rebuild the menu after the last | 449 // this order. On this unusual case, we must rebuild the menu after the last |
450 // RegisterProperties. For the other cases, no rebuild is needed. Actually | 450 // RegisterProperties. For the other cases, no rebuild is needed. Actually |
451 // it is better to be avoided. Otherwise users can sometimes observe the | 451 // it is better to be avoided. Otherwise users can sometimes observe the |
452 // awkward clear-then-register behavior. | 452 // awkward clear-then-register behavior. |
453 if (!current_ime_properties.empty()) { | 453 if (!current_ime_properties.empty()) { |
454 const input_method::InputMethodDescriptor& input_method = | 454 const input_method::InputMethodDescriptor& input_method = |
455 manager->current_input_method(); | 455 manager->GetCurrentInputMethod(); |
456 size_t num_active_input_methods = manager->GetNumActiveInputMethods(); | 456 size_t num_active_input_methods = manager->GetNumActiveInputMethods(); |
457 UpdateUIFromInputMethod(input_method, num_active_input_methods); | 457 UpdateUIFromInputMethod(input_method, num_active_input_methods); |
458 } | 458 } |
459 } | 459 } |
460 | 460 |
461 void InputMethodMenu::FirstObserverIsAdded(InputMethodManager* manager) { | 461 void InputMethodMenu::FirstObserverIsAdded(InputMethodManager* manager) { |
462 // NOTICE: Since this function might be called from the constructor of this | 462 // NOTICE: Since this function might be called from the constructor of this |
463 // class, it's better to avoid calling virtual functions. | 463 // class, it's better to avoid calling virtual functions. |
464 | 464 |
465 if (pref_service_ && (StatusAreaViewChromeos::IsBrowserMode())) { | 465 if (pref_service_ && (StatusAreaViewChromeos::IsBrowserMode())) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 // We "abuse" the command_id and group_id arguments of AddRadioItem method. | 519 // We "abuse" the command_id and group_id arguments of AddRadioItem method. |
520 // A COMMAND_ID_XXX enum value is passed as command_id, and array index of | 520 // A COMMAND_ID_XXX enum value is passed as command_id, and array index of |
521 // |input_method_descriptors_| or |property_list| is passed as group_id. | 521 // |input_method_descriptors_| or |property_list| is passed as group_id. |
522 for (size_t i = 0; i < input_method_descriptors_->size(); ++i) { | 522 for (size_t i = 0; i < input_method_descriptors_->size(); ++i) { |
523 model_->AddRadioItem(COMMAND_ID_INPUT_METHODS, dummy_label, i); | 523 model_->AddRadioItem(COMMAND_ID_INPUT_METHODS, dummy_label, i); |
524 } | 524 } |
525 | 525 |
526 need_separator = true; | 526 need_separator = true; |
527 } | 527 } |
528 | 528 |
529 const input_method::ImePropertyList& property_list | 529 const input_method::InputMethodPropertyList& property_list |
530 = InputMethodManager::GetInstance()->current_ime_properties(); | 530 = InputMethodManager::GetInstance()->GetCurrentInputMethodProperties(); |
531 if (!property_list.empty()) { | 531 if (!property_list.empty()) { |
532 if (need_separator) { | 532 if (need_separator) { |
533 model_->AddSeparator(); | 533 model_->AddSeparator(); |
534 } | 534 } |
535 for (size_t i = 0; i < property_list.size(); ++i) { | 535 for (size_t i = 0; i < property_list.size(); ++i) { |
536 model_->AddRadioItem(COMMAND_ID_IME_PROPERTIES, dummy_label, i); | 536 model_->AddRadioItem(COMMAND_ID_IME_PROPERTIES, dummy_label, i); |
537 } | 537 } |
538 need_separator = true; | 538 need_separator = true; |
539 } | 539 } |
540 | 540 |
(...skipping 28 matching lines...) Expand all Loading... |
569 DCHECK_GE(index, 0); | 569 DCHECK_GE(index, 0); |
570 DCHECK(property_index); | 570 DCHECK(property_index); |
571 DCHECK(model_.get()); | 571 DCHECK(model_.get()); |
572 if (index >= model_->GetItemCount()) { | 572 if (index >= model_->GetItemCount()) { |
573 return false; | 573 return false; |
574 } | 574 } |
575 | 575 |
576 if ((model_->GetTypeAt(index) == ui::MenuModel::TYPE_RADIO) && | 576 if ((model_->GetTypeAt(index) == ui::MenuModel::TYPE_RADIO) && |
577 (model_->GetCommandIdAt(index) == COMMAND_ID_IME_PROPERTIES)) { | 577 (model_->GetCommandIdAt(index) == COMMAND_ID_IME_PROPERTIES)) { |
578 const int tmp_property_index = model_->GetGroupIdAt(index); | 578 const int tmp_property_index = model_->GetGroupIdAt(index); |
579 const input_method::ImePropertyList& property_list | 579 const input_method::InputMethodPropertyList& property_list |
580 = InputMethodManager::GetInstance()->current_ime_properties(); | 580 = InputMethodManager::GetInstance()->GetCurrentInputMethodProperties(); |
581 if (tmp_property_index < static_cast<int>(property_list.size())) { | 581 if (tmp_property_index < static_cast<int>(property_list.size())) { |
582 *property_index = tmp_property_index; | 582 *property_index = tmp_property_index; |
583 return true; | 583 return true; |
584 } | 584 } |
585 } | 585 } |
586 return false; | 586 return false; |
587 } | 587 } |
588 | 588 |
589 bool InputMethodMenu::IndexPointsToConfigureImeMenuItem(int index) const { | 589 bool InputMethodMenu::IndexPointsToConfigureImeMenuItem(int index) const { |
590 DCHECK_GE(index, 0); | 590 DCHECK_GE(index, 0); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 // When a user logs in, we should remove |this| object from the observer | 692 // When a user logs in, we should remove |this| object from the observer |
693 // list so that PreferenceUpdateNeeded() does not update the local state | 693 // list so that PreferenceUpdateNeeded() does not update the local state |
694 // anymore. | 694 // anymore. |
695 RemoveObservers(); | 695 RemoveObservers(); |
696 } | 696 } |
697 #if defined(USE_AURA) | 697 #if defined(USE_AURA) |
698 if (type == chrome::NOTIFICATION_SESSION_STARTED) { | 698 if (type == chrome::NOTIFICATION_SESSION_STARTED) { |
699 InitializePrefMembers(); | 699 InitializePrefMembers(); |
700 AddObservers(); | 700 AddObservers(); |
701 InputMethodManager* manager = InputMethodManager::GetInstance(); | 701 InputMethodManager* manager = InputMethodManager::GetInstance(); |
702 UpdateUIFromInputMethod(manager->current_input_method(), | 702 UpdateUIFromInputMethod(manager->GetCurrentInputMethod(), |
703 manager->GetNumActiveInputMethods()); | 703 manager->GetNumActiveInputMethods()); |
704 } | 704 } |
705 #endif | 705 #endif |
706 } | 706 } |
707 | 707 |
708 void InputMethodMenu::SetMinimumWidth(int width) { | 708 void InputMethodMenu::SetMinimumWidth(int width) { |
709 // On the OOBE network selection screen, fixed width menu would be preferable. | 709 // On the OOBE network selection screen, fixed width menu would be preferable. |
710 minimum_input_method_menu_width_ = width; | 710 minimum_input_method_menu_width_ = width; |
711 } | 711 } |
712 | 712 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 if (!initialized_prefs_) { | 744 if (!initialized_prefs_) { |
745 initialized_prefs_ = true; | 745 initialized_prefs_ = true; |
746 previous_input_method_pref_.Init( | 746 previous_input_method_pref_.Init( |
747 prefs::kLanguagePreviousInputMethod, pref_service_, this); | 747 prefs::kLanguagePreviousInputMethod, pref_service_, this); |
748 current_input_method_pref_.Init( | 748 current_input_method_pref_.Init( |
749 prefs::kLanguageCurrentInputMethod, pref_service_, this); | 749 prefs::kLanguageCurrentInputMethod, pref_service_, this); |
750 } | 750 } |
751 } | 751 } |
752 | 752 |
753 } // namespace chromeos | 753 } // namespace chromeos |
OLD | NEW |