OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_LANGUAGE_OPTIONS_UTIL_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_LANGUAGE_OPTIONS_UTIL_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" |
| 13 #include "chrome/browser/chromeos/language_preferences.h" |
| 14 #include "ui/base/l10n/l10n_util.h" |
| 15 |
| 16 namespace base { |
| 17 class ListValue; |
| 18 } |
| 19 |
| 20 namespace chromeos { |
| 21 |
| 22 // Returns an i18n-content value corresponding to |preference|. |
| 23 template <typename T> |
| 24 std::string GetI18nContentValue(const T& preference, const char* prefix) { |
| 25 return std::string(prefix) + preference.ibus_config_name; |
| 26 } |
| 27 |
| 28 // Returns a property name of templateData corresponding to |preference|. |
| 29 template <typename T> |
| 30 std::string GetTemplateDataPropertyName(const T& preference, |
| 31 const char* prefix) { |
| 32 return std::string(prefix) + preference.ibus_config_name + "Value"; |
| 33 } |
| 34 |
| 35 // Returns an property name of templateData corresponding the value of the min |
| 36 // attribute. |
| 37 template <typename T> |
| 38 std::string GetTemplateDataMinName(const T& preference, const char* prefix) { |
| 39 return std::string(prefix) + preference.ibus_config_name + "Min"; |
| 40 } |
| 41 |
| 42 // Returns an property name of templateData corresponding the value of the max |
| 43 // attribute. |
| 44 template <typename T> |
| 45 std::string GetTemplateDataMaxName(const T& preference, const char* prefix) { |
| 46 return std::string(prefix) + preference.ibus_config_name + "Max"; |
| 47 } |
| 48 |
| 49 // Creates a Value object from the given value. Here we use function |
| 50 // overloading to handle string and integer preferences in |
| 51 // CreateMultipleChoiceList. |
| 52 Value* CreateValue(const char* in_value); |
| 53 Value* CreateValue(int in_value); |
| 54 |
| 55 // Creates a multiple choice list from the given preference. |
| 56 template <typename T> |
| 57 base::ListValue* CreateMultipleChoiceList( |
| 58 const language_prefs::LanguageMultipleChoicePreference<T>& preference) { |
| 59 int list_length = 0; |
| 60 for (size_t i = 0; |
| 61 i < language_prefs::LanguageMultipleChoicePreference<T>::kMaxItems; |
| 62 ++i) { |
| 63 if (preference.values_and_ids[i].item_message_id == 0) |
| 64 break; |
| 65 ++list_length; |
| 66 } |
| 67 DCHECK_GT(list_length, 0); |
| 68 |
| 69 base::ListValue* list_value = new base::ListValue(); |
| 70 for (int i = 0; i < list_length; ++i) { |
| 71 base::ListValue* option = new base::ListValue(); |
| 72 option->Append(CreateValue( |
| 73 preference.values_and_ids[i].ibus_config_value)); |
| 74 option->Append(base::Value::CreateStringValue(l10n_util::GetStringUTF16( |
| 75 preference.values_and_ids[i].item_message_id))); |
| 76 list_value->Append(option); |
| 77 } |
| 78 return list_value; |
| 79 } |
| 80 |
| 81 } // namespace chromeos |
| 82 |
| 83 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_LANGUAGE_OPTIONS_UTIL_H_ |
OLD | NEW |