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

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

Issue 1292673002: [DevTools] Group options in network presets select. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated visual design Created 5 years, 4 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 | « no previous file | Source/devtools/front_end/components/module.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 /** @type {!Array.<!WebInspector.NetworkConditionsProfile>} */ 57 /** @type {!Array.<!WebInspector.NetworkConditionsProfile>} */
58 WebInspector.NetworkConditionsSelector._networkConditionsPresets = [ 58 WebInspector.NetworkConditionsSelector._networkConditionsPresets = [
59 {title: "Offline", value: {throughput: 0 * 1024 / 8, latency: 0}}, 59 {title: "Offline", value: {throughput: 0 * 1024 / 8, latency: 0}},
60 {title: "GPRS", value: {throughput: 50 * 1024 / 8, latency: 500}}, 60 {title: "GPRS", value: {throughput: 50 * 1024 / 8, latency: 500}},
61 {title: "Regular 2G", value: {throughput: 250 * 1024 / 8, latency: 300}}, 61 {title: "Regular 2G", value: {throughput: 250 * 1024 / 8, latency: 300}},
62 {title: "Good 2G", value: {throughput: 450 * 1024 / 8, latency: 150}}, 62 {title: "Good 2G", value: {throughput: 450 * 1024 / 8, latency: 150}},
63 {title: "Regular 3G", value: {throughput: 750 * 1024 / 8, latency: 100}}, 63 {title: "Regular 3G", value: {throughput: 750 * 1024 / 8, latency: 100}},
64 {title: "Good 3G", value: {throughput: 1.5 * 1024 * 1024 / 8, latency: 40}}, 64 {title: "Good 3G", value: {throughput: 1.5 * 1024 * 1024 / 8, latency: 40}},
65 {title: "Regular 4G", value: {throughput: 4 * 1024 * 1024 / 8, latency: 20}} , 65 {title: "Regular 4G", value: {throughput: 4 * 1024 * 1024 / 8, latency: 20}} ,
66 {title: "DSL", value: {throughput: 2 * 1024 * 1024 / 8, latency: 5}}, 66 {title: "DSL", value: {throughput: 2 * 1024 * 1024 / 8, latency: 5}},
67 {title: "WiFi", value: {throughput: 30 * 1024 * 1024 / 8, latency: 2}}, 67 {title: "WiFi", value: {throughput: 30 * 1024 * 1024 / 8, latency: 2}}
68 {title: "No throttling", value: {throughput: -1, latency: 0}}
69 ]; 68 ];
70 69
70 /** @type {!WebInspector.NetworkConditionsProfile} */
71 WebInspector.NetworkConditionsSelector._disabledPreset = {title: "No throttling" , value: {throughput: -1, latency: 0}};
72
71 WebInspector.NetworkConditionsSelector.prototype = { 73 WebInspector.NetworkConditionsSelector.prototype = {
72 _populateOptions: function() 74 _populateOptions: function()
73 { 75 {
74 this._selectElement.removeChildren(); 76 this._selectElement.removeChildren();
75 var presets = this._customSetting.get().concat(WebInspector.NetworkCondi tionsSelector._networkConditionsPresets); 77
78 var customGroup = this._addGroup(this._customSetting.get(), WebInspector .UIString("Custom"));
79 customGroup.insertBefore(new Option(WebInspector.UIString("Add..."), Web Inspector.UIString("Add...")), customGroup.firstChild);
pfeldman 2015/08/17 19:00:12 Use ellipsis from the unicode set.
dgozman 2015/08/19 01:59:11 Done.
80
81 this._addGroup(WebInspector.NetworkConditionsSelector._networkConditions Presets, WebInspector.UIString("Presets"));
82 this._addGroup([WebInspector.NetworkConditionsSelector._disabledPreset], WebInspector.UIString("Disabled"));
83
84 this._settingChanged();
85 },
86
87 /**
88 * @param {!Array.<!WebInspector.NetworkConditionsProfile>} presets
89 * @param {string} groupName
90 * @return {!Element}
91 */
92 _addGroup: function(presets, groupName)
93 {
94 var groupElement = this._selectElement.createChild("optgroup");
95 groupElement.label = groupName;
76 for (var i = 0; i < presets.length; ++i) { 96 for (var i = 0; i < presets.length; ++i) {
77 var preset = presets[i]; 97 var preset = presets[i];
78 var throughputInKbps = preset.value.throughput / (1024 / 8); 98 var throughputInKbps = preset.value.throughput / (1024 / 8);
79 var isThrottling = (throughputInKbps > 0) || preset.value.latency; 99 var isThrottling = (throughputInKbps > 0) || preset.value.latency;
80 var option; 100 var option;
101 var presetTitle = WebInspector.UIString(preset.title);
81 if (!isThrottling) { 102 if (!isThrottling) {
82 option = new Option(preset.title, preset.title); 103 option = new Option(presetTitle, presetTitle);
83 } else { 104 } else {
84 var throughputText = WebInspector.NetworkConditionsSelector.thro ughputText(preset.value); 105 var throughputText = WebInspector.NetworkConditionsSelector.thro ughputText(preset.value);
85 var title = WebInspector.UIString("%s (%s %dms RTT)", preset.tit le, throughputText, preset.value.latency); 106 var title = WebInspector.UIString("%s (%s %dms RTT)", presetTitl e, throughputText, preset.value.latency);
86 option = new Option(title, preset.title); 107 option = new Option(title, presetTitle);
87 option.title = WebInspector.UIString("Maximum download throughpu t: %s.\r\nMinimum round-trip time: %dms.", throughputText, preset.value.latency) ; 108 option.title = WebInspector.UIString("Maximum download throughpu t: %s.\r\nMinimum round-trip time: %dms.", throughputText, preset.value.latency) ;
88 } 109 }
89 option.settingValue = preset.value; 110 option.settingValue = preset.value;
90 this._selectElement.appendChild(option); 111 groupElement.appendChild(option);
91 } 112 }
92 this._settingChanged(); 113 return groupElement;
93 }, 114 },
94 115
95 _optionSelected: function() 116 _optionSelected: function()
96 { 117 {
118 if (this._selectElement.selectedIndex === 0) {
119 WebInspector.Revealer.reveal(this._customSetting);
120 this._settingChanged();
121 return;
122 }
123
97 this._setting.removeChangeListener(this._settingChanged, this); 124 this._setting.removeChangeListener(this._settingChanged, this);
98 this._setting.set(this._selectElement.options[this._selectElement.select edIndex].settingValue); 125 this._setting.set(this._selectElement.options[this._selectElement.select edIndex].settingValue);
99 this._setting.addChangeListener(this._settingChanged, this); 126 this._setting.addChangeListener(this._settingChanged, this);
100 }, 127 },
101 128
102 _settingChanged: function() 129 _settingChanged: function()
103 { 130 {
104 var value = this._setting.get(); 131 var value = this._setting.get();
105 var options = this._selectElement.options; 132 var options = this._selectElement.options;
106 for (var index = 0; index < options.length; ++index) { 133 for (var index = 1; index < options.length; ++index) {
107 var option = options[index]; 134 var option = options[index];
108 if (option.settingValue.throughput === value.throughput && option.se ttingValue.latency === value.latency) 135 if (option.settingValue.throughput === value.throughput && option.se ttingValue.latency === value.latency)
109 this._selectElement.selectedIndex = index; 136 this._selectElement.selectedIndex = index;
110 } 137 }
111 } 138 }
112 } 139 }
113 140
114 141
115 /** 142 /**
116 * @constructor 143 * @constructor
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 if (this._editConditionsListItem) 399 if (this._editConditionsListItem)
373 this._editConditionsListItem.classList.remove("hidden"); 400 this._editConditionsListItem.classList.remove("hidden");
374 if (this._editConditionsElement.parentElement) 401 if (this._editConditionsElement.parentElement)
375 this._conditionsList.removeChild(this._editConditionsElement); 402 this._conditionsList.removeChild(this._editConditionsElement);
376 this._addCustomButton.disabled = false; 403 this._addCustomButton.disabled = false;
377 this._addCustomButton.focus(); 404 this._addCustomButton.focus();
378 }, 405 },
379 406
380 __proto__: WebInspector.VBox.prototype 407 __proto__: WebInspector.VBox.prototype
381 } 408 }
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/components/module.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698