Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: ui/base/ime/chromeos/input_method_util.cc

Issue 2919583002: chromeos: Move InputMethodUtil into //ui/base/ime/chromeos (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/input_method/input_method_util.h" 5 #include "ui/base/ime/chromeos/input_method_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <functional> 10 #include <functional>
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <unordered_set> 13 #include <unordered_set>
14 #include <utility> 14 #include <utility>
15 15
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/strings/string_split.h" 17 #include "base/strings/string_split.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "chrome/common/extensions/extension_constants.h"
21 // TODO(nona): move this header from this file.
22 #include "chrome/grit/generated_resources.h"
23 #include "components/prefs/pref_service.h"
24 #include "ui/base/ime/chromeos/component_extension_ime_manager.h" 20 #include "ui/base/ime/chromeos/component_extension_ime_manager.h"
25 #include "ui/base/ime/chromeos/extension_ime_util.h" 21 #include "ui/base/ime/chromeos/extension_ime_util.h"
26 // For SetHardwareKeyboardLayoutForTesting. 22 // For SetHardwareKeyboardLayoutForTesting.
27 #include "ui/base/ime/chromeos/fake_input_method_delegate.h" 23 #include "ui/base/ime/chromeos/fake_input_method_delegate.h"
28 #include "ui/base/ime/chromeos/input_method_delegate.h" 24 #include "ui/base/ime/chromeos/input_method_delegate.h"
29 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/chromeos/strings/grit/ui_chromeos_strings.h"
30 27
31 namespace { 28 namespace {
32 29
33 // A mapping from an input method id to a resource id for a 30 // A mapping from an input method id to a resource id for a
34 // medium length language indicator. 31 // medium length language indicator.
35 // For those languages that want to display a slightly longer text in the 32 // For those languages that want to display a slightly longer text in the
36 // "Your input method has changed to..." bubble than in the status tray. 33 // "Your input method has changed to..." bubble than in the status tray.
37 // If an entry is not found in this table the short name is used. 34 // If an entry is not found in this table the short name is used.
38 const struct { 35 const struct {
39 const char* engine_id; 36 const char* engine_id;
40 const int resource_id; 37 const int resource_id;
41 } kMappingImeIdToMediumLenNameResourceId[] = { 38 } kMappingImeIdToMediumLenNameResourceId[] = {
42 { "hangul_2set", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN }, 39 { "hangul_2set", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN },
43 { "hangul_3set390", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN }, 40 { "hangul_3set390", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN },
44 { "hangul_3setfinal", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN }, 41 { "hangul_3setfinal", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN },
45 { "hangul_3setnoshift", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN }, 42 { "hangul_3setnoshift", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN },
46 { "hangul_3setromaja", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN }, 43 { "hangul_3setromaja", IDS_LANGUAGES_MEDIUM_LEN_NAME_KOREAN },
47 { "zh-t-i0-pinyin", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_SIMPLIFIED}, 44 { "zh-t-i0-pinyin", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_SIMPLIFIED},
48 { "zh-t-i0-wubi-1986", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_SIMPLIFIED }, 45 { "zh-t-i0-wubi-1986", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_SIMPLIFIED },
49 { "zh-hant-t-i0-und", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, 46 { "zh-hant-t-i0-und", IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL },
50 { "zh-hant-t-i0-cangjie-1987", 47 { "zh-hant-t-i0-cangjie-1987",
51 IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, 48 IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL },
52 { "zh-hant-t-i0-cangjie-1987-x-m0-simplified", 49 { "zh-hant-t-i0-cangjie-1987-x-m0-simplified",
53 IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL }, 50 IDS_LANGUAGES_MEDIUM_LEN_NAME_CHINESE_TRADITIONAL },
54 { extension_misc::kBrailleImeEngineId, 51 { chromeos::extension_ime_util::kBrailleImeEngineId,
55 IDS_LANGUAGES_MEDIUM_LEN_NAME_BRAILLE }, 52 IDS_LANGUAGES_MEDIUM_LEN_NAME_BRAILLE },
56 }; 53 };
57 const size_t kMappingImeIdToMediumLenNameResourceIdLen = 54 const size_t kMappingImeIdToMediumLenNameResourceIdLen =
58 arraysize(kMappingImeIdToMediumLenNameResourceId); 55 arraysize(kMappingImeIdToMediumLenNameResourceId);
59 56
60 // Due to asynchronous initialization of component extension manager, 57 // Due to asynchronous initialization of component extension manager,
61 // GetFirstLoginInputMethodIds may miss component extension IMEs. To enable 58 // GetFirstLoginInputMethodIds may miss component extension IMEs. To enable
62 // component extension IME as the first loging input method, we have to prepare 59 // component extension IME as the first loging input method, we have to prepare
63 // component extension IME IDs. 60 // component extension IME IDs.
64 // Note: empty layout means the rule applies for all layouts. 61 // Note: empty layout means the rule applies for all layouts.
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // Initialize a map from English string to Chrome string resource ID as well. 378 // Initialize a map from English string to Chrome string resource ID as well.
382 for (size_t i = 0; i < kEnglishToResourceIdArraySize; ++i) { 379 for (size_t i = 0; i < kEnglishToResourceIdArraySize; ++i) {
383 const EnglishToResouceId& map_entry = kEnglishToResourceIdArray[i]; 380 const EnglishToResouceId& map_entry = kEnglishToResourceIdArray[i];
384 const bool result = english_to_resource_id_.insert(std::make_pair( 381 const bool result = english_to_resource_id_.insert(std::make_pair(
385 map_entry.english_string_from_ibus, map_entry.resource_id)).second; 382 map_entry.english_string_from_ibus, map_entry.resource_id)).second;
386 DCHECK(result) << "Duplicated string is found: " 383 DCHECK(result) << "Duplicated string is found: "
387 << map_entry.english_string_from_ibus; 384 << map_entry.english_string_from_ibus;
388 } 385 }
389 } 386 }
390 387
391 InputMethodUtil::~InputMethodUtil() { 388 InputMethodUtil::~InputMethodUtil() {}
392 }
393 389
394 std::string InputMethodUtil::GetLocalizedDisplayName( 390 std::string InputMethodUtil::GetLocalizedDisplayName(
395 const InputMethodDescriptor& descriptor) const { 391 const InputMethodDescriptor& descriptor) const {
396 // Localizes the input method name. 392 // Localizes the input method name.
397 const std::string& disp = descriptor.name(); 393 const std::string& disp = descriptor.name();
398 if (base::StartsWith(disp, "__MSG_", base::CompareCase::SENSITIVE)) { 394 if (base::StartsWith(disp, "__MSG_", base::CompareCase::SENSITIVE)) {
399 const InputMethodNameMap* map = kInputMethodNameMap; 395 const InputMethodNameMap* map = kInputMethodNameMap;
400 size_t map_size = arraysize(kInputMethodNameMap); 396 size_t map_size = arraysize(kInputMethodNameMap);
401 std::string name = base::ToUpperASCII(disp); 397 std::string name = base::ToUpperASCII(disp);
402 const InputMethodNameMap map_key = {name.c_str(), 0}; 398 const InputMethodNameMap map_key = {name.c_str(), 0};
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 if (language_code == "de" || language_code == "fr" || language_code == "nl") { 518 if (language_code == "de" || language_code == "fr" || language_code == "nl") {
523 const base::string16 language_name = delegate_->GetDisplayLanguageName( 519 const base::string16 language_name = delegate_->GetDisplayLanguageName(
524 language_code); 520 language_code);
525 text = language_name + base::UTF8ToUTF16(" - ") + text; 521 text = language_name + base::UTF8ToUTF16(" - ") + text;
526 } 522 }
527 523
528 DCHECK(!text.empty()); 524 DCHECK(!text.empty());
529 return text; 525 return text;
530 } 526 }
531 527
532
533 base::string16 InputMethodUtil::GetInputMethodLongNameStripped( 528 base::string16 InputMethodUtil::GetInputMethodLongNameStripped(
534 const InputMethodDescriptor& input_method) const { 529 const InputMethodDescriptor& input_method) const {
535 return GetInputMethodLongNameInternal(input_method, true /* short_name */); 530 return GetInputMethodLongNameInternal(input_method, true /* short_name */);
536 } 531 }
537 532
538 base::string16 InputMethodUtil::GetInputMethodLongName( 533 base::string16 InputMethodUtil::GetInputMethodLongName(
539 const InputMethodDescriptor& input_method) const { 534 const InputMethodDescriptor& input_method) const {
540 return GetInputMethodLongNameInternal(input_method, false /* short_name */); 535 return GetInputMethodLongNameInternal(input_method, false /* short_name */);
541 } 536 }
542 537
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 void InputMethodUtil::GetFirstLoginInputMethodIds( 582 void InputMethodUtil::GetFirstLoginInputMethodIds(
588 const std::string& language_code, 583 const std::string& language_code,
589 const InputMethodDescriptor& preferred_input_method, 584 const InputMethodDescriptor& preferred_input_method,
590 std::vector<std::string>* out_input_method_ids) const { 585 std::vector<std::string>* out_input_method_ids) const {
591 out_input_method_ids->clear(); 586 out_input_method_ids->clear();
592 587
593 // First, add the preferred keyboard layout (e.g. one used on the login 588 // First, add the preferred keyboard layout (e.g. one used on the login
594 // screen or set in UserContext when starting a public session). 589 // screen or set in UserContext when starting a public session).
595 out_input_method_ids->push_back(preferred_input_method.id()); 590 out_input_method_ids->push_back(preferred_input_method.id());
596 591
597 const std::string current_layout 592 const std::string current_layout =
598 = preferred_input_method.GetPreferredKeyboardLayout(); 593 preferred_input_method.GetPreferredKeyboardLayout();
599 for (size_t i = 0; i < arraysize(kDefaultInputMethodRecommendation); 594 for (size_t i = 0; i < arraysize(kDefaultInputMethodRecommendation); ++i) {
600 ++i) { 595 if (kDefaultInputMethodRecommendation[i].locale == language_code &&
601 if (kDefaultInputMethodRecommendation[i].locale == language_code && ( 596 (!kDefaultInputMethodRecommendation[i].layout[0] ||
602 !kDefaultInputMethodRecommendation[i].layout[0] || 597 kDefaultInputMethodRecommendation[i].layout == current_layout)) {
603 kDefaultInputMethodRecommendation[i].layout == current_layout)) {
604 out_input_method_ids->push_back( 598 out_input_method_ids->push_back(
605 extension_ime_util::GetInputMethodIDByEngineID( 599 extension_ime_util::GetInputMethodIDByEngineID(
606 kDefaultInputMethodRecommendation[i].engine_id)); 600 kDefaultInputMethodRecommendation[i].engine_id));
607 return; 601 return;
608 } 602 }
609 } 603 }
610 604
611 std::vector<std::string> input_method_ids; 605 std::vector<std::string> input_method_ids;
612 GetInputMethodIdsFromLanguageCode( 606 GetInputMethodIdsFromLanguageCode(
613 language_code, kAllInputMethods, &input_method_ids); 607 language_code, kAllInputMethods, &input_method_ids);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 for (size_t j = 0; j < arraysize(kEngineIdMigrationMap); ++j) { 653 for (size_t j = 0; j < arraysize(kEngineIdMigrationMap); ++j) {
660 size_t pos = engine_id.find(kEngineIdMigrationMap[j][0]); 654 size_t pos = engine_id.find(kEngineIdMigrationMap[j][0]);
661 if (pos == 0) { 655 if (pos == 0) {
662 engine_id.replace(0, 656 engine_id.replace(0,
663 strlen(kEngineIdMigrationMap[j][0]), 657 strlen(kEngineIdMigrationMap[j][0]),
664 kEngineIdMigrationMap[j][1]); 658 kEngineIdMigrationMap[j][1]);
665 break; 659 break;
666 } 660 }
667 } 661 }
668 // Migrates the extension IDs. 662 // Migrates the extension IDs.
669 std::string id = 663 std::string id = extension_ime_util::GetInputMethodIDByEngineID(engine_id);
670 extension_ime_util::GetInputMethodIDByEngineID(engine_id);
671 if (extension_ime_util::IsComponentExtensionIME(id)) { 664 if (extension_ime_util::IsComponentExtensionIME(id)) {
672 std::string id_new = extension_ime_util::GetInputMethodIDByEngineID( 665 std::string id_new = extension_ime_util::GetInputMethodIDByEngineID(
673 extension_ime_util::GetComponentIDByInputMethodID(id)); 666 extension_ime_util::GetComponentIDByInputMethodID(id));
674 if (extension_ime_util::IsComponentExtensionIME(id_new)) 667 if (extension_ime_util::IsComponentExtensionIME(id_new))
675 id = id_new; 668 id = id_new;
676 } 669 }
677 return id; 670 return id;
678 } 671 }
679 672
680 bool InputMethodUtil::MigrateInputMethods( 673 bool InputMethodUtil::MigrateInputMethods(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 } 739 }
747 } 740 }
748 741
749 void InputMethodUtil::SetHardwareKeyboardLayoutForTesting( 742 void InputMethodUtil::SetHardwareKeyboardLayoutForTesting(
750 const std::string& layout) { 743 const std::string& layout) {
751 delegate_->SetHardwareKeyboardLayoutForTesting(layout); 744 delegate_->SetHardwareKeyboardLayoutForTesting(layout);
752 cached_hardware_layouts_.clear(); 745 cached_hardware_layouts_.clear();
753 UpdateHardwareLayoutCache(); 746 UpdateHardwareLayoutCache();
754 } 747 }
755 748
756 const std::vector<std::string>& 749 const std::vector<std::string>& InputMethodUtil::GetHardwareInputMethodIds() {
757 InputMethodUtil::GetHardwareInputMethodIds() {
758 DCHECK(thread_checker_.CalledOnValidThread()); 750 DCHECK(thread_checker_.CalledOnValidThread());
759 UpdateHardwareLayoutCache(); 751 UpdateHardwareLayoutCache();
760 return hardware_layouts_; 752 return hardware_layouts_;
761 } 753 }
762 754
763 const std::vector<std::string>& 755 const std::vector<std::string>&
764 InputMethodUtil::GetHardwareLoginInputMethodIds() { 756 InputMethodUtil::GetHardwareLoginInputMethodIds() {
765 DCHECK(thread_checker_.CalledOnValidThread()); 757 DCHECK(thread_checker_.CalledOnValidThread());
766 UpdateHardwareLayoutCache(); 758 UpdateHardwareLayoutCache();
767 return hardware_login_layouts_; 759 return hardware_login_layouts_;
768 } 760 }
769 761
770 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) 762 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id)
771 const { 763 const {
772 const InputMethodDescriptor* ime = 764 const InputMethodDescriptor* ime =
773 GetInputMethodDescriptorFromId(input_method_id); 765 GetInputMethodDescriptorFromId(input_method_id);
774 return ime ? ime->is_login_keyboard() : false; 766 return ime ? ime->is_login_keyboard() : false;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 "US", 820 "US",
829 layouts, 821 layouts,
830 languages, 822 languages,
831 true, // login keyboard. 823 true, // login keyboard.
832 GURL(), // options page, not available. 824 GURL(), // options page, not available.
833 GURL()); // input view page, not available. 825 GURL()); // input view page, not available.
834 } 826 }
835 827
836 } // namespace input_method 828 } // namespace input_method
837 } // namespace chromeos 829 } // namespace chromeos
OLDNEW
« no previous file with comments | « ui/base/ime/chromeos/input_method_util.h ('k') | ui/base/ime/chromeos/input_method_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698