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 /** | 5 /** |
6 * @constructor | 6 * @constructor |
7 * @extends {WebInspector.VBox} | 7 * @extends {WebInspector.VBox} |
8 * @implements {WebInspector.ListWidget.Delegate} | 8 * @implements {WebInspector.ListWidget.Delegate} |
9 */ | 9 */ |
10 WebInspector.DevicesSettingsTab = function() | 10 WebInspector.DevicesSettingsTab = function() |
11 { | 11 { |
12 WebInspector.VBox.call(this); | 12 WebInspector.VBox.call(this); |
13 this.element.classList.add("settings-tab-container"); | 13 this.element.classList.add("settings-tab-container"); |
14 this.element.classList.add("devices-settings-tab"); | 14 this.element.classList.add("devices-settings-tab"); |
15 this.registerRequiredCSS("emulation/devicesSettingsTab.css"); | 15 this.registerRequiredCSS("emulation/devicesSettingsTab.css"); |
16 | 16 |
17 var header = this.element.createChild("header"); | 17 var header = this.element.createChild("header"); |
18 header.createChild("h3").createTextChild(WebInspector.UIString("Emulated Dev ices")); | 18 header.createChild("h3").createTextChild(WebInspector.UIString("Emulated Dev ices")); |
19 this.containerElement = this.element.createChild("div", "help-container-wrap per").createChild("div", "settings-tab help-content help-container"); | 19 this.containerElement = this.element.createChild("div", "help-container-wrap per").createChild("div", "settings-tab help-content help-container"); |
20 | 20 |
21 if (Runtime.experiments.isEnabled("cpuThrottling")) | |
22 this._createOctaneScoreInput(); | |
pfeldman
2016/05/06 23:13:09
Lets do that later.
alph
2016/05/07 00:02:27
ok
| |
23 | |
21 var buttonsRow = this.containerElement.createChild("div", "devices-button-ro w"); | 24 var buttonsRow = this.containerElement.createChild("div", "devices-button-ro w"); |
22 this._addCustomButton = createTextButton(WebInspector.UIString("Add custom d evice..."), this._addCustomDevice.bind(this)); | 25 this._addCustomButton = createTextButton(WebInspector.UIString("Add custom d evice..."), this._addCustomDevice.bind(this)); |
23 buttonsRow.appendChild(this._addCustomButton); | 26 buttonsRow.appendChild(this._addCustomButton); |
24 | 27 |
25 this._list = new WebInspector.ListWidget(this); | 28 this._list = new WebInspector.ListWidget(this); |
26 this._list.registerRequiredCSS("emulation/devicesSettingsTab.css"); | 29 this._list.registerRequiredCSS("emulation/devicesSettingsTab.css"); |
27 this._list.element.classList.add("devices-list"); | 30 this._list.element.classList.add("devices-list"); |
28 this._list.show(this.containerElement); | 31 this._list.show(this.containerElement); |
29 | 32 |
30 this._muteUpdate = false; | 33 this._muteUpdate = false; |
31 this._emulatedDevicesList = WebInspector.EmulatedDevicesList.instance(); | 34 this._emulatedDevicesList = WebInspector.EmulatedDevicesList.instance(); |
32 this._emulatedDevicesList.addEventListener(WebInspector.EmulatedDevicesList. Events.CustomDevicesUpdated, this._devicesUpdated, this); | 35 this._emulatedDevicesList.addEventListener(WebInspector.EmulatedDevicesList. Events.CustomDevicesUpdated, this._devicesUpdated, this); |
33 this._emulatedDevicesList.addEventListener(WebInspector.EmulatedDevicesList. Events.StandardDevicesUpdated, this._devicesUpdated, this); | 36 this._emulatedDevicesList.addEventListener(WebInspector.EmulatedDevicesList. Events.StandardDevicesUpdated, this._devicesUpdated, this); |
34 | 37 |
35 this.setDefaultFocusedElement(this._addCustomButton); | 38 this.setDefaultFocusedElement(this._addCustomButton); |
36 } | 39 } |
37 | 40 |
41 /** | |
42 * @param {number} minValue | |
43 * @param {number} maxValue | |
44 * @param {string} text | |
45 * @return {boolean} | |
46 */ | |
47 WebInspector.DevicesSettingsTab.numberValidator = function(minValue, maxValue, t ext) | |
48 { | |
49 if (text === "") | |
50 return true; | |
51 var value = Number.parseInt(text, 10); | |
52 return String(value) === text && minValue <= value && value <= maxValue; | |
53 } | |
54 | |
38 WebInspector.DevicesSettingsTab.prototype = { | 55 WebInspector.DevicesSettingsTab.prototype = { |
39 wasShown: function() | 56 wasShown: function() |
40 { | 57 { |
41 WebInspector.VBox.prototype.wasShown.call(this); | 58 WebInspector.VBox.prototype.wasShown.call(this); |
42 this._devicesUpdated(); | 59 this._devicesUpdated(); |
43 }, | 60 }, |
44 | 61 |
45 _devicesUpdated: function() | 62 _devicesUpdated: function() |
46 { | 63 { |
47 if (this._muteUpdate) | 64 if (this._muteUpdate) |
(...skipping 19 matching lines...) Expand all Loading... | |
67 _muteAndSaveDeviceList: function(custom) | 84 _muteAndSaveDeviceList: function(custom) |
68 { | 85 { |
69 this._muteUpdate = true; | 86 this._muteUpdate = true; |
70 if (custom) | 87 if (custom) |
71 this._emulatedDevicesList.saveCustomDevices(); | 88 this._emulatedDevicesList.saveCustomDevices(); |
72 else | 89 else |
73 this._emulatedDevicesList.saveStandardDevices(); | 90 this._emulatedDevicesList.saveStandardDevices(); |
74 this._muteUpdate = false; | 91 this._muteUpdate = false; |
75 }, | 92 }, |
76 | 93 |
94 _createOctaneScoreInput: function() | |
95 { | |
96 var octaneRow = this.containerElement.createChild("div", "octane-score-r ow"); | |
97 var labelElement = octaneRow.createChild("label"); | |
98 labelElement.textContent = WebInspector.UIString("Host Octane 2.0 score" ); | |
99 var inputElement = octaneRow.createChild("input"); | |
100 inputElement.type = "text"; | |
101 inputElement.style.width = "100px"; | |
102 octaneRow.appendChild(WebInspector.linkifyURLAsNode("http://chromium.git hub.io/octane/", WebInspector.UIString("Obtain score"), undefined, true)); | |
103 var hostOctaneScore = WebInspector.settings.createSetting("hostOctaneSco re", 0); | |
104 WebInspector.bindInput(inputElement, hostOctaneScore.set.bind(hostOctane Score), WebInspector.DevicesSettingsTab.numberValidator.bind(null, 1, 1e6), fals e); | |
105 inputElement.value = hostOctaneScore.get() ? hostOctaneScore.get() : ""; | |
106 }, | |
107 | |
77 _addCustomDevice: function() | 108 _addCustomDevice: function() |
78 { | 109 { |
79 var device = new WebInspector.EmulatedDevice(); | 110 var device = new WebInspector.EmulatedDevice(); |
80 device.deviceScaleFactor = 0; | 111 device.deviceScaleFactor = 0; |
81 device.horizontal.width = 700; | 112 device.horizontal.width = 700; |
82 device.horizontal.height = 400; | 113 device.horizontal.height = 400; |
83 device.vertical.width = 400; | 114 device.vertical.width = 400; |
84 device.vertical.height = 700; | 115 device.vertical.height = 700; |
116 device.octaneScore = 0; | |
85 this._list.addNewItem(this._emulatedDevicesList.custom().length, device) ; | 117 this._list.addNewItem(this._emulatedDevicesList.custom().length, device) ; |
86 }, | 118 }, |
87 | 119 |
88 /** | 120 /** |
89 * @param {number} value | 121 * @param {number} value |
90 * @return {string} | 122 * @return {string} |
91 */ | 123 */ |
92 _toNumericInputValue: function(value) | 124 _toNumericInputValue: function(value) |
93 { | 125 { |
94 return value ? String(value) : ""; | 126 return value ? String(value) : ""; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 */ | 175 */ |
144 commitEdit: function(item, editor, isNew) | 176 commitEdit: function(item, editor, isNew) |
145 { | 177 { |
146 var device = /** @type {!WebInspector.EmulatedDevice} */ (item); | 178 var device = /** @type {!WebInspector.EmulatedDevice} */ (item); |
147 device.title = editor.control("title").value.trim(); | 179 device.title = editor.control("title").value.trim(); |
148 device.vertical.width = editor.control("width").value ? parseInt(editor. control("width").value, 10) : 0; | 180 device.vertical.width = editor.control("width").value ? parseInt(editor. control("width").value, 10) : 0; |
149 device.vertical.height = editor.control("height").value ? parseInt(edito r.control("height").value, 10) : 0; | 181 device.vertical.height = editor.control("height").value ? parseInt(edito r.control("height").value, 10) : 0; |
150 device.horizontal.width = device.vertical.height; | 182 device.horizontal.width = device.vertical.height; |
151 device.horizontal.height = device.vertical.width; | 183 device.horizontal.height = device.vertical.width; |
152 device.deviceScaleFactor = editor.control("scale").value ? parseFloat(ed itor.control("scale").value) : 0; | 184 device.deviceScaleFactor = editor.control("scale").value ? parseFloat(ed itor.control("scale").value) : 0; |
185 device.octaneScore = editor.control("octane").value ? parseInt(editor.co ntrol("octane").value, 10) : 0; | |
153 device.userAgent = editor.control("user-agent").value; | 186 device.userAgent = editor.control("user-agent").value; |
154 device.modes = []; | 187 device.modes = []; |
155 device.modes.push({title: "", orientation: WebInspector.EmulatedDevice.V ertical, insets: new Insets(0, 0, 0, 0), image: null}); | 188 device.modes.push({title: "", orientation: WebInspector.EmulatedDevice.V ertical, insets: new Insets(0, 0, 0, 0), image: null}); |
156 device.modes.push({title: "", orientation: WebInspector.EmulatedDevice.H orizontal, insets: new Insets(0, 0, 0, 0), image: null}); | 189 device.modes.push({title: "", orientation: WebInspector.EmulatedDevice.H orizontal, insets: new Insets(0, 0, 0, 0), image: null}); |
157 device.capabilities = []; | 190 device.capabilities = []; |
158 var uaType = editor.control("ua-type").value; | 191 var uaType = editor.control("ua-type").value; |
159 if (uaType === WebInspector.DeviceModeModel.UA.Mobile || uaType === WebI nspector.DeviceModeModel.UA.MobileNoTouch) | 192 if (uaType === WebInspector.DeviceModeModel.UA.Mobile || uaType === WebI nspector.DeviceModeModel.UA.MobileNoTouch) |
160 device.capabilities.push(WebInspector.EmulatedDevice.Capability.Mobi le); | 193 device.capabilities.push(WebInspector.EmulatedDevice.Capability.Mobi le); |
161 if (uaType === WebInspector.DeviceModeModel.UA.Mobile || uaType === WebI nspector.DeviceModeModel.UA.DesktopTouch) | 194 if (uaType === WebInspector.DeviceModeModel.UA.Mobile || uaType === WebI nspector.DeviceModeModel.UA.DesktopTouch) |
162 device.capabilities.push(WebInspector.EmulatedDevice.Capability.Touc h); | 195 device.capabilities.push(WebInspector.EmulatedDevice.Capability.Touc h); |
(...skipping 12 matching lines...) Expand all Loading... | |
175 */ | 208 */ |
176 beginEdit: function(item) | 209 beginEdit: function(item) |
177 { | 210 { |
178 var device = /** @type {!WebInspector.EmulatedDevice} */ (item); | 211 var device = /** @type {!WebInspector.EmulatedDevice} */ (item); |
179 var editor = this._createEditor(); | 212 var editor = this._createEditor(); |
180 editor.control("title").value = device.title; | 213 editor.control("title").value = device.title; |
181 editor.control("width").value = this._toNumericInputValue(device.vertica l.width); | 214 editor.control("width").value = this._toNumericInputValue(device.vertica l.width); |
182 editor.control("height").value = this._toNumericInputValue(device.vertic al.height); | 215 editor.control("height").value = this._toNumericInputValue(device.vertic al.height); |
183 editor.control("scale").value = this._toNumericInputValue(device.deviceS caleFactor); | 216 editor.control("scale").value = this._toNumericInputValue(device.deviceS caleFactor); |
184 editor.control("user-agent").value = device.userAgent; | 217 editor.control("user-agent").value = device.userAgent; |
218 editor.control("octane").value = this._toNumericInputValue(device.octane Score); | |
185 var uaType; | 219 var uaType; |
186 if (device.mobile()) | 220 if (device.mobile()) |
187 uaType = device.touch() ? WebInspector.DeviceModeModel.UA.Mobile : W ebInspector.DeviceModeModel.UA.MobileNoTouch; | 221 uaType = device.touch() ? WebInspector.DeviceModeModel.UA.Mobile : W ebInspector.DeviceModeModel.UA.MobileNoTouch; |
188 else | 222 else |
189 uaType = device.touch() ? WebInspector.DeviceModeModel.UA.DesktopTou ch : WebInspector.DeviceModeModel.UA.Desktop; | 223 uaType = device.touch() ? WebInspector.DeviceModeModel.UA.DesktopTou ch : WebInspector.DeviceModeModel.UA.Desktop; |
190 editor.control("ua-type").value = uaType; | 224 editor.control("ua-type").value = uaType; |
191 return editor; | 225 return editor; |
192 }, | 226 }, |
193 | 227 |
194 /** | 228 /** |
(...skipping 14 matching lines...) Expand all Loading... | |
209 screen.appendChild(editor.createInput("width", "text", WebInspector.UISt ring("Width"), sizeValidator)); | 243 screen.appendChild(editor.createInput("width", "text", WebInspector.UISt ring("Width"), sizeValidator)); |
210 screen.appendChild(editor.createInput("height", "text", WebInspector.UIS tring("height"), sizeValidator)); | 244 screen.appendChild(editor.createInput("height", "text", WebInspector.UIS tring("height"), sizeValidator)); |
211 var dpr = editor.createInput("scale", "text", WebInspector.UIString("Dev ice pixel ratio"), scaleValidator); | 245 var dpr = editor.createInput("scale", "text", WebInspector.UIString("Dev ice pixel ratio"), scaleValidator); |
212 dpr.classList.add("device-edit-fixed"); | 246 dpr.classList.add("device-edit-fixed"); |
213 screen.appendChild(dpr); | 247 screen.appendChild(dpr); |
214 var ua = fields.createChild("div", "hbox"); | 248 var ua = fields.createChild("div", "hbox"); |
215 ua.appendChild(editor.createInput("user-agent", "text", WebInspector.UIS tring("User agent string"), () => true)); | 249 ua.appendChild(editor.createInput("user-agent", "text", WebInspector.UIS tring("User agent string"), () => true)); |
216 var uaType = editor.createSelect("ua-type", [WebInspector.DeviceModeMode l.UA.Mobile, WebInspector.DeviceModeModel.UA.MobileNoTouch, WebInspector.DeviceM odeModel.UA.Desktop, WebInspector.DeviceModeModel.UA.DesktopTouch], () => true); | 250 var uaType = editor.createSelect("ua-type", [WebInspector.DeviceModeMode l.UA.Mobile, WebInspector.DeviceModeModel.UA.MobileNoTouch, WebInspector.DeviceM odeModel.UA.Desktop, WebInspector.DeviceModeModel.UA.DesktopTouch], () => true); |
217 uaType.classList.add("device-edit-fixed"); | 251 uaType.classList.add("device-edit-fixed"); |
218 ua.appendChild(uaType); | 252 ua.appendChild(uaType); |
253 fields.createChild("div", "hbox").appendChild(editor.createInput("octane ", "text", WebInspector.UIString("Octane 2.0 score"), numberValidator.bind(null, 1, 1e6))); | |
219 | 254 |
220 return editor; | 255 return editor; |
221 | 256 |
222 /** | 257 /** |
223 * @param {*} item | 258 * @param {*} item |
224 * @param {number} index | 259 * @param {number} index |
225 * @param {!HTMLInputElement|!HTMLSelectElement} input | 260 * @param {!HTMLInputElement|!HTMLSelectElement} input |
226 * @return {boolean} | 261 * @return {boolean} |
227 */ | 262 */ |
228 function titleValidator(item, index, input) | 263 function titleValidator(item, index, input) |
(...skipping 16 matching lines...) Expand all Loading... | |
245 /** | 280 /** |
246 * @param {*} item | 281 * @param {*} item |
247 * @param {number} index | 282 * @param {number} index |
248 * @param {!HTMLInputElement|!HTMLSelectElement} input | 283 * @param {!HTMLInputElement|!HTMLSelectElement} input |
249 * @return {boolean} | 284 * @return {boolean} |
250 */ | 285 */ |
251 function scaleValidator(item, index, input) | 286 function scaleValidator(item, index, input) |
252 { | 287 { |
253 return WebInspector.DeviceModeModel.deviceScaleFactorValidator(input .value); | 288 return WebInspector.DeviceModeModel.deviceScaleFactorValidator(input .value); |
254 } | 289 } |
290 | |
291 /** | |
292 * @param {number} minValue | |
293 * @param {number} maxValue | |
294 * @param {*} item | |
295 * @param {number} index | |
296 * @param {!HTMLInputElement|!HTMLSelectElement} input | |
297 * @return {boolean} | |
298 */ | |
299 function numberValidator(minValue, maxValue, item, index, input) | |
300 { | |
301 return WebInspector.DevicesSettingsTab.numberValidator(minValue, max Value, input.value.trim()); | |
302 } | |
303 | |
255 }, | 304 }, |
256 | 305 |
257 __proto__: WebInspector.VBox.prototype | 306 __proto__: WebInspector.VBox.prototype |
258 } | 307 } |
OLD | NEW |