| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @fileoverview | 6 * @fileoverview |
| 7 * Provide support for drag-and-drop operations in shaped windows. The | 7 * Provide support for drag-and-drop operations in shaped windows. The |
| 8 * standard API doesn't work because no "dragover" events are generated | 8 * standard API doesn't work because no "dragover" events are generated |
| 9 * if the mouse moves outside the window region. | 9 * if the mouse moves outside the window region. |
| 10 */ | 10 */ |
| 11 'use strict'; | 11 'use strict'; |
| 12 | 12 |
| 13 /** @suppress {duplicate} */ | 13 /** @suppress {duplicate} */ |
| 14 var remoting = remoting || {}; | 14 var remoting = remoting || {}; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * @constructor | 17 * @constructor |
| 18 * @param {Element} element The element to register for drag and drop. | 18 * @param {Element} element The element to register for drag and drop. |
| 19 * @param {function(number, number):void} dragUpdate Callback to receive the | 19 * @param {function(number, number):void} dragUpdate Callback to receive the |
| 20 * X and Y deltas as the element is dragged. | 20 * X and Y deltas as the element is dragged. |
| 21 * @param {function():void=} opt_dragStart Initiation callback. | 21 * @param {function():void=} opt_dragStart Initiation callback. |
| 22 * @param {function():void=} opt_dragEnd Completion callback. | 22 * @param {function():void=} opt_dragEnd Completion callback. |
| 23 */ | 23 */ |
| 24 remoting.DragAndDrop = function(element, dragUpdate, | 24 remoting.DragAndDrop = function(element, dragUpdate, |
| 25 opt_dragStart, opt_dragEnd) { | 25 opt_dragStart, opt_dragEnd) { |
| 26 /** | 26 /** @private */ |
| 27 * @private | |
| 28 */ | |
| 29 this.element_ = element; | 27 this.element_ = element; |
| 30 | 28 |
| 31 /** | 29 /** @private */ |
| 32 * @private | |
| 33 */ | |
| 34 this.dragUpdate_ = dragUpdate; | 30 this.dragUpdate_ = dragUpdate; |
| 35 | 31 |
| 36 /** | 32 /** @private */ |
| 37 * @private | |
| 38 */ | |
| 39 this.dragStart_ = opt_dragStart; | 33 this.dragStart_ = opt_dragStart; |
| 40 | 34 |
| 41 /** | 35 /** @private */ |
| 42 * @private | |
| 43 */ | |
| 44 this.dragEnd_ = opt_dragEnd; | 36 this.dragEnd_ = opt_dragEnd; |
| 45 | 37 |
| 46 /** | 38 /** @private {number} */ |
| 47 * @type {number} | |
| 48 * @private | |
| 49 */ | |
| 50 this.previousDeltaX_ = 0; | 39 this.previousDeltaX_ = 0; |
| 51 | 40 |
| 52 /** | 41 /** @private {number} */ |
| 53 * @type {number} | |
| 54 * @private | |
| 55 */ | |
| 56 this.previousDeltaY_ = 0; | 42 this.previousDeltaY_ = 0; |
| 57 | 43 |
| 58 /** | 44 /** @type {boolean} */ |
| 59 * @type {boolean} | |
| 60 */ | |
| 61 this.seenNonZeroDelta_ = false; | 45 this.seenNonZeroDelta_ = false; |
| 62 | 46 |
| 63 /** | 47 /** @private {function(Event):void} */ |
| 64 * @type {function(Event):void} | |
| 65 * @private | |
| 66 */ | |
| 67 this.callOnMouseUp_ = this.onMouseUp_.bind(this); | 48 this.callOnMouseUp_ = this.onMouseUp_.bind(this); |
| 68 | 49 |
| 69 /** | 50 /** @private {function(Event):void} */ |
| 70 * @type {function(Event):void} | |
| 71 * @private | |
| 72 */ | |
| 73 this.callOnMouseMove_ = this.onMouseMove_.bind(this); | 51 this.callOnMouseMove_ = this.onMouseMove_.bind(this); |
| 74 | 52 |
| 75 element.addEventListener('mousedown', this.onMouseDown_.bind(this), false); | 53 element.addEventListener('mousedown', this.onMouseDown_.bind(this), false); |
| 76 }; | 54 }; |
| 77 | 55 |
| 78 /** | 56 /** |
| 79 * @param {Event} event | 57 * @param {Event} event |
| 80 */ | 58 */ |
| 81 remoting.DragAndDrop.prototype.onMouseDown_ = function(event) { | 59 remoting.DragAndDrop.prototype.onMouseDown_ = function(event) { |
| 82 if (event.button != 0) { | 60 if (event.button != 0) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 * @param {Event} event | 111 * @param {Event} event |
| 134 */ | 112 */ |
| 135 remoting.DragAndDrop.prototype.onMouseUp_ = function(event) { | 113 remoting.DragAndDrop.prototype.onMouseUp_ = function(event) { |
| 136 this.element_.removeEventListener('mousemove', this.callOnMouseMove_, false); | 114 this.element_.removeEventListener('mousemove', this.callOnMouseMove_, false); |
| 137 this.element_.removeEventListener('mouseup', this.callOnMouseUp_, false); | 115 this.element_.removeEventListener('mouseup', this.callOnMouseUp_, false); |
| 138 document.exitPointerLock(); | 116 document.exitPointerLock(); |
| 139 if (this.dragEnd_) { | 117 if (this.dragEnd_) { |
| 140 this.dragEnd_(); | 118 this.dragEnd_(); |
| 141 } | 119 } |
| 142 }; | 120 }; |
| OLD | NEW |