| 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 * @unrestricted | 8 * @unrestricted |
| 9 */ | 9 */ |
| 10 WebInspector.TransformController = class extends WebInspector.Object { | 10 LayerViewer.TransformController = class extends Common.Object { |
| 11 /** | 11 /** |
| 12 * @param {!Element} element | 12 * @param {!Element} element |
| 13 * @param {boolean=} disableRotate | 13 * @param {boolean=} disableRotate |
| 14 */ | 14 */ |
| 15 constructor(element, disableRotate) { | 15 constructor(element, disableRotate) { |
| 16 super(); | 16 super(); |
| 17 this._shortcuts = {}; | 17 this._shortcuts = {}; |
| 18 this.element = element; | 18 this.element = element; |
| 19 if (this.element.tabIndex < 0) | 19 if (this.element.tabIndex < 0) |
| 20 this.element.tabIndex = 0; | 20 this.element.tabIndex = 0; |
| 21 this._registerShortcuts(); | 21 this._registerShortcuts(); |
| 22 WebInspector.installDragHandle( | 22 UI.installDragHandle( |
| 23 element, this._onDragStart.bind(this), this._onDrag.bind(this), this._on
DragEnd.bind(this), 'move', null); | 23 element, this._onDragStart.bind(this), this._onDrag.bind(this), this._on
DragEnd.bind(this), 'move', null); |
| 24 element.addEventListener('keydown', this._onKeyDown.bind(this), false); | 24 element.addEventListener('keydown', this._onKeyDown.bind(this), false); |
| 25 element.addEventListener('keyup', this._onKeyUp.bind(this), false); | 25 element.addEventListener('keyup', this._onKeyUp.bind(this), false); |
| 26 element.addEventListener('mousewheel', this._onMouseWheel.bind(this), false)
; | 26 element.addEventListener('mousewheel', this._onMouseWheel.bind(this), false)
; |
| 27 this._minScale = 0; | 27 this._minScale = 0; |
| 28 this._maxScale = Infinity; | 28 this._maxScale = Infinity; |
| 29 | 29 |
| 30 this._controlPanelToolbar = new WebInspector.Toolbar('transform-control-pane
l'); | 30 this._controlPanelToolbar = new UI.Toolbar('transform-control-panel'); |
| 31 | 31 |
| 32 /** @type {!Object<string, !WebInspector.ToolbarToggle>} */ | 32 /** @type {!Object<string, !UI.ToolbarToggle>} */ |
| 33 this._modeButtons = {}; | 33 this._modeButtons = {}; |
| 34 if (!disableRotate) { | 34 if (!disableRotate) { |
| 35 var panModeButton = new WebInspector.ToolbarToggle(WebInspector.UIString('
Pan mode (X)'), 'largeicon-pan'); | 35 var panModeButton = new UI.ToolbarToggle(Common.UIString('Pan mode (X)'),
'largeicon-pan'); |
| 36 panModeButton.addEventListener('click', this._setMode.bind(this, WebInspec
tor.TransformController.Modes.Pan)); | 36 panModeButton.addEventListener('click', this._setMode.bind(this, LayerView
er.TransformController.Modes.Pan)); |
| 37 this._modeButtons[WebInspector.TransformController.Modes.Pan] = panModeBut
ton; | 37 this._modeButtons[LayerViewer.TransformController.Modes.Pan] = panModeButt
on; |
| 38 this._controlPanelToolbar.appendToolbarItem(panModeButton); | 38 this._controlPanelToolbar.appendToolbarItem(panModeButton); |
| 39 var rotateModeButton = | 39 var rotateModeButton = |
| 40 new WebInspector.ToolbarToggle(WebInspector.UIString('Rotate mode (V)'
), 'largeicon-rotate'); | 40 new UI.ToolbarToggle(Common.UIString('Rotate mode (V)'), 'largeicon-ro
tate'); |
| 41 rotateModeButton.addEventListener( | 41 rotateModeButton.addEventListener( |
| 42 'click', this._setMode.bind(this, WebInspector.TransformController.Mod
es.Rotate)); | 42 'click', this._setMode.bind(this, LayerViewer.TransformController.Mode
s.Rotate)); |
| 43 this._modeButtons[WebInspector.TransformController.Modes.Rotate] = rotateM
odeButton; | 43 this._modeButtons[LayerViewer.TransformController.Modes.Rotate] = rotateMo
deButton; |
| 44 this._controlPanelToolbar.appendToolbarItem(rotateModeButton); | 44 this._controlPanelToolbar.appendToolbarItem(rotateModeButton); |
| 45 } | 45 } |
| 46 this._setMode(WebInspector.TransformController.Modes.Pan); | 46 this._setMode(LayerViewer.TransformController.Modes.Pan); |
| 47 | 47 |
| 48 var resetButton = | 48 var resetButton = |
| 49 new WebInspector.ToolbarButton(WebInspector.UIString('Reset transform (0
)'), 'largeicon-center'); | 49 new UI.ToolbarButton(Common.UIString('Reset transform (0)'), 'largeicon-
center'); |
| 50 resetButton.addEventListener('click', this.resetAndNotify.bind(this, undefin
ed)); | 50 resetButton.addEventListener('click', this.resetAndNotify.bind(this, undefin
ed)); |
| 51 this._controlPanelToolbar.appendToolbarItem(resetButton); | 51 this._controlPanelToolbar.appendToolbarItem(resetButton); |
| 52 | 52 |
| 53 this._reset(); | 53 this._reset(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * @return {!WebInspector.Toolbar} | 57 * @return {!UI.Toolbar} |
| 58 */ | 58 */ |
| 59 toolbar() { | 59 toolbar() { |
| 60 return this._controlPanelToolbar; | 60 return this._controlPanelToolbar; |
| 61 } | 61 } |
| 62 | 62 |
| 63 _onKeyDown(event) { | 63 _onKeyDown(event) { |
| 64 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Shift.code) { | 64 if (event.keyCode === UI.KeyboardShortcut.Keys.Shift.code) { |
| 65 this._toggleMode(); | 65 this._toggleMode(); |
| 66 return; | 66 return; |
| 67 } | 67 } |
| 68 | 68 |
| 69 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEventIgnoringModi
fiers(event); | 69 var shortcutKey = UI.KeyboardShortcut.makeKeyFromEventIgnoringModifiers(even
t); |
| 70 var handler = this._shortcuts[shortcutKey]; | 70 var handler = this._shortcuts[shortcutKey]; |
| 71 if (handler && handler(event)) | 71 if (handler && handler(event)) |
| 72 event.consume(); | 72 event.consume(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 _onKeyUp(event) { | 75 _onKeyUp(event) { |
| 76 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Shift.code) | 76 if (event.keyCode === UI.KeyboardShortcut.Keys.Shift.code) |
| 77 this._toggleMode(); | 77 this._toggleMode(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 _addShortcuts(keys, handler) { | 80 _addShortcuts(keys, handler) { |
| 81 for (var i = 0; i < keys.length; ++i) | 81 for (var i = 0; i < keys.length; ++i) |
| 82 this._shortcuts[keys[i].key] = handler; | 82 this._shortcuts[keys[i].key] = handler; |
| 83 } | 83 } |
| 84 | 84 |
| 85 _registerShortcuts() { | 85 _registerShortcuts() { |
| 86 this._addShortcuts(WebInspector.ShortcutsScreen.LayersPanelShortcuts.ResetVi
ew, this.resetAndNotify.bind(this)); | 86 this._addShortcuts(Components.ShortcutsScreen.LayersPanelShortcuts.ResetView
, this.resetAndNotify.bind(this)); |
| 87 this._addShortcuts( | 87 this._addShortcuts( |
| 88 WebInspector.ShortcutsScreen.LayersPanelShortcuts.PanMode, | 88 Components.ShortcutsScreen.LayersPanelShortcuts.PanMode, |
| 89 this._setMode.bind(this, WebInspector.TransformController.Modes.Pan)); | 89 this._setMode.bind(this, LayerViewer.TransformController.Modes.Pan)); |
| 90 this._addShortcuts( | 90 this._addShortcuts( |
| 91 WebInspector.ShortcutsScreen.LayersPanelShortcuts.RotateMode, | 91 Components.ShortcutsScreen.LayersPanelShortcuts.RotateMode, |
| 92 this._setMode.bind(this, WebInspector.TransformController.Modes.Rotate))
; | 92 this._setMode.bind(this, LayerViewer.TransformController.Modes.Rotate)); |
| 93 var zoomFactor = 1.1; | 93 var zoomFactor = 1.1; |
| 94 this._addShortcuts( | 94 this._addShortcuts( |
| 95 WebInspector.ShortcutsScreen.LayersPanelShortcuts.ZoomIn, this._onKeyboa
rdZoom.bind(this, zoomFactor)); | 95 Components.ShortcutsScreen.LayersPanelShortcuts.ZoomIn, this._onKeyboard
Zoom.bind(this, zoomFactor)); |
| 96 this._addShortcuts( | 96 this._addShortcuts( |
| 97 WebInspector.ShortcutsScreen.LayersPanelShortcuts.ZoomOut, this._onKeybo
ardZoom.bind(this, 1 / zoomFactor)); | 97 Components.ShortcutsScreen.LayersPanelShortcuts.ZoomOut, this._onKeyboar
dZoom.bind(this, 1 / zoomFactor)); |
| 98 this._addShortcuts( | 98 this._addShortcuts( |
| 99 WebInspector.ShortcutsScreen.LayersPanelShortcuts.Up, this._onKeyboardPa
nOrRotate.bind(this, 0, -1)); | 99 Components.ShortcutsScreen.LayersPanelShortcuts.Up, this._onKeyboardPanO
rRotate.bind(this, 0, -1)); |
| 100 this._addShortcuts( | 100 this._addShortcuts( |
| 101 WebInspector.ShortcutsScreen.LayersPanelShortcuts.Down, this._onKeyboard
PanOrRotate.bind(this, 0, 1)); | 101 Components.ShortcutsScreen.LayersPanelShortcuts.Down, this._onKeyboardPa
nOrRotate.bind(this, 0, 1)); |
| 102 this._addShortcuts( | 102 this._addShortcuts( |
| 103 WebInspector.ShortcutsScreen.LayersPanelShortcuts.Left, this._onKeyboard
PanOrRotate.bind(this, -1, 0)); | 103 Components.ShortcutsScreen.LayersPanelShortcuts.Left, this._onKeyboardPa
nOrRotate.bind(this, -1, 0)); |
| 104 this._addShortcuts( | 104 this._addShortcuts( |
| 105 WebInspector.ShortcutsScreen.LayersPanelShortcuts.Right, this._onKeyboar
dPanOrRotate.bind(this, 1, 0)); | 105 Components.ShortcutsScreen.LayersPanelShortcuts.Right, this._onKeyboardP
anOrRotate.bind(this, 1, 0)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 _postChangeEvent() { | 108 _postChangeEvent() { |
| 109 this.dispatchEventToListeners(WebInspector.TransformController.Events.Transf
ormChanged); | 109 this.dispatchEventToListeners(LayerViewer.TransformController.Events.Transfo
rmChanged); |
| 110 } | 110 } |
| 111 | 111 |
| 112 _reset() { | 112 _reset() { |
| 113 this._scale = 1; | 113 this._scale = 1; |
| 114 this._offsetX = 0; | 114 this._offsetX = 0; |
| 115 this._offsetY = 0; | 115 this._offsetY = 0; |
| 116 this._rotateX = 0; | 116 this._rotateX = 0; |
| 117 this._rotateY = 0; | 117 this._rotateY = 0; |
| 118 } | 118 } |
| 119 | 119 |
| 120 _toggleMode() { | 120 _toggleMode() { |
| 121 this._setMode( | 121 this._setMode( |
| 122 this._mode === WebInspector.TransformController.Modes.Pan ? WebInspector
.TransformController.Modes.Rotate : | 122 this._mode === LayerViewer.TransformController.Modes.Pan ? LayerViewer.T
ransformController.Modes.Rotate : |
| 123 WebInspector
.TransformController.Modes.Pan); | 123 LayerViewer.
TransformController.Modes.Pan); |
| 124 } | 124 } |
| 125 | 125 |
| 126 /** | 126 /** |
| 127 * @param {!WebInspector.TransformController.Modes} mode | 127 * @param {!LayerViewer.TransformController.Modes} mode |
| 128 */ | 128 */ |
| 129 _setMode(mode) { | 129 _setMode(mode) { |
| 130 if (this._mode === mode) | 130 if (this._mode === mode) |
| 131 return; | 131 return; |
| 132 this._mode = mode; | 132 this._mode = mode; |
| 133 this._updateModeButtons(); | 133 this._updateModeButtons(); |
| 134 this.element.focus(); | 134 this.element.focus(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 _updateModeButtons() { | 137 _updateModeButtons() { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } | 247 } |
| 248 | 248 |
| 249 /** | 249 /** |
| 250 * @param {number} xMultiplier | 250 * @param {number} xMultiplier |
| 251 * @param {number} yMultiplier | 251 * @param {number} yMultiplier |
| 252 */ | 252 */ |
| 253 _onKeyboardPanOrRotate(xMultiplier, yMultiplier) { | 253 _onKeyboardPanOrRotate(xMultiplier, yMultiplier) { |
| 254 var panStepInPixels = 6; | 254 var panStepInPixels = 6; |
| 255 var rotateStepInDegrees = 5; | 255 var rotateStepInDegrees = 5; |
| 256 | 256 |
| 257 if (this._mode === WebInspector.TransformController.Modes.Rotate) { | 257 if (this._mode === LayerViewer.TransformController.Modes.Rotate) { |
| 258 // Sic! _onRotate treats X and Y as "rotate around X" and "rotate around Y
", so swap X/Y multiplers. | 258 // Sic! _onRotate treats X and Y as "rotate around X" and "rotate around Y
", so swap X/Y multiplers. |
| 259 this._onRotate( | 259 this._onRotate( |
| 260 this._rotateX + yMultiplier * rotateStepInDegrees, this._rotateY + xMu
ltiplier * rotateStepInDegrees); | 260 this._rotateX + yMultiplier * rotateStepInDegrees, this._rotateY + xMu
ltiplier * rotateStepInDegrees); |
| 261 } else { | 261 } else { |
| 262 this._onPan(xMultiplier * panStepInPixels, yMultiplier * panStepInPixels); | 262 this._onPan(xMultiplier * panStepInPixels, yMultiplier * panStepInPixels); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 | 265 |
| 266 /** | 266 /** |
| 267 * @param {!Event} event | 267 * @param {!Event} event |
| 268 */ | 268 */ |
| 269 _onMouseWheel(event) { | 269 _onMouseWheel(event) { |
| 270 /** @const */ | 270 /** @const */ |
| 271 var zoomFactor = 1.1; | 271 var zoomFactor = 1.1; |
| 272 /** @const */ | 272 /** @const */ |
| 273 var mouseWheelZoomSpeed = 1 / 120; | 273 var mouseWheelZoomSpeed = 1 / 120; |
| 274 var scaleFactor = Math.pow(zoomFactor, event.wheelDeltaY * mouseWheelZoomSpe
ed); | 274 var scaleFactor = Math.pow(zoomFactor, event.wheelDeltaY * mouseWheelZoomSpe
ed); |
| 275 this._onScale( | 275 this._onScale( |
| 276 scaleFactor, event.clientX - this.element.totalOffsetLeft(), event.clien
tY - this.element.totalOffsetTop()); | 276 scaleFactor, event.clientX - this.element.totalOffsetLeft(), event.clien
tY - this.element.totalOffsetTop()); |
| 277 } | 277 } |
| 278 | 278 |
| 279 /** | 279 /** |
| 280 * @param {!Event} event | 280 * @param {!Event} event |
| 281 */ | 281 */ |
| 282 _onDrag(event) { | 282 _onDrag(event) { |
| 283 if (this._mode === WebInspector.TransformController.Modes.Rotate) { | 283 if (this._mode === LayerViewer.TransformController.Modes.Rotate) { |
| 284 this._onRotate( | 284 this._onRotate( |
| 285 this._oldRotateX + (this._originY - event.clientY) / this.element.clie
ntHeight * 180, | 285 this._oldRotateX + (this._originY - event.clientY) / this.element.clie
ntHeight * 180, |
| 286 this._oldRotateY - (this._originX - event.clientX) / this.element.clie
ntWidth * 180); | 286 this._oldRotateY - (this._originX - event.clientX) / this.element.clie
ntWidth * 180); |
| 287 } else { | 287 } else { |
| 288 this._onPan(event.clientX - this._originX, event.clientY - this._originY); | 288 this._onPan(event.clientX - this._originX, event.clientY - this._originY); |
| 289 this._originX = event.clientX; | 289 this._originX = event.clientX; |
| 290 this._originY = event.clientY; | 290 this._originY = event.clientY; |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 | 293 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 305 | 305 |
| 306 _onDragEnd() { | 306 _onDragEnd() { |
| 307 delete this._originX; | 307 delete this._originX; |
| 308 delete this._originY; | 308 delete this._originY; |
| 309 delete this._oldRotateX; | 309 delete this._oldRotateX; |
| 310 delete this._oldRotateY; | 310 delete this._oldRotateY; |
| 311 } | 311 } |
| 312 }; | 312 }; |
| 313 | 313 |
| 314 /** @enum {symbol} */ | 314 /** @enum {symbol} */ |
| 315 WebInspector.TransformController.Events = { | 315 LayerViewer.TransformController.Events = { |
| 316 TransformChanged: Symbol('TransformChanged') | 316 TransformChanged: Symbol('TransformChanged') |
| 317 }; | 317 }; |
| 318 | 318 |
| 319 /** | 319 /** |
| 320 * @enum {string} | 320 * @enum {string} |
| 321 */ | 321 */ |
| 322 WebInspector.TransformController.Modes = { | 322 LayerViewer.TransformController.Modes = { |
| 323 Pan: 'Pan', | 323 Pan: 'Pan', |
| 324 Rotate: 'Rotate', | 324 Rotate: 'Rotate', |
| 325 }; | 325 }; |
| OLD | NEW |