Index: third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.js |
diff --git a/third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.js b/third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.js |
index 7cc50addaff718cebb4a396f303cf21831fb54aa..c16b54580f46a147b6e4664e41272982aa70e040 100644 |
--- a/third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.js |
+++ b/third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.js |
@@ -54,6 +54,43 @@ UI.SettingsUI.createSettingCheckbox = function(name, setting, omitParagraphEleme |
}; |
/** |
+ * @param {string} name |
+ * @param {!Array<!{text: string, value: *, raw: (boolean|undefined)}>} options |
+ * @param {!Common.Setting} setting |
+ * @return {!Element} |
+ */ |
+UI.SettingsUI.createSettingSelect = function(name, options, setting) { |
+ var p = createElement('p'); |
+ p.createChild('label').textContent = name; |
+ var select = p.createChild('select', 'chrome-select'); |
+ |
+ for (var i = 0; i < options.length; ++i) { |
+ // The "raw" flag indicates text is non-i18n-izable. |
+ var option = options[i]; |
+ var optionName = option.raw ? option.text : Common.UIString(option.text); |
+ select.add(new Option(optionName, option.value)); |
+ } |
+ |
+ setting.addChangeListener(settingChanged); |
+ settingChanged(); |
+ select.addEventListener('change', selectChanged, false); |
+ return p; |
+ |
+ function settingChanged() { |
+ var newValue = setting.get(); |
+ for (var i = 0; i < options.length; i++) { |
+ if (options[i].value === newValue) |
+ select.selectedIndex = i; |
+ } |
+ } |
+ |
+ function selectChanged() { |
+ // Don't use event.target.value to avoid conversion of the value to string. |
+ setting.set(options[select.selectedIndex].value); |
+ } |
+}; |
+ |
+/** |
* @param {!Element} input |
* @param {!Common.Setting} setting |
*/ |