| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 WebInspector.OverridesUI = {} | 5 WebInspector.OverridesUI = {} |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @return {!Element} | 8 * @constructor |
| 9 * @param {!Element} rotateButton |
| 9 */ | 10 */ |
| 10 WebInspector.OverridesUI.createDeviceSelect = function() | 11 WebInspector.DeviceSelect = function(rotateButton) |
| 11 { | 12 { |
| 12 var p = createElement("p"); | 13 this._callback = null; |
| 13 | 14 this._rotateButton = rotateButton; |
| 14 var deviceSelectElement = p.createChild("select"); | 15 this.element = createElement("p"); |
| 15 deviceSelectElement.addEventListener("change", deviceSelected, false); | 16 |
| 16 | 17 this._deviceSelectElement = this.element.createChild("select", "device-selec
t"); |
| 17 // This has to be object, not boolean, otherwise its value doesn't update pr
operly. | 18 this._deviceSelectElement.addEventListener("change", this._deviceSelected.bi
nd(this), false); |
| 18 var emulatedSettingChangedMuted = { muted: false }; | 19 |
| 19 WebInspector.overridesSupport.settings.emulateResolution.addChangeListener(e
mulatedSettingChanged); | 20 var container = this.element.createChild("div", "mode-container"); |
| 20 WebInspector.overridesSupport.settings.deviceWidth.addChangeListener(emulate
dSettingChanged); | 21 container.appendChild(this._rotateButton); |
| 21 WebInspector.overridesSupport.settings.deviceHeight.addChangeListener(emulat
edSettingChanged); | 22 this._rotateButton.addEventListener("click", this._rotateButtonClicked.bind(
this), false); |
| 22 WebInspector.overridesSupport.settings.deviceScaleFactor.addChangeListener(e
mulatedSettingChanged); | 23 this._rotateButton.title = WebInspector.UIString("Change orientation"); |
| 23 WebInspector.overridesSupport.settings.emulateMobile.addChangeListener(emula
tedSettingChanged); | 24 |
| 24 WebInspector.overridesSupport.settings.emulateTouch.addChangeListener(emulat
edSettingChanged); | 25 var modeSelectContainer = container.createChild("span", "mode-select"); |
| 25 WebInspector.overridesSupport.settings.userAgent.addChangeListener(emulatedS
ettingChanged); | 26 this._modeSelectElement = modeSelectContainer.createChild("select"); |
| 26 | 27 this._modeSelectElement.addEventListener("change", this._modeSelected.bind(t
his), false); |
| 27 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.CustomDevicesUpdated, deviceListChanged); | 28 this._modeLabelElement = modeSelectContainer.createChild("label"); |
| 28 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.StandardDevicesUpdated, deviceListChanged); | 29 this._modeLabelElement.addEventListener("click", this._rotateButtonClicked.b
ind(this), false); |
| 29 deviceListChanged(); | 30 this._modeLabelElement.title = WebInspector.UIString("Change orientation"); |
| 30 | 31 |
| 31 function deviceSelected() | 32 this._emulatedSettingChangedMuted = false; |
| 32 { | 33 |
| 33 if (deviceSelectElement.selectedIndex === 0) | 34 WebInspector.overridesSupport.settings.emulateResolution.addChangeListener(t
his._emulatedSettingChanged, this); |
| 35 WebInspector.overridesSupport.settings.deviceWidth.addChangeListener(this._e
mulatedSettingChanged, this); |
| 36 WebInspector.overridesSupport.settings.deviceHeight.addChangeListener(this._
emulatedSettingChanged, this); |
| 37 WebInspector.overridesSupport.settings.deviceScaleFactor.addChangeListener(t
his._emulatedSettingChanged, this); |
| 38 WebInspector.overridesSupport.settings.emulateMobile.addChangeListener(this.
_emulatedSettingChanged, this); |
| 39 WebInspector.overridesSupport.settings.emulateTouch.addChangeListener(this._
emulatedSettingChanged, this); |
| 40 WebInspector.overridesSupport.settings.userAgent.addChangeListener(this._emu
latedSettingChanged, this); |
| 41 |
| 42 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.CustomDevicesUpdated, this._deviceListChanged, this); |
| 43 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.StandardDevicesUpdated, this._deviceListChanged, this); |
| 44 this._deviceListChanged(); |
| 45 } |
| 46 |
| 47 WebInspector.DeviceSelect.prototype = { |
| 48 /** |
| 49 * @param {function(!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevi
ce.Mode)=} callback |
| 50 */ |
| 51 setCallback: function(callback) |
| 52 { |
| 53 this._callback = callback; |
| 54 }, |
| 55 |
| 56 _deviceListChanged: function() |
| 57 { |
| 58 this._deviceSelectElement.removeChildren(); |
| 59 |
| 60 var selectDeviceOption = new Option(WebInspector.UIString("<Select model
>"), WebInspector.UIString("<Select model>")); |
| 61 selectDeviceOption.device = null; |
| 62 selectDeviceOption.disabled = true; |
| 63 this._deviceSelectElement.appendChild(selectDeviceOption); |
| 64 |
| 65 this._addDeviceGroup(WebInspector.UIString("Custom"), WebInspector.emula
tedDevicesList.custom()); |
| 66 this._addDeviceGroup(WebInspector.UIString("Devices"), WebInspector.emul
atedDevicesList.standard()); |
| 67 this._emulatedSettingChanged(); |
| 68 }, |
| 69 |
| 70 /** |
| 71 * @param {string} name |
| 72 * @param {!Array.<!WebInspector.EmulatedDevice>} devices |
| 73 */ |
| 74 _addDeviceGroup: function(name, devices) |
| 75 { |
| 76 devices = devices.filter(function (d) { return d.show(); }); |
| 77 if (!devices.length) |
| 34 return; | 78 return; |
| 35 | 79 devices.sort(WebInspector.EmulatedDevice.compareByTitle); |
| 36 var option = deviceSelectElement.options[deviceSelectElement.selectedInd
ex]; | 80 var groupElement = this._deviceSelectElement.createChild("optgroup"); |
| 37 emulatedSettingChangedMuted.muted = true; | 81 groupElement.label = name; |
| 38 WebInspector.overridesSupport.emulateDevice(option.overridesDevice); | 82 for (var i = 0; i < devices.length; ++i) { |
| 39 emulatedSettingChangedMuted.muted = false; | 83 var option = new Option(devices[i].title, devices[i].title); |
| 84 option.device = devices[i]; |
| 85 option.lastSelectedIndex = 0; |
| 86 groupElement.appendChild(option); |
| 87 } |
| 88 }, |
| 89 |
| 90 _emulatedSettingChanged: function() |
| 91 { |
| 92 if (this._emulatedSettingChangedMuted) |
| 93 return; |
| 94 |
| 95 for (var i = 1; i < this._deviceSelectElement.options.length; ++i) { |
| 96 var option = this._deviceSelectElement.options[i]; |
| 97 var device = /** @type {!WebInspector.EmulatedDevice} */ (option.dev
ice); |
| 98 for (var j = 0; j < device.modes.length; j++) { |
| 99 if (WebInspector.overridesSupport.isEmulatingDevice(device.modeT
oOverridesDevice(device.modes[j]))) { |
| 100 this._select(device, device.modes[j]); |
| 101 return; |
| 102 } |
| 103 } |
| 104 } |
| 105 |
| 106 this._select(null, null); |
| 107 }, |
| 108 |
| 109 /** |
| 110 * @param {?WebInspector.EmulatedDevice} device |
| 111 * @param {?WebInspector.EmulatedDevice.Mode} mode |
| 112 */ |
| 113 _select: function(device, mode) |
| 114 { |
| 115 for (var i = 0; i < this._deviceSelectElement.options.length; i++) { |
| 116 if (this._deviceSelectElement.options[i].device === device) |
| 117 this._deviceSelectElement.selectedIndex = i; |
| 118 } |
| 119 this._updateModeSelect(); |
| 120 for (var i = 0; i < this._modeSelectElement.options.length; i++) { |
| 121 if (this._modeSelectElement.options[i].mode === mode) |
| 122 this._modeSelectElement.selectedIndex = i; |
| 123 } |
| 124 this._updateModeControls(); |
| 125 this._saveLastSelectedIndex(); |
| 126 if (this._callback) { |
| 127 var option = this._modeSelectElement.options[this._modeSelectElement
.selectedIndex]; |
| 128 this._callback(option.device, option.mode); |
| 129 } |
| 130 }, |
| 131 |
| 132 _deviceSelected: function() |
| 133 { |
| 134 this._updateModeSelect(); |
| 135 this._modeSelected(); |
| 136 }, |
| 137 |
| 138 _updateModeSelect: function() |
| 139 { |
| 140 this._modeSelectElement.removeChildren(); |
| 141 var option = this._deviceSelectElement.options[this._deviceSelectElement
.selectedIndex]; |
| 142 var device = /** @type {!WebInspector.EmulatedDevice} */ (option.device)
; |
| 143 |
| 144 if (this._deviceSelectElement.selectedIndex === 0) { |
| 145 this._addMode(device, null, ""); |
| 146 } else if (device.modes.length === 1) { |
| 147 this._addMode(device, device.modes[0], WebInspector.UIString("Defaul
t")); |
| 148 } else { |
| 149 this._addOrientation(device, WebInspector.EmulatedDevice.Vertical, W
ebInspector.UIString("Portrait")); |
| 150 this._addOrientation(device, WebInspector.EmulatedDevice.Horizontal,
WebInspector.UIString("Landscape")); |
| 151 } |
| 152 this._updateRotateModes(); |
| 153 |
| 154 this._modeSelectElement.selectedIndex = option.lastSelectedIndex; |
| 155 this._updateModeControls(); |
| 156 }, |
| 157 |
| 158 /** |
| 159 * @param {!WebInspector.EmulatedDevice} device |
| 160 * @param {string} orientation |
| 161 * @param {string} title |
| 162 */ |
| 163 _addOrientation: function(device, orientation, title) |
| 164 { |
| 165 var modes = device.modesForOrientation(orientation); |
| 166 if (!modes.length) |
| 167 return; |
| 168 if (modes.length === 1) { |
| 169 this._addMode(device, modes[0], title); |
| 170 } else { |
| 171 for (var index = 0; index < modes.length; index++) |
| 172 this._addMode(device, modes[index], title + " \u2013 " + modes[i
ndex].title); |
| 173 } |
| 174 }, |
| 175 |
| 176 /** |
| 177 * @param {!WebInspector.EmulatedDevice} device |
| 178 * @param {?WebInspector.EmulatedDevice.Mode} mode |
| 179 * @param {string} title |
| 180 */ |
| 181 _addMode: function(device, mode, title) |
| 182 { |
| 183 var option = new Option(title, title); |
| 184 option.mode = mode; |
| 185 option.device = device; |
| 186 this._modeSelectElement.appendChild(option); |
| 187 }, |
| 188 |
| 189 _updateRotateModes: function() |
| 190 { |
| 191 for (var i = 0; i < this._modeSelectElement.options.length; i++) { |
| 192 var modeI = this._modeSelectElement.options[i].mode; |
| 193 this._modeSelectElement.options[i].rotateIndex = -1; |
| 194 for (var j = 0; j < this._modeSelectElement.options.length; j++) { |
| 195 var modeJ = this._modeSelectElement.options[j].mode; |
| 196 if (modeI && modeJ && modeI.orientation !== modeJ.orientation &&
modeI.title === modeJ.title) |
| 197 this._modeSelectElement.options[i].rotateIndex = j; |
| 198 } |
| 199 } |
| 200 }, |
| 201 |
| 202 _updateModeControls: function() |
| 203 { |
| 204 this._modeLabelElement.textContent = this._modeSelectElement.options[thi
s._modeSelectElement.selectedIndex].label; |
| 205 |
| 206 if (this._modeSelectElement.options.length <= 1) { |
| 207 this._modeSelectElement.classList.toggle("hidden", true); |
| 208 this._modeLabelElement.classList.toggle("hidden", true); |
| 209 } else { |
| 210 var showLabel = this._modeSelectElement.options.length === 2 && this
._modeSelectElement.options[0].rotateIndex === 1; |
| 211 this._modeSelectElement.classList.toggle("hidden", showLabel); |
| 212 this._modeLabelElement.classList.toggle("hidden", !showLabel); |
| 213 } |
| 214 |
| 215 this._rotateButton.classList.toggle("hidden", this._modeSelectElement.op
tions[this._modeSelectElement.selectedIndex].rotateIndex === -1); |
| 216 }, |
| 217 |
| 218 _modeSelected: function() |
| 219 { |
| 220 this._saveLastSelectedIndex(); |
| 221 this._updateModeControls(); |
| 222 var option = this._modeSelectElement.options[this._modeSelectElement.sel
ectedIndex]; |
| 223 if (this._callback) |
| 224 this._callback(option.device, option.mode); |
| 225 this._emulatedSettingChangedMuted = true; |
| 226 WebInspector.overridesSupport.emulateDevice(option.device.modeToOverride
sDevice(option.mode)); |
| 227 this._emulatedSettingChangedMuted = false; |
| 228 }, |
| 229 |
| 230 _saveLastSelectedIndex: function() |
| 231 { |
| 232 this._deviceSelectElement.options[this._deviceSelectElement.selectedInde
x].lastSelectedIndex = this._modeSelectElement.selectedIndex; |
| 233 }, |
| 234 |
| 235 _rotateButtonClicked: function() |
| 236 { |
| 237 this._modeSelectElement.selectedIndex = this._modeSelectElement.options[
this._modeSelectElement.selectedIndex].rotateIndex; |
| 238 this._modeSelected(); |
| 40 } | 239 } |
| 41 | |
| 42 function emulatedSettingChanged() | |
| 43 { | |
| 44 if (emulatedSettingChangedMuted.muted) | |
| 45 return; | |
| 46 | |
| 47 var index = 0; | |
| 48 for (var i = 1; i < deviceSelectElement.options.length; ++i) { | |
| 49 var option = deviceSelectElement.options[i]; | |
| 50 if (WebInspector.overridesSupport.isEmulatingDevice(option.overrides
Device)) { | |
| 51 index = i; | |
| 52 break; | |
| 53 } | |
| 54 } | |
| 55 deviceSelectElement.selectedIndex = index; | |
| 56 } | |
| 57 | |
| 58 function deviceListChanged() | |
| 59 { | |
| 60 deviceSelectElement.removeChildren(); | |
| 61 | |
| 62 var selectDeviceOption = new Option(WebInspector.UIString("<Select model
>"), WebInspector.UIString("<Select model>")); | |
| 63 selectDeviceOption.device = {title: WebInspector.UIString("<Select model
>"), width: 0, height: 0, deviceScaleFactor: 0, userAgent: "", touch: false, mob
ile: false}; | |
| 64 selectDeviceOption.disabled = true; | |
| 65 deviceSelectElement.appendChild(selectDeviceOption); | |
| 66 | |
| 67 addGroup(WebInspector.UIString("Custom"), WebInspector.emulatedDevicesLi
st.custom(), true); | |
| 68 addGroup(WebInspector.UIString("Devices"), WebInspector.emulatedDevicesL
ist.standard()); | |
| 69 | |
| 70 /** | |
| 71 * @param {string} name | |
| 72 * @param {!Array.<!WebInspector.EmulatedDevice>} devices | |
| 73 * @param {boolean=} custom | |
| 74 */ | |
| 75 function addGroup(name, devices, custom) | |
| 76 { | |
| 77 devices = devices.filter(function (d) { return d.show(); }); | |
| 78 if (!devices.length) | |
| 79 return; | |
| 80 devices.sort(WebInspector.EmulatedDevice.compareByTitle); | |
| 81 var groupElement = deviceSelectElement.createChild("optgroup"); | |
| 82 groupElement.label = name; | |
| 83 for (var i = 0; i < devices.length; ++i) { | |
| 84 var option = new Option(devices[i].title, devices[i].title); | |
| 85 option.device = devices[i]; | |
| 86 option.overridesDevice = devices[i].toOverridesDevice(); | |
| 87 option.custom = custom; | |
| 88 groupElement.appendChild(option); | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 emulatedSettingChanged(); | |
| 93 } | |
| 94 | |
| 95 return p; | |
| 96 } | 240 } |
| 97 | 241 |
| 242 |
| 98 /** | 243 /** |
| 99 * @return {{select: !Element, input: !Element}} | 244 * @return {{select: !Element, input: !Element}} |
| 100 */ | 245 */ |
| 101 WebInspector.OverridesUI.createUserAgentSelectAndInput = function() | 246 WebInspector.OverridesUI.createUserAgentSelectAndInput = function() |
| 102 { | 247 { |
| 103 var userAgentSetting = WebInspector.overridesSupport.settings.userAgent; | 248 var userAgentSetting = WebInspector.overridesSupport.settings.userAgent; |
| 104 const noOverride = {title: WebInspector.UIString("No override"), value: ""}; | 249 const noOverride = {title: WebInspector.UIString("No override"), value: ""}; |
| 105 const customOverride = {title: WebInspector.UIString("Other"), value: "Other
"}; | 250 const customOverride = {title: WebInspector.UIString("Other"), value: "Other
"}; |
| 106 var userAgents = [noOverride].concat(WebInspector.OverridesUI._userAgents).c
oncat([customOverride]); | 251 var userAgents = [noOverride].concat(WebInspector.OverridesUI._userAgents).c
oncat([customOverride]); |
| 107 | 252 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 {title: "iPhone \u2014 iOS 7", value: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_
0_2 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/1
1A4449d Safari/9537.53"}, | 360 {title: "iPhone \u2014 iOS 7", value: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_
0_2 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/1
1A4449d Safari/9537.53"}, |
| 216 {title: "iPhone \u2014 iOS 6", value: "Mozilla/5.0 (iPhone; CPU iPhone OS 6_
0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A53
76e Safari/8536.25"}, | 361 {title: "iPhone \u2014 iOS 6", value: "Mozilla/5.0 (iPhone; CPU iPhone OS 6_
0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A53
76e Safari/8536.25"}, |
| 217 {title: "MeeGo \u2014 Nokia N9", value: "Mozilla/5.0 (MeeGo; NokiaN9) AppleW
ebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13"}, | 362 {title: "MeeGo \u2014 Nokia N9", value: "Mozilla/5.0 (MeeGo; NokiaN9) AppleW
ebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13"}, |
| 218 {title: "Opera 18 \u2014 Mac", value: "Mozilla/5.0 (Macintosh; Intel Mac OS
X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.
36 OPR/18.0.1284.68"}, | 363 {title: "Opera 18 \u2014 Mac", value: "Mozilla/5.0 (Macintosh; Intel Mac OS
X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.
36 OPR/18.0.1284.68"}, |
| 219 {title: "Opera 18 \u2014 Windows", value: "Mozilla/5.0 (Windows NT 6.1) Appl
eWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 OPR/18.0.12
84.68"}, | 364 {title: "Opera 18 \u2014 Windows", value: "Mozilla/5.0 (Windows NT 6.1) Appl
eWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 OPR/18.0.12
84.68"}, |
| 220 {title: "Opera 12 \u2014 Mac", value: "Opera/9.80 (Macintosh; Intel Mac OS X
10.9.1) Presto/2.12.388 Version/12.16"}, | 365 {title: "Opera 12 \u2014 Mac", value: "Opera/9.80 (Macintosh; Intel Mac OS X
10.9.1) Presto/2.12.388 Version/12.16"}, |
| 221 {title: "Opera 12 \u2014 Windows", value: "Opera/9.80 (Windows NT 6.1) Prest
o/2.12.388 Version/12.16"}, | 366 {title: "Opera 12 \u2014 Windows", value: "Opera/9.80 (Windows NT 6.1) Prest
o/2.12.388 Version/12.16"}, |
| 222 {title: "Silk \u2014 Kindle Fire (Desktop view)", value: "Mozilla/5.0 (Linux
; U; en-us; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13
Safari/535.19 Silk-Accelerated=true"}, | 367 {title: "Silk \u2014 Kindle Fire (Desktop view)", value: "Mozilla/5.0 (Linux
; U; en-us; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13
Safari/535.19 Silk-Accelerated=true"}, |
| 223 {title: "Silk \u2014 Kindle Fire (Mobile view)", value: "Mozilla/5.0 (Linux;
U; Android 4.2.2; en-us; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Ge
cko) Silk/3.13 Mobile Safari/535.19 Silk-Accelerated=true"} | 368 {title: "Silk \u2014 Kindle Fire (Mobile view)", value: "Mozilla/5.0 (Linux;
U; Android 4.2.2; en-us; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Ge
cko) Silk/3.13 Mobile Safari/535.19 Silk-Accelerated=true"} |
| 224 ]; | 369 ]; |
| OLD | NEW |