| 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 * @implements {WebInspector.ListWidget.Delegate} | 5 * @implements {UI.ListWidget.Delegate} |
| 6 * @unrestricted | 6 * @unrestricted |
| 7 */ | 7 */ |
| 8 WebInspector.DevicesSettingsTab = class extends WebInspector.VBox { | 8 Emulation.DevicesSettingsTab = class extends UI.VBox { |
| 9 constructor() { | 9 constructor() { |
| 10 super(); | 10 super(); |
| 11 this.element.classList.add('settings-tab-container'); | 11 this.element.classList.add('settings-tab-container'); |
| 12 this.element.classList.add('devices-settings-tab'); | 12 this.element.classList.add('devices-settings-tab'); |
| 13 this.registerRequiredCSS('emulation/devicesSettingsTab.css'); | 13 this.registerRequiredCSS('emulation/devicesSettingsTab.css'); |
| 14 | 14 |
| 15 var header = this.element.createChild('header'); | 15 var header = this.element.createChild('header'); |
| 16 header.createChild('h3').createTextChild(WebInspector.UIString('Emulated Dev
ices')); | 16 header.createChild('h3').createTextChild(Common.UIString('Emulated Devices')
); |
| 17 this.containerElement = this.element.createChild('div', 'help-container-wrap
per') | 17 this.containerElement = this.element.createChild('div', 'help-container-wrap
per') |
| 18 .createChild('div', 'settings-tab help-content h
elp-container'); | 18 .createChild('div', 'settings-tab help-content h
elp-container'); |
| 19 | 19 |
| 20 var buttonsRow = this.containerElement.createChild('div', 'devices-button-ro
w'); | 20 var buttonsRow = this.containerElement.createChild('div', 'devices-button-ro
w'); |
| 21 this._addCustomButton = | 21 this._addCustomButton = |
| 22 createTextButton(WebInspector.UIString('Add custom device...'), this._ad
dCustomDevice.bind(this)); | 22 createTextButton(Common.UIString('Add custom device...'), this._addCusto
mDevice.bind(this)); |
| 23 buttonsRow.appendChild(this._addCustomButton); | 23 buttonsRow.appendChild(this._addCustomButton); |
| 24 | 24 |
| 25 this._list = new WebInspector.ListWidget(this); | 25 this._list = new UI.ListWidget(this); |
| 26 this._list.registerRequiredCSS('emulation/devicesSettingsTab.css'); | 26 this._list.registerRequiredCSS('emulation/devicesSettingsTab.css'); |
| 27 this._list.element.classList.add('devices-list'); | 27 this._list.element.classList.add('devices-list'); |
| 28 this._list.show(this.containerElement); | 28 this._list.show(this.containerElement); |
| 29 | 29 |
| 30 this._muteUpdate = false; | 30 this._muteUpdate = false; |
| 31 this._emulatedDevicesList = WebInspector.EmulatedDevicesList.instance(); | 31 this._emulatedDevicesList = Emulation.EmulatedDevicesList.instance(); |
| 32 this._emulatedDevicesList.addEventListener( | 32 this._emulatedDevicesList.addEventListener( |
| 33 WebInspector.EmulatedDevicesList.Events.CustomDevicesUpdated, this._devi
cesUpdated, this); | 33 Emulation.EmulatedDevicesList.Events.CustomDevicesUpdated, this._devices
Updated, this); |
| 34 this._emulatedDevicesList.addEventListener( | 34 this._emulatedDevicesList.addEventListener( |
| 35 WebInspector.EmulatedDevicesList.Events.StandardDevicesUpdated, this._de
vicesUpdated, this); | 35 Emulation.EmulatedDevicesList.Events.StandardDevicesUpdated, this._devic
esUpdated, this); |
| 36 | 36 |
| 37 this.setDefaultFocusedElement(this._addCustomButton); | 37 this.setDefaultFocusedElement(this._addCustomButton); |
| 38 } | 38 } |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * @override | 41 * @override |
| 42 */ | 42 */ |
| 43 wasShown() { | 43 wasShown() { |
| 44 super.wasShown(); | 44 super.wasShown(); |
| 45 this._devicesUpdated(); | 45 this._devicesUpdated(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 _devicesUpdated() { | 48 _devicesUpdated() { |
| 49 if (this._muteUpdate) | 49 if (this._muteUpdate) |
| 50 return; | 50 return; |
| 51 | 51 |
| 52 this._list.clear(); | 52 this._list.clear(); |
| 53 | 53 |
| 54 var devices = this._emulatedDevicesList.custom().slice(); | 54 var devices = this._emulatedDevicesList.custom().slice(); |
| 55 for (var i = 0; i < devices.length; ++i) | 55 for (var i = 0; i < devices.length; ++i) |
| 56 this._list.appendItem(devices[i], true); | 56 this._list.appendItem(devices[i], true); |
| 57 | 57 |
| 58 this._list.appendSeparator(); | 58 this._list.appendSeparator(); |
| 59 | 59 |
| 60 devices = this._emulatedDevicesList.standard().slice(); | 60 devices = this._emulatedDevicesList.standard().slice(); |
| 61 devices.sort(WebInspector.EmulatedDevice.deviceComparator); | 61 devices.sort(Emulation.EmulatedDevice.deviceComparator); |
| 62 for (var i = 0; i < devices.length; ++i) | 62 for (var i = 0; i < devices.length; ++i) |
| 63 this._list.appendItem(devices[i], false); | 63 this._list.appendItem(devices[i], false); |
| 64 } | 64 } |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * @param {boolean} custom | 67 * @param {boolean} custom |
| 68 */ | 68 */ |
| 69 _muteAndSaveDeviceList(custom) { | 69 _muteAndSaveDeviceList(custom) { |
| 70 this._muteUpdate = true; | 70 this._muteUpdate = true; |
| 71 if (custom) | 71 if (custom) |
| 72 this._emulatedDevicesList.saveCustomDevices(); | 72 this._emulatedDevicesList.saveCustomDevices(); |
| 73 else | 73 else |
| 74 this._emulatedDevicesList.saveStandardDevices(); | 74 this._emulatedDevicesList.saveStandardDevices(); |
| 75 this._muteUpdate = false; | 75 this._muteUpdate = false; |
| 76 } | 76 } |
| 77 | 77 |
| 78 _addCustomDevice() { | 78 _addCustomDevice() { |
| 79 var device = new WebInspector.EmulatedDevice(); | 79 var device = new Emulation.EmulatedDevice(); |
| 80 device.deviceScaleFactor = 0; | 80 device.deviceScaleFactor = 0; |
| 81 device.horizontal.width = 700; | 81 device.horizontal.width = 700; |
| 82 device.horizontal.height = 400; | 82 device.horizontal.height = 400; |
| 83 device.vertical.width = 400; | 83 device.vertical.width = 400; |
| 84 device.vertical.height = 700; | 84 device.vertical.height = 700; |
| 85 this._list.addNewItem(this._emulatedDevicesList.custom().length, device); | 85 this._list.addNewItem(this._emulatedDevicesList.custom().length, device); |
| 86 } | 86 } |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * @param {number} value | 89 * @param {number} value |
| 90 * @return {string} | 90 * @return {string} |
| 91 */ | 91 */ |
| 92 _toNumericInputValue(value) { | 92 _toNumericInputValue(value) { |
| 93 return value ? String(value) : ''; | 93 return value ? String(value) : ''; |
| 94 } | 94 } |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * @override | 97 * @override |
| 98 * @param {*} item | 98 * @param {*} item |
| 99 * @param {boolean} editable | 99 * @param {boolean} editable |
| 100 * @return {!Element} | 100 * @return {!Element} |
| 101 */ | 101 */ |
| 102 renderItem(item, editable) { | 102 renderItem(item, editable) { |
| 103 var device = /** @type {!WebInspector.EmulatedDevice} */ (item); | 103 var device = /** @type {!Emulation.EmulatedDevice} */ (item); |
| 104 var element = createElementWithClass('div', 'devices-list-item'); | 104 var element = createElementWithClass('div', 'devices-list-item'); |
| 105 var checkbox = element.createChild('input', 'devices-list-checkbox'); | 105 var checkbox = element.createChild('input', 'devices-list-checkbox'); |
| 106 checkbox.type = 'checkbox'; | 106 checkbox.type = 'checkbox'; |
| 107 checkbox.checked = device.show(); | 107 checkbox.checked = device.show(); |
| 108 element.createChild('div', 'devices-list-title').textContent = device.title; | 108 element.createChild('div', 'devices-list-title').textContent = device.title; |
| 109 element.addEventListener('click', onItemClicked.bind(this), false); | 109 element.addEventListener('click', onItemClicked.bind(this), false); |
| 110 return element; | 110 return element; |
| 111 | 111 |
| 112 /** | 112 /** |
| 113 * @param {!Event} event | 113 * @param {!Event} event |
| 114 * @this {WebInspector.DevicesSettingsTab} | 114 * @this {Emulation.DevicesSettingsTab} |
| 115 */ | 115 */ |
| 116 function onItemClicked(event) { | 116 function onItemClicked(event) { |
| 117 var show = !checkbox.checked; | 117 var show = !checkbox.checked; |
| 118 device.setShow(show); | 118 device.setShow(show); |
| 119 this._muteAndSaveDeviceList(editable); | 119 this._muteAndSaveDeviceList(editable); |
| 120 checkbox.checked = show; | 120 checkbox.checked = show; |
| 121 event.consume(); | 121 event.consume(); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 /** | 125 /** |
| 126 * @override | 126 * @override |
| 127 * @param {*} item | 127 * @param {*} item |
| 128 * @param {number} index | 128 * @param {number} index |
| 129 */ | 129 */ |
| 130 removeItemRequested(item, index) { | 130 removeItemRequested(item, index) { |
| 131 this._emulatedDevicesList.removeCustomDevice(/** @type {!WebInspector.Emulat
edDevice} */ (item)); | 131 this._emulatedDevicesList.removeCustomDevice(/** @type {!Emulation.EmulatedD
evice} */ (item)); |
| 132 } | 132 } |
| 133 | 133 |
| 134 /** | 134 /** |
| 135 * @override | 135 * @override |
| 136 * @param {*} item | 136 * @param {*} item |
| 137 * @param {!WebInspector.ListWidget.Editor} editor | 137 * @param {!UI.ListWidget.Editor} editor |
| 138 * @param {boolean} isNew | 138 * @param {boolean} isNew |
| 139 */ | 139 */ |
| 140 commitEdit(item, editor, isNew) { | 140 commitEdit(item, editor, isNew) { |
| 141 var device = /** @type {!WebInspector.EmulatedDevice} */ (item); | 141 var device = /** @type {!Emulation.EmulatedDevice} */ (item); |
| 142 device.title = editor.control('title').value.trim(); | 142 device.title = editor.control('title').value.trim(); |
| 143 device.vertical.width = editor.control('width').value ? parseInt(editor.cont
rol('width').value, 10) : 0; | 143 device.vertical.width = editor.control('width').value ? parseInt(editor.cont
rol('width').value, 10) : 0; |
| 144 device.vertical.height = editor.control('height').value ? parseInt(editor.co
ntrol('height').value, 10) : 0; | 144 device.vertical.height = editor.control('height').value ? parseInt(editor.co
ntrol('height').value, 10) : 0; |
| 145 device.horizontal.width = device.vertical.height; | 145 device.horizontal.width = device.vertical.height; |
| 146 device.horizontal.height = device.vertical.width; | 146 device.horizontal.height = device.vertical.width; |
| 147 device.deviceScaleFactor = editor.control('scale').value ? parseFloat(editor
.control('scale').value) : 0; | 147 device.deviceScaleFactor = editor.control('scale').value ? parseFloat(editor
.control('scale').value) : 0; |
| 148 device.userAgent = editor.control('user-agent').value; | 148 device.userAgent = editor.control('user-agent').value; |
| 149 device.modes = []; | 149 device.modes = []; |
| 150 device.modes.push( | 150 device.modes.push( |
| 151 {title: '', orientation: WebInspector.EmulatedDevice.Vertical, insets: n
ew Insets(0, 0, 0, 0), image: null}); | 151 {title: '', orientation: Emulation.EmulatedDevice.Vertical, insets: new
Insets(0, 0, 0, 0), image: null}); |
| 152 device.modes.push( | 152 device.modes.push( |
| 153 {title: '', orientation: WebInspector.EmulatedDevice.Horizontal, insets:
new Insets(0, 0, 0, 0), image: null}); | 153 {title: '', orientation: Emulation.EmulatedDevice.Horizontal, insets: ne
w Insets(0, 0, 0, 0), image: null}); |
| 154 device.capabilities = []; | 154 device.capabilities = []; |
| 155 var uaType = editor.control('ua-type').value; | 155 var uaType = editor.control('ua-type').value; |
| 156 if (uaType === WebInspector.DeviceModeModel.UA.Mobile || uaType === WebInspe
ctor.DeviceModeModel.UA.MobileNoTouch) | 156 if (uaType === Emulation.DeviceModeModel.UA.Mobile || uaType === Emulation.D
eviceModeModel.UA.MobileNoTouch) |
| 157 device.capabilities.push(WebInspector.EmulatedDevice.Capability.Mobile); | 157 device.capabilities.push(Emulation.EmulatedDevice.Capability.Mobile); |
| 158 if (uaType === WebInspector.DeviceModeModel.UA.Mobile || uaType === WebInspe
ctor.DeviceModeModel.UA.DesktopTouch) | 158 if (uaType === Emulation.DeviceModeModel.UA.Mobile || uaType === Emulation.D
eviceModeModel.UA.DesktopTouch) |
| 159 device.capabilities.push(WebInspector.EmulatedDevice.Capability.Touch); | 159 device.capabilities.push(Emulation.EmulatedDevice.Capability.Touch); |
| 160 if (isNew) | 160 if (isNew) |
| 161 this._emulatedDevicesList.addCustomDevice(device); | 161 this._emulatedDevicesList.addCustomDevice(device); |
| 162 else | 162 else |
| 163 this._emulatedDevicesList.saveCustomDevices(); | 163 this._emulatedDevicesList.saveCustomDevices(); |
| 164 this._addCustomButton.scrollIntoViewIfNeeded(); | 164 this._addCustomButton.scrollIntoViewIfNeeded(); |
| 165 this._addCustomButton.focus(); | 165 this._addCustomButton.focus(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 /** | 168 /** |
| 169 * @override | 169 * @override |
| 170 * @param {*} item | 170 * @param {*} item |
| 171 * @return {!WebInspector.ListWidget.Editor} | 171 * @return {!UI.ListWidget.Editor} |
| 172 */ | 172 */ |
| 173 beginEdit(item) { | 173 beginEdit(item) { |
| 174 var device = /** @type {!WebInspector.EmulatedDevice} */ (item); | 174 var device = /** @type {!Emulation.EmulatedDevice} */ (item); |
| 175 var editor = this._createEditor(); | 175 var editor = this._createEditor(); |
| 176 editor.control('title').value = device.title; | 176 editor.control('title').value = device.title; |
| 177 editor.control('width').value = this._toNumericInputValue(device.vertical.wi
dth); | 177 editor.control('width').value = this._toNumericInputValue(device.vertical.wi
dth); |
| 178 editor.control('height').value = this._toNumericInputValue(device.vertical.h
eight); | 178 editor.control('height').value = this._toNumericInputValue(device.vertical.h
eight); |
| 179 editor.control('scale').value = this._toNumericInputValue(device.deviceScale
Factor); | 179 editor.control('scale').value = this._toNumericInputValue(device.deviceScale
Factor); |
| 180 editor.control('user-agent').value = device.userAgent; | 180 editor.control('user-agent').value = device.userAgent; |
| 181 var uaType; | 181 var uaType; |
| 182 if (device.mobile()) | 182 if (device.mobile()) |
| 183 uaType = device.touch() ? WebInspector.DeviceModeModel.UA.Mobile : WebInsp
ector.DeviceModeModel.UA.MobileNoTouch; | 183 uaType = device.touch() ? Emulation.DeviceModeModel.UA.Mobile : Emulation.
DeviceModeModel.UA.MobileNoTouch; |
| 184 else | 184 else |
| 185 uaType = device.touch() ? WebInspector.DeviceModeModel.UA.DesktopTouch : W
ebInspector.DeviceModeModel.UA.Desktop; | 185 uaType = device.touch() ? Emulation.DeviceModeModel.UA.DesktopTouch : Emul
ation.DeviceModeModel.UA.Desktop; |
| 186 editor.control('ua-type').value = uaType; | 186 editor.control('ua-type').value = uaType; |
| 187 return editor; | 187 return editor; |
| 188 } | 188 } |
| 189 | 189 |
| 190 /** | 190 /** |
| 191 * @return {!WebInspector.ListWidget.Editor} | 191 * @return {!UI.ListWidget.Editor} |
| 192 */ | 192 */ |
| 193 _createEditor() { | 193 _createEditor() { |
| 194 if (this._editor) | 194 if (this._editor) |
| 195 return this._editor; | 195 return this._editor; |
| 196 | 196 |
| 197 var editor = new WebInspector.ListWidget.Editor(); | 197 var editor = new UI.ListWidget.Editor(); |
| 198 this._editor = editor; | 198 this._editor = editor; |
| 199 var content = editor.contentElement(); | 199 var content = editor.contentElement(); |
| 200 | 200 |
| 201 var fields = content.createChild('div', 'devices-edit-fields'); | 201 var fields = content.createChild('div', 'devices-edit-fields'); |
| 202 fields.createChild('div', 'hbox') | 202 fields.createChild('div', 'hbox') |
| 203 .appendChild(editor.createInput('title', 'text', WebInspector.UIString('
Device name'), titleValidator)); | 203 .appendChild(editor.createInput('title', 'text', Common.UIString('Device
name'), titleValidator)); |
| 204 var screen = fields.createChild('div', 'hbox'); | 204 var screen = fields.createChild('div', 'hbox'); |
| 205 screen.appendChild(editor.createInput('width', 'text', WebInspector.UIString
('Width'), sizeValidator)); | 205 screen.appendChild(editor.createInput('width', 'text', Common.UIString('Widt
h'), sizeValidator)); |
| 206 screen.appendChild(editor.createInput('height', 'text', WebInspector.UIStrin
g('height'), sizeValidator)); | 206 screen.appendChild(editor.createInput('height', 'text', Common.UIString('hei
ght'), sizeValidator)); |
| 207 var dpr = editor.createInput('scale', 'text', WebInspector.UIString('Device
pixel ratio'), scaleValidator); | 207 var dpr = editor.createInput('scale', 'text', Common.UIString('Device pixel
ratio'), scaleValidator); |
| 208 dpr.classList.add('device-edit-fixed'); | 208 dpr.classList.add('device-edit-fixed'); |
| 209 screen.appendChild(dpr); | 209 screen.appendChild(dpr); |
| 210 var ua = fields.createChild('div', 'hbox'); | 210 var ua = fields.createChild('div', 'hbox'); |
| 211 ua.appendChild(editor.createInput('user-agent', 'text', WebInspector.UIStrin
g('User agent string'), () => true)); | 211 ua.appendChild(editor.createInput('user-agent', 'text', Common.UIString('Use
r agent string'), () => true)); |
| 212 var uaType = editor.createSelect( | 212 var uaType = editor.createSelect( |
| 213 'ua-type', | 213 'ua-type', |
| 214 [ | 214 [ |
| 215 WebInspector.DeviceModeModel.UA.Mobile, WebInspector.DeviceModeModel.U
A.MobileNoTouch, | 215 Emulation.DeviceModeModel.UA.Mobile, Emulation.DeviceModeModel.UA.Mobi
leNoTouch, |
| 216 WebInspector.DeviceModeModel.UA.Desktop, WebInspector.DeviceModeModel.
UA.DesktopTouch | 216 Emulation.DeviceModeModel.UA.Desktop, Emulation.DeviceModeModel.UA.Des
ktopTouch |
| 217 ], | 217 ], |
| 218 () => true); | 218 () => true); |
| 219 uaType.classList.add('device-edit-fixed'); | 219 uaType.classList.add('device-edit-fixed'); |
| 220 ua.appendChild(uaType); | 220 ua.appendChild(uaType); |
| 221 | 221 |
| 222 return editor; | 222 return editor; |
| 223 | 223 |
| 224 /** | 224 /** |
| 225 * @param {*} item | 225 * @param {*} item |
| 226 * @param {number} index | 226 * @param {number} index |
| 227 * @param {!HTMLInputElement|!HTMLSelectElement} input | 227 * @param {!HTMLInputElement|!HTMLSelectElement} input |
| 228 * @return {boolean} | 228 * @return {boolean} |
| 229 */ | 229 */ |
| 230 function titleValidator(item, index, input) { | 230 function titleValidator(item, index, input) { |
| 231 var value = input.value.trim(); | 231 var value = input.value.trim(); |
| 232 return value.length > 0 && value.length < 50; | 232 return value.length > 0 && value.length < 50; |
| 233 } | 233 } |
| 234 | 234 |
| 235 /** | 235 /** |
| 236 * @param {*} item | 236 * @param {*} item |
| 237 * @param {number} index | 237 * @param {number} index |
| 238 * @param {!HTMLInputElement|!HTMLSelectElement} input | 238 * @param {!HTMLInputElement|!HTMLSelectElement} input |
| 239 * @return {boolean} | 239 * @return {boolean} |
| 240 */ | 240 */ |
| 241 function sizeValidator(item, index, input) { | 241 function sizeValidator(item, index, input) { |
| 242 return WebInspector.DeviceModeModel.deviceSizeValidator(input.value); | 242 return Emulation.DeviceModeModel.deviceSizeValidator(input.value); |
| 243 } | 243 } |
| 244 | 244 |
| 245 /** | 245 /** |
| 246 * @param {*} item | 246 * @param {*} item |
| 247 * @param {number} index | 247 * @param {number} index |
| 248 * @param {!HTMLInputElement|!HTMLSelectElement} input | 248 * @param {!HTMLInputElement|!HTMLSelectElement} input |
| 249 * @return {boolean} | 249 * @return {boolean} |
| 250 */ | 250 */ |
| 251 function scaleValidator(item, index, input) { | 251 function scaleValidator(item, index, input) { |
| 252 return WebInspector.DeviceModeModel.deviceScaleFactorValidator(input.value
); | 252 return Emulation.DeviceModeModel.deviceScaleFactorValidator(input.value); |
| 253 } | 253 } |
| 254 } | 254 } |
| 255 }; | 255 }; |
| OLD | NEW |