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/ui/webui/options/chromeos/cros_language_options_handler
.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler
.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 DictionaryValue* dictionary = new DictionaryValue(); | 158 DictionaryValue* dictionary = new DictionaryValue(); |
159 dictionary->SetString("id", descriptor.id()); | 159 dictionary->SetString("id", descriptor.id()); |
160 dictionary->SetString("displayName", display_name); | 160 dictionary->SetString("displayName", display_name); |
161 | 161 |
162 // One input method can be associated with multiple languages, hence | 162 // One input method can be associated with multiple languages, hence |
163 // we use a dictionary here. | 163 // we use a dictionary here. |
164 DictionaryValue* languages = new DictionaryValue(); | 164 DictionaryValue* languages = new DictionaryValue(); |
165 for (size_t i = 0; i < descriptor.language_codes().size(); ++i) { | 165 for (size_t i = 0; i < descriptor.language_codes().size(); ++i) { |
166 languages->SetBoolean(descriptor.language_codes().at(i), true); | 166 languages->SetBoolean(descriptor.language_codes().at(i), true); |
167 } | 167 } |
168 // Check extra languages to see if there are languages associated with | |
169 // this input method. If these are present, add these. | |
170 const std::vector<std::string> extra_language_codes = | |
171 manager->GetInputMethodUtil()->GetExtraLanguageCodesFromId( | |
172 descriptor.id()); | |
173 for (size_t j = 0; j < extra_language_codes.size(); ++j) | |
174 languages->SetBoolean(extra_language_codes[j], true); | |
175 dictionary->Set("languageCodeSet", languages); | 168 dictionary->Set("languageCodeSet", languages); |
176 | 169 |
177 input_method_list->Append(dictionary); | 170 input_method_list->Append(dictionary); |
178 } | 171 } |
179 | 172 |
180 return input_method_list; | 173 return input_method_list; |
181 } | 174 } |
182 | 175 |
183 // static | 176 // static |
184 ListValue* CrosLanguageOptionsHandler::GetLanguageListInternal( | 177 ListValue* CrosLanguageOptionsHandler::GetLanguageListInternal( |
185 const input_method::InputMethodDescriptors& descriptors, | 178 const input_method::InputMethodDescriptors& descriptors, |
186 const std::vector<std::string>& base_language_codes) { | 179 const std::vector<std::string>& base_language_codes) { |
187 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 180 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
188 | 181 |
189 std::set<std::string> language_codes; | 182 std::set<std::string> language_codes; |
190 // Collect the language codes from the supported input methods. | 183 // Collect the language codes from the supported input methods. |
191 for (size_t i = 0; i < descriptors.size(); ++i) { | 184 for (size_t i = 0; i < descriptors.size(); ++i) { |
192 const input_method::InputMethodDescriptor& descriptor = descriptors[i]; | 185 const input_method::InputMethodDescriptor& descriptor = descriptors[i]; |
193 const std::vector<std::string>& languages = | 186 const std::vector<std::string>& languages = |
194 descriptor.language_codes(); | 187 descriptor.language_codes(); |
195 for (size_t i = 0; i < languages.size(); ++i) | 188 for (size_t i = 0; i < languages.size(); ++i) |
196 language_codes.insert(languages[i]); | 189 language_codes.insert(languages[i]); |
197 } | 190 } |
198 // Collect the language codes from extra languages. | |
199 const std::vector<std::string> extra_language_codes = | |
200 input_method::InputMethodManager::Get()->GetInputMethodUtil() | |
201 ->GetExtraLanguageCodeList(); | |
202 for (size_t i = 0; i < extra_language_codes.size(); ++i) | |
203 language_codes.insert(extra_language_codes[i]); | |
204 | 191 |
205 // Map of display name -> {language code, native_display_name}. | 192 // Map of display name -> {language code, native_display_name}. |
206 // In theory, we should be able to create a map that is sorted by | 193 // In theory, we should be able to create a map that is sorted by |
207 // display names using ICU comparator, but doing it is hard, thus we'll | 194 // display names using ICU comparator, but doing it is hard, thus we'll |
208 // use an auxiliary vector to achieve the same result. | 195 // use an auxiliary vector to achieve the same result. |
209 typedef std::pair<std::string, string16> LanguagePair; | 196 typedef std::pair<std::string, string16> LanguagePair; |
210 typedef std::map<string16, LanguagePair> LanguageMap; | 197 typedef std::map<string16, LanguagePair> LanguageMap; |
211 LanguageMap language_map; | 198 LanguageMap language_map; |
212 // The auxiliary vector mentioned above. | 199 // The auxiliary vector mentioned above. |
213 std::vector<string16> display_names; | 200 std::vector<string16> display_names; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 ConvertInputMethodDescriptosToIMEList( | 383 ConvertInputMethodDescriptosToIMEList( |
397 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); | 384 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); |
398 web_ui()->CallJavascriptFunction( | 385 web_ui()->CallJavascriptFunction( |
399 "options.LanguageOptions.onComponentManagerInitialized", | 386 "options.LanguageOptions.onComponentManagerInitialized", |
400 *ime_list); | 387 *ime_list); |
401 composition_extension_appended_ = true; | 388 composition_extension_appended_ = true; |
402 } | 389 } |
403 | 390 |
404 } // namespace options | 391 } // namespace options |
405 } // namespace chromeos | 392 } // namespace chromeos |
OLD | NEW |