Chromium Code Reviews| 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 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 Components.NetworkConditionsSelector = class { | 7 Components.NetworkConditionsSelector = class { |
| 8 /** | 8 /** |
| 9 * @param {function(!Array<!Components.NetworkConditionsGroup>):!Array<?SDK.Ne tworkManager.Conditions>} populateCallback | 9 * @param {function(!Array<!Components.NetworkConditionsGroup>):!Array<?SDK.Ne tworkManager.Conditions>} populateCallback |
| 10 * @param {function(number)} selectCallback | 10 * @param {function(number)} selectCallback |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 * @param {!Array.<!Components.NetworkConditionsGroup>} groups | 74 * @param {!Array.<!Components.NetworkConditionsGroup>} groups |
| 75 * @return {!Array<?SDK.NetworkManager.Conditions>} | 75 * @return {!Array<?SDK.NetworkManager.Conditions>} |
| 76 */ | 76 */ |
| 77 function populate(groups) { | 77 function populate(groups) { |
| 78 selectElement.removeChildren(); | 78 selectElement.removeChildren(); |
| 79 options = []; | 79 options = []; |
| 80 for (var i = 0; i < groups.length; ++i) { | 80 for (var i = 0; i < groups.length; ++i) { |
| 81 var group = groups[i]; | 81 var group = groups[i]; |
| 82 var groupElement = selectElement.createChild('optgroup'); | 82 var groupElement = selectElement.createChild('optgroup'); |
| 83 groupElement.label = group.title; | 83 groupElement.label = group.title; |
| 84 if (!i) { | 84 if (i === groups.length - 1) { |
|
caseq
2016/12/21 00:22:45
Don't you want this to be the last?
| |
| 85 groupElement.appendChild(new Option(Common.UIString('Add\u2026'), Comm on.UIString('Add\u2026'))); | 85 groupElement.appendChild(new Option(Common.UIString('Add\u2026'), Comm on.UIString('Add\u2026'))); |
| 86 options.push(null); | 86 options.push(null); |
| 87 } | 87 } |
| 88 for (var conditions of group.items) { | 88 for (var conditions of group.items) { |
| 89 var title = Components.NetworkConditionsSelector._conditionsTitle(cond itions, true); | 89 var title = Components.NetworkConditionsSelector._conditionsTitle(cond itions, true); |
| 90 var option = new Option(title.text, title.text); | 90 var option = new Option(title.text, title.text); |
| 91 option.title = title.title; | 91 option.title = title.title; |
| 92 groupElement.appendChild(option); | 92 groupElement.appendChild(option); |
| 93 options.push(conditions); | 93 options.push(conditions); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 return options; | 96 return options; |
| 97 } | 97 } |
| 98 | 98 |
| 99 function optionSelected() { | 99 function optionSelected() { |
| 100 if (selectElement.selectedIndex === 0) | 100 if (selectElement.selectedIndex === selectElement.options.length - 1) |
| 101 selector.revealAndUpdate(); | 101 selector.revealAndUpdate(); |
| 102 else | 102 else |
| 103 selector.optionSelected(options[selectElement.selectedIndex]); | 103 selector.optionSelected(options[selectElement.selectedIndex]); |
| 104 } | 104 } |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * @param {number} index | 107 * @param {number} index |
| 108 */ | 108 */ |
| 109 function select(index) { | 109 function select(index) { |
| 110 if (selectElement.selectedIndex !== index) | 110 if (selectElement.selectedIndex !== index) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 lastNetworkConditions = conditions; | 193 lastNetworkConditions = conditions; |
| 194 checkbox.setChecked(conditions === SDK.NetworkManager.OfflineConditions); | 194 checkbox.setChecked(conditions === SDK.NetworkManager.OfflineConditions); |
| 195 } | 195 } |
| 196 return checkbox; | 196 return checkbox; |
| 197 } | 197 } |
| 198 | 198 |
| 199 _populateOptions() { | 199 _populateOptions() { |
| 200 var customGroup = {title: Common.UIString('Custom'), items: this._customSett ing.get()}; | 200 var customGroup = {title: Common.UIString('Custom'), items: this._customSett ing.get()}; |
| 201 var presetsGroup = {title: Common.UIString('Presets'), items: Components.Net workConditionsSelector._presets}; | 201 var presetsGroup = {title: Common.UIString('Presets'), items: Components.Net workConditionsSelector._presets}; |
| 202 var disabledGroup = {title: Common.UIString('Disabled'), items: [SDK.Network Manager.NoThrottlingConditions]}; | 202 var disabledGroup = {title: Common.UIString('Disabled'), items: [SDK.Network Manager.NoThrottlingConditions]}; |
| 203 this._options = this._populateCallback([customGroup, presetsGroup, disabledG roup]); | 203 this._options = this._populateCallback([disabledGroup, presetsGroup, customG roup]); |
| 204 if (!this._conditionsChanged()) { | 204 if (!this._conditionsChanged()) { |
| 205 for (var i = this._options.length - 1; i >= 0; i--) { | 205 for (var i = this._options.length - 1; i >= 0; i--) { |
| 206 if (this._options[i]) { | 206 if (this._options[i]) { |
| 207 this.optionSelected(/** @type {!SDK.NetworkManager.Conditions} */ (thi s._options[i])); | 207 this.optionSelected(/** @type {!SDK.NetworkManager.Conditions} */ (thi s._options[i])); |
| 208 break; | 208 break; |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 | 213 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 [Protocol.Network.ResourcePriority.VeryLow, Common.UIString('Lowest')], | 494 [Protocol.Network.ResourcePriority.VeryLow, Common.UIString('Lowest')], |
| 495 [Protocol.Network.ResourcePriority.Low, Common.UIString('Low')], | 495 [Protocol.Network.ResourcePriority.Low, Common.UIString('Low')], |
| 496 [Protocol.Network.ResourcePriority.Medium, Common.UIString('Medium')], | 496 [Protocol.Network.ResourcePriority.Medium, Common.UIString('Medium')], |
| 497 [Protocol.Network.ResourcePriority.High, Common.UIString('High')], | 497 [Protocol.Network.ResourcePriority.High, Common.UIString('High')], |
| 498 [Protocol.Network.ResourcePriority.VeryHigh, Common.UIString('Highest')] | 498 [Protocol.Network.ResourcePriority.VeryHigh, Common.UIString('Highest')] |
| 499 ]); | 499 ]); |
| 500 Components.uiLabelForPriority._priorityToUILabel = labelMap; | 500 Components.uiLabelForPriority._priorityToUILabel = labelMap; |
| 501 } | 501 } |
| 502 return labelMap.get(priority) || Common.UIString('Unknown'); | 502 return labelMap.get(priority) || Common.UIString('Unknown'); |
| 503 }; | 503 }; |
| OLD | NEW |