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

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

Issue 340723005: [DevTools] Remove unnecessary emulation checkboxes and simplify UX. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/devtools/front_end/sdk/OverridesSupport.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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 82 }
83 83
84 /** 84 /**
85 * @param {string} label 85 * @param {string} label
86 * @param {!WebInspector.Setting} setting 86 * @param {!WebInspector.Setting} setting
87 * @param {boolean} numeric 87 * @param {boolean} numeric
88 * @param {number=} maxLength 88 * @param {number=} maxLength
89 * @param {string=} width 89 * @param {string=} width
90 * @param {function(string):?string=} validatorCallback 90 * @param {function(string):?string=} validatorCallback
91 * @param {boolean=} instant 91 * @param {boolean=} instant
92 * @param {boolean=} clearForZero
93 * @param {string=} placeholder
92 * @return {!Element} 94 * @return {!Element}
93 */ 95 */
94 WebInspector.SettingsUI.createSettingInputField = function(label, setting, numer ic, maxLength, width, validatorCallback, instant) 96 WebInspector.SettingsUI.createSettingInputField = function(label, setting, numer ic, maxLength, width, validatorCallback, instant, clearForZero, placeholder)
95 { 97 {
96 var p = document.createElement("p"); 98 var p = document.createElement("p");
97 var labelElement = p.createChild("label"); 99 var labelElement = p.createChild("label");
98 labelElement.textContent = label; 100 labelElement.textContent = label;
99 var inputElement = p.createChild("input"); 101 var inputElement = p.createChild("input");
100 inputElement.value = setting.get();
101 inputElement.type = "text"; 102 inputElement.type = "text";
102 if (numeric) 103 if (numeric)
103 inputElement.className = "numeric"; 104 inputElement.className = "numeric";
104 if (maxLength) 105 if (maxLength)
105 inputElement.maxLength = maxLength; 106 inputElement.maxLength = maxLength;
106 if (width) 107 if (width)
107 inputElement.style.width = width; 108 inputElement.style.width = width;
109 inputElement.placeholder = placeholder || "";
108 110
109 if (validatorCallback || instant) { 111 if (validatorCallback || instant) {
110 inputElement.addEventListener("change", onInput, false); 112 inputElement.addEventListener("change", onInput, false);
111 inputElement.addEventListener("input", onInput, false); 113 inputElement.addEventListener("input", onInput, false);
112 } 114 }
113 inputElement.addEventListener("keydown", onKeyDown, false); 115 inputElement.addEventListener("keydown", onKeyDown, false);
114 116
115 var errorMessageLabel; 117 var errorMessageLabel;
116 if (validatorCallback) { 118 if (validatorCallback) {
117 errorMessageLabel = p.createChild("div"); 119 errorMessageLabel = p.createChild("div");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 return; 153 return;
152 setting.removeChangeListener(onSettingChange); 154 setting.removeChangeListener(onSettingChange);
153 setting.set(numeric ? Number(inputElement.value) : inputElement.value); 155 setting.set(numeric ? Number(inputElement.value) : inputElement.value);
154 setting.addChangeListener(onSettingChange); 156 setting.addChangeListener(onSettingChange);
155 } 157 }
156 158
157 setting.addChangeListener(onSettingChange); 159 setting.addChangeListener(onSettingChange);
158 160
159 function onSettingChange() 161 function onSettingChange()
160 { 162 {
161 inputElement.value = setting.get(); 163 var value = setting.get();
164 if (clearForZero && !value)
165 value = "";
166 inputElement.value = value;
162 } 167 }
168 onSettingChange();
163 169
164 return p; 170 return p;
165 } 171 }
166 172
167 /**
168 * @param {string} label
169 * @param {!WebInspector.Setting} setting
170 * @param {number=} maxLength
171 * @param {string=} width
172 * @param {string=} defaultText
173 * @return {!Element}
174 */
175 WebInspector.SettingsUI.createSettingLabel = function(label, setting, maxLength, width, defaultText)
176 {
177 var p = document.createElement("p");
178 var labelElement = p.createChild("span");
179 labelElement.textContent = label;
180 if (label)
181 labelElement.style.marginRight = "5px";
182 var spanElement = p.createChild("span");
183 spanElement.textContent = setting.get();
184 if (width)
185 p.style.width = width;
186
187 setting.addChangeListener(onSettingChange);
188 onSettingChange();
189
190 function onSettingChange()
191 {
192 var text = setting.get() || defaultText;
193 spanElement.title = text;
194 if (maxLength && text.length > maxLength)
195 text = text.substring(0, maxLength - 2) + "...";
196 spanElement.textContent = text;
197 }
198
199 return p;
200 }
201
202 /** 173 /**
203 * @param {string} name 174 * @param {string} name
204 * @param {!Element} element 175 * @param {!Element} element
205 * @return {!Element} 176 * @return {!Element}
206 */ 177 */
207 WebInspector.SettingsUI.createCustomSetting = function(name, element) 178 WebInspector.SettingsUI.createCustomSetting = function(name, element)
208 { 179 {
209 var p = document.createElement("p"); 180 var p = document.createElement("p");
210 var fieldsetElement = document.createElement("fieldset"); 181 var fieldsetElement = document.createElement("fieldset");
211 fieldsetElement.createChild("label").textContent = name; 182 fieldsetElement.createChild("label").textContent = name;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 256
286 WebInspector.UISettingDelegate.prototype = { 257 WebInspector.UISettingDelegate.prototype = {
287 /** 258 /**
288 * @return {?Element} 259 * @return {?Element}
289 */ 260 */
290 settingElement: function() 261 settingElement: function()
291 { 262 {
292 return null; 263 return null;
293 } 264 }
294 } 265 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/sdk/OverridesSupport.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698