Index: Source/devtools/front_end/components/NetworkConditionsSelector.js |
diff --git a/Source/devtools/front_end/components/NetworkConditionsSelector.js b/Source/devtools/front_end/components/NetworkConditionsSelector.js |
index 0a4fb32344c24bfb3b23e0d8042cd9abb1bd8532..07d685c5d9edc533790f2041e05ae5f4b2236c95 100644 |
--- a/Source/devtools/front_end/components/NetworkConditionsSelector.js |
+++ b/Source/devtools/front_end/components/NetworkConditionsSelector.js |
@@ -64,36 +64,63 @@ WebInspector.NetworkConditionsSelector._networkConditionsPresets = [ |
{title: "Good 3G", value: {throughput: 1.5 * 1024 * 1024 / 8, latency: 40}}, |
{title: "Regular 4G", value: {throughput: 4 * 1024 * 1024 / 8, latency: 20}}, |
{title: "DSL", value: {throughput: 2 * 1024 * 1024 / 8, latency: 5}}, |
- {title: "WiFi", value: {throughput: 30 * 1024 * 1024 / 8, latency: 2}}, |
- {title: "No throttling", value: {throughput: -1, latency: 0}} |
+ {title: "WiFi", value: {throughput: 30 * 1024 * 1024 / 8, latency: 2}} |
]; |
+/** @type {!WebInspector.NetworkConditionsProfile} */ |
+WebInspector.NetworkConditionsSelector._disabledPreset = {title: "No throttling", value: {throughput: -1, latency: 0}}; |
+ |
WebInspector.NetworkConditionsSelector.prototype = { |
_populateOptions: function() |
{ |
this._selectElement.removeChildren(); |
- var presets = this._customSetting.get().concat(WebInspector.NetworkConditionsSelector._networkConditionsPresets); |
+ |
+ var customGroup = this._addGroup(this._customSetting.get(), WebInspector.UIString("Custom")); |
+ customGroup.insertBefore(new Option(WebInspector.UIString("Add\u2026"), WebInspector.UIString("Add\u2026")), customGroup.firstChild); |
+ |
+ this._addGroup(WebInspector.NetworkConditionsSelector._networkConditionsPresets, WebInspector.UIString("Presets")); |
+ this._addGroup([WebInspector.NetworkConditionsSelector._disabledPreset], WebInspector.UIString("Disabled")); |
+ |
+ this._settingChanged(); |
+ }, |
+ |
+ /** |
+ * @param {!Array.<!WebInspector.NetworkConditionsProfile>} presets |
+ * @param {string} groupName |
+ * @return {!Element} |
+ */ |
+ _addGroup: function(presets, groupName) |
+ { |
+ var groupElement = this._selectElement.createChild("optgroup"); |
+ groupElement.label = groupName; |
for (var i = 0; i < presets.length; ++i) { |
var preset = presets[i]; |
var throughputInKbps = preset.value.throughput / (1024 / 8); |
var isThrottling = (throughputInKbps > 0) || preset.value.latency; |
var option; |
+ var presetTitle = WebInspector.UIString(preset.title); |
if (!isThrottling) { |
- option = new Option(preset.title, preset.title); |
+ option = new Option(presetTitle, presetTitle); |
} else { |
var throughputText = WebInspector.NetworkConditionsSelector.throughputText(preset.value); |
- var title = WebInspector.UIString("%s (%s %dms RTT)", preset.title, throughputText, preset.value.latency); |
- option = new Option(title, preset.title); |
+ var title = WebInspector.UIString("%s (%s %dms RTT)", presetTitle, throughputText, preset.value.latency); |
+ option = new Option(title, presetTitle); |
option.title = WebInspector.UIString("Maximum download throughput: %s.\r\nMinimum round-trip time: %dms.", throughputText, preset.value.latency); |
} |
option.settingValue = preset.value; |
- this._selectElement.appendChild(option); |
+ groupElement.appendChild(option); |
} |
- this._settingChanged(); |
+ return groupElement; |
}, |
_optionSelected: function() |
{ |
+ if (this._selectElement.selectedIndex === 0) { |
+ WebInspector.Revealer.reveal(this._customSetting); |
+ this._settingChanged(); |
+ return; |
+ } |
+ |
this._setting.removeChangeListener(this._settingChanged, this); |
this._setting.set(this._selectElement.options[this._selectElement.selectedIndex].settingValue); |
this._setting.addChangeListener(this._settingChanged, this); |
@@ -103,7 +130,7 @@ WebInspector.NetworkConditionsSelector.prototype = { |
{ |
var value = this._setting.get(); |
var options = this._selectElement.options; |
- for (var index = 0; index < options.length; ++index) { |
+ for (var index = 1; index < options.length; ++index) { |
var option = options[index]; |
if (option.settingValue.throughput === value.throughput && option.settingValue.latency === value.latency) |
this._selectElement.selectedIndex = index; |