Chromium Code Reviews| 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('Mobile 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('customThrottlingConditions'); |
| 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 /** |
| 33 * @override | 33 * @override |
| 34 */ | 34 */ |
| 35 wasShown() { | 35 wasShown() { |
| 36 super.wasShown(); | 36 super.wasShown(); |
| 37 this._conditionsUpdated(); | 37 this._conditionsUpdated(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 _conditionsUpdated() { | 40 _conditionsUpdated() { |
| 41 this._list.clear(); | 41 this._list.clear(); |
| 42 | 42 |
| 43 var conditions = this._customSetting.get(); | 43 var conditions = this._customSetting.get(); |
| 44 for (var i = 0; i < conditions.length; ++i) | 44 for (var i = 0; i < conditions.length; ++i) |
| 45 this._list.appendItem(conditions[i], true); | 45 this._list.appendItem(conditions[i], true); |
| 46 | 46 |
| 47 this._list.appendSeparator(); | 47 this._list.appendSeparator(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 _addButtonClicked() { | 50 _addButtonClicked() { |
| 51 this._list.addNewItem(this._customSetting.get().length, {title: '', download : -1, upload: -1, latency: 0}); | 51 this._list.addNewItem( |
| 52 this._customSetting.get().length, {title: '', download: -1, upload: -1, latency: 0, cpuThrottlingRate: 0}); | |
| 52 } | 53 } |
| 53 | 54 |
| 54 /** | 55 /** |
| 55 * @override | 56 * @override |
| 56 * @param {*} item | 57 * @param {*} item |
| 57 * @param {boolean} editable | 58 * @param {boolean} editable |
| 58 * @return {!Element} | 59 * @return {!Element} |
| 59 */ | 60 */ |
| 60 renderItem(item, editable) { | 61 renderItem(item, editable) { |
| 61 var conditions = /** @type {!SDK.NetworkManager.Conditions} */ (item); | 62 var conditions = /** @type {!SDK.MobileThrottling.Conditions} */ (item); |
| 62 var element = createElementWithClass('div', 'conditions-list-item'); | 63 var element = createElementWithClass('div', 'conditions-list-item'); |
| 63 var title = element.createChild('div', 'conditions-list-text conditions-list -title'); | 64 var title = element.createChild('div', 'conditions-list-text conditions-list -title'); |
| 64 var titleText = title.createChild('div', 'conditions-list-title-text'); | 65 var titleText = title.createChild('div', 'conditions-list-title-text'); |
| 65 titleText.textContent = conditions.title; | 66 titleText.textContent = conditions.title; |
| 66 titleText.title = conditions.title; | 67 titleText.title = conditions.title; |
| 67 element.createChild('div', 'conditions-list-separator'); | 68 element.createChild('div', 'conditions-list-separator'); |
| 68 element.createChild('div', 'conditions-list-text').textContent = | 69 element.createChild('div', 'conditions-list-text').textContent = |
| 69 MobileThrottling.NetworkConditionsSelector.throughputText(conditions.dow nload); | 70 MobileThrottling.ThrottlingSelector.throughputText(conditions.download); |
| 70 element.createChild('div', 'conditions-list-separator'); | 71 element.createChild('div', 'conditions-list-separator'); |
| 71 element.createChild('div', 'conditions-list-text').textContent = | 72 element.createChild('div', 'conditions-list-text').textContent = |
| 72 MobileThrottling.NetworkConditionsSelector.throughputText(conditions.upl oad); | 73 MobileThrottling.ThrottlingSelector.throughputText(conditions.upload); |
| 73 element.createChild('div', 'conditions-list-separator'); | 74 element.createChild('div', 'conditions-list-separator'); |
| 74 element.createChild('div', 'conditions-list-text').textContent = Common.UISt ring('%dms', conditions.latency); | 75 element.createChild('div', 'conditions-list-text').textContent = Common.UISt ring('%dms', conditions.latency); |
| 76 element.createChild('div', 'conditions-list-separator'); | |
| 77 element.createChild('div', 'conditions-list-text').textContent = | |
| 78 Common.UIString('%d\xD7', conditions.cpuThrottlingRate); | |
|
dgozman
2017/06/13 01:47:08
'%d times' maybe? 'x' looks strange.
chenwilliam
2017/06/13 21:54:51
Yeah looks a bit weird. Done.
| |
| 75 return element; | 79 return element; |
| 76 } | 80 } |
| 77 | 81 |
| 78 /** | 82 /** |
| 79 * @override | 83 * @override |
| 80 * @param {*} item | 84 * @param {*} item |
| 81 * @param {number} index | 85 * @param {number} index |
| 82 */ | 86 */ |
| 83 removeItemRequested(item, index) { | 87 removeItemRequested(item, index) { |
| 84 var list = this._customSetting.get(); | 88 var list = this._customSetting.get(); |
| 85 list.splice(index, 1); | 89 list.splice(index, 1); |
| 86 this._customSetting.set(list); | 90 this._customSetting.set(list); |
| 87 } | 91 } |
| 88 | 92 |
| 89 /** | 93 /** |
| 90 * @override | 94 * @override |
| 91 * @param {*} item | 95 * @param {*} item |
| 92 * @param {!UI.ListWidget.Editor} editor | 96 * @param {!UI.ListWidget.Editor} editor |
| 93 * @param {boolean} isNew | 97 * @param {boolean} isNew |
| 94 */ | 98 */ |
| 95 commitEdit(item, editor, isNew) { | 99 commitEdit(item, editor, isNew) { |
| 96 var conditions = /** @type {?SDK.NetworkManager.Conditions} */ (item); | 100 var conditions = /** @type {?SDK.MobileThrottling.Conditions} */ (item); |
| 97 conditions.title = editor.control('title').value.trim(); | 101 conditions.title = editor.control('title').value.trim(); |
| 98 var download = editor.control('download').value.trim(); | 102 var download = editor.control('download').value.trim(); |
| 99 conditions.download = download ? parseInt(download, 10) * (1024 / 8) : -1; | 103 conditions.download = download ? parseInt(download, 10) * (1024 / 8) : -1; |
| 100 var upload = editor.control('upload').value.trim(); | 104 var upload = editor.control('upload').value.trim(); |
| 101 conditions.upload = upload ? parseInt(upload, 10) * (1024 / 8) : -1; | 105 conditions.upload = upload ? parseInt(upload, 10) * (1024 / 8) : -1; |
| 102 var latency = editor.control('latency').value.trim(); | 106 var latency = editor.control('latency').value.trim(); |
| 103 conditions.latency = latency ? parseInt(latency, 10) : 0; | 107 conditions.latency = latency ? parseInt(latency, 10) : 0; |
| 108 var cpuThrottlingRate = editor.control('cpuThrottlingRate').value.trim(); | |
| 109 conditions.cpuThrottlingRate = cpuThrottlingRate ? parseInt(cpuThrottlingRat e, 10) : 1; | |
| 104 | 110 |
| 105 var list = this._customSetting.get(); | 111 var list = this._customSetting.get(); |
| 106 if (isNew) | 112 if (isNew) |
| 107 list.push(conditions); | 113 list.push(conditions); |
| 108 this._customSetting.set(list); | 114 this._customSetting.set(list); |
| 109 } | 115 } |
| 110 | 116 |
| 111 /** | 117 /** |
| 112 * @override | 118 * @override |
| 113 * @param {*} item | 119 * @param {*} item |
| 114 * @return {!UI.ListWidget.Editor} | 120 * @return {!UI.ListWidget.Editor} |
| 115 */ | 121 */ |
| 116 beginEdit(item) { | 122 beginEdit(item) { |
| 117 var conditions = /** @type {?SDK.NetworkManager.Conditions} */ (item); | 123 var conditions = /** @type {?SDK.MobileThrottling.Conditions} */ (item); |
| 118 var editor = this._createEditor(); | 124 var editor = this._createEditor(); |
| 119 editor.control('title').value = conditions.title; | 125 editor.control('title').value = conditions.title; |
| 120 editor.control('download').value = conditions.download <= 0 ? '' : String(co nditions.download / (1024 / 8)); | 126 editor.control('download').value = conditions.download <= 0 ? '' : String(co nditions.download / (1024 / 8)); |
| 121 editor.control('upload').value = conditions.upload <= 0 ? '' : String(condit ions.upload / (1024 / 8)); | 127 editor.control('upload').value = conditions.upload <= 0 ? '' : String(condit ions.upload / (1024 / 8)); |
| 122 editor.control('latency').value = conditions.latency ? String(conditions.lat ency) : ''; | 128 editor.control('latency').value = conditions.latency ? String(conditions.lat ency) : ''; |
| 129 editor.control('cpuThrottlingRate').value = | |
| 130 conditions.cpuThrottlingRate ? String(conditions.cpuThrottlingRate) : '' ; | |
| 123 return editor; | 131 return editor; |
| 124 } | 132 } |
| 125 | 133 |
| 126 /** | 134 /** |
| 127 * @return {!UI.ListWidget.Editor} | 135 * @return {!UI.ListWidget.Editor} |
| 128 */ | 136 */ |
| 129 _createEditor() { | 137 _createEditor() { |
| 130 if (this._editor) | 138 if (this._editor) |
| 131 return this._editor; | 139 return this._editor; |
| 132 | 140 |
| 133 var editor = new UI.ListWidget.Editor(); | 141 var editor = new UI.ListWidget.Editor(); |
| 134 this._editor = editor; | 142 this._editor = editor; |
| 135 var content = editor.contentElement(); | 143 var content = editor.contentElement(); |
| 136 | 144 |
| 137 var titles = content.createChild('div', 'conditions-edit-row'); | 145 var titles = content.createChild('div', 'conditions-header-row'); |
| 138 titles.createChild('div', 'conditions-list-text conditions-list-title').text Content = | 146 titles.createChild('div', 'conditions-list-text conditions-list-title').text Content = |
| 139 Common.UIString('Profile Name'); | 147 Common.UIString('Profile Name'); |
| 140 titles.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); | 148 titles.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); |
| 141 titles.createChild('div', 'conditions-list-text').textContent = Common.UIStr ing('Download'); | 149 titles.createChild('div', 'conditions-list-text').textContent = Common.UIStr ing('Download'); |
| 142 titles.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); | 150 titles.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); |
| 143 titles.createChild('div', 'conditions-list-text').textContent = Common.UIStr ing('Upload'); | 151 titles.createChild('div', 'conditions-list-text').textContent = Common.UIStr ing('Upload'); |
| 144 titles.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); | 152 titles.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); |
| 145 titles.createChild('div', 'conditions-list-text').textContent = Common.UIStr ing('Latency'); | 153 titles.createChild('div', 'conditions-list-text').textContent = Common.UIStr ing('Latency'); |
| 154 titles.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); | |
| 155 titles.createChild('div', 'conditions-list-text').textContent = Common.UIStr ing('CPU Slowdown'); | |
| 146 | 156 |
| 147 var fields = content.createChild('div', 'conditions-edit-row'); | 157 var fields = content.createChild('div', 'conditions-edit-row'); |
| 148 fields.createChild('div', 'conditions-list-text conditions-list-title') | 158 fields.createChild('div', 'conditions-list-text conditions-list-title') |
| 149 .appendChild(editor.createInput('title', 'text', '', titleValidator)); | 159 .appendChild(editor.createInput('title', 'text', '', titleValidator)); |
| 150 fields.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); | 160 fields.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); |
| 151 | 161 |
| 152 var cell = fields.createChild('div', 'conditions-list-text'); | 162 var cell = fields.createChild('div', 'conditions-list-text'); |
| 153 cell.appendChild(editor.createInput('download', 'text', Common.UIString('kb/ s'), throughputValidator)); | 163 cell.appendChild(editor.createInput('download', 'text', Common.UIString('kb/ s'), throughputValidator)); |
| 154 cell.createChild('div', 'conditions-edit-optional').textContent = Common.UIS tring('optional'); | 164 cell.createChild('div', 'conditions-edit-optional').textContent = Common.UIS tring('optional'); |
| 155 fields.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); | 165 fields.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); |
| 156 | 166 |
| 157 cell = fields.createChild('div', 'conditions-list-text'); | 167 cell = fields.createChild('div', 'conditions-list-text'); |
| 158 cell.appendChild(editor.createInput('upload', 'text', Common.UIString('kb/s' ), throughputValidator)); | 168 cell.appendChild(editor.createInput('upload', 'text', Common.UIString('kb/s' ), throughputValidator)); |
| 159 cell.createChild('div', 'conditions-edit-optional').textContent = Common.UIS tring('optional'); | 169 cell.createChild('div', 'conditions-edit-optional').textContent = Common.UIS tring('optional'); |
| 160 fields.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); | 170 fields.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); |
| 161 | 171 |
| 162 cell = fields.createChild('div', 'conditions-list-text'); | 172 cell = fields.createChild('div', 'conditions-list-text'); |
| 163 cell.appendChild(editor.createInput('latency', 'text', Common.UIString('ms') , latencyValidator)); | 173 cell.appendChild(editor.createInput('latency', 'text', Common.UIString('ms') , latencyValidator)); |
| 164 cell.createChild('div', 'conditions-edit-optional').textContent = Common.UIS tring('optional'); | 174 cell.createChild('div', 'conditions-edit-optional').textContent = Common.UIS tring('optional'); |
| 175 fields.createChild('div', 'conditions-list-separator conditions-list-separat or-invisible'); | |
| 176 | |
| 177 cell = fields.createChild('div', 'conditions-list-text'); | |
| 178 cell.appendChild( | |
| 179 editor.createInput('cpuThrottlingRate', 'text', Common.UIString('\xD7'), cpuThrottlingRateValidator)); | |
| 180 cell.createChild('div', 'conditions-edit-optional').textContent = Common.UIS tring('optional'); | |
| 165 | 181 |
| 166 return editor; | 182 return editor; |
| 167 | 183 |
| 168 /** | 184 /** |
| 169 * @param {*} item | 185 * @param {*} item |
| 170 * @param {number} index | 186 * @param {number} index |
| 171 * @param {!HTMLInputElement|!HTMLSelectElement} input | 187 * @param {!HTMLInputElement|!HTMLSelectElement} input |
| 172 * @return {boolean} | 188 * @return {boolean} |
| 173 */ | 189 */ |
| 174 function titleValidator(item, index, input) { | 190 function titleValidator(item, index, input) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 190 /** | 206 /** |
| 191 * @param {*} item | 207 * @param {*} item |
| 192 * @param {number} index | 208 * @param {number} index |
| 193 * @param {!HTMLInputElement|!HTMLSelectElement} input | 209 * @param {!HTMLInputElement|!HTMLSelectElement} input |
| 194 * @return {boolean} | 210 * @return {boolean} |
| 195 */ | 211 */ |
| 196 function latencyValidator(item, index, input) { | 212 function latencyValidator(item, index, input) { |
| 197 var value = input.value.trim(); | 213 var value = input.value.trim(); |
| 198 return !value || (/^[\d]+$/.test(value) && value >= 0 && value <= 1000000) ; | 214 return !value || (/^[\d]+$/.test(value) && value >= 0 && value <= 1000000) ; |
| 199 } | 215 } |
| 216 | |
| 217 /** | |
| 218 * @param {*} item | |
| 219 * @param {number} index | |
| 220 * @param {!HTMLInputElement|!HTMLSelectElement} input | |
| 221 * @return {boolean} | |
| 222 */ | |
| 223 function cpuThrottlingRateValidator(item, index, input) { | |
| 224 var value = input.value.trim(); | |
| 225 return !value || (/^[\d]+$/.test(value) && value >= 1 && value <= 1000000) ; | |
| 226 } | |
| 200 } | 227 } |
| 201 }; | 228 }; |
| OLD | NEW |