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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.js

Issue 2744883003: DevTools: generalize setting UI for enum/select settings (Closed)
Patch Set: Created 3 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 if (omitParagraphElement) 48 if (omitParagraphElement)
49 return label; 49 return label;
50 50
51 var p = createElement('p'); 51 var p = createElement('p');
52 p.appendChild(label); 52 p.appendChild(label);
53 return p; 53 return p;
54 }; 54 };
55 55
56 /** 56 /**
57 * @param {string} name
58 * @param {!Common.Setting} setting
59 * @return {!Element}
60 */
61 UI.SettingsUI.createSettingSelect = function(name, setting) {
62 var p = createElement('p');
63 p.createChild('label').textContent = name;
64 var select = p.createChild('select', 'chrome-select');
65 var settingValue = setting.get();
66 var options = setting.options();
67
68 for (var i = 0; i < options.length; ++i) {
69 var option = options[i];
70 // The "raw" flag indicates text is non-i18n-izable.
71 var optionName = option.raw ? option.text : Common.UIString(option.text);
72 select.add(new Option(optionName, option.value));
73 if (settingValue === option.value)
74 select.selectedIndex = i;
75 }
76
77 setting.addChangeListener(settingChanged);
78 settingChanged();
79 select.addEventListener('change', selectChanged, false);
80 return p;
81
82 function settingChanged() {
83 var newValue = setting.get();
84 if (options[select.selectedIndex].value !== newValue) {
85 for (var i = 0; i < options.length; i++) {
86 if (options[i].value === newValue)
87 select.selectedIndex = i;
88 }
89 }
90 }
91
92 function selectChanged() {
93 // Don't use event.target.value to avoid conversion of the value to string.
94 setting.set(options[select.selectedIndex].value);
95 }
96 };
97
98 /**
57 * @param {!Element} input 99 * @param {!Element} input
58 * @param {!Common.Setting} setting 100 * @param {!Common.Setting} setting
59 */ 101 */
60 UI.SettingsUI.bindCheckbox = function(input, setting) { 102 UI.SettingsUI.bindCheckbox = function(input, setting) {
61 function settingChanged() { 103 function settingChanged() {
62 if (input.checked !== setting.get()) 104 if (input.checked !== setting.get())
63 input.checked = setting.get(); 105 input.checked = setting.get();
64 } 106 }
65 setting.addChangeListener(settingChanged); 107 setting.addChangeListener(settingChanged);
66 settingChanged(); 108 settingChanged();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 * @interface 146 * @interface
105 */ 147 */
106 UI.SettingUI = function() {}; 148 UI.SettingUI = function() {};
107 149
108 UI.SettingUI.prototype = { 150 UI.SettingUI.prototype = {
109 /** 151 /**
110 * @return {?Element} 152 * @return {?Element}
111 */ 153 */
112 settingElement() {} 154 settingElement() {}
113 }; 155 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698