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

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: acc Created 3 years, 7 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/settings/SettingsScreen.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {!Array<!{title: string, text: (string|undefined), value: *, raw: (boo lean|undefined)}>} options
dgozman 2017/05/15 18:57:25 You are not using title anywhere.
luoe 2017/05/16 00:05:37 Done.
59 * @param {!Common.Setting} setting
60 * @return {!Element}
61 */
62 UI.SettingsUI.createSettingSelect = function(name, options, setting) {
63 var p = createElement('p');
64 p.createChild('label').textContent = name;
65 var select = p.createChild('select', 'chrome-select');
66
67 for (var i = 0; i < options.length; ++i) {
68 // The "raw" flag indicates text is non-i18n-izable.
69 var option = options[i];
70 var optionText = /** @type {string} */ (option.text);
dgozman 2017/05/15 18:57:25 option.text || '' Or even better - make text non-
luoe 2017/05/16 00:05:38 Yeah, it makes sense that a select dropdown requir
71 var optionName = option.raw ? optionText : Common.UIString(optionText);
72 select.add(new Option(optionName, option.value));
73 }
74
75 setting.addChangeListener(settingChanged);
76 settingChanged();
77 select.addEventListener('change', selectChanged, false);
78 return p;
79
80 function settingChanged() {
81 var newValue = setting.get();
82 for (var i = 0; i < options.length; i++) {
83 if (options[i].value === newValue)
84 select.selectedIndex = i;
85 }
86 }
87
88 function selectChanged() {
89 // Don't use event.target.value to avoid conversion of the value to string.
90 setting.set(options[select.selectedIndex].value);
91 }
92 };
93
94 /**
57 * @param {!Element} input 95 * @param {!Element} input
58 * @param {!Common.Setting} setting 96 * @param {!Common.Setting} setting
59 */ 97 */
60 UI.SettingsUI.bindCheckbox = function(input, setting) { 98 UI.SettingsUI.bindCheckbox = function(input, setting) {
61 function settingChanged() { 99 function settingChanged() {
62 if (input.checked !== setting.get()) 100 if (input.checked !== setting.get())
63 input.checked = setting.get(); 101 input.checked = setting.get();
64 } 102 }
65 setting.addChangeListener(settingChanged); 103 setting.addChangeListener(settingChanged);
66 settingChanged(); 104 settingChanged();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 * @interface 142 * @interface
105 */ 143 */
106 UI.SettingUI = function() {}; 144 UI.SettingUI = function() {};
107 145
108 UI.SettingUI.prototype = { 146 UI.SettingUI.prototype = {
109 /** 147 /**
110 * @return {?Element} 148 * @return {?Element}
111 */ 149 */
112 settingElement() {} 150 settingElement() {}
113 }; 151 };
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/settings/SettingsScreen.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698