Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/emulation/SensorsView.js

Issue 1975723003: DevTools: fix janky transition in sensors panel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated test and rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
170 fields.appendChild(this._deviceOrientationFieldset); 171 fields.appendChild(this._deviceOrientationFieldset);
171 this._enableOrientationFields(true); 172 this._enableOrientationFields(true);
172 this._setBoxOrientation(this._deviceOrientation); 173 this._setBoxOrientation(this._deviceOrientation, false);
173 }, 174 },
174 175
175 /** 176 /**
176 * @param {?boolean} disable 177 * @param {?boolean} disable
177 */ 178 */
178 _enableOrientationFields: function(disable) 179 _enableOrientationFields: function(disable)
179 { 180 {
180 if (disable) { 181 if (disable) {
181 this._deviceOrientationFieldset.disabled = true; 182 this._deviceOrientationFieldset.disabled = true;
182 this._stageElement.classList.add("disabled"); 183 this._stageElement.classList.add("disabled");
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 animate = modificationSource !== WebInspector.SensorsView.DeviceOrie ntationModificationSource.UserDrag;
265 this._setBoxOrientation(deviceOrientation); 266 this._setBoxOrientation(deviceOrientation, animate);
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
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} animate
316 */ 316 */
317 _setBoxOrientation: function(deviceOrientation) 317 _setBoxOrientation: function(deviceOrientation, animate)
318 { 318 {
319 var matrix = this._viewportPreviewMatrix(true); 319 if (animate)
320 this._stageElement.classList.add("is-animating");
321 else
322 this._stageElement.classList.remove("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}
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698