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

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

Issue 6176007: Revert "Use libcros to convert input method ID to keyboard overlay ID." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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) 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/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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 { "xkb:tr::tur", "tr" }, 102 { "xkb:tr::tur", "tr" },
103 { "xkb:ua::ukr", "uk" }, 103 { "xkb:ua::ukr", "uk" },
104 }; 104 };
105 105
106 // Map from language code to associated input method IDs, etc. 106 // Map from language code to associated input method IDs, etc.
107 typedef std::multimap<std::string, std::string> LanguageCodeToIdsMap; 107 typedef std::multimap<std::string, std::string> LanguageCodeToIdsMap;
108 struct IdMaps { 108 struct IdMaps {
109 scoped_ptr<LanguageCodeToIdsMap> language_code_to_ids; 109 scoped_ptr<LanguageCodeToIdsMap> language_code_to_ids;
110 scoped_ptr<std::map<std::string, std::string> > id_to_language_code; 110 scoped_ptr<std::map<std::string, std::string> > id_to_language_code;
111 scoped_ptr<std::map<std::string, std::string> > id_to_display_name; 111 scoped_ptr<std::map<std::string, std::string> > id_to_display_name;
112 scoped_ptr<std::map<std::string, std::string> > id_to_keyboard_overlay_id;
112 113
113 // Returns the singleton instance. 114 // Returns the singleton instance.
114 static IdMaps* GetInstance() { 115 static IdMaps* GetInstance() {
115 return Singleton<IdMaps>::get(); 116 return Singleton<IdMaps>::get();
116 } 117 }
117 118
118 void ReloadMaps() { 119 void ReloadMaps() {
119 chromeos::InputMethodLibrary* library = 120 chromeos::InputMethodLibrary* library =
120 chromeos::CrosLibrary::Get()->GetInputMethodLibrary(); 121 chromeos::CrosLibrary::Get()->GetInputMethodLibrary();
121 scoped_ptr<chromeos::InputMethodDescriptors> supported_input_methods( 122 scoped_ptr<chromeos::InputMethodDescriptors> supported_input_methods(
122 library->GetSupportedInputMethods()); 123 library->GetSupportedInputMethods());
123 if (supported_input_methods->size() <= 1) { 124 if (supported_input_methods->size() <= 1) {
124 LOG(ERROR) << "GetSupportedInputMethods returned a fallback ID"; 125 LOG(ERROR) << "GetSupportedInputMethods returned a fallback ID";
125 // TODO(yusukes): Handle this error in nicer way. 126 // TODO(yusukes): Handle this error in nicer way.
126 } 127 }
127 128
128 language_code_to_ids->clear(); 129 language_code_to_ids->clear();
129 id_to_language_code->clear(); 130 id_to_language_code->clear();
130 id_to_display_name->clear(); 131 id_to_display_name->clear();
132 id_to_keyboard_overlay_id->clear();
131 133
132 // Build the id to descriptor map for handling kExtraLanguages later. 134 // Build the id to descriptor map for handling kExtraLanguages later.
133 typedef std::map<std::string, 135 typedef std::map<std::string,
134 const chromeos::InputMethodDescriptor*> DescMap; 136 const chromeos::InputMethodDescriptor*> DescMap;
135 DescMap id_to_descriptor_map; 137 DescMap id_to_descriptor_map;
136 138
137 for (size_t i = 0; i < supported_input_methods->size(); ++i) { 139 for (size_t i = 0; i < supported_input_methods->size(); ++i) {
138 const chromeos::InputMethodDescriptor& input_method = 140 const chromeos::InputMethodDescriptor& input_method =
139 supported_input_methods->at(i); 141 supported_input_methods->at(i);
140 const std::string language_code = 142 const std::string language_code =
141 chromeos::input_method::GetLanguageCodeFromDescriptor(input_method); 143 chromeos::input_method::GetLanguageCodeFromDescriptor(input_method);
142 AddInputMethodToMaps(language_code, input_method); 144 AddInputMethodToMaps(language_code, input_method);
143 // Remember the pair. 145 // Remember the pair.
144 id_to_descriptor_map.insert( 146 id_to_descriptor_map.insert(
145 std::make_pair(input_method.id, &input_method)); 147 std::make_pair(input_method.id, &input_method));
146 } 148 }
147 149
150 for (size_t i = 0; i < arraysize(kInputMethodIdToKeyboardOverlayId); ++i) {
151 InputMethodIdToKeyboardOverlayId id_pair =
152 kInputMethodIdToKeyboardOverlayId[i];
153 id_to_keyboard_overlay_id->insert(
154 std::make_pair(id_pair.input_method_id, id_pair.keyboard_overlay_id));
155 }
156
148 // Go through the languages listed in kExtraLanguages. 157 // Go through the languages listed in kExtraLanguages.
149 using chromeos::input_method::kExtraLanguages; 158 using chromeos::input_method::kExtraLanguages;
150 for (size_t i = 0; i < arraysize(kExtraLanguages); ++i) { 159 for (size_t i = 0; i < arraysize(kExtraLanguages); ++i) {
151 const char* language_code = kExtraLanguages[i].language_code; 160 const char* language_code = kExtraLanguages[i].language_code;
152 const char* input_method_id = kExtraLanguages[i].input_method_id; 161 const char* input_method_id = kExtraLanguages[i].input_method_id;
153 DescMap::const_iterator iter = id_to_descriptor_map.find(input_method_id); 162 DescMap::const_iterator iter = id_to_descriptor_map.find(input_method_id);
154 // If the associated input method descriptor is found, add the 163 // If the associated input method descriptor is found, add the
155 // language code and the input method. 164 // language code and the input method.
156 if (iter != id_to_descriptor_map.end()) { 165 if (iter != id_to_descriptor_map.end()) {
157 const chromeos::InputMethodDescriptor& input_method = *(iter->second); 166 const chromeos::InputMethodDescriptor& input_method = *(iter->second);
158 AddInputMethodToMaps(language_code, input_method); 167 AddInputMethodToMaps(language_code, input_method);
159 } 168 }
160 } 169 }
161 } 170 }
162 171
163 private: 172 private:
164 IdMaps() : language_code_to_ids(new LanguageCodeToIdsMap), 173 IdMaps() : language_code_to_ids(new LanguageCodeToIdsMap),
165 id_to_language_code(new std::map<std::string, std::string>), 174 id_to_language_code(new std::map<std::string, std::string>),
166 id_to_display_name(new std::map<std::string, std::string>) { 175 id_to_display_name(new std::map<std::string, std::string>),
176 id_to_keyboard_overlay_id(new std::map<std::string, std::string>) {
167 ReloadMaps(); 177 ReloadMaps();
168 } 178 }
169 179
170 void AddInputMethodToMaps( 180 void AddInputMethodToMaps(
171 const std::string& language_code, 181 const std::string& language_code,
172 const chromeos::InputMethodDescriptor& input_method) { 182 const chromeos::InputMethodDescriptor& input_method) {
173 language_code_to_ids->insert( 183 language_code_to_ids->insert(
174 std::make_pair(language_code, input_method.id)); 184 std::make_pair(language_code, input_method.id));
175 id_to_language_code->insert( 185 id_to_language_code->insert(
176 std::make_pair(input_method.id, language_code)); 186 std::make_pair(input_method.id, language_code));
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 std::string GetKeyboardLayoutName(const std::string& input_method_id) { 554 std::string GetKeyboardLayoutName(const std::string& input_method_id) {
545 if (!StartsWithASCII(input_method_id, "xkb:", true)) { 555 if (!StartsWithASCII(input_method_id, "xkb:", true)) {
546 return ""; 556 return "";
547 } 557 }
548 558
549 std::vector<std::string> splitted_id; 559 std::vector<std::string> splitted_id;
550 base::SplitString(input_method_id, ':', &splitted_id); 560 base::SplitString(input_method_id, ':', &splitted_id);
551 return (splitted_id.size() > 1) ? splitted_id[1] : ""; 561 return (splitted_id.size() > 1) ? splitted_id[1] : "";
552 } 562 }
553 563
564 std::string GetKeyboardOverlayId(const std::string& input_method_id) {
565 const std::map<std::string, std::string>& id_map =
566 *(IdMaps::GetInstance()->id_to_keyboard_overlay_id);
567 std::map<std::string, std::string>::const_iterator iter =
568 id_map.find(input_method_id);
569 return (iter == id_map.end() ? "" : iter->second);
570 }
571
554 std::string GetInputMethodDisplayNameFromId( 572 std::string GetInputMethodDisplayNameFromId(
555 const std::string& input_method_id) { 573 const std::string& input_method_id) {
556 static const char kDefaultDisplayName[] = "USA"; 574 static const char kDefaultDisplayName[] = "USA";
557 std::map<std::string, std::string>::const_iterator iter 575 std::map<std::string, std::string>::const_iterator iter
558 = IdMaps::GetInstance()->id_to_display_name->find(input_method_id); 576 = IdMaps::GetInstance()->id_to_display_name->find(input_method_id);
559 return (iter == IdMaps::GetInstance()->id_to_display_name->end()) ? 577 return (iter == IdMaps::GetInstance()->id_to_display_name->end()) ?
560 kDefaultDisplayName : iter->second; 578 kDefaultDisplayName : iter->second;
561 } 579 }
562 580
563 string16 GetLanguageDisplayNameFromCode(const std::string& language_code) { 581 string16 GetLanguageDisplayNameFromCode(const std::string& language_code) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 library->ChangeInputMethod(initial_input_method_id); 692 library->ChangeInputMethod(initial_input_method_id);
675 } 693 }
676 } 694 }
677 695
678 void OnLocaleChanged() { 696 void OnLocaleChanged() {
679 IdMaps::GetInstance()->ReloadMaps(); 697 IdMaps::GetInstance()->ReloadMaps();
680 } 698 }
681 699
682 } // namespace input_method 700 } // namespace input_method
683 } // namespace chromeos 701 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698