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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/NetworkConditionsSelector.js

Issue 1422703003: [DevTools] Use ListWidget for rendering of EditFileSystemView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @param {!HTMLSelectElement} selectElement 7 * @param {!HTMLSelectElement} selectElement
8 */ 8 */
9 WebInspector.NetworkConditionsSelector = function(selectElement) 9 WebInspector.NetworkConditionsSelector = function(selectElement)
10 { 10 {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 165
166 this._list.appendSeparator(); 166 this._list.appendSeparator();
167 167
168 conditions = WebInspector.NetworkConditionsSelector._networkConditionsPr esets; 168 conditions = WebInspector.NetworkConditionsSelector._networkConditionsPr esets;
169 for (var i = 0; i < conditions.length; ++i) 169 for (var i = 0; i < conditions.length; ++i)
170 this._list.appendItem(conditions[i], false); 170 this._list.appendItem(conditions[i], false);
171 }, 171 },
172 172
173 _addButtonClicked: function() 173 _addButtonClicked: function()
174 { 174 {
175 this._list.addNewItem(this._customSetting.get().length); 175 this._list.addNewItem(this._customSetting.get().length, {title: "", valu e: {throughput: 0, latency: 0}});
176 }, 176 },
177 177
178 /** 178 /**
179 * @override 179 * @override
180 * @param {*} item 180 * @param {*} item
181 * @param {boolean} editable
181 * @return {!Element} 182 * @return {!Element}
182 */ 183 */
183 renderItem: function(item) 184 renderItem: function(item, editable)
184 { 185 {
185 var conditions = /** @type {!WebInspector.NetworkConditionsProfile} */ ( item); 186 var conditions = /** @type {!WebInspector.NetworkConditionsProfile} */ ( item);
186 var element = createElementWithClass("div", "conditions-list-item"); 187 var element = createElementWithClass("div", "conditions-list-item");
187 var title = element.createChild("div", "conditions-list-text conditions- list-title"); 188 var title = element.createChild("div", "conditions-list-text conditions- list-title");
188 var titleText = title.createChild("div", "conditions-list-title-text"); 189 var titleText = title.createChild("div", "conditions-list-title-text");
189 titleText.textContent = conditions.title; 190 titleText.textContent = conditions.title;
190 titleText.title = conditions.title; 191 titleText.title = conditions.title;
191 element.createChild("div", "conditions-list-separator"); 192 element.createChild("div", "conditions-list-separator");
192 element.createChild("div", "conditions-list-text").textContent = WebInsp ector.NetworkConditionsSelector.throughputText(conditions.value); 193 element.createChild("div", "conditions-list-text").textContent = WebInsp ector.NetworkConditionsSelector.throughputText(conditions.value);
193 element.createChild("div", "conditions-list-separator"); 194 element.createChild("div", "conditions-list-separator");
194 element.createChild("div", "conditions-list-text").textContent = WebInsp ector.UIString("%dms", conditions.value.latency); 195 element.createChild("div", "conditions-list-text").textContent = WebInsp ector.UIString("%dms", conditions.value.latency);
195 return element; 196 return element;
196 }, 197 },
197 198
198 /** 199 /**
199 * @override 200 * @override
201 * @param {*} item
200 * @param {number} index 202 * @param {number} index
201 */ 203 */
202 removeItemRequested: function(index) 204 removeItemRequested: function(item, index)
203 { 205 {
204 var list = this._customSetting.get(); 206 var list = this._customSetting.get();
205 list.splice(index, 1); 207 list.splice(index, 1);
206 this._muteUpdate = true; 208 this._muteUpdate = true;
207 this._customSetting.set(list); 209 this._customSetting.set(list);
208 this._muteUpdate = false; 210 this._muteUpdate = false;
209 this._list.removeItem(index); 211 this._list.removeItem(index);
210 }, 212 },
211 213
212 /** 214 /**
213 * @override 215 * @override
214 * @param {*|null} item 216 * @param {*} item
215 * @param {!WebInspector.ListWidget.Editor} editor 217 * @param {!WebInspector.ListWidget.Editor} editor
218 * @param {boolean} isNew
216 */ 219 */
217 commitEdit: function(item, editor) 220 commitEdit: function(item, editor, isNew)
218 { 221 {
219 var conditions = /** @type {?WebInspector.NetworkConditionsProfile} */ ( item); 222 var conditions = /** @type {?WebInspector.NetworkConditionsProfile} */ ( item);
220 if (!conditions)
221 conditions = {title: "", value: {throughput: 0, latency: 0}};
222
223 conditions.title = editor.control("title").value.trim(); 223 conditions.title = editor.control("title").value.trim();
224 var throughput = editor.control("throughput").value.trim(); 224 var throughput = editor.control("throughput").value.trim();
225 conditions.value.throughput = throughput ? parseInt(throughput, 10) * (1 024 / 8) : -1; 225 conditions.value.throughput = throughput ? parseInt(throughput, 10) * (1 024 / 8) : -1;
226 var latency = editor.control("latency").value.trim(); 226 var latency = editor.control("latency").value.trim();
227 conditions.value.latency = latency ? parseInt(latency, 10) : 0; 227 conditions.value.latency = latency ? parseInt(latency, 10) : 0;
228 228
229 var list = this._customSetting.get(); 229 var list = this._customSetting.get();
230 if (!item) 230 if (isNew)
231 list.push(conditions); 231 list.push(conditions);
232 this._customSetting.set(list); 232 this._customSetting.set(list);
233 }, 233 },
234 234
235 /** 235 /**
236 * @override 236 * @override
237 * @param {*|null} item 237 * @param {*} item
238 * @return {!WebInspector.ListWidget.Editor} 238 * @return {!WebInspector.ListWidget.Editor}
239 */ 239 */
240 beginEdit: function(item) 240 beginEdit: function(item)
241 { 241 {
242 var conditions = /** @type {?WebInspector.NetworkConditionsProfile} */ ( item); 242 var conditions = /** @type {?WebInspector.NetworkConditionsProfile} */ ( item);
243 var editor = this._createEditor(); 243 var editor = this._createEditor();
244 if (conditions) { 244 editor.control("title").value = conditions.title;
245 editor.control("title").value = conditions.title; 245 editor.control("throughput").value = conditions.value.throughput < 0 ? " " : String(conditions.value.throughput / (1024 / 8));
246 editor.control("throughput").value = conditions.value.throughput < 0 ? "" : String(conditions.value.throughput / (1024 / 8)); 246 editor.control("latency").value = String(conditions.value.latency);
247 editor.control("latency").value = String(conditions.value.latency);
248 } else {
249 editor.control("title").value = "";
250 editor.control("throughput").value = "";
251 editor.control("latency").value = "";
252 }
253 return editor; 247 return editor;
254 }, 248 },
255 249
256 /** 250 /**
257 * @return {!WebInspector.ListWidget.Editor} 251 * @return {!WebInspector.ListWidget.Editor}
258 */ 252 */
259 _createEditor: function() 253 _createEditor: function()
260 { 254 {
261 if (this._editor) 255 if (this._editor)
262 return this._editor; 256 return this._editor;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 */ 307 */
314 function latencyValidator(input) 308 function latencyValidator(input)
315 { 309 {
316 var value = input.value.trim(); 310 var value = input.value.trim();
317 return !value || (/^[\d]+$/.test(value) && value >= 0 && value <= 10 00000); 311 return !value || (/^[\d]+$/.test(value) && value >= 0 && value <= 10 00000);
318 } 312 }
319 }, 313 },
320 314
321 __proto__: WebInspector.VBox.prototype 315 __proto__: WebInspector.VBox.prototype
322 } 316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698