| 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 * @param {function(!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M
ode)=} callback |
| 8 * @return {!Element} | 9 * @return {!Element} |
| 9 */ | 10 */ |
| 10 WebInspector.OverridesUI.createDeviceSelect = function() | 11 WebInspector.OverridesUI.createDeviceSelect = function(callback) |
| 11 { | 12 { |
| 12 var p = createElement("p"); | 13 var p = createElement("p"); |
| 13 | 14 |
| 14 var deviceSelectElement = p.createChild("select"); | 15 var deviceSelectElement = p.createChild("select"); |
| 15 deviceSelectElement.addEventListener("change", deviceSelected, false); | 16 deviceSelectElement.classList.add("device-select"); |
| 17 deviceSelectElement.addEventListener("change", deviceSelected.bind(null, tru
e), false); |
| 18 |
| 19 var modeSelectElement = p.createChild("select"); |
| 20 modeSelectElement.classList.add("mode-select"); |
| 21 modeSelectElement.addEventListener("change", modeSelected, false); |
| 16 | 22 |
| 17 // This has to be object, not boolean, otherwise its value doesn't update pr
operly. | 23 // This has to be object, not boolean, otherwise its value doesn't update pr
operly. |
| 18 var emulatedSettingChangedMuted = { muted: false }; | 24 var emulatedSettingChangedMuted = { muted: false }; |
| 19 WebInspector.overridesSupport.settings.emulateResolution.addChangeListener(e
mulatedSettingChanged); | 25 WebInspector.overridesSupport.settings.emulateResolution.addChangeListener(e
mulatedSettingChanged); |
| 20 WebInspector.overridesSupport.settings.deviceWidth.addChangeListener(emulate
dSettingChanged); | 26 WebInspector.overridesSupport.settings.deviceWidth.addChangeListener(emulate
dSettingChanged); |
| 21 WebInspector.overridesSupport.settings.deviceHeight.addChangeListener(emulat
edSettingChanged); | 27 WebInspector.overridesSupport.settings.deviceHeight.addChangeListener(emulat
edSettingChanged); |
| 22 WebInspector.overridesSupport.settings.deviceScaleFactor.addChangeListener(e
mulatedSettingChanged); | 28 WebInspector.overridesSupport.settings.deviceScaleFactor.addChangeListener(e
mulatedSettingChanged); |
| 23 WebInspector.overridesSupport.settings.emulateMobile.addChangeListener(emula
tedSettingChanged); | 29 WebInspector.overridesSupport.settings.emulateMobile.addChangeListener(emula
tedSettingChanged); |
| 24 WebInspector.overridesSupport.settings.emulateTouch.addChangeListener(emulat
edSettingChanged); | 30 WebInspector.overridesSupport.settings.emulateTouch.addChangeListener(emulat
edSettingChanged); |
| 25 WebInspector.overridesSupport.settings.userAgent.addChangeListener(emulatedS
ettingChanged); | 31 WebInspector.overridesSupport.settings.userAgent.addChangeListener(emulatedS
ettingChanged); |
| 26 | 32 |
| 27 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.CustomDevicesUpdated, deviceListChanged); | 33 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.CustomDevicesUpdated, deviceListChanged); |
| 28 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.StandardDevicesUpdated, deviceListChanged); | 34 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.StandardDevicesUpdated, deviceListChanged); |
| 29 deviceListChanged(); | 35 deviceListChanged(); |
| 30 | 36 |
| 31 function deviceSelected() | 37 /** |
| 38 * @param {boolean} apply |
| 39 */ |
| 40 function deviceSelected(apply) |
| 32 { | 41 { |
| 33 if (deviceSelectElement.selectedIndex === 0) | 42 modeSelectElement.removeChildren(); |
| 43 var option = deviceSelectElement.options[deviceSelectElement.selectedInd
ex]; |
| 44 var device = /** @type {!WebInspector.EmulatedDevice} */ (option.device)
; |
| 45 |
| 46 if (deviceSelectElement.selectedIndex === 0) { |
| 47 addMode(null, ""); |
| 48 modeSelectElement.classList.add("invisible"); |
| 34 return; | 49 return; |
| 50 } |
| 35 | 51 |
| 36 var option = deviceSelectElement.options[deviceSelectElement.selectedInd
ex]; | 52 if (device.modes.length === 1) { |
| 53 addMode(device.modes[0], WebInspector.UIString("Default")); |
| 54 modeSelectElement.classList.add("invisible"); |
| 55 } else { |
| 56 addOrientation(WebInspector.EmulatedDevice.Vertical, WebInspector.UI
String("Portrait")); |
| 57 addOrientation(WebInspector.EmulatedDevice.Horizontal, WebInspector.
UIString("Landscape")); |
| 58 modeSelectElement.classList.remove("invisible"); |
| 59 } |
| 60 |
| 61 modeSelectElement.selectedIndex = option.lastSelectedIndex; |
| 62 if (apply) |
| 63 modeSelected(); |
| 64 |
| 65 /** |
| 66 * @param {string} orientation |
| 67 * @param {string} title |
| 68 */ |
| 69 function addOrientation(orientation, title) |
| 70 { |
| 71 var modes = device.modesForOrientation(orientation); |
| 72 if (!modes.length) |
| 73 return; |
| 74 if (modes.length === 1) { |
| 75 addMode(modes[0], title); |
| 76 } else { |
| 77 for (var index = 0; index < modes.length; index++) { |
| 78 addMode(modes[index], title + " \u2013 " + modes[index].titl
e); |
| 79 } |
| 80 } |
| 81 } |
| 82 |
| 83 /** |
| 84 * @param {?WebInspector.EmulatedDevice.Mode} mode |
| 85 * @param {string} title |
| 86 */ |
| 87 function addMode(mode, title) |
| 88 { |
| 89 var option = new Option(title, title); |
| 90 option.mode = mode; |
| 91 option.device = device; |
| 92 modeSelectElement.appendChild(option); |
| 93 } |
| 94 } |
| 95 |
| 96 function saveLastSelectedIndex() |
| 97 { |
| 98 deviceSelectElement.options[deviceSelectElement.selectedIndex].lastSelec
tedIndex = modeSelectElement.selectedIndex; |
| 99 } |
| 100 |
| 101 function modeSelected() |
| 102 { |
| 103 saveLastSelectedIndex(); |
| 104 var option = modeSelectElement.options[modeSelectElement.selectedIndex]; |
| 105 if (callback) |
| 106 callback(option.device, option.mode); |
| 37 emulatedSettingChangedMuted.muted = true; | 107 emulatedSettingChangedMuted.muted = true; |
| 38 WebInspector.overridesSupport.emulateDevice(option.overridesDevice); | 108 WebInspector.overridesSupport.emulateDevice(option.device.modeToOverride
sDevice(option.mode)); |
| 39 emulatedSettingChangedMuted.muted = false; | 109 emulatedSettingChangedMuted.muted = false; |
| 40 } | 110 } |
| 41 | 111 |
| 42 function emulatedSettingChanged() | 112 function emulatedSettingChanged() |
| 43 { | 113 { |
| 44 if (emulatedSettingChangedMuted.muted) | 114 if (emulatedSettingChangedMuted.muted) |
| 45 return; | 115 return; |
| 46 | 116 |
| 47 var index = 0; | |
| 48 for (var i = 1; i < deviceSelectElement.options.length; ++i) { | 117 for (var i = 1; i < deviceSelectElement.options.length; ++i) { |
| 49 var option = deviceSelectElement.options[i]; | 118 var option = deviceSelectElement.options[i]; |
| 50 if (WebInspector.overridesSupport.isEmulatingDevice(option.overrides
Device)) { | 119 var device = /** @type {!WebInspector.EmulatedDevice} */ (option.dev
ice); |
| 51 index = i; | 120 for (var j = 0; j < device.modes.length; j++) { |
| 52 break; | 121 if (WebInspector.overridesSupport.isEmulatingDevice(device.modeT
oOverridesDevice(device.modes[j]))) { |
| 122 select(i, j); |
| 123 return; |
| 124 } |
| 53 } | 125 } |
| 54 } | 126 } |
| 55 deviceSelectElement.selectedIndex = index; | 127 |
| 128 select(0, 0); |
| 129 |
| 130 /** |
| 131 * @param {number} deviceIndex |
| 132 * @param {number} modeIndex |
| 133 */ |
| 134 function select(deviceIndex, modeIndex) |
| 135 { |
| 136 deviceSelectElement.selectedIndex = deviceIndex; |
| 137 deviceSelected(false); |
| 138 modeSelectElement.selectedIndex = modeIndex; |
| 139 saveLastSelectedIndex(); |
| 140 if (callback) { |
| 141 var option = modeSelectElement.options[modeSelectElement.selecte
dIndex]; |
| 142 callback(option.device, option.mode); |
| 143 } |
| 144 } |
| 56 } | 145 } |
| 57 | 146 |
| 58 function deviceListChanged() | 147 function deviceListChanged() |
| 59 { | 148 { |
| 60 deviceSelectElement.removeChildren(); | 149 deviceSelectElement.removeChildren(); |
| 61 | 150 |
| 62 var selectDeviceOption = new Option(WebInspector.UIString("<Select model
>"), WebInspector.UIString("<Select model>")); | 151 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}; | 152 selectDeviceOption.device = null; |
| 64 selectDeviceOption.disabled = true; | 153 selectDeviceOption.disabled = true; |
| 65 deviceSelectElement.appendChild(selectDeviceOption); | 154 deviceSelectElement.appendChild(selectDeviceOption); |
| 66 | 155 |
| 67 addGroup(WebInspector.UIString("Custom"), WebInspector.emulatedDevicesLi
st.custom(), true); | 156 addGroup(WebInspector.UIString("Custom"), WebInspector.emulatedDevicesLi
st.custom(), true); |
| 68 addGroup(WebInspector.UIString("Devices"), WebInspector.emulatedDevicesL
ist.standard()); | 157 addGroup(WebInspector.UIString("Devices"), WebInspector.emulatedDevicesL
ist.standard(), false); |
| 69 | 158 |
| 70 /** | 159 /** |
| 71 * @param {string} name | 160 * @param {string} name |
| 72 * @param {!Array.<!WebInspector.EmulatedDevice>} devices | 161 * @param {!Array.<!WebInspector.EmulatedDevice>} devices |
| 73 * @param {boolean=} custom | 162 * @param {boolean} custom |
| 74 */ | 163 */ |
| 75 function addGroup(name, devices, custom) | 164 function addGroup(name, devices, custom) |
| 76 { | 165 { |
| 77 devices = devices.filter(function (d) { return d.show(); }); | 166 devices = devices.filter(function (d) { return d.show(); }); |
| 78 if (!devices.length) | 167 if (!devices.length) |
| 79 return; | 168 return; |
| 80 devices.sort(WebInspector.EmulatedDevice.compareByTitle); | 169 devices.sort(WebInspector.EmulatedDevice.compareByTitle); |
| 81 var groupElement = deviceSelectElement.createChild("optgroup"); | 170 var groupElement = deviceSelectElement.createChild("optgroup"); |
| 82 groupElement.label = name; | 171 groupElement.label = name; |
| 83 for (var i = 0; i < devices.length; ++i) { | 172 for (var i = 0; i < devices.length; ++i) { |
| 84 var option = new Option(devices[i].title, devices[i].title); | 173 var option = new Option(devices[i].title, devices[i].title); |
| 85 option.device = devices[i]; | 174 option.device = devices[i]; |
| 86 option.overridesDevice = devices[i].toOverridesDevice(); | 175 option.lastSelectedIndex = 0; |
| 87 option.custom = custom; | |
| 88 groupElement.appendChild(option); | 176 groupElement.appendChild(option); |
| 89 } | 177 } |
| 90 } | 178 } |
| 91 | 179 |
| 92 emulatedSettingChanged(); | 180 emulatedSettingChanged(); |
| 93 } | 181 } |
| 94 | 182 |
| 95 return p; | 183 return p; |
| 96 } | 184 } |
| 97 | 185 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 {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"}, | 381 {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"}, |
| 294 {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"}, | 382 {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"}, |
| 295 {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"}, | 383 {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"}, |
| 296 {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"}, | 384 {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"}, |
| 297 {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"}, | 385 {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"}, |
| 298 {title: "Opera 12 \u2014 Mac", value: "Opera/9.80 (Macintosh; Intel Mac OS X
10.9.1) Presto/2.12.388 Version/12.16"}, | 386 {title: "Opera 12 \u2014 Mac", value: "Opera/9.80 (Macintosh; Intel Mac OS X
10.9.1) Presto/2.12.388 Version/12.16"}, |
| 299 {title: "Opera 12 \u2014 Windows", value: "Opera/9.80 (Windows NT 6.1) Prest
o/2.12.388 Version/12.16"}, | 387 {title: "Opera 12 \u2014 Windows", value: "Opera/9.80 (Windows NT 6.1) Prest
o/2.12.388 Version/12.16"}, |
| 300 {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"}, | 388 {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"}, |
| 301 {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"} | 389 {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"} |
| 302 ]; | 390 ]; |
| OLD | NEW |