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/language_menu_button.h" | 5 #include "chrome/browser/chromeos/status/language_menu_button.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 DCHECK(input_method_descriptors_.get()); | 314 DCHECK(input_method_descriptors_.get()); |
315 | 315 |
316 // We use IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE here as the button | 316 // We use IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE here as the button |
317 // opens the same dialog that is opened from the main options dialog. | 317 // opens the same dialog that is opened from the main options dialog. |
318 if (IndexPointsToConfigureImeMenuItem(index)) { | 318 if (IndexPointsToConfigureImeMenuItem(index)) { |
319 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE); | 319 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE); |
320 } | 320 } |
321 | 321 |
322 std::wstring name; | 322 std::wstring name; |
323 if (IndexIsInInputMethodList(index)) { | 323 if (IndexIsInInputMethodList(index)) { |
324 const std::string language_code = | 324 name = GetTextForMenu(input_method_descriptors_->at(index)); |
325 input_method::GetLanguageCodeFromDescriptor( | |
326 input_method_descriptors_->at(index)); | |
327 const bool need_method_name = | |
328 (ambiguous_language_code_set_.count(language_code) > 0); | |
329 name = GetTextForMenu(input_method_descriptors_->at(index), | |
330 need_method_name); | |
331 } else if (GetPropertyIndex(index, &index)) { | 325 } else if (GetPropertyIndex(index, &index)) { |
332 const ImePropertyList& property_list | 326 const ImePropertyList& property_list |
333 = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); | 327 = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); |
334 return input_method::GetStringUTF16(property_list.at(index).label); | 328 return input_method::GetStringUTF16(property_list.at(index).label); |
335 } | 329 } |
336 | 330 |
337 return WideToUTF16(name); | 331 return WideToUTF16(name); |
338 } | 332 } |
339 | 333 |
340 void LanguageMenuButton::ActivatedAt(int index) { | 334 void LanguageMenuButton::ActivatedAt(int index) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 SetEnabled(true); | 480 SetEnabled(true); |
487 SetTooltipText(tooltip); | 481 SetTooltipText(tooltip); |
488 } | 482 } |
489 SetText(name); | 483 SetText(name); |
490 SchedulePaint(); | 484 SchedulePaint(); |
491 } | 485 } |
492 | 486 |
493 void LanguageMenuButton::UpdateIndicatorFromInputMethod( | 487 void LanguageMenuButton::UpdateIndicatorFromInputMethod( |
494 const InputMethodDescriptor& input_method) { | 488 const InputMethodDescriptor& input_method) { |
495 const std::wstring name = GetTextForIndicator(input_method); | 489 const std::wstring name = GetTextForIndicator(input_method); |
496 const std::wstring tooltip = | 490 const std::wstring tooltip = GetTextForMenu(input_method); |
497 GetTextForMenu(input_method, true /* add_method_name */); | |
498 UpdateIndicator(name, tooltip); | 491 UpdateIndicator(name, tooltip); |
499 } | 492 } |
500 | 493 |
501 void LanguageMenuButton::RebuildModel() { | 494 void LanguageMenuButton::RebuildModel() { |
502 model_.reset(new menus::SimpleMenuModel(NULL)); | 495 model_.reset(new menus::SimpleMenuModel(NULL)); |
503 string16 dummy_label = UTF8ToUTF16(""); | 496 string16 dummy_label = UTF8ToUTF16(""); |
504 // Indicates if separator's needed before each section. | 497 // Indicates if separator's needed before each section. |
505 bool need_separator = false; | 498 bool need_separator = false; |
506 | 499 |
507 ambiguous_language_code_set_.clear(); | |
508 if (!input_method_descriptors_->empty()) { | 500 if (!input_method_descriptors_->empty()) { |
509 // We "abuse" the command_id and group_id arguments of AddRadioItem method. | 501 // We "abuse" the command_id and group_id arguments of AddRadioItem method. |
510 // A COMMAND_ID_XXX enum value is passed as command_id, and array index of | 502 // A COMMAND_ID_XXX enum value is passed as command_id, and array index of |
511 // |input_method_descriptors_| or |property_list| is passed as group_id. | 503 // |input_method_descriptors_| or |property_list| is passed as group_id. |
512 for (size_t i = 0; i < input_method_descriptors_->size(); ++i) { | 504 for (size_t i = 0; i < input_method_descriptors_->size(); ++i) { |
513 model_->AddRadioItem(COMMAND_ID_INPUT_METHODS, dummy_label, i); | 505 model_->AddRadioItem(COMMAND_ID_INPUT_METHODS, dummy_label, i); |
514 } | 506 } |
515 | 507 |
516 GetAmbiguousLanguageCodeSet(*input_method_descriptors_, | |
517 &ambiguous_language_code_set_); | |
518 need_separator = true; | 508 need_separator = true; |
519 } | 509 } |
520 | 510 |
521 const ImePropertyList& property_list | 511 const ImePropertyList& property_list |
522 = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); | 512 = CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties(); |
523 if (!property_list.empty()) { | 513 if (!property_list.empty()) { |
524 if (need_separator) | 514 if (need_separator) |
525 model_->AddSeparator(); | 515 model_->AddSeparator(); |
526 for (size_t i = 0; i < property_list.size(); ++i) { | 516 for (size_t i = 0; i < property_list.size(); ++i) { |
527 model_->AddRadioItem(COMMAND_ID_IME_PROPERTIES, dummy_label, i); | 517 model_->AddRadioItem(COMMAND_ID_IME_PROPERTIES, dummy_label, i); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 } | 620 } |
631 | 621 |
632 text = StringToUpperASCII(UTF8ToWide(language_code)).substr( | 622 text = StringToUpperASCII(UTF8ToWide(language_code)).substr( |
633 0, kMaxLanguageNameLen); | 623 0, kMaxLanguageNameLen); |
634 } | 624 } |
635 DCHECK(!text.empty()); | 625 DCHECK(!text.empty()); |
636 return text; | 626 return text; |
637 } | 627 } |
638 | 628 |
639 std::wstring LanguageMenuButton::GetTextForMenu( | 629 std::wstring LanguageMenuButton::GetTextForMenu( |
640 const InputMethodDescriptor& input_method, bool add_method_name) { | 630 const InputMethodDescriptor& input_method) { |
| 631 // We don't show language here. Name of keyboard layout or input method |
| 632 // usually imply (or explicitly include) its language. |
| 633 |
| 634 // Special case for Dutch, French and German: these languages have multiple |
| 635 // keyboard layouts and share the same laout of keyboard (Belgian). We need to |
| 636 // show explicitly the language for the layout. |
| 637 // For Arabic, Hebrew and Hindi: they share "Standard Input Method". |
641 const std::string language_code | 638 const std::string language_code |
642 = input_method::GetLanguageCodeFromDescriptor(input_method); | 639 = input_method::GetLanguageCodeFromDescriptor(input_method); |
| 640 std::wstring text; |
| 641 if (language_code == "ar" || |
| 642 language_code == "he" || |
| 643 language_code == "hi" || |
| 644 language_code == "nl" || |
| 645 language_code == "fr" || |
| 646 language_code == "de") { |
| 647 text = GetLanguageName(language_code) + L" - "; |
| 648 } |
| 649 text += input_method::GetString(input_method.display_name); |
643 | 650 |
644 // For the drop-down menu and tooltip, we'll show language names like | |
645 // "Chinese (Simplified)" and "Japanese", instead of input method names | |
646 // like "Pinyin" and "Mozc". | |
647 std::wstring text = GetLanguageName(language_code); | |
648 if (add_method_name) { | |
649 text += L" - "; | |
650 text += input_method::GetString(input_method.display_name); | |
651 } | |
652 DCHECK(!text.empty()); | 651 DCHECK(!text.empty()); |
653 return text; | 652 return text; |
654 } | 653 } |
655 | 654 |
656 void LanguageMenuButton::RegisterPrefs(PrefService* local_state) { | 655 void LanguageMenuButton::RegisterPrefs(PrefService* local_state) { |
657 local_state->RegisterStringPref(language_prefs::kPreferredKeyboardLayout, | 656 local_state->RegisterStringPref(language_prefs::kPreferredKeyboardLayout, |
658 ""); | 657 ""); |
659 } | 658 } |
660 | 659 |
661 void LanguageMenuButton::GetAmbiguousLanguageCodeSet( | |
662 const InputMethodDescriptors& input_method_descriptors, | |
663 std::set<std::string>* ambiguous_language_code_set) { | |
664 DCHECK(ambiguous_language_code_set); | |
665 ambiguous_language_code_set->clear(); | |
666 | |
667 std::set<std::string> languages_seen; | |
668 for (size_t i = 0; i < input_method_descriptors.size(); ++i) { | |
669 const std::string language_code | |
670 = input_method::GetLanguageCodeFromDescriptor( | |
671 input_method_descriptors.at(i)); | |
672 // If there is more than one input method for this language, then we need | |
673 // to display the method name. | |
674 if (languages_seen.count(language_code) > 0 || | |
675 // Special-case Japanese as showing the language name alone is | |
676 // confusing when Japanese keyboard is enabled but Japanese | |
677 // input methods are not. | |
678 language_code == "ja") { | |
679 ambiguous_language_code_set->insert(language_code); | |
680 } else { | |
681 languages_seen.insert(language_code); | |
682 } | |
683 } | |
684 } | |
685 | |
686 void LanguageMenuButton::Observe(NotificationType type, | 660 void LanguageMenuButton::Observe(NotificationType type, |
687 const NotificationSource& source, | 661 const NotificationSource& source, |
688 const NotificationDetails& details) { | 662 const NotificationDetails& details) { |
689 if (type == NotificationType::LOGIN_USER_CHANGED) { | 663 if (type == NotificationType::LOGIN_USER_CHANGED) { |
690 logged_in_ = true; | 664 logged_in_ = true; |
691 } | 665 } |
692 } | 666 } |
693 | 667 |
694 } // namespace chromeos | 668 } // namespace chromeos |
OLD | NEW |