| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 * @implements {UI.ListWidget.Delegate} | 6 * @implements {UI.ListWidget.Delegate} |
| 7 * @unrestricted | 7 * @unrestricted |
| 8 */ | 8 */ |
| 9 MobileThrottling.NetworkConditionsSettingsTab = class extends UI.VBox { | 9 MobileThrottling.ThrottlingSettingsTab = class extends UI.VBox { |
| 10 constructor() { | 10 constructor() { |
| 11 super(true); | 11 super(true); |
| 12 this.registerRequiredCSS('mobile_throttling/networkConditionsSettingsTab.css
'); | 12 this.registerRequiredCSS('mobile_throttling/throttlingSettingsTab.css'); |
| 13 | 13 |
| 14 this.contentElement.createChild('div', 'header').textContent = Common.UIStri
ng('Network Throttling Profiles'); | 14 this.contentElement.createChild('div', 'header').textContent = Common.UIStri
ng('Network Throttling Profiles'); |
| 15 | 15 |
| 16 var addButton = UI.createTextButton( | 16 var addButton = UI.createTextButton( |
| 17 Common.UIString('Add custom profile...'), this._addButtonClicked.bind(th
is), 'add-conditions-button'); | 17 Common.UIString('Add custom profile...'), this._addButtonClicked.bind(th
is), 'add-conditions-button'); |
| 18 this.contentElement.appendChild(addButton); | 18 this.contentElement.appendChild(addButton); |
| 19 | 19 |
| 20 this._list = new UI.ListWidget(this); | 20 this._list = new UI.ListWidget(this); |
| 21 this._list.element.classList.add('conditions-list'); | 21 this._list.element.classList.add('conditions-list'); |
| 22 this._list.registerRequiredCSS('mobile_throttling/networkConditionsSettingsT
ab.css'); | 22 this._list.registerRequiredCSS('mobile_throttling/throttlingSettingsTab.css'
); |
| 23 this._list.show(this.contentElement); | 23 this._list.show(this.contentElement); |
| 24 | 24 |
| 25 this._customSetting = Common.moduleSetting('customNetworkConditions'); | 25 this._customSetting = Common.moduleSetting('customNetworkConditions'); |
| 26 this._customSetting.addChangeListener(this._conditionsUpdated, this); | 26 this._customSetting.addChangeListener(this._conditionsUpdated, this); |
| 27 | 27 |
| 28 this.setDefaultFocusedElement(addButton); | 28 this.setDefaultFocusedElement(addButton); |
| 29 this.contentElement.tabIndex = 0; | 29 this.contentElement.tabIndex = 0; |
| 30 } | 30 } |
| 31 | 31 |
| 32 /** | 32 /** |
| (...skipping 26 matching lines...) Expand all Loading... |
| 59 */ | 59 */ |
| 60 renderItem(item, editable) { | 60 renderItem(item, editable) { |
| 61 var conditions = /** @type {!SDK.NetworkManager.Conditions} */ (item); | 61 var conditions = /** @type {!SDK.NetworkManager.Conditions} */ (item); |
| 62 var element = createElementWithClass('div', 'conditions-list-item'); | 62 var element = createElementWithClass('div', 'conditions-list-item'); |
| 63 var title = element.createChild('div', 'conditions-list-text conditions-list
-title'); | 63 var title = element.createChild('div', 'conditions-list-text conditions-list
-title'); |
| 64 var titleText = title.createChild('div', 'conditions-list-title-text'); | 64 var titleText = title.createChild('div', 'conditions-list-title-text'); |
| 65 titleText.textContent = conditions.title; | 65 titleText.textContent = conditions.title; |
| 66 titleText.title = conditions.title; | 66 titleText.title = conditions.title; |
| 67 element.createChild('div', 'conditions-list-separator'); | 67 element.createChild('div', 'conditions-list-separator'); |
| 68 element.createChild('div', 'conditions-list-text').textContent = | 68 element.createChild('div', 'conditions-list-text').textContent = |
| 69 MobileThrottling.NetworkConditionsSelector.throughputText(conditions.dow
nload); | 69 MobileThrottling.throughputText(conditions.download); |
| 70 element.createChild('div', 'conditions-list-separator'); | 70 element.createChild('div', 'conditions-list-separator'); |
| 71 element.createChild('div', 'conditions-list-text').textContent = | 71 element.createChild('div', 'conditions-list-text').textContent = MobileThrot
tling.throughputText(conditions.upload); |
| 72 MobileThrottling.NetworkConditionsSelector.throughputText(conditions.upl
oad); | |
| 73 element.createChild('div', 'conditions-list-separator'); | 72 element.createChild('div', 'conditions-list-separator'); |
| 74 element.createChild('div', 'conditions-list-text').textContent = Common.UISt
ring('%dms', conditions.latency); | 73 element.createChild('div', 'conditions-list-text').textContent = Common.UISt
ring('%dms', conditions.latency); |
| 75 return element; | 74 return element; |
| 76 } | 75 } |
| 77 | 76 |
| 78 /** | 77 /** |
| 79 * @override | 78 * @override |
| 80 * @param {*} item | 79 * @param {*} item |
| 81 * @param {number} index | 80 * @param {number} index |
| 82 */ | 81 */ |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 * @param {number} index | 191 * @param {number} index |
| 193 * @param {!HTMLInputElement|!HTMLSelectElement} input | 192 * @param {!HTMLInputElement|!HTMLSelectElement} input |
| 194 * @return {boolean} | 193 * @return {boolean} |
| 195 */ | 194 */ |
| 196 function latencyValidator(item, index, input) { | 195 function latencyValidator(item, index, input) { |
| 197 var value = input.value.trim(); | 196 var value = input.value.trim(); |
| 198 return !value || (/^[\d]+$/.test(value) && value >= 0 && value <= 1000000)
; | 197 return !value || (/^[\d]+$/.test(value) && value >= 0 && value <= 1000000)
; |
| 199 } | 198 } |
| 200 } | 199 } |
| 201 }; | 200 }; |
| 201 |
| 202 /** |
| 203 * @param {number} throughput |
| 204 * @param {boolean=} plainText |
| 205 * @return {string} |
| 206 */ |
| 207 MobileThrottling.throughputText = function(throughput, plainText) { |
| 208 if (throughput < 0) |
| 209 return ''; |
| 210 var throughputInKbps = throughput / (1024 / 8); |
| 211 var delimiter = plainText ? '' : ' '; |
| 212 if (throughputInKbps < 1024) |
| 213 return Common.UIString('%d%skb/s', throughputInKbps, delimiter); |
| 214 if (throughputInKbps < 1024 * 10) |
| 215 return Common.UIString('%.1f%sMb/s', throughputInKbps / 1024, delimiter); |
| 216 return Common.UIString('%d%sMb/s', (throughputInKbps / 1024) | 0, delimiter); |
| 217 }; |
| OLD | NEW |