Chromium Code Reviews| 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 { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 groupElement.appendChild(new Option(group[j].title, group[j].ori entation)); | 149 groupElement.appendChild(new Option(group[j].title, group[j].ori entation)); |
| 150 } | 150 } |
| 151 this._orientationSelectElement.selectedIndex = 0; | 151 this._orientationSelectElement.selectedIndex = 0; |
| 152 fields.appendChild(this._orientationSelectElement); | 152 fields.appendChild(this._orientationSelectElement); |
| 153 this._orientationSelectElement.addEventListener("change", this._orientat ionSelectChanged.bind(this)); | 153 this._orientationSelectElement.addEventListener("change", this._orientat ionSelectChanged.bind(this)); |
| 154 | 154 |
| 155 this._deviceOrientationFieldset = this._createDeviceOrientationOverrideE lement(this._deviceOrientation); | 155 this._deviceOrientationFieldset = this._createDeviceOrientationOverrideE lement(this._deviceOrientation); |
| 156 | 156 |
| 157 this._stageElement = orientationContent.createChild("div", "orientation- stage"); | 157 this._stageElement = orientationContent.createChild("div", "orientation- stage"); |
| 158 this._stageElement.title = WebInspector.UIString("Shift+drag horizontall y to rotate around the y-axis"); | 158 this._stageElement.title = WebInspector.UIString("Shift+drag horizontall y to rotate around the y-axis"); |
| 159 this._boxElement = this._stageElement.createChild("section", "orientatio n-box orientation-element"); | 159 this._orientationLayer = this._stageElement.createChild("div", "orientat ion-layer"); |
| 160 this._boxElement = this._orientationLayer.createChild("section", "orient ation-box orientation-element"); | |
| 160 | 161 |
| 161 this._boxElement.createChild("section", "orientation-front orientation-e lement"); | 162 this._boxElement.createChild("section", "orientation-front orientation-e lement"); |
| 162 this._boxElement.createChild("section", "orientation-top orientation-ele ment"); | 163 this._boxElement.createChild("section", "orientation-top orientation-ele ment"); |
| 163 this._boxElement.createChild("section", "orientation-back orientation-el ement"); | 164 this._boxElement.createChild("section", "orientation-back orientation-el ement"); |
| 164 this._boxElement.createChild("section", "orientation-left orientation-el ement"); | 165 this._boxElement.createChild("section", "orientation-left orientation-el ement"); |
| 165 this._boxElement.createChild("section", "orientation-right orientation-e lement"); | 166 this._boxElement.createChild("section", "orientation-right orientation-e lement"); |
| 166 this._boxElement.createChild("section", "orientation-bottom orientation- element"); | 167 this._boxElement.createChild("section", "orientation-bottom orientation- element"); |
| 167 | 168 |
| 168 WebInspector.installDragHandle(this._stageElement, this._onBoxDragStart. bind(this), this._onBoxDrag.bind(this), null, "-webkit-grabbing", "-webkit-grab" ); | 169 WebInspector.installDragHandle(this._stageElement, this._onBoxDragStart. bind(this), this._onBoxDrag.bind(this), null, "-webkit-grabbing", "-webkit-grab" ); |
| 169 | 170 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 { | 255 { |
| 255 return Math.round(angle*10000)/10000; | 256 return Math.round(angle*10000)/10000; |
| 256 } | 257 } |
| 257 | 258 |
| 258 if (modificationSource != WebInspector.SensorsView.DeviceOrientationModi ficationSource.UserInput) { | 259 if (modificationSource != WebInspector.SensorsView.DeviceOrientationModi ficationSource.UserInput) { |
| 259 this._alphaSetter(roundAngle(deviceOrientation.alpha)); | 260 this._alphaSetter(roundAngle(deviceOrientation.alpha)); |
| 260 this._betaSetter(roundAngle(deviceOrientation.beta)); | 261 this._betaSetter(roundAngle(deviceOrientation.beta)); |
| 261 this._gammaSetter(roundAngle(deviceOrientation.gamma)); | 262 this._gammaSetter(roundAngle(deviceOrientation.gamma)); |
| 262 } | 263 } |
| 263 | 264 |
| 264 if (modificationSource != WebInspector.SensorsView.DeviceOrientationModi ficationSource.UserDrag) | 265 var noAnimation = modificationSource === WebInspector.SensorsView.Device OrientationModificationSource.UserDrag; |
|
lushnikov
2016/05/16 21:51:08
var animate = ...
luoe
2016/05/16 22:15:56
Done.
| |
| 265 this._setBoxOrientation(deviceOrientation); | 266 this._setBoxOrientation(deviceOrientation, noAnimation); |
| 266 else | |
| 267 this._boxElement.classList.remove("is-animating"); | |
| 268 | 267 |
| 269 this._deviceOrientation = deviceOrientation; | 268 this._deviceOrientation = deviceOrientation; |
| 270 this._applyDeviceOrientation(); | 269 this._applyDeviceOrientation(); |
| 271 }, | 270 }, |
| 272 | 271 |
| 273 /** | 272 /** |
| 274 * @param {!Element} parentElement | 273 * @param {!Element} parentElement |
| 275 * @param {!Element} input | 274 * @param {!Element} input |
| 276 * @param {string} label | 275 * @param {string} label |
| 277 * @return {function(string)} | 276 * @return {function(string)} |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 306 this._gammaElement = createElement("input"); | 305 this._gammaElement = createElement("input"); |
| 307 this._gammaSetter = this._createAxisInput(cellElement, this._gammaElemen t, WebInspector.UIString("\u03B3 (gamma)")); | 306 this._gammaSetter = this._createAxisInput(cellElement, this._gammaElemen t, WebInspector.UIString("\u03B3 (gamma)")); |
| 308 this._gammaSetter(String(deviceOrientation.gamma)); | 307 this._gammaSetter(String(deviceOrientation.gamma)); |
| 309 | 308 |
| 310 cellElement.appendChild(createTextButton(WebInspector.UIString("Reset"), this._resetDeviceOrientation.bind(this), "orientation-reset-button")); | 309 cellElement.appendChild(createTextButton(WebInspector.UIString("Reset"), this._resetDeviceOrientation.bind(this), "orientation-reset-button")); |
| 311 return fieldsetElement; | 310 return fieldsetElement; |
| 312 }, | 311 }, |
| 313 | 312 |
| 314 /** | 313 /** |
| 315 * @param {!WebInspector.DeviceOrientation} deviceOrientation | 314 * @param {!WebInspector.DeviceOrientation} deviceOrientation |
| 315 * @param {boolean=} noAnimation | |
|
lushnikov
2016/05/16 21:51:08
let's pass a non-optional "animate" parameter here
luoe
2016/05/16 22:15:56
Done.
| |
| 316 */ | 316 */ |
| 317 _setBoxOrientation: function(deviceOrientation) | 317 _setBoxOrientation: function(deviceOrientation, noAnimation) |
| 318 { | 318 { |
| 319 var matrix = this._viewportPreviewMatrix(true); | 319 if (noAnimation) |
| 320 this._stageElement.classList.remove("is-animating"); | |
| 321 else | |
| 322 this._stageElement.classList.add("is-animating"); | |
| 323 | |
| 324 var matrix = new WebKitCSSMatrix(); | |
| 320 this._boxMatrix = matrix.rotate(-deviceOrientation.beta, deviceOrientati on.gamma, -deviceOrientation.alpha); | 325 this._boxMatrix = matrix.rotate(-deviceOrientation.beta, deviceOrientati on.gamma, -deviceOrientation.alpha); |
| 321 | 326 var eulerAngles = WebInspector.Geometry.EulerAngles.fromRotationMatrix(t his._boxMatrix); |
| 322 this._boxElement.classList.add("is-animating"); | 327 this._orientationLayer.style.transform = eulerAngles.toRotate3DString(); |
| 323 this._boxElement.style.transform = this._boxMatrix.toString(); | |
| 324 }, | 328 }, |
| 325 | 329 |
| 326 /** | 330 /** |
| 327 * @param {boolean=} toViewportPreview | |
| 328 * @return {!CSSMatrix} | |
| 329 */ | |
| 330 _viewportPreviewMatrix: function(toViewportPreview) | |
| 331 { | |
| 332 // The default orientation [0, 0, 0] represents a device with | |
| 333 // screen facing up. This transformation shifts the | |
| 334 // orientation displayed in the 3D preview to be front-facing | |
| 335 // instead of top-down. | |
| 336 var betaRotate = toViewportPreview ? 90 : -90; | |
| 337 var matrix = new WebKitCSSMatrix(); | |
| 338 return matrix.rotate(betaRotate, 0, 0); | |
| 339 }, | |
| 340 | |
| 341 /** | |
| 342 * @param {!MouseEvent} event | 331 * @param {!MouseEvent} event |
| 343 * @return {boolean} | 332 * @return {boolean} |
| 344 */ | 333 */ |
| 345 _onBoxDrag: function(event) | 334 _onBoxDrag: function(event) |
| 346 { | 335 { |
| 347 var mouseMoveVector = this._calculateRadiusVector(event.x, event.y); | 336 var mouseMoveVector = this._calculateRadiusVector(event.x, event.y); |
| 348 if (!mouseMoveVector) | 337 if (!mouseMoveVector) |
| 349 return true; | 338 return true; |
| 350 | 339 |
| 351 event.consume(true); | 340 event.consume(true); |
| 352 var axis, angle; | 341 var axis, angle; |
| 353 if (event.shiftKey) { | 342 if (event.shiftKey) { |
| 354 axis = new WebInspector.Geometry.Vector(0, 0, -1); | 343 axis = new WebInspector.Geometry.Vector(0, 0, -1); |
| 355 angle = (this._mouseDownVector.x - mouseMoveVector.x)*WebInspector.S ensorsView.ShiftDragOrientationSpeed; | 344 angle = (this._mouseDownVector.x - mouseMoveVector.x)*WebInspector.S ensorsView.ShiftDragOrientationSpeed; |
| 356 } else { | 345 } else { |
| 357 axis = WebInspector.Geometry.crossProduct(this._mouseDownVector, mou seMoveVector); | 346 axis = WebInspector.Geometry.crossProduct(this._mouseDownVector, mou seMoveVector); |
| 358 axis.normalize(); | |
| 359 angle = WebInspector.Geometry.calculateAngle(this._mouseDownVector, mouseMoveVector); | 347 angle = WebInspector.Geometry.calculateAngle(this._mouseDownVector, mouseMoveVector); |
| 360 } | 348 } |
| 361 var matrix = new WebKitCSSMatrix(); | |
| 362 var rotationMatrix = matrix.rotateAxisAngle(axis.x, axis.y, axis.z, angl e); | |
| 363 var transformFromScreen = this._viewportPreviewMatrix(); | |
| 364 | 349 |
| 365 this._boxMatrix = rotationMatrix.multiply(this._originalBoxMatrix); | 350 // The mouse movement vectors occur in the screen space, which is offset by 90 degrees from |
| 366 this._boxElement.style.transform = this._boxMatrix.toString(); | 351 // the actual device orientation. |
| 352 var currentMatrix = new WebKitCSSMatrix(); | |
| 353 currentMatrix = currentMatrix | |
| 354 .rotate(-90, 0, 0) | |
| 355 .rotateAxisAngle(axis.x, axis.y, axis.z, angle) | |
| 356 .rotate(90, 0, 0) | |
| 357 .multiply(this._originalBoxMatrix); | |
| 367 | 358 |
| 368 var currentMatrix = transformFromScreen.multiply(this._boxMatrix); | |
| 369 var eulerAngles = WebInspector.Geometry.EulerAngles.fromRotationMatrix(c urrentMatrix); | 359 var eulerAngles = WebInspector.Geometry.EulerAngles.fromRotationMatrix(c urrentMatrix); |
| 370 var newOrientation = new WebInspector.DeviceOrientation(-eulerAngles.alp ha, -eulerAngles.beta, eulerAngles.gamma); | 360 var newOrientation = new WebInspector.DeviceOrientation(-eulerAngles.alp ha, -eulerAngles.beta, eulerAngles.gamma); |
| 371 this._setDeviceOrientation(newOrientation, WebInspector.SensorsView.Devi ceOrientationModificationSource.UserDrag); | 361 this._setDeviceOrientation(newOrientation, WebInspector.SensorsView.Devi ceOrientationModificationSource.UserDrag); |
| 372 this._setSelectElementLabel(this._orientationSelectElement, WebInspector .SensorsView.NonPresetOptions.Custom); | 362 this._setSelectElementLabel(this._orientationSelectElement, WebInspector .SensorsView.NonPresetOptions.Custom); |
| 373 return false; | 363 return false; |
| 374 }, | 364 }, |
| 375 | 365 |
| 376 /** | 366 /** |
| 377 * @param {!MouseEvent} event | 367 * @param {!MouseEvent} event |
| 378 * @return {boolean} | 368 * @return {boolean} |
| 379 */ | 369 */ |
| 380 _onBoxDragStart: function(event) | 370 _onBoxDragStart: function(event) |
| 381 { | 371 { |
| 382 if (!this._deviceOrientationOverrideEnabled) | 372 if (!this._deviceOrientationOverrideEnabled) |
| 383 return false; | 373 return false; |
| 384 | 374 |
| 385 this._mouseDownVector = this._calculateRadiusVector(event.x, event.y); | 375 this._mouseDownVector = this._calculateRadiusVector(event.x, event.y); |
| 386 this._originalBoxMatrix = this._boxMatrix; | 376 this._originalBoxMatrix = this._boxMatrix.scale(1); |
|
lushnikov
2016/05/16 21:51:08
what is this for?
luoe
2016/05/16 22:15:56
Ah, no need for this anymore! I was originally us
| |
| 387 | 377 |
| 388 if (!this._mouseDownVector) | 378 if (!this._mouseDownVector) |
| 389 return false; | 379 return false; |
| 390 | 380 |
| 391 event.consume(true); | 381 event.consume(true); |
| 392 return true; | 382 return true; |
| 393 }, | 383 }, |
| 394 | 384 |
| 395 /** | 385 /** |
| 396 * @param {number} x | 386 * @param {number} x |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 * @return {boolean} | 501 * @return {boolean} |
| 512 */ | 502 */ |
| 513 handleAction: function(context, actionId) | 503 handleAction: function(context, actionId) |
| 514 { | 504 { |
| 515 WebInspector.inspectorView.showViewInDrawer("sensors"); | 505 WebInspector.inspectorView.showViewInDrawer("sensors"); |
| 516 return true; | 506 return true; |
| 517 } | 507 } |
| 518 } | 508 } |
| 519 | 509 |
| 520 WebInspector.SensorsView.ShiftDragOrientationSpeed = 16; | 510 WebInspector.SensorsView.ShiftDragOrientationSpeed = 16; |
| OLD | NEW |