Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 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 | |
| 4 * found in the LICENSE file. | |
| 5 */ | |
| 6 | |
| 7 /** | |
| 8 * @constructor | |
| 9 * @extends {WebInspector.Object} | |
| 10 * @param {!Element} element | |
| 11 */ | |
| 12 WebInspector.TransformController = function(element) | |
| 13 { | |
| 14 this.element = element; | |
| 15 element.addEventListener("mousemove", this._onMouseMove.bind(this), false); | |
| 16 element.addEventListener("mouseout", this._onMouseMove.bind(this), false); | |
| 17 element.addEventListener("mousedown", this._onMouseDown.bind(this), false); | |
| 18 element.addEventListener("mouseup", this._onMouseUp.bind(this), false); | |
| 19 element.addEventListener("mousewheel", this._onMouseWheel.bind(this), false) ; | |
| 20 this.reset(); | |
| 21 } | |
| 22 | |
| 23 /** | |
| 24 * @enum {string} | |
| 25 */ | |
| 26 WebInspector.TransformController.Events = { | |
| 27 TransformChanged: "TransformChanged" | |
| 28 } | |
| 29 | |
| 30 /** | |
| 31 * @enum {number} | |
| 32 */ | |
| 33 WebInspector.TransformController.TransformType = { | |
| 34 Offset: 1, | |
|
pfeldman
2014/03/04 15:55:49
1 << 0
| |
| 35 Scale: 2, | |
|
pfeldman
2014/03/04 15:55:49
1 << 1
| |
| 36 Rotation: 4 | |
|
pfeldman
2014/03/04 15:55:49
1 << 2
| |
| 37 } | |
| 38 | |
| 39 WebInspector.TransformController.prototype = { | |
| 40 /** | |
| 41 * @param {number} changeType | |
| 42 */ | |
| 43 _postChangeEvent: function(changeType) | |
| 44 { | |
| 45 this.dispatchEventToListeners(WebInspector.TransformController.Events.Tr ansformChanged, changeType); | |
| 46 }, | |
| 47 | |
| 48 /** | |
| 49 * @param {?Event} event | |
| 50 */ | |
| 51 _onMouseMove: function(event) | |
| 52 { | |
| 53 if (event.which !== 1) | |
| 54 return; | |
| 55 // Set reference point if we missed mousedown. | |
| 56 if (typeof this._originX !== "number") | |
| 57 this._setReferencePoint(event); | |
| 58 this._rotateX = this._oldRotateX + (this._originY - event.clientY) / 2; | |
| 59 this._rotateY = this._oldRotateY - (this._originX - event.clientX) / 4; | |
| 60 this._postChangeEvent(WebInspector.TransformController.TransformType.Rot ation); | |
| 61 }, | |
| 62 | |
| 63 reset: function() | |
| 64 { | |
| 65 this._scale = 1; | |
| 66 this._offsetX = 0; | |
| 67 this._offsetY = 0; | |
| 68 this._rotateX = 0; | |
| 69 this._rotateY = 0; | |
| 70 }, | |
| 71 | |
| 72 /** | |
| 73 * @return {number} | |
| 74 */ | |
| 75 scale: function() | |
| 76 { | |
| 77 return this._scale; | |
| 78 }, | |
| 79 | |
| 80 /** | |
| 81 * @return {number} | |
| 82 */ | |
| 83 offsetX: function() | |
| 84 { | |
| 85 return this._offsetX; | |
| 86 }, | |
| 87 | |
| 88 /** | |
| 89 * @return {number} | |
| 90 */ | |
| 91 offsetY: function() | |
| 92 { | |
| 93 return this._offsetY; | |
| 94 }, | |
| 95 | |
| 96 /** | |
| 97 * @return {number} | |
| 98 */ | |
| 99 rotateX: function() | |
| 100 { | |
| 101 return this._rotateX; | |
| 102 }, | |
| 103 | |
| 104 /** | |
| 105 * @return {number} | |
| 106 */ | |
| 107 rotateY: function() | |
| 108 { | |
| 109 return this._rotateY; | |
| 110 }, | |
| 111 | |
| 112 /** | |
| 113 * @param {?Event} event | |
| 114 */ | |
| 115 _onMouseWheel: function(event) | |
| 116 { | |
| 117 if (event.shiftKey) { | |
| 118 const zoomFactor = 1.1; | |
| 119 const mouseWheelZoomSpeed = 1 / 120; | |
| 120 var scaleFactor = Math.pow(zoomFactor, event.wheelDeltaY * mouseWhee lZoomSpeed); | |
| 121 this._scale *= scaleFactor; | |
| 122 this._offsetX -= (event.clientX - this.element.totalOffsetLeft() - t his._offsetX) * (scaleFactor - 1); | |
| 123 this._offsetY -= (event.clientY - this.element.totalOffsetTop() - th is._offsetY) * (scaleFactor - 1); | |
| 124 this._postChangeEvent(WebInspector.TransformController.TransformType .Scale | WebInspector.TransformController.TransformType.Offset); | |
| 125 } else { | |
| 126 this._offsetX += event.wheelDeltaX; | |
| 127 this._offsetY += event.wheelDeltaY; | |
| 128 this._postChangeEvent(WebInspector.TransformController.TransformType .Offset); | |
| 129 } | |
| 130 }, | |
| 131 | |
| 132 /** | |
| 133 * @param {?Event} event | |
| 134 */ | |
| 135 _setReferencePoint: function(event) | |
| 136 { | |
| 137 this._originX = event.clientX; | |
| 138 this._originY = event.clientY; | |
| 139 this._oldRotateX = this._rotateX; | |
| 140 this._oldRotateY = this._rotateY; | |
| 141 }, | |
| 142 | |
| 143 _resetReferencePoint: function() | |
| 144 { | |
| 145 delete this._originX; | |
| 146 delete this._originY; | |
| 147 delete this._oldRotateX; | |
| 148 delete this._oldRotateY; | |
| 149 }, | |
| 150 | |
| 151 /** | |
| 152 * @param {?Event} event | |
| 153 */ | |
| 154 _onMouseDown: function(event) | |
| 155 { | |
| 156 if (event.which !== 1) | |
| 157 return; | |
| 158 this._setReferencePoint(event); | |
| 159 }, | |
| 160 | |
| 161 /** | |
| 162 * @param {?Event} event | |
| 163 */ | |
| 164 _onMouseUp: function(event) | |
| 165 { | |
| 166 if (event.which !== 1) | |
| 167 return; | |
| 168 this._resetReferencePoint(); | |
| 169 }, | |
| 170 | |
| 171 __proto__: WebInspector.Object.prototype | |
| 172 } | |
| OLD | NEW |