OLD | NEW |
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 Loading... |
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 this._addGroup(this._customSetting.get(), WebInspector.UIString("Custom"
)); |
| 78 this._addGroup(WebInspector.NetworkConditionsSelector._networkConditions
Presets, WebInspector.UIString("Presets")); |
| 79 this._addGroup([WebInspector.NetworkConditionsSelector._disabledPreset],
WebInspector.UIString("Disabled")); |
| 80 |
| 81 var editOption = new Option(WebInspector.UIString("Edit..."), WebInspect
or.UIString("Edit...")); |
| 82 this._selectElement.appendChild(editOption); |
| 83 |
| 84 this._settingChanged(); |
| 85 }, |
| 86 |
| 87 /** |
| 88 * @param {!Array.<!WebInspector.NetworkConditionsProfile>} presets |
| 89 * @param {string} groupName |
| 90 */ |
| 91 _addGroup: function(presets, groupName) |
| 92 { |
| 93 if (!presets.length) |
| 94 return; |
| 95 var groupElement = this._selectElement.createChild("optgroup"); |
| 96 groupElement.label = groupName; |
76 for (var i = 0; i < presets.length; ++i) { | 97 for (var i = 0; i < presets.length; ++i) { |
77 var preset = presets[i]; | 98 var preset = presets[i]; |
78 var throughputInKbps = preset.value.throughput / (1024 / 8); | 99 var throughputInKbps = preset.value.throughput / (1024 / 8); |
79 var isThrottling = (throughputInKbps > 0) || preset.value.latency; | 100 var isThrottling = (throughputInKbps > 0) || preset.value.latency; |
80 var option; | 101 var option; |
| 102 var presetTitle = WebInspector.UIString(preset.title); |
81 if (!isThrottling) { | 103 if (!isThrottling) { |
82 option = new Option(preset.title, preset.title); | 104 option = new Option(presetTitle, presetTitle); |
83 } else { | 105 } else { |
84 var throughputText = WebInspector.NetworkConditionsSelector.thro
ughputText(preset.value); | 106 var throughputText = WebInspector.NetworkConditionsSelector.thro
ughputText(preset.value); |
85 var title = WebInspector.UIString("%s (%s %dms RTT)", preset.tit
le, throughputText, preset.value.latency); | 107 var title = WebInspector.UIString("%s (%s %dms RTT)", presetTitl
e, throughputText, preset.value.latency); |
86 option = new Option(title, preset.title); | 108 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)
; | 109 option.title = WebInspector.UIString("Maximum download throughpu
t: %s.\r\nMinimum round-trip time: %dms.", throughputText, preset.value.latency)
; |
88 } | 110 } |
89 option.settingValue = preset.value; | 111 option.settingValue = preset.value; |
90 this._selectElement.appendChild(option); | 112 groupElement.appendChild(option); |
91 } | 113 } |
92 this._settingChanged(); | |
93 }, | 114 }, |
94 | 115 |
95 _optionSelected: function() | 116 _optionSelected: function() |
96 { | 117 { |
| 118 if (this._selectElement.selectedIndex === this._selectElement.options.le
ngth - 1) { |
| 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 = 0; index < options.length - 1; ++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 Loading... |
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 } |
OLD | NEW |