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

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_util.cc

Issue 7663008: Add GetInputMethodDescriptorFromXkbId function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
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/input_method/input_method_util.h" 5 #include "chrome/browser/chromeos/input_method/input_method_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
(...skipping 20 matching lines...) Expand all
31 namespace chromeos { 31 namespace chromeos {
32 namespace input_method { 32 namespace input_method {
33 33
34 namespace { 34 namespace {
35 35
36 // Map from language code to associated input method IDs, etc. 36 // Map from language code to associated input method IDs, etc.
37 typedef std::multimap<std::string, std::string> LanguageCodeToIdsMap; 37 typedef std::multimap<std::string, std::string> LanguageCodeToIdsMap;
38 // Map from input method ID to associated input method descriptor. 38 // Map from input method ID to associated input method descriptor.
39 typedef std::map<std::string, InputMethodDescriptor> 39 typedef std::map<std::string, InputMethodDescriptor>
40 InputMethodIdToDescriptorMap; 40 InputMethodIdToDescriptorMap;
41 // Map from XKB layout ID to associated input method descriptor.
42 typedef std::map<std::string, InputMethodDescriptor> XkbIdToDescriptorMap;
41 43
42 struct IdMaps { 44 struct IdMaps {
43 scoped_ptr<LanguageCodeToIdsMap> language_code_to_ids; 45 scoped_ptr<LanguageCodeToIdsMap> language_code_to_ids;
44 scoped_ptr<std::map<std::string, std::string> > id_to_language_code; 46 scoped_ptr<std::map<std::string, std::string> > id_to_language_code;
45 scoped_ptr<InputMethodIdToDescriptorMap> id_to_descriptor; 47 scoped_ptr<InputMethodIdToDescriptorMap> id_to_descriptor;
48 scoped_ptr<XkbIdToDescriptorMap> xkb_id_to_descriptor;
46 49
47 // Returns the singleton instance. 50 // Returns the singleton instance.
48 static IdMaps* GetInstance() { 51 static IdMaps* GetInstance() {
49 return Singleton<IdMaps>::get(); 52 return Singleton<IdMaps>::get();
50 } 53 }
51 54
52 void ReloadMaps() { 55 void ReloadMaps() {
53 scoped_ptr<InputMethodDescriptors> supported_input_methods( 56 scoped_ptr<InputMethodDescriptors> supported_input_methods(
54 GetSupportedInputMethods()); 57 GetSupportedInputMethods());
55 if (supported_input_methods->size() <= 1) { 58 if (supported_input_methods->size() <= 1) {
56 LOG(ERROR) << "GetSupportedInputMethods returned a fallback ID"; 59 LOG(ERROR) << "GetSupportedInputMethods returned a fallback ID";
57 // TODO(yusukes): Handle this error in nicer way. 60 // TODO(yusukes): Handle this error in nicer way.
58 } 61 }
59 62
60 // Clear the existing maps. 63 // Clear the existing maps.
61 language_code_to_ids->clear(); 64 language_code_to_ids->clear();
62 id_to_language_code->clear(); 65 id_to_language_code->clear();
63 id_to_descriptor->clear(); 66 id_to_descriptor->clear();
67 xkb_id_to_descriptor->clear();
64 68
65 for (size_t i = 0; i < supported_input_methods->size(); ++i) { 69 for (size_t i = 0; i < supported_input_methods->size(); ++i) {
66 const InputMethodDescriptor& input_method = 70 const InputMethodDescriptor& input_method =
67 supported_input_methods->at(i); 71 supported_input_methods->at(i);
68 const std::string language_code = 72 const std::string language_code =
69 GetLanguageCodeFromDescriptor(input_method); 73 GetLanguageCodeFromDescriptor(input_method);
70 language_code_to_ids->insert( 74 language_code_to_ids->insert(
71 std::make_pair(language_code, input_method.id())); 75 std::make_pair(language_code, input_method.id()));
72 // Remember the pairs. 76 // Remember the pairs.
73 id_to_language_code->insert( 77 id_to_language_code->insert(
74 std::make_pair(input_method.id(), language_code)); 78 std::make_pair(input_method.id(), language_code));
75 id_to_descriptor->insert( 79 id_to_descriptor->insert(
76 std::make_pair(input_method.id(), input_method)); 80 std::make_pair(input_method.id(), input_method));
81 if (IsKeyboardLayout(input_method.id())) {
82 xkb_id_to_descriptor->insert(
83 std::make_pair(input_method.keyboard_layout(), input_method));
84 }
77 } 85 }
78 86
79 // Go through the languages listed in kExtraLanguages. 87 // Go through the languages listed in kExtraLanguages.
80 for (size_t i = 0; i < kExtraLanguagesLength; ++i) { 88 for (size_t i = 0; i < kExtraLanguagesLength; ++i) {
81 const char* language_code = kExtraLanguages[i].language_code; 89 const char* language_code = kExtraLanguages[i].language_code;
82 const char* input_method_id = kExtraLanguages[i].input_method_id; 90 const char* input_method_id = kExtraLanguages[i].input_method_id;
83 InputMethodIdToDescriptorMap::const_iterator iter = 91 InputMethodIdToDescriptorMap::const_iterator iter =
84 id_to_descriptor->find(input_method_id); 92 id_to_descriptor->find(input_method_id);
85 // If the associated input method descriptor is found, add the 93 // If the associated input method descriptor is found, add the
86 // language code and the input method. 94 // language code and the input method.
87 if (iter != id_to_descriptor->end()) { 95 if (iter != id_to_descriptor->end()) {
88 const InputMethodDescriptor& input_method = iter->second; 96 const InputMethodDescriptor& input_method = iter->second;
89 language_code_to_ids->insert( 97 language_code_to_ids->insert(
90 std::make_pair(language_code, input_method.id())); 98 std::make_pair(language_code, input_method.id()));
91 } 99 }
92 } 100 }
93 } 101 }
94 102
95 private: 103 private:
96 IdMaps() : language_code_to_ids(new LanguageCodeToIdsMap), 104 IdMaps() : language_code_to_ids(new LanguageCodeToIdsMap),
97 id_to_language_code(new std::map<std::string, std::string>), 105 id_to_language_code(new std::map<std::string, std::string>),
98 id_to_descriptor(new InputMethodIdToDescriptorMap) { 106 id_to_descriptor(new InputMethodIdToDescriptorMap),
107 xkb_id_to_descriptor(new XkbIdToDescriptorMap) {
99 ReloadMaps(); 108 ReloadMaps();
100 } 109 }
101 110
102 friend struct DefaultSingletonTraits<IdMaps>; 111 friend struct DefaultSingletonTraits<IdMaps>;
103 112
104 DISALLOW_COPY_AND_ASSIGN(IdMaps); 113 DISALLOW_COPY_AND_ASSIGN(IdMaps);
105 }; 114 };
106 115
107 const struct EnglishToResouceId { 116 const struct EnglishToResouceId {
108 const char* english_string_from_ibus; 117 const char* english_string_from_ibus;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 } 520 }
512 521
513 const InputMethodDescriptor* GetInputMethodDescriptorFromId( 522 const InputMethodDescriptor* GetInputMethodDescriptorFromId(
514 const std::string& input_method_id) { 523 const std::string& input_method_id) {
515 InputMethodIdToDescriptorMap::const_iterator iter 524 InputMethodIdToDescriptorMap::const_iterator iter
516 = IdMaps::GetInstance()->id_to_descriptor->find(input_method_id); 525 = IdMaps::GetInstance()->id_to_descriptor->find(input_method_id);
517 return (iter == IdMaps::GetInstance()->id_to_descriptor->end()) ? 526 return (iter == IdMaps::GetInstance()->id_to_descriptor->end()) ?
518 NULL : &(iter->second); 527 NULL : &(iter->second);
519 } 528 }
520 529
530 const InputMethodDescriptor* GetInputMethodDescriptorFromXkbId(
531 const std::string& xkb_id) {
532 InputMethodIdToDescriptorMap::const_iterator iter
533 = IdMaps::GetInstance()->xkb_id_to_descriptor->find(xkb_id);
534 return (iter == IdMaps::GetInstance()->xkb_id_to_descriptor->end()) ?
535 NULL : &(iter->second);
536 }
537
521 string16 GetLanguageDisplayNameFromCode(const std::string& language_code) { 538 string16 GetLanguageDisplayNameFromCode(const std::string& language_code) {
522 if (!g_browser_process) { 539 if (!g_browser_process) {
523 return string16(); 540 return string16();
524 } 541 }
525 return l10n_util::GetDisplayNameForLocale( 542 return l10n_util::GetDisplayNameForLocale(
526 language_code, g_browser_process->GetApplicationLocale(), true); 543 language_code, g_browser_process->GetApplicationLocale(), true);
527 } 544 }
528 545
529 string16 GetLanguageNativeDisplayNameFromCode( 546 string16 GetLanguageNativeDisplayNameFromCode(
530 const std::string& language_code) { 547 const std::string& language_code) {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 void ReloadInternalMaps() { 762 void ReloadInternalMaps() {
746 IdMaps::GetInstance()->ReloadMaps(); 763 IdMaps::GetInstance()->ReloadMaps();
747 } 764 }
748 765
749 void OnLocaleChanged() { 766 void OnLocaleChanged() {
750 ReloadInternalMaps(); 767 ReloadInternalMaps();
751 } 768 }
752 769
753 } // namespace input_method 770 } // namespace input_method
754 } // namespace chromeos 771 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698