| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 */ | 8 */ |
| 9 WebInspector.SensorsView = function() | 9 WebInspector.SensorsView = function() |
| 10 { | 10 { |
| 11 WebInspector.VBox.call(this, true); | 11 WebInspector.VBox.call(this, true); |
| 12 this.registerRequiredCSS("emulation/sensors.css"); | 12 this.registerRequiredCSS("emulation/sensors.css"); |
| 13 this.contentElement.classList.add("sensors-view"); | 13 this.contentElement.classList.add("sensors-view"); |
| 14 | 14 |
| 15 this._geolocationSetting = WebInspector.settings.createSetting("emulation.ge
olocationOverride", ""); | 15 this._geolocationSetting = WebInspector.settings.createSetting("emulation.ge
olocationOverride", ""); |
| 16 this._geolocation = WebInspector.Geolocation.parseSetting(this._geolocationS
etting.get()); | 16 this._geolocation = WebInspector.Geolocation.parseSetting(this._geolocationS
etting.get()); |
| 17 this._geolocationEnabled = false; | 17 this._geolocationOverrideEnabled = false; |
| 18 this._appendGeolocationOverrideControl(); | 18 this._createGeolocationSection(this._geolocation); |
| 19 |
| 20 this.contentElement.createChild("div").classList.add("panel-section-separato
r"); |
| 19 | 21 |
| 20 this._deviceOrientationSetting = WebInspector.settings.createSetting("emulat
ion.deviceOrientationOverride", ""); | 22 this._deviceOrientationSetting = WebInspector.settings.createSetting("emulat
ion.deviceOrientationOverride", ""); |
| 21 this._deviceOrientation = WebInspector.DeviceOrientation.parseSetting(this._
deviceOrientationSetting.get()); | 23 this._deviceOrientation = WebInspector.DeviceOrientation.parseSetting(this._
deviceOrientationSetting.get()); |
| 22 this._deviceOrientationEnabled = false; | 24 this._deviceOrientationOverrideEnabled = false; |
| 23 this._appendDeviceOrientationOverrideControl(); | 25 this._createDeviceOrientationSection(); |
| 26 |
| 27 this.contentElement.createChild("div").classList.add("panel-section-separato
r"); |
| 24 | 28 |
| 25 this._appendTouchControl(); | 29 this._appendTouchControl(); |
| 26 } | 30 } |
| 27 | 31 |
| 28 WebInspector.SensorsView.prototype = { | 32 WebInspector.SensorsView.prototype = { |
| 29 _appendGeolocationOverrideControl: function() | 33 /** |
| 34 * @param {!WebInspector.Geolocation} geolocation |
| 35 */ |
| 36 _createGeolocationSection: function(geolocation) |
| 30 { | 37 { |
| 31 var checkboxLabel = createCheckboxLabel(WebInspector.UIString("Emulate g
eolocation coordinates")); | 38 var geogroup = this.contentElement.createChild("section", "sensors-group
"); |
| 32 this._geolocationOverrideCheckbox = checkboxLabel.checkboxElement; | 39 geogroup.createChild("div", "sensors-group-title").textContent = WebInsp
ector.UIString("Geolocation"); |
| 33 this._geolocationOverrideCheckbox.addEventListener("click", this._geoloc
ationOverrideCheckboxClicked.bind(this)); | 40 var fields = geogroup.createChild("div", "geo-fields"); |
| 34 this.contentElement.appendChild(checkboxLabel); | 41 |
| 35 this._geolocationFieldset = this._createGeolocationOverrideElement(this.
_geolocation); | 42 const noOverrideOption = {title: WebInspector.UIString("No override"), l
ocation: WebInspector.SensorsView.NonPresetOptions.NoOverride}; |
| 36 this._geolocationFieldset.disabled = true; | 43 const customLocationOption = {title: WebInspector.UIString("Custom locat
ion..."), location: WebInspector.SensorsView.NonPresetOptions.Custom}; |
| 37 this.contentElement.appendChild(this._geolocationFieldset); | 44 this._locationSelectElement = this.contentElement.createChild("select",
"chrome-select"); |
| 45 this._locationSelectElement.appendChild(new Option(noOverrideOption.titl
e, noOverrideOption.location)); |
| 46 this._locationSelectElement.appendChild(new Option(customLocationOption.
title, customLocationOption.location)); |
| 47 |
| 48 var locationGroups = WebInspector.SensorsView.PresetLocations; |
| 49 for (var i = 0; i < locationGroups.length; ++i) { |
| 50 var group = locationGroups[i].value; |
| 51 var groupElement = this._locationSelectElement.createChild("optgroup
"); |
| 52 groupElement.label = locationGroups[i].title; |
| 53 for (var j = 0; j < group.length; ++j) |
| 54 groupElement.appendChild(new Option(group[j].title, group[j].loc
ation)); |
| 55 } |
| 56 this._locationSelectElement.selectedIndex = 0; |
| 57 fields.appendChild(this._locationSelectElement); |
| 58 this._locationSelectElement.addEventListener("change", this._geolocation
SelectChanged.bind(this)); |
| 59 |
| 60 // Validated input fieldset. |
| 61 this._fieldsetElement = fields.createChild("fieldset"); |
| 62 this._fieldsetElement.disabled = !this._geolocationOverrideEnabled; |
| 63 this._fieldsetElement.id = "geolocation-override-section"; |
| 64 |
| 65 var latitudeGroup = this._fieldsetElement.createChild("div", "latlong-gr
oup"); |
| 66 var longitudeGroup = this._fieldsetElement.createChild("div", "latlong-g
roup"); |
| 67 |
| 68 this._latitudeInput = latitudeGroup.createChild("input"); |
| 69 this._latitudeInput.setAttribute("type", "text"); |
| 70 this._latitudeInput.value = 0; |
| 71 WebInspector.bindInput(this._latitudeInput, this._applyGeolocationUserIn
put.bind(this), WebInspector.Geolocation.latitudeValidator, true)(String(geoloca
tion.latitude)); |
| 72 |
| 73 this._longitudeInput = longitudeGroup.createChild("input"); |
| 74 this._longitudeInput.setAttribute("type", "text"); |
| 75 this._longitudeInput.value = 0; |
| 76 WebInspector.bindInput(this._longitudeInput, this._applyGeolocationUserI
nput.bind(this), WebInspector.Geolocation.longitudeValidator, true)(String(geolo
cation.longitude)); |
| 77 |
| 78 latitudeGroup.createChild("div", "latlong-title").textContent = WebInspe
ctor.UIString("Latitude"); |
| 79 longitudeGroup.createChild("div", "latlong-title").textContent = WebInsp
ector.UIString("Longitude"); |
| 38 }, | 80 }, |
| 39 | 81 |
| 40 _geolocationOverrideCheckboxClicked: function() | 82 _geolocationSelectChanged: function() |
| 41 { | 83 { |
| 42 var enabled = this._geolocationOverrideCheckbox.checked; | 84 this._fieldsetElement.disabled = false; |
| 85 var value = this._locationSelectElement.options[this._locationSelectElem
ent.selectedIndex].value; |
| 86 if (value === WebInspector.SensorsView.NonPresetOptions.NoOverride) { |
| 87 this._geolocationOverrideEnabled = false; |
| 88 this._fieldsetElement.disabled = true; |
| 89 } else if (value === WebInspector.SensorsView.NonPresetOptions.Custom) { |
| 90 this._geolocationOverrideEnabled = true; |
| 91 } else if (value === WebInspector.SensorsView.NonPresetOptions.Unavailab
le) { |
| 92 this._geolocationOverrideEnabled = true; |
| 93 this._geolocation = new WebInspector.Geolocation(0, 0, true); |
| 94 } else { |
| 95 this._geolocationOverrideEnabled = true; |
| 96 var coordinates = JSON.parse(value); |
| 97 this._geolocation = new WebInspector.Geolocation(coordinates[0], coo
rdinates[1], false); |
| 98 this._latitudeInput.value = coordinates[0]; |
| 99 this._longitudeInput.value = coordinates[1]; |
| 100 } |
| 43 | 101 |
| 44 this._geolocationEnabled = enabled; | |
| 45 this._applyGeolocation(); | 102 this._applyGeolocation(); |
| 46 | 103 if (value === WebInspector.SensorsView.NonPresetOptions.Custom) |
| 47 if (enabled && !this._latitudeElement.value) | 104 this._latitudeInput.focus(); |
| 48 this._latitudeElement.focus(); | |
| 49 this._geolocationFieldset.disabled = !enabled; | |
| 50 }, | 105 }, |
| 51 | 106 |
| 52 _applyGeolocationUserInput: function() | 107 _applyGeolocationUserInput: function() |
| 53 { | 108 { |
| 54 var geolocation = WebInspector.Geolocation.parseUserInput(this._latitude
Element.value.trim(), this._longitudeElement.value.trim(), this._geolocationErro
rElement.checked); | 109 var geolocation = WebInspector.Geolocation.parseUserInput(this._latitude
Input.value.trim(), this._longitudeInput.value.trim(), ""); |
| 55 if (!geolocation) | 110 if (!geolocation) |
| 56 return; | 111 return; |
| 57 | 112 |
| 113 this._setSelectElementLabel(this._locationSelectElement, WebInspector.Se
nsorsView.NonPresetOptions.Custom); |
| 58 this._geolocation = geolocation; | 114 this._geolocation = geolocation; |
| 59 this._applyGeolocation(); | 115 this._applyGeolocation(); |
| 60 }, | 116 }, |
| 61 | 117 |
| 62 _applyGeolocation: function() | 118 _applyGeolocation: function() |
| 63 { | 119 { |
| 64 if (this._geolocationEnabled) { | 120 if (this._geolocationOverrideEnabled) { |
| 65 this._geolocationSetting.set(this._geolocation.toSetting()); | 121 this._geolocationSetting.set(this._geolocation.toSetting()); |
| 66 this._geolocation.apply(); | 122 this._geolocation.apply(); |
| 67 } else { | 123 } else { |
| 68 this._geolocation.clear(); | 124 this._geolocation.clear(); |
| 69 } | 125 } |
| 70 }, | 126 }, |
| 71 | 127 |
| 72 /** | 128 _createDeviceOrientationSection: function() |
| 73 * @param {!WebInspector.Geolocation} geolocation | |
| 74 * @return {!Element} | |
| 75 */ | |
| 76 _createGeolocationOverrideElement: function(geolocation) | |
| 77 { | 129 { |
| 78 var fieldsetElement = createElement("fieldset"); | 130 var orientationGroup = this.contentElement.createChild("section", "senso
rs-group"); |
| 79 fieldsetElement.id = "geolocation-override-section"; | 131 orientationGroup.createChild("div", "sensors-group-title").textContent =
WebInspector.UIString("Accelerometer"); |
| 132 var orientationContent = orientationGroup.createChild("div", "orientatio
n-content"); |
| 133 var fields = orientationContent.createChild("div", "orientation-fields")
; |
| 80 | 134 |
| 81 var tableElement = fieldsetElement.createChild("table"); | 135 const accelerometerOffOption = {title: WebInspector.UIString("Off"), ori
entation: WebInspector.SensorsView.NonPresetOptions.NoOverride}; |
| 82 var rowElement = tableElement.createChild("tr"); | 136 const customOrientationOption = {title: WebInspector.UIString("Custom or
ientation..."), orientation: WebInspector.SensorsView.NonPresetOptions.Custom}; |
| 83 var cellElement = rowElement.createChild("td"); | 137 this._orientationSelectElement = this.contentElement.createChild("select
", "chrome-select"); |
| 84 cellElement = rowElement.createChild("td"); | 138 this._orientationSelectElement.appendChild(new Option(accelerometerOffOp
tion.title, accelerometerOffOption.orientation)); |
| 85 cellElement.createTextChild(WebInspector.UIString("Lat = ")); | 139 this._orientationSelectElement.appendChild(new Option(customOrientationO
ption.title, customOrientationOption.orientation)); |
| 86 this._latitudeElement = cellElement.createChild("input"); | |
| 87 this._latitudeElement.type = "text"; | |
| 88 WebInspector.bindInput(this._latitudeElement, this._applyGeolocationUser
Input.bind(this), WebInspector.Geolocation.latitudeValidator, true)(String(geolo
cation.latitude)); | |
| 89 cellElement.createTextChild(" , "); | |
| 90 cellElement.createTextChild(WebInspector.UIString("Lon = ")); | |
| 91 this._longitudeElement = cellElement.createChild("input"); | |
| 92 this._longitudeElement.type = "text"; | |
| 93 WebInspector.bindInput(this._longitudeElement, this._applyGeolocationUse
rInput.bind(this), WebInspector.Geolocation.longitudeValidator, true)(String(geo
location.longitude)); | |
| 94 rowElement = tableElement.createChild("tr"); | |
| 95 cellElement = rowElement.createChild("td"); | |
| 96 cellElement.colSpan = 2; | |
| 97 var geolocationErrorLabelElement = createCheckboxLabel(WebInspector.UISt
ring("Emulate position unavailable"), !geolocation || !!geolocation.error); | |
| 98 var geolocationErrorCheckboxElement = geolocationErrorLabelElement.check
boxElement; | |
| 99 geolocationErrorCheckboxElement.id = "geolocation-error"; | |
| 100 geolocationErrorCheckboxElement.addEventListener("click", this._applyGeo
locationUserInput.bind(this), false); | |
| 101 this._geolocationErrorElement = geolocationErrorCheckboxElement; | |
| 102 cellElement.appendChild(geolocationErrorLabelElement); | |
| 103 | 140 |
| 104 return fieldsetElement; | 141 var orientationGroups = WebInspector.SensorsView.PresetOrientations; |
| 142 for (var i = 0; i < orientationGroups.length; ++i) { |
| 143 var groupElement = this._orientationSelectElement.createChild("optgr
oup"); |
| 144 groupElement.label = orientationGroups[i].title; |
| 145 var group = orientationGroups[i].value; |
| 146 for (var j = 0; j < group.length; ++j) |
| 147 groupElement.appendChild(new Option(group[j].title, group[j].ori
entation)); |
| 148 } |
| 149 this._orientationSelectElement.selectedIndex = 0; |
| 150 fields.appendChild(this._orientationSelectElement); |
| 151 this._orientationSelectElement.addEventListener("change", this._orientat
ionSelectChanged.bind(this)); |
| 152 |
| 153 this._deviceOrientationFieldset = this._createDeviceOrientationOverrideE
lement(this._deviceOrientation); |
| 154 |
| 155 this._stageElement = orientationContent.createChild("div", "acceleromete
r-stage"); |
| 156 this._stageElement.title = WebInspector.UIString("shift+drag to rotate a
round the z-axis"); |
| 157 this._boxElement = this._stageElement.createChild("section", "accelerome
ter-box"); |
| 158 |
| 159 this._boxElement.createChild("section", "accelerometer-front"); |
| 160 this._boxElement.createChild("section", "accelerometer-top"); |
| 161 this._boxElement.createChild("section", "accelerometer-back"); |
| 162 this._boxElement.createChild("section", "accelerometer-left"); |
| 163 this._boxElement.createChild("section", "accelerometer-right"); |
| 164 this._boxElement.createChild("section", "accelerometer-bottom"); |
| 165 |
| 166 WebInspector.installDragHandle(this._stageElement, this._onBoxDragStart.
bind(this), this._onBoxDrag.bind(this), this._onBoxDragEnd.bind(this), "-webkit-
grabbing", "-webkit-grab"); |
| 167 |
| 168 fields.appendChild(this._deviceOrientationFieldset); |
| 169 this._enableOrientationFields(true); |
| 170 this._setBoxOrientation(this._deviceOrientation); |
| 105 }, | 171 }, |
| 106 | 172 |
| 107 _appendDeviceOrientationOverrideControl: function() | 173 /** |
| 174 * @param {?boolean} disable |
| 175 */ |
| 176 _enableOrientationFields: function(disable) |
| 108 { | 177 { |
| 109 var checkboxLabel = createCheckboxLabel(WebInspector.UIString("Emulate d
evice orientation")); | 178 if (disable) { |
| 110 this._overrideDeviceOrientationCheckbox = checkboxLabel.checkboxElement; | 179 this._deviceOrientationFieldset.disabled = true; |
| 111 this._overrideDeviceOrientationCheckbox.addEventListener("click", this._
deviceOrientationOverrideCheckboxClicked.bind(this)); | 180 this._stageElement.classList.add("disabled"); |
| 112 this.contentElement.appendChild(checkboxLabel); | 181 } else { |
| 113 this._deviceOrientationFieldset = this._createDeviceOrientationOverrideE
lement(this._deviceOrientation); | 182 this._deviceOrientationFieldset.disabled = false; |
| 114 this._deviceOrientationFieldset.disabled = true; | 183 this._stageElement.classList.remove("disabled"); |
| 115 this.contentElement.appendChild(this._deviceOrientationFieldset); | 184 } |
| 116 }, | 185 }, |
| 117 | 186 |
| 118 _deviceOrientationOverrideCheckboxClicked: function() | 187 _orientationSelectChanged: function() |
| 119 { | 188 { |
| 120 var enabled = this._overrideDeviceOrientationCheckbox.checked; | 189 var value = this._orientationSelectElement.options[this._orientationSele
ctElement.selectedIndex].value; |
| 190 this._enableOrientationFields(false); |
| 121 | 191 |
| 122 this._deviceOrientationEnabled = enabled; | 192 if (value === WebInspector.SensorsView.NonPresetOptions.NoOverride) { |
| 123 this._applyDeviceOrientation(); | 193 this._deviceOrientationOverrideEnabled = false; |
| 124 | 194 this._enableOrientationFields(true); |
| 125 if (enabled && !this._alphaElement.value) | 195 } else if (value === WebInspector.SensorsView.NonPresetOptions.Custom) { |
| 196 this._deviceOrientationOverrideEnabled = true; |
| 126 this._alphaElement.focus(); | 197 this._alphaElement.focus(); |
| 127 this._deviceOrientationFieldset.disabled = !enabled; | 198 } else { |
| 199 var parsedValue = JSON.parse(value); |
| 200 this._deviceOrientationOverrideEnabled = true; |
| 201 this._deviceOrientation = new WebInspector.DeviceOrientation(parsedV
alue[0], parsedValue[1], parsedValue[2]); |
| 202 this._setDeviceOrientation(this._deviceOrientation, WebInspector.Sen
sorsView.DeviceOrientationModificationSource.SelectPreset); |
| 203 } |
| 128 }, | 204 }, |
| 129 | 205 |
| 130 _applyDeviceOrientation: function() | 206 _applyDeviceOrientation: function() |
| 131 { | 207 { |
| 132 if (this._deviceOrientationEnabled) { | 208 if (this._deviceOrientationOverrideEnabled) { |
| 133 this._deviceOrientationSetting.set(this._deviceOrientation.toSetting
()); | 209 this._deviceOrientationSetting.set(this._deviceOrientation.toSetting
()); |
| 134 this._deviceOrientation.apply(); | 210 this._deviceOrientation.apply(); |
| 135 } else { | 211 } else { |
| 136 this._deviceOrientation.clear(); | 212 this._deviceOrientation.clear(); |
| 137 } | 213 } |
| 138 }, | 214 }, |
| 139 | 215 |
| 216 /** |
| 217 * @param {!Element} selectElement |
| 218 * @param {string} labelValue |
| 219 */ |
| 220 _setSelectElementLabel: function(selectElement, labelValue) |
| 221 { |
| 222 var optionValues = Array.prototype.map.call(selectElement.options, x =>
x.value); |
| 223 selectElement.selectedIndex = optionValues.indexOf(labelValue); |
| 224 }, |
| 225 |
| 140 _applyDeviceOrientationUserInput: function() | 226 _applyDeviceOrientationUserInput: function() |
| 141 { | 227 { |
| 142 this._setDeviceOrientation(WebInspector.DeviceOrientation.parseUserInput
(this._alphaElement.value.trim(), this._betaElement.value.trim(), this._gammaEle
ment.value.trim()), WebInspector.SensorsView.DeviceOrientationModificationSource
.UserInput); | 228 this._setDeviceOrientation(WebInspector.DeviceOrientation.parseUserInput
(this._alphaElement.value.trim(), this._betaElement.value.trim(), this._gammaEle
ment.value.trim()), WebInspector.SensorsView.DeviceOrientationModificationSource
.UserInput); |
| 229 this._setSelectElementLabel(this._orientationSelectElement, WebInspector
.SensorsView.NonPresetOptions.Custom); |
| 143 }, | 230 }, |
| 144 | 231 |
| 145 _resetDeviceOrientation: function() | 232 _resetDeviceOrientation: function() |
| 146 { | 233 { |
| 147 this._setDeviceOrientation(new WebInspector.DeviceOrientation(0, 0, 0),
WebInspector.SensorsView.DeviceOrientationModificationSource.ResetButton); | 234 this._setDeviceOrientation(new WebInspector.DeviceOrientation(0, 90, 0),
WebInspector.SensorsView.DeviceOrientationModificationSource.ResetButton); |
| 148 }, | 235 }, |
| 149 | 236 |
| 150 /** | 237 /** |
| 151 * @param {?WebInspector.DeviceOrientation} deviceOrientation | 238 * @param {?WebInspector.DeviceOrientation} deviceOrientation |
| 152 * @param {!WebInspector.SensorsView.DeviceOrientationModificationSource} mo
dificationSource | 239 * @param {!WebInspector.SensorsView.DeviceOrientationModificationSource} mo
dificationSource |
| 153 */ | 240 */ |
| 154 _setDeviceOrientation: function(deviceOrientation, modificationSource) | 241 _setDeviceOrientation: function(deviceOrientation, modificationSource) |
| 155 { | 242 { |
| 156 if (!deviceOrientation) | 243 if (!deviceOrientation) |
| 157 return; | 244 return; |
| 158 | 245 |
| 246 /** |
| 247 * @param {number} angle |
| 248 * @return {number} |
| 249 */ |
| 250 function roundAngle(angle) |
| 251 { |
| 252 return Math.round(angle*10000)/10000; |
| 253 } |
| 254 |
| 159 if (modificationSource != WebInspector.SensorsView.DeviceOrientationModi
ficationSource.UserInput) { | 255 if (modificationSource != WebInspector.SensorsView.DeviceOrientationModi
ficationSource.UserInput) { |
| 160 this._alphaSetter(deviceOrientation.alpha); | 256 this._alphaSetter(roundAngle(deviceOrientation.alpha)); |
| 161 this._betaSetter(deviceOrientation.beta); | 257 this._betaSetter(roundAngle(deviceOrientation.beta)); |
| 162 this._gammaSetter(deviceOrientation.gamma); | 258 this._gammaSetter(roundAngle(deviceOrientation.gamma)); |
| 163 } | 259 } |
| 164 | 260 |
| 165 if (modificationSource != WebInspector.SensorsView.DeviceOrientationModi
ficationSource.UserDrag) | 261 if (modificationSource != WebInspector.SensorsView.DeviceOrientationModi
ficationSource.UserDrag) |
| 166 this._setBoxOrientation(deviceOrientation); | 262 this._setBoxOrientation(deviceOrientation); |
| 263 else |
| 264 this._boxElement.classList.remove("is-animating"); |
| 167 | 265 |
| 168 this._deviceOrientation = deviceOrientation; | 266 this._deviceOrientation = deviceOrientation; |
| 169 this._applyDeviceOrientation(); | 267 this._applyDeviceOrientation(); |
| 170 }, | 268 }, |
| 171 | 269 |
| 172 /** | 270 /** |
| 173 * @param {!Element} parentElement | 271 * @param {!Element} parentElement |
| 174 * @param {!Element} input | 272 * @param {!Element} input |
| 175 * @param {string} label | 273 * @param {string} label |
| 176 * @return {function(string)} | 274 * @return {function(string)} |
| 177 */ | 275 */ |
| 178 _createAxisInput: function(parentElement, input, label) | 276 _createAxisInput: function(parentElement, input, label) |
| 179 { | 277 { |
| 180 var div = parentElement.createChild("div", "accelerometer-axis-input-con
tainer"); | 278 var div = parentElement.createChild("div", "accelerometer-axis-input-con
tainer"); |
| 279 div.appendChild(input); |
| 181 div.createTextChild(label); | 280 div.createTextChild(label); |
| 182 div.appendChild(input); | 281 input.type = "number"; |
| 183 input.type = "text"; | |
| 184 return WebInspector.bindInput(input, this._applyDeviceOrientationUserInp
ut.bind(this), WebInspector.DeviceOrientation.validator, true); | 282 return WebInspector.bindInput(input, this._applyDeviceOrientationUserInp
ut.bind(this), WebInspector.DeviceOrientation.validator, true); |
| 185 }, | 283 }, |
| 186 | 284 |
| 187 /** | 285 /** |
| 188 * @param {!WebInspector.DeviceOrientation} deviceOrientation | 286 * @param {!WebInspector.DeviceOrientation} deviceOrientation |
| 287 * @return {!Element} |
| 189 */ | 288 */ |
| 190 _createDeviceOrientationOverrideElement: function(deviceOrientation) | 289 _createDeviceOrientationOverrideElement: function(deviceOrientation) |
| 191 { | 290 { |
| 192 var fieldsetElement = createElement("fieldset"); | 291 var fieldsetElement = createElement("fieldset"); |
| 193 fieldsetElement.classList.add("device-orientation-override-section"); | 292 fieldsetElement.classList.add("device-orientation-override-section"); |
| 194 var tableElement = fieldsetElement.createChild("table"); | 293 var cellElement = fieldsetElement.createChild("td", "accelerometer-input
s-cell"); |
| 195 var rowElement = tableElement.createChild("tr"); | |
| 196 var cellElement = rowElement.createChild("td", "accelerometer-inputs-cel
l"); | |
| 197 | 294 |
| 198 this._alphaElement = createElement("input"); | 295 this._alphaElement = createElement("input"); |
| 199 this._alphaSetter = this._createAxisInput(cellElement, this._alphaElemen
t, "\u03B1: "); | 296 this._alphaSetter = this._createAxisInput(cellElement, this._alphaElemen
t, WebInspector.UIString("Tilt left/right (\u03B1)")); |
| 200 this._alphaSetter(String(deviceOrientation.alpha)); | 297 this._alphaSetter(String(deviceOrientation.alpha)); |
| 201 | 298 |
| 202 this._betaElement = createElement("input"); | 299 this._betaElement = createElement("input"); |
| 203 this._betaSetter = this._createAxisInput(cellElement, this._betaElement,
"\u03B2: "); | 300 this._betaSetter = this._createAxisInput(cellElement, this._betaElement,
WebInspector.UIString("Tilt front/back (\u03B2)")); |
| 204 this._betaSetter(String(deviceOrientation.beta)); | 301 this._betaSetter(String(deviceOrientation.beta)); |
| 205 | 302 |
| 206 this._gammaElement = createElement("input"); | 303 this._gammaElement = createElement("input"); |
| 207 this._gammaSetter = this._createAxisInput(cellElement, this._gammaElemen
t, "\u03B3: "); | 304 this._gammaSetter = this._createAxisInput(cellElement, this._gammaElemen
t, WebInspector.UIString("Rotate (\u03B3)")); |
| 208 this._gammaSetter(String(deviceOrientation.gamma)); | 305 this._gammaSetter(String(deviceOrientation.gamma)); |
| 209 | 306 |
| 210 cellElement.appendChild(createTextButton(WebInspector.UIString("Reset"),
this._resetDeviceOrientation.bind(this), "accelerometer-reset-button")); | 307 cellElement.appendChild(createTextButton(WebInspector.UIString("Reset"),
this._resetDeviceOrientation.bind(this), "accelerometer-reset-button")); |
| 211 | |
| 212 this._stageElement = rowElement.createChild("td","accelerometer-stage"); | |
| 213 this._boxElement = this._stageElement.createChild("section", "accelerome
ter-box"); | |
| 214 | |
| 215 this._boxElement.createChild("section", "front"); | |
| 216 this._boxElement.createChild("section", "top"); | |
| 217 this._boxElement.createChild("section", "back"); | |
| 218 this._boxElement.createChild("section", "left"); | |
| 219 this._boxElement.createChild("section", "right"); | |
| 220 this._boxElement.createChild("section", "bottom"); | |
| 221 | |
| 222 WebInspector.installDragHandle(this._stageElement, this._onBoxDragStart.
bind(this), this._onBoxDrag.bind(this), this._onBoxDragEnd.bind(this), "move"); | |
| 223 this._setBoxOrientation(deviceOrientation); | |
| 224 return fieldsetElement; | 308 return fieldsetElement; |
| 225 }, | 309 }, |
| 226 | 310 |
| 227 /** | 311 /** |
| 228 * @param {!WebInspector.DeviceOrientation} deviceOrientation | 312 * @param {!WebInspector.DeviceOrientation} deviceOrientation |
| 229 */ | 313 */ |
| 230 _setBoxOrientation: function(deviceOrientation) | 314 _setBoxOrientation: function(deviceOrientation) |
| 231 { | 315 { |
| 232 var matrix = new WebKitCSSMatrix(); | 316 var matrix = new WebKitCSSMatrix(); |
| 233 this._boxMatrix = matrix.rotate(-deviceOrientation.beta, deviceOrientati
on.gamma, -deviceOrientation.alpha); | 317 this._boxMatrix = matrix.rotate(90-deviceOrientation.beta, deviceOrienta
tion.gamma, -deviceOrientation.alpha); |
| 318 this._boxElement.classList.add("is-animating"); |
| 234 this._boxElement.style.webkitTransform = this._boxMatrix.toString(); | 319 this._boxElement.style.webkitTransform = this._boxMatrix.toString(); |
| 235 }, | 320 }, |
| 236 | 321 |
| 237 /** | 322 /** |
| 238 * @param {!MouseEvent} event | 323 * @param {!MouseEvent} event |
| 239 * @return {boolean} | 324 * @return {boolean} |
| 240 */ | 325 */ |
| 241 _onBoxDrag: function(event) | 326 _onBoxDrag: function(event) |
| 242 { | 327 { |
| 243 var mouseMoveVector = this._calculateRadiusVector(event.x, event.y); | 328 var mouseMoveVector = this._calculateRadiusVector(event.x, event.y); |
| 244 if (!mouseMoveVector) | 329 if (!mouseMoveVector) |
| 245 return true; | 330 return true; |
| 246 | 331 |
| 247 event.consume(true); | 332 event.consume(true); |
| 248 var axis = WebInspector.Geometry.crossProduct(this._mouseDownVector, mou
seMoveVector); | 333 var axis, angle; |
| 249 axis.normalize(); | 334 if (event.shiftKey) { |
| 250 var angle = WebInspector.Geometry.calculateAngle(this._mouseDownVector,
mouseMoveVector); | 335 axis = new WebInspector.Geometry.Vector(0, 0, 1); |
| 336 angle = (this._mouseDownVector.x - mouseMoveVector.x)*WebInspector.S
ensorsView.ShiftDragOrientationSpeed; |
| 337 } else { |
| 338 axis = WebInspector.Geometry.crossProduct(this._mouseDownVector, mou
seMoveVector); |
| 339 axis.normalize(); |
| 340 angle = WebInspector.Geometry.calculateAngle(this._mouseDownVector,
mouseMoveVector); |
| 341 } |
| 251 var matrix = new WebKitCSSMatrix(); | 342 var matrix = new WebKitCSSMatrix(); |
| 252 var rotationMatrix = matrix.rotateAxisAngle(axis.x, axis.y, axis.z, angl
e); | 343 var rotationMatrix = matrix.rotateAxisAngle(axis.x, axis.y, axis.z, angl
e); |
| 253 this._currentMatrix = rotationMatrix.multiply(this._boxMatrix); | 344 this._currentMatrix = rotationMatrix.multiply(this._boxMatrix); |
| 254 this._boxElement.style.webkitTransform = this._currentMatrix; | 345 |
| 346 var mat90 = new WebKitCSSMatrix(); |
| 347 mat90.rotate(90); |
| 348 this._boxElement.style.webkitTransform = mat90.multiply(this._currentMat
rix); |
| 255 var eulerAngles = WebInspector.Geometry.EulerAngles.fromRotationMatrix(t
his._currentMatrix); | 349 var eulerAngles = WebInspector.Geometry.EulerAngles.fromRotationMatrix(t
his._currentMatrix); |
| 256 var newOrientation = new WebInspector.DeviceOrientation(-eulerAngles.alp
ha, -eulerAngles.beta, eulerAngles.gamma); | 350 var newOrientation = new WebInspector.DeviceOrientation(-eulerAngles.alp
ha, -eulerAngles.beta, eulerAngles.gamma); |
| 257 this._setDeviceOrientation(newOrientation, WebInspector.SensorsView.Devi
ceOrientationModificationSource.UserDrag); | 351 this._setDeviceOrientation(newOrientation, WebInspector.SensorsView.Devi
ceOrientationModificationSource.UserDrag); |
| 352 this._setSelectElementLabel(this._orientationSelectElement, WebInspector
.SensorsView.NonPresetOptions.Custom); |
| 258 return false; | 353 return false; |
| 259 }, | 354 }, |
| 260 | 355 |
| 261 /** | 356 /** |
| 262 * @param {!MouseEvent} event | 357 * @param {!MouseEvent} event |
| 263 * @return {boolean} | 358 * @return {boolean} |
| 264 */ | 359 */ |
| 265 _onBoxDragStart: function(event) | 360 _onBoxDragStart: function(event) |
| 266 { | 361 { |
| 267 if (!this._overrideDeviceOrientationCheckbox.checked) | 362 if (!this._deviceOrientationOverrideEnabled) |
| 268 return false; | 363 return false; |
| 269 | 364 |
| 270 this._mouseDownVector = this._calculateRadiusVector(event.x, event.y); | 365 this._mouseDownVector = this._calculateRadiusVector(event.x, event.y); |
| 271 | 366 |
| 272 if (!this._mouseDownVector) | 367 if (!this._mouseDownVector) |
| 273 return false; | 368 return false; |
| 274 | 369 |
| 275 event.consume(true); | 370 event.consume(true); |
| 276 return true; | 371 return true; |
| 277 }, | 372 }, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 294 var sphereY = (y - rect.top - rect.height / 2) / radius; | 389 var sphereY = (y - rect.top - rect.height / 2) / radius; |
| 295 var sqrSum = sphereX * sphereX + sphereY * sphereY; | 390 var sqrSum = sphereX * sphereX + sphereY * sphereY; |
| 296 if (sqrSum > 0.5) | 391 if (sqrSum > 0.5) |
| 297 return new WebInspector.Geometry.Vector(sphereX, sphereY, 0.5 / Math
.sqrt(sqrSum)); | 392 return new WebInspector.Geometry.Vector(sphereX, sphereY, 0.5 / Math
.sqrt(sqrSum)); |
| 298 | 393 |
| 299 return new WebInspector.Geometry.Vector(sphereX, sphereY, Math.sqrt(1 -
sqrSum)); | 394 return new WebInspector.Geometry.Vector(sphereX, sphereY, Math.sqrt(1 -
sqrSum)); |
| 300 }, | 395 }, |
| 301 | 396 |
| 302 _appendTouchControl: function() | 397 _appendTouchControl: function() |
| 303 { | 398 { |
| 304 var label = this.contentElement.createChild("label", "touch-label"); | 399 var groupElement = this.contentElement.createChild("div", "sensors-group
"); |
| 305 label.createChild("span", "").textContent = WebInspector.UIString("Touch
"); | 400 var title = groupElement.createChild("div", "sensors-group-title"); |
| 306 var select = label.createChild("select", "chrome-select"); | 401 var fieldsElement = groupElement.createChild("div", "sensors-group-field
s"); |
| 402 |
| 403 title.textContent = WebInspector.UIString("Touch"); |
| 404 var select = fieldsElement.createChild("select", "chrome-select"); |
| 307 select.appendChild(new Option(WebInspector.UIString("Device-based"), "au
to")); | 405 select.appendChild(new Option(WebInspector.UIString("Device-based"), "au
to")); |
| 308 select.appendChild(new Option(WebInspector.UIString("Force enabled"), "e
nabled")); | 406 select.appendChild(new Option(WebInspector.UIString("Force enabled"), "e
nabled")); |
| 309 select.addEventListener("change", applyTouch, false); | 407 select.addEventListener("change", applyTouch, false); |
| 310 | 408 |
| 311 function applyTouch() | 409 function applyTouch() |
| 312 { | 410 { |
| 313 WebInspector.MultitargetTouchModel.instance().setCustomTouchEnabled(
select.value === "enabled"); | 411 WebInspector.MultitargetTouchModel.instance().setCustomTouchEnabled(
select.value === "enabled"); |
| 314 } | 412 } |
| 315 }, | 413 }, |
| 316 | 414 |
| 317 __proto__ : WebInspector.VBox.prototype | 415 __proto__ : WebInspector.VBox.prototype |
| 318 } | 416 } |
| 319 | 417 |
| 320 /** @enum {string} */ | 418 /** @enum {string} */ |
| 321 WebInspector.SensorsView.DeviceOrientationModificationSource = { | 419 WebInspector.SensorsView.DeviceOrientationModificationSource = { |
| 322 UserInput: "userInput", | 420 UserInput: "userInput", |
| 323 UserDrag: "userDrag", | 421 UserDrag: "userDrag", |
| 324 ResetButton: "resetButton" | 422 ResetButton: "resetButton", |
| 423 SelectPreset: "selectPreset" |
| 325 } | 424 } |
| 326 | 425 |
| 426 /** {string} */ |
| 427 WebInspector.SensorsView.NonPresetOptions = { |
| 428 "NoOverride": "noOverride", |
| 429 "Custom": "custom", |
| 430 "Unavailable": "unavailable" |
| 431 } |
| 432 |
| 433 /** @type {!Array.<{title: string, value: !Array.<{title: string, location: stri
ng}>}>} */ |
| 434 WebInspector.SensorsView.PresetLocations = [ |
| 435 { |
| 436 title: "Presets", |
| 437 value: [ |
| 438 {title: WebInspector.UIString("Berlin"), location: "[52.520007, 13.4
04954]"}, |
| 439 {title: WebInspector.UIString("London"), location: "[51.507351, -0.1
27758]"}, |
| 440 {title: WebInspector.UIString("Moscow"), location: "[55.755826, 37.6
17300]"}, |
| 441 {title: WebInspector.UIString("Mountain View"), location: "[37.38605
2, -122.083851]"}, |
| 442 {title: WebInspector.UIString("Mumbai"), location: "[19.075984, 72.8
77656]"}, |
| 443 {title: WebInspector.UIString("San Francisco"), location: "[37.77492
9, -122.419416]"}, |
| 444 {title: WebInspector.UIString("Shanghai"), location: "[31.230416, 12
1.473701]"}, |
| 445 {title: WebInspector.UIString("São Paulo"), location: "[-23.550520,
-46.633309]"}, |
| 446 {title: WebInspector.UIString("Tokyo"), location: "[35.689487, 139.6
91706]"}, |
| 447 ] |
| 448 }, |
| 449 { |
| 450 title: "Error", |
| 451 value: [ |
| 452 {title: WebInspector.UIString("Location unavailable"), location: Web
Inspector.SensorsView.NonPresetOptions.Unavailable} |
| 453 ] |
| 454 } |
| 455 ] |
| 456 |
| 457 /** @type {!Array.<{title: string, value: !Array.<{title: string, orientation: !
WebInspector.DeviceOrientation}>}>} */ |
| 458 WebInspector.SensorsView.PresetOrientations = [ |
| 459 { |
| 460 title: "Presets", |
| 461 value: [ |
| 462 {title: WebInspector.UIString("Portrait"), orientation: "[0, 90, 0]"
}, |
| 463 {title: WebInspector.UIString("Portrait upside down"), orientation:
"[180, 90, 0]"}, |
| 464 {title: WebInspector.UIString("Landscape left"), orientation: "[90,
90, 0]"}, |
| 465 {title: WebInspector.UIString("Landscape right"), orientation: "[270
, 90, 0]"}, |
| 466 {title: WebInspector.UIString("Display up"), orientation: "[0, 0, 0]
"}, |
| 467 {title: WebInspector.UIString("Display down"), orientation: "[0, 180
, 0]"} |
| 468 ] |
| 469 } |
| 470 ] |
| 471 |
| 327 /** | 472 /** |
| 328 * @return {!WebInspector.SensorsView} | 473 * @return {!WebInspector.SensorsView} |
| 329 */ | 474 */ |
| 330 WebInspector.SensorsView.instance = function() | 475 WebInspector.SensorsView.instance = function() |
| 331 { | 476 { |
| 332 if (!WebInspector.SensorsView._instanceObject) | 477 if (!WebInspector.SensorsView._instanceObject) |
| 333 WebInspector.SensorsView._instanceObject = new WebInspector.SensorsView(
); | 478 WebInspector.SensorsView._instanceObject = new WebInspector.SensorsView(
); |
| 334 return WebInspector.SensorsView._instanceObject; | 479 return WebInspector.SensorsView._instanceObject; |
| 335 } | 480 } |
| 336 | 481 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 348 * @param {!WebInspector.Context} context | 493 * @param {!WebInspector.Context} context |
| 349 * @param {string} actionId | 494 * @param {string} actionId |
| 350 * @return {boolean} | 495 * @return {boolean} |
| 351 */ | 496 */ |
| 352 handleAction: function(context, actionId) | 497 handleAction: function(context, actionId) |
| 353 { | 498 { |
| 354 WebInspector.inspectorView.showViewInDrawer("sensors"); | 499 WebInspector.inspectorView.showViewInDrawer("sensors"); |
| 355 return true; | 500 return true; |
| 356 } | 501 } |
| 357 } | 502 } |
| 503 |
| 504 WebInspector.SensorsView.ShiftDragOrientationSpeed = 16; |
| OLD | NEW |