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

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

Issue 304693002: DevTools: get rid of deviceMetics settings. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Tests fixed. 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 input.addEventListener("change", inputChanged, false); 81 input.addEventListener("change", inputChanged, false);
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 */ 92 */
92 WebInspector.SettingsUI.createSettingInputField = function(label, setting, numer ic, maxLength, width, validatorCallback) 93 WebInspector.SettingsUI.createSettingInputField = function(label, setting, numer ic, maxLength, width, validatorCallback, instant)
93 { 94 {
94 var p = document.createElement("p"); 95 var p = document.createElement("p");
95 var labelElement = p.createChild("label"); 96 var labelElement = p.createChild("label");
96 labelElement.textContent = label; 97 labelElement.textContent = label;
97 var inputElement = p.createChild("input"); 98 var inputElement = p.createChild("input");
98 inputElement.value = setting.get(); 99 inputElement.value = setting.get();
99 inputElement.type = "text"; 100 inputElement.type = "text";
100 if (numeric) 101 if (numeric)
101 inputElement.className = "numeric"; 102 inputElement.className = "numeric";
102 if (maxLength) 103 if (maxLength)
103 inputElement.maxLength = maxLength; 104 inputElement.maxLength = maxLength;
104 if (width) 105 if (width)
105 inputElement.style.width = width; 106 inputElement.style.width = width;
106 107
108 if (validatorCallback || instant) {
109 inputElement.addEventListener("change", onInput, false);
110 inputElement.addEventListener("input", onInput, false);
111 }
112
107 var errorMessageLabel; 113 var errorMessageLabel;
108 if (validatorCallback) { 114 if (validatorCallback) {
109 errorMessageLabel = p.createChild("div"); 115 errorMessageLabel = p.createChild("div");
110 errorMessageLabel.classList.add("field-error-message"); 116 errorMessageLabel.classList.add("field-error-message");
111 inputElement.oninput = onInput; 117 validate();
112 onInput();
113 } 118 }
114 119
115 function onInput() 120 function onInput()
116 { 121 {
122 if (validatorCallback)
123 validate();
124 if (instant)
125 apply();
126 }
127
128 function validate()
129 {
117 var error = validatorCallback(inputElement.value); 130 var error = validatorCallback(inputElement.value);
118 if (!error) 131 if (!error)
119 error = ""; 132 error = "";
133 inputElement.classList.toggle("error-input", !!error);
120 errorMessageLabel.textContent = error; 134 errorMessageLabel.textContent = error;
121 } 135 }
122 136
123 function onBlur() 137 if (!instant)
138 inputElement.addEventListener("blur", apply, false);
139
140 function apply()
124 { 141 {
142 if (validatorCallback && validatorCallback(inputElement.value))
143 return;
144 setting.removeChangeListener(onSettingChange);
125 setting.set(numeric ? Number(inputElement.value) : inputElement.value); 145 setting.set(numeric ? Number(inputElement.value) : inputElement.value);
146 setting.addChangeListener(onSettingChange);
126 } 147 }
127 inputElement.addEventListener("blur", onBlur, false); 148
149 setting.addChangeListener(onSettingChange);
150
151 function onSettingChange()
152 {
153 inputElement.value = setting.get();
154 }
128 155
129 return p; 156 return p;
130 } 157 }
131 158
132 WebInspector.SettingsUI.createCustomSetting = function(name, element) 159 WebInspector.SettingsUI.createCustomSetting = function(name, element)
133 { 160 {
134 var p = document.createElement("p"); 161 var p = document.createElement("p");
135 var fieldsetElement = document.createElement("fieldset"); 162 var fieldsetElement = document.createElement("fieldset");
136 fieldsetElement.createChild("label").textContent = name; 163 fieldsetElement.createChild("label").textContent = name;
137 fieldsetElement.appendChild(element); 164 fieldsetElement.appendChild(element);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 element.addEventListener("keydown", keyDownListener, false); 222 element.addEventListener("keydown", keyDownListener, false);
196 function keyDownListener(event) 223 function keyDownListener(event)
197 { 224 {
198 if (isEnterKey(event)) 225 if (isEnterKey(event))
199 eventListener(event); 226 eventListener(event);
200 } 227 }
201 return element; 228 return element;
202 } 229 }
203 230
204 /** 231 /**
205 * @param {string} title
206 * @param {function(boolean)} callback
207 */
208 WebInspector.SettingsUI.createNonPersistedCheckbox = function(title, callback)
209 {
210 var labelElement = document.createElement("label");
211 var checkboxElement = labelElement.createChild("input");
212 checkboxElement.type = "checkbox";
213 checkboxElement.checked = false;
214 checkboxElement.addEventListener("click", onclick, false);
215 labelElement.appendChild(document.createTextNode(title));
216 return labelElement;
217
218 function onclick()
219 {
220 callback(checkboxElement.checked);
221 }
222 }
223
224 /**
225 * @constructor 232 * @constructor
226 */ 233 */
227 WebInspector.UISettingDelegate = function() 234 WebInspector.UISettingDelegate = function()
228 { 235 {
229 } 236 }
230 237
231 WebInspector.UISettingDelegate.prototype = { 238 WebInspector.UISettingDelegate.prototype = {
232 /** 239 /**
233 * @return {?Element} 240 * @return {?Element}
234 */ 241 */
235 settingElement: function() 242 settingElement: function()
236 { 243 {
237 return null; 244 return null;
238 } 245 }
239 } 246 }
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