| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 The Chromium Authors. All rights reserved. | 2 * Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @constructor | 8 * @constructor |
| 9 * @extends {WebInspector.Object} | 9 * @extends {WebInspector.Object} |
| 10 * @param {!Element} element | 10 * @param {!Element} element |
| 11 * @param {boolean=} disableRotate | 11 * @param {boolean=} disableRotate |
| 12 */ | 12 */ |
| 13 WebInspector.TransformController = function(element, disableRotate) | 13 WebInspector.TransformController = function(element, disableRotate) |
| 14 { | 14 { |
| 15 this._shortcuts = {}; | 15 this._shortcuts = {}; |
| 16 this.element = element; | 16 this.element = element; |
| 17 if (this.element.tabIndex < 0) |
| 18 this.element.tabIndex = 0; |
| 17 this._registerShortcuts(); | 19 this._registerShortcuts(); |
| 20 WebInspector.installDragHandle(element, this._onDragStart.bind(this), this._
onDrag.bind(this), this._onDragEnd.bind(this), "move", null); |
| 18 element.addEventListener("keydown", this._onKeyDown.bind(this), false); | 21 element.addEventListener("keydown", this._onKeyDown.bind(this), false); |
| 19 element.addEventListener("keyup", this._onKeyUp.bind(this), false); | 22 element.addEventListener("keyup", this._onKeyUp.bind(this), false); |
| 20 element.addEventListener("mousemove", this._onMouseMove.bind(this), false); | |
| 21 element.addEventListener("mousedown", this._onMouseDown.bind(this), false); | |
| 22 element.addEventListener("mouseup", this._onMouseUp.bind(this), false); | |
| 23 element.addEventListener("mousewheel", this._onMouseWheel.bind(this), false)
; | 23 element.addEventListener("mousewheel", this._onMouseWheel.bind(this), false)
; |
| 24 this._disableRotate = disableRotate; | 24 this._disableRotate = disableRotate; |
| 25 | 25 |
| 26 this._controlPanelElement = createElement("div"); | 26 this._controlPanelElement = createElement("div"); |
| 27 this._controlPanelElement.classList.add("transform-control-panel"); | 27 this._controlPanelElement.classList.add("transform-control-panel"); |
| 28 | 28 |
| 29 this._modeButtons = {}; | 29 this._modeButtons = {}; |
| 30 if (!disableRotate) { | 30 if (!disableRotate) { |
| 31 var panModeButton = new WebInspector.StatusBarButton(WebInspector.UIStri
ng("Pan mode (X)"), "transform-mode-pan"); | 31 var panModeButton = new WebInspector.StatusBarButton(WebInspector.UIStri
ng("Pan mode (X)"), "transform-mode-pan"); |
| 32 panModeButton.addEventListener("click", this._setMode.bind(this, WebInsp
ector.TransformController.Modes.Pan)); | 32 panModeButton.addEventListener("click", this._setMode.bind(this, WebInsp
ector.TransformController.Modes.Pan)); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 var zoomFactor = 1.1; | 267 var zoomFactor = 1.1; |
| 268 /** @const */ | 268 /** @const */ |
| 269 var mouseWheelZoomSpeed = 1 / 120; | 269 var mouseWheelZoomSpeed = 1 / 120; |
| 270 var scaleFactor = Math.pow(zoomFactor, event.wheelDeltaY * mouseWheelZoo
mSpeed); | 270 var scaleFactor = Math.pow(zoomFactor, event.wheelDeltaY * mouseWheelZoo
mSpeed); |
| 271 this._onScale(scaleFactor, event.clientX - this.element.totalOffsetLeft(
), event.clientY - this.element.totalOffsetTop()); | 271 this._onScale(scaleFactor, event.clientX - this.element.totalOffsetLeft(
), event.clientY - this.element.totalOffsetTop()); |
| 272 }, | 272 }, |
| 273 | 273 |
| 274 /** | 274 /** |
| 275 * @param {!Event} event | 275 * @param {!Event} event |
| 276 */ | 276 */ |
| 277 _onMouseMove: function(event) | 277 _onDrag: function(event) |
| 278 { | 278 { |
| 279 if (event.which !== 1 || typeof this._originX !== "number") | |
| 280 return; | |
| 281 if (this._mode === WebInspector.TransformController.Modes.Rotate) { | 279 if (this._mode === WebInspector.TransformController.Modes.Rotate) { |
| 282 this._onRotate(this._oldRotateX + (this._originY - event.clientY) /
this.element.clientHeight * 180, this._oldRotateY - (this._originX - event.clien
tX) / this.element.clientWidth * 180); | 280 this._onRotate(this._oldRotateX + (this._originY - event.clientY) /
this.element.clientHeight * 180, this._oldRotateY - (this._originX - event.clien
tX) / this.element.clientWidth * 180); |
| 283 } else { | 281 } else { |
| 284 this._onPan(event.clientX - this._originX, event.clientY - this._ori
ginY); | 282 this._onPan(event.clientX - this._originX, event.clientY - this._ori
ginY); |
| 285 this._originX = event.clientX; | 283 this._originX = event.clientX; |
| 286 this._originY = event.clientY; | 284 this._originY = event.clientY; |
| 287 } | 285 } |
| 288 }, | 286 }, |
| 289 | 287 |
| 290 /** | 288 /** |
| 291 * @param {!Event} event | 289 * @param {!MouseEvent} event |
| 292 */ | 290 */ |
| 293 _setReferencePoint: function(event) | 291 _onDragStart: function(event) |
| 294 { | 292 { |
| 293 this.element.focus(); |
| 295 this._originX = event.clientX; | 294 this._originX = event.clientX; |
| 296 this._originY = event.clientY; | 295 this._originY = event.clientY; |
| 297 this._oldRotateX = this._rotateX; | 296 this._oldRotateX = this._rotateX; |
| 298 this._oldRotateY = this._rotateY; | 297 this._oldRotateY = this._rotateY; |
| 298 return true; |
| 299 }, | 299 }, |
| 300 | 300 |
| 301 _resetReferencePoint: function() | 301 _onDragEnd: function() |
| 302 { | 302 { |
| 303 delete this._originX; | 303 delete this._originX; |
| 304 delete this._originY; | 304 delete this._originY; |
| 305 delete this._oldRotateX; | 305 delete this._oldRotateX; |
| 306 delete this._oldRotateY; | 306 delete this._oldRotateY; |
| 307 }, | 307 }, |
| 308 | 308 |
| 309 /** | |
| 310 * @param {!Event} event | |
| 311 */ | |
| 312 _onMouseDown: function(event) | |
| 313 { | |
| 314 if (event.which !== 1) | |
| 315 return; | |
| 316 this._setReferencePoint(event); | |
| 317 }, | |
| 318 | |
| 319 /** | |
| 320 * @param {!Event} event | |
| 321 */ | |
| 322 _onMouseUp: function(event) | |
| 323 { | |
| 324 if (event.which !== 1) | |
| 325 return; | |
| 326 this._resetReferencePoint(); | |
| 327 }, | |
| 328 | |
| 329 __proto__: WebInspector.Object.prototype | 309 __proto__: WebInspector.Object.prototype |
| 330 } | 310 } |
| OLD | NEW |