| OLD | NEW |
| 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/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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 DictionaryValue* dictionary = new DictionaryValue(); | 94 DictionaryValue* dictionary = new DictionaryValue(); |
| 95 dictionary->SetString("id", descriptor.id()); | 95 dictionary->SetString("id", descriptor.id()); |
| 96 dictionary->SetString("displayName", display_name); | 96 dictionary->SetString("displayName", display_name); |
| 97 | 97 |
| 98 // One input method can be associated with multiple languages, hence | 98 // One input method can be associated with multiple languages, hence |
| 99 // we use a dictionary here. | 99 // we use a dictionary here. |
| 100 DictionaryValue* language_codes = new DictionaryValue(); | 100 DictionaryValue* language_codes = new DictionaryValue(); |
| 101 language_codes->SetBoolean(language_code, true); | 101 language_codes->SetBoolean(language_code, true); |
| 102 // Check kExtraLanguages to see if there are languages associated with | 102 // Check kExtraLanguages to see if there are languages associated with |
| 103 // this input method. If these are present, add these. | 103 // this input method. If these are present, add these. |
| 104 for (size_t j = 0; j < arraysize(input_method::kExtraLanguages); | 104 for (size_t j = 0; j < input_method::kExtraLanguagesLength; ++j) { |
| 105 ++j) { | |
| 106 const std::string extra_input_method_id = | 105 const std::string extra_input_method_id = |
| 107 input_method::kExtraLanguages[j].input_method_id; | 106 input_method::kExtraLanguages[j].input_method_id; |
| 108 const std::string extra_language_code = | 107 const std::string extra_language_code = |
| 109 input_method::kExtraLanguages[j].language_code; | 108 input_method::kExtraLanguages[j].language_code; |
| 110 if (extra_input_method_id == descriptor.id()) { | 109 if (extra_input_method_id == descriptor.id()) { |
| 111 language_codes->SetBoolean(extra_language_code, true); | 110 language_codes->SetBoolean(extra_language_code, true); |
| 112 } | 111 } |
| 113 } | 112 } |
| 114 dictionary->Set("languageCodeSet", language_codes); | 113 dictionary->Set("languageCodeSet", language_codes); |
| 115 | 114 |
| 116 input_method_list->Append(dictionary); | 115 input_method_list->Append(dictionary); |
| 117 } | 116 } |
| 118 | 117 |
| 119 return input_method_list; | 118 return input_method_list; |
| 120 } | 119 } |
| 121 | 120 |
| 122 ListValue* CrosLanguageOptionsHandler::GetLanguageList( | 121 ListValue* CrosLanguageOptionsHandler::GetLanguageList( |
| 123 const input_method::InputMethodDescriptors& descriptors) { | 122 const input_method::InputMethodDescriptors& descriptors) { |
| 124 std::set<std::string> language_codes; | 123 std::set<std::string> language_codes; |
| 125 // Collect the language codes from the supported input methods. | 124 // Collect the language codes from the supported input methods. |
| 126 for (size_t i = 0; i < descriptors.size(); ++i) { | 125 for (size_t i = 0; i < descriptors.size(); ++i) { |
| 127 const input_method::InputMethodDescriptor& descriptor = descriptors[i]; | 126 const input_method::InputMethodDescriptor& descriptor = descriptors[i]; |
| 128 const std::string language_code = | 127 const std::string language_code = |
| 129 input_method::GetLanguageCodeFromDescriptor(descriptor); | 128 input_method::GetLanguageCodeFromDescriptor(descriptor); |
| 130 language_codes.insert(language_code); | 129 language_codes.insert(language_code); |
| 131 } | 130 } |
| 132 // Collect the language codes from kExtraLanguages. | 131 // Collect the language codes from kExtraLanguages. |
| 133 for (size_t i = 0; i < arraysize(input_method::kExtraLanguages); | 132 for (size_t i = 0; i < input_method::kExtraLanguagesLength; ++i) { |
| 134 ++i) { | |
| 135 const char* language_code = | 133 const char* language_code = |
| 136 input_method::kExtraLanguages[i].language_code; | 134 input_method::kExtraLanguages[i].language_code; |
| 137 language_codes.insert(language_code); | 135 language_codes.insert(language_code); |
| 138 } | 136 } |
| 139 | 137 |
| 140 // Map of display name -> {language code, native_display_name}. | 138 // Map of display name -> {language code, native_display_name}. |
| 141 // In theory, we should be able to create a map that is sorted by | 139 // In theory, we should be able to create a map that is sorted by |
| 142 // display names using ICU comparator, but doing it is hard, thus we'll | 140 // display names using ICU comparator, but doing it is hard, thus we'll |
| 143 // use an auxiliary vector to achieve the same result. | 141 // use an auxiliary vector to achieve the same result. |
| 144 typedef std::pair<std::string, string16> LanguagePair; | 142 typedef std::pair<std::string, string16> LanguagePair; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 213 |
| 216 void CrosLanguageOptionsHandler::InputMethodOptionsOpenCallback( | 214 void CrosLanguageOptionsHandler::InputMethodOptionsOpenCallback( |
| 217 const ListValue* args) { | 215 const ListValue* args) { |
| 218 const std::string input_method_id = UTF16ToASCII(ExtractStringValue(args)); | 216 const std::string input_method_id = UTF16ToASCII(ExtractStringValue(args)); |
| 219 const std::string action = StringPrintf( | 217 const std::string action = StringPrintf( |
| 220 "InputMethodOptions_Open_%s", input_method_id.c_str()); | 218 "InputMethodOptions_Open_%s", input_method_id.c_str()); |
| 221 UserMetrics::RecordComputedAction(action); | 219 UserMetrics::RecordComputedAction(action); |
| 222 } | 220 } |
| 223 | 221 |
| 224 } // namespace chromeos | 222 } // namespace chromeos |
| OLD | NEW |