Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 
| 3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 
| 4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). | 4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). | 
| 5 * Copyright (C) 2009 Joseph Pecoraro | 5 * Copyright (C) 2009 Joseph Pecoraro | 
| 6 * | 6 * | 
| 7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without | 
| 8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions | 
| 9 * are met: | 9 * are met: | 
| 10 * | 10 * | 
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 * @param {?string=} hoverCursor | 41 * @param {?string=} hoverCursor | 
| 42 * @param {number=} startDelay | 42 * @param {number=} startDelay | 
| 43 */ | 43 */ | 
| 44 WebInspector.installDragHandle = function(element, elementDragStart, elementDrag , elementDragEnd, cursor, hoverCursor, startDelay) | 44 WebInspector.installDragHandle = function(element, elementDragStart, elementDrag , elementDragEnd, cursor, hoverCursor, startDelay) | 
| 45 { | 45 { | 
| 46 /** | 46 /** | 
| 47 * @param {!Event} event | 47 * @param {!Event} event | 
| 48 */ | 48 */ | 
| 49 function onMouseDown(event) | 49 function onMouseDown(event) | 
| 50 { | 50 { | 
| 51 var dragStart = WebInspector.elementDragStart.bind(null, element, elemen tDragStart, elementDrag, elementDragEnd, cursor, event); | 51 var dragHandler = new WebInspector.DragHandler(); | 
| 52 var dragStart = dragHandler.elementDragStart.bind(dragHandler, element, elementDragStart, elementDrag, elementDragEnd, cursor, event); | |
| 52 if (startDelay) | 53 if (startDelay) | 
| 53 startTimer = setTimeout(dragStart, startDelay); | 54 startTimer = setTimeout(dragStart, startDelay); | 
| 54 else | 55 else | 
| 55 dragStart(); | 56 dragStart(); | 
| 56 } | 57 } | 
| 57 | 58 | 
| 58 function onMouseUp() | 59 function onMouseUp() | 
| 59 { | 60 { | 
| 60 if (startTimer) | 61 if (startTimer) | 
| 61 clearTimeout(startTimer); | 62 clearTimeout(startTimer); | 
| (...skipping 11 matching lines...) Expand all Loading... | |
| 73 /** | 74 /** | 
| 74 * @param {!Element} targetElement | 75 * @param {!Element} targetElement | 
| 75 * @param {?function(!MouseEvent):boolean} elementDragStart | 76 * @param {?function(!MouseEvent):boolean} elementDragStart | 
| 76 * @param {function(!MouseEvent)} elementDrag | 77 * @param {function(!MouseEvent)} elementDrag | 
| 77 * @param {?function(!MouseEvent)} elementDragEnd | 78 * @param {?function(!MouseEvent)} elementDragEnd | 
| 78 * @param {string} cursor | 79 * @param {string} cursor | 
| 79 * @param {!Event} event | 80 * @param {!Event} event | 
| 80 */ | 81 */ | 
| 81 WebInspector.elementDragStart = function(targetElement, elementDragStart, elemen tDrag, elementDragEnd, cursor, event) | 82 WebInspector.elementDragStart = function(targetElement, elementDragStart, elemen tDrag, elementDragEnd, cursor, event) | 
| 82 { | 83 { | 
| 84 var dragHandler = new WebInspector.DragHandler(); | |
| 85 dragHandler.elementDragStart(targetElement, elementDragStart, elementDrag, e lementDragEnd, cursor, event); | |
| 86 }; | |
| 87 | |
| 88 /** | |
| 89 * @constructor | |
| 90 */ | |
| 91 WebInspector.DragHandler = function() | |
| 92 { | |
| 93 this._elementDragMove = this._elementDragMove.bind(this); | |
| 94 this._elementDragEnd = this._elementDragEnd.bind(this); | |
| 95 this._mouseOutWhileDragging = this._mouseOutWhileDragging.bind(this); | |
| 96 } | |
| 97 | |
| 98 WebInspector.DragHandler._glassPaneUsageCount = 0; | |
| 99 | |
| 100 WebInspector.DragHandler.prototype = { | |
| 101 _createGlassPane: function() | |
| 102 { | |
| 103 this._glassPaneInUse = true; | |
| 104 if (!WebInspector.DragHandler._glassPaneUsageCount++) | |
| 105 WebInspector.DragHandler._glassPane = new WebInspector.GlassPane(thi s._mouseOutWhileDraggingTargetDocument); | |
| 
 
pfeldman
2016/10/26 19:30:07
_documentForMouseOut, also this will break on simu
 
 | |
| 106 }, | |
| 107 | |
| 108 _disposeGlassPane: function() | |
| 109 { | |
| 110 if (!this._glassPaneInUse) | |
| 111 return; | |
| 112 this._glassPaneInUse = false; | |
| 113 if (--WebInspector.DragHandler._glassPaneUsageCount) | |
| 114 return; | |
| 115 WebInspector.DragHandler._glassPane.dispose(); | |
| 116 delete WebInspector.DragHandler._glassPane; | |
| 117 } | |
| 118 }; | |
| 119 | |
| 120 /** | |
| 121 * @param {!Element} targetElement | |
| 122 * @param {?function(!MouseEvent):boolean} elementDragStart | |
| 123 * @param {function(!MouseEvent)} elementDrag | |
| 124 * @param {?function(!MouseEvent)} elementDragEnd | |
| 125 * @param {string} cursor | |
| 126 * @param {!Event} event | |
| 127 */ | |
| 128 WebInspector.DragHandler.prototype.elementDragStart = function(targetElement, el ementDragStart, elementDrag, elementDragEnd, cursor, event) | |
| 129 { | |
| 83 // Only drag upon left button. Right will likely cause a context menu. So wi ll ctrl-click on mac. | 130 // Only drag upon left button. Right will likely cause a context menu. So wi ll ctrl-click on mac. | 
| 84 if (event.button || (WebInspector.isMac() && event.ctrlKey)) | 131 if (event.button || (WebInspector.isMac() && event.ctrlKey)) | 
| 85 return; | 132 return; | 
| 86 | 133 | 
| 87 if (WebInspector._elementDraggingEventListener) | 134 if (this._elementDraggingEventListener) | 
| 88 return; | 135 return; | 
| 89 | 136 | 
| 90 if (elementDragStart && !elementDragStart(/** @type {!MouseEvent} */ (event) )) | 137 if (elementDragStart && !elementDragStart(/** @type {!MouseEvent} */ (event) )) | 
| 91 return; | 138 return; | 
| 92 | 139 | 
| 93 if (WebInspector._elementDraggingGlassPane) { | 140 this._disposeGlassPane(); | 
| 94 WebInspector._elementDraggingGlassPane.dispose(); | |
| 95 delete WebInspector._elementDraggingGlassPane; | |
| 96 } | |
| 97 | 141 | 
| 98 var targetDocument = event.target.ownerDocument; | 142 var targetDocument = event.target.ownerDocument; | 
| 99 | 143 | 
| 100 WebInspector._elementDraggingEventListener = elementDrag; | 144 this._elementDraggingEventListener = elementDrag; | 
| 101 WebInspector._elementEndDraggingEventListener = elementDragEnd; | 145 this._elementEndDraggingEventListener = elementDragEnd; | 
| 102 WebInspector._mouseOutWhileDraggingTargetDocument = targetDocument; | 146 this._mouseOutWhileDraggingTargetDocument = targetDocument; | 
| 103 WebInspector._dragEventsTargetDocument = targetDocument; | 147 this._dragEventsTargetDocument = targetDocument; | 
| 104 WebInspector._dragEventsTargetDocumentTop = targetDocument.defaultView.top.d ocument; | 148 this._dragEventsTargetDocumentTop = targetDocument.defaultView.top.document; | 
| 105 | 149 | 
| 106 targetDocument.addEventListener("mousemove", WebInspector._elementDragMove, true); | 150 targetDocument.addEventListener("mousemove", this._elementDragMove, true); | 
| 107 targetDocument.addEventListener("mouseup", WebInspector._elementDragEnd, tru e); | 151 targetDocument.addEventListener("mouseup", this._elementDragEnd, true); | 
| 108 targetDocument.addEventListener("mouseout", WebInspector._mouseOutWhileDragg ing, true); | 152 targetDocument.addEventListener("mouseout", this._mouseOutWhileDragging, tru e); | 
| 109 if (targetDocument !== WebInspector._dragEventsTargetDocumentTop) | 153 if (targetDocument !== this._dragEventsTargetDocumentTop) | 
| 110 WebInspector._dragEventsTargetDocumentTop.addEventListener("mouseup", We bInspector._elementDragEnd, true); | 154 this._dragEventsTargetDocumentTop.addEventListener("mouseup", this._elem entDragEnd, true); | 
| 111 | 155 | 
| 112 if (typeof cursor === "string") { | 156 if (typeof cursor === "string") { | 
| 113 WebInspector._restoreCursorAfterDrag = restoreCursor.bind(null, targetEl ement.style.cursor); | 157 this._restoreCursorAfterDrag = restoreCursor.bind(this, targetElement.st yle.cursor); | 
| 114 targetElement.style.cursor = cursor; | 158 targetElement.style.cursor = cursor; | 
| 115 targetDocument.body.style.cursor = cursor; | 159 targetDocument.body.style.cursor = cursor; | 
| 116 } | 160 } | 
| 161 /** | |
| 162 * @param {string} oldCursor | |
| 163 * @this {WebInspector.DragHandler} | |
| 164 */ | |
| 117 function restoreCursor(oldCursor) | 165 function restoreCursor(oldCursor) | 
| 118 { | 166 { | 
| 119 targetDocument.body.style.removeProperty("cursor"); | 167 targetDocument.body.style.removeProperty("cursor"); | 
| 120 targetElement.style.cursor = oldCursor; | 168 targetElement.style.cursor = oldCursor; | 
| 121 WebInspector._restoreCursorAfterDrag = null; | 169 this._restoreCursorAfterDrag = null; | 
| 122 } | 170 } | 
| 123 event.preventDefault(); | 171 event.preventDefault(); | 
| 124 }; | 172 }; | 
| 125 | 173 | 
| 126 WebInspector._mouseOutWhileDragging = function() | 174 WebInspector.DragHandler.prototype._mouseOutWhileDragging = function() | 
| 127 { | 175 { | 
| 128 var document = WebInspector._mouseOutWhileDraggingTargetDocument; | 176 this._unregisterMouseOutWhileDragging(); | 
| 129 WebInspector._unregisterMouseOutWhileDragging(); | 177 this._createGlassPane(); | 
| 130 WebInspector._elementDraggingGlassPane = new WebInspector.GlassPane(document ); | |
| 131 }; | 178 }; | 
| 132 | 179 | 
| 133 WebInspector._unregisterMouseOutWhileDragging = function() | 180 WebInspector.DragHandler.prototype._unregisterMouseOutWhileDragging = function() | 
| 134 { | 181 { | 
| 135 if (!WebInspector._mouseOutWhileDraggingTargetDocument) | 182 if (!this._mouseOutWhileDraggingTargetDocument) | 
| 136 return; | 183 return; | 
| 137 WebInspector._mouseOutWhileDraggingTargetDocument.removeEventListener("mouse out", WebInspector._mouseOutWhileDragging, true); | 184 this._mouseOutWhileDraggingTargetDocument.removeEventListener("mouseout", th is._mouseOutWhileDragging, true); | 
| 138 delete WebInspector._mouseOutWhileDraggingTargetDocument; | 185 delete this._mouseOutWhileDraggingTargetDocument; | 
| 139 }; | 186 }; | 
| 140 | 187 | 
| 141 WebInspector._unregisterDragEvents = function() | 188 WebInspector.DragHandler.prototype._unregisterDragEvents = function() | 
| 142 { | 189 { | 
| 143 if (!WebInspector._dragEventsTargetDocument) | 190 if (!this._dragEventsTargetDocument) | 
| 144 return; | 191 return; | 
| 145 WebInspector._dragEventsTargetDocument.removeEventListener("mousemove", WebI nspector._elementDragMove, true); | 192 this._dragEventsTargetDocument.removeEventListener("mousemove", this._elemen tDragMove, true); | 
| 146 WebInspector._dragEventsTargetDocument.removeEventListener("mouseup", WebIns pector._elementDragEnd, true); | 193 this._dragEventsTargetDocument.removeEventListener("mouseup", this._elementD ragEnd, true); | 
| 147 if (WebInspector._dragEventsTargetDocument !== WebInspector._dragEventsTarge tDocumentTop) | 194 if (this._dragEventsTargetDocument !== this._dragEventsTargetDocumentTop) | 
| 148 WebInspector._dragEventsTargetDocumentTop.removeEventListener("mouseup", WebInspector._elementDragEnd, true); | 195 this._dragEventsTargetDocumentTop.removeEventListener("mouseup", this._e lementDragEnd, true); | 
| 149 delete WebInspector._dragEventsTargetDocument; | 196 delete this._dragEventsTargetDocument; | 
| 150 delete WebInspector._dragEventsTargetDocumentTop; | 197 delete this._dragEventsTargetDocumentTop; | 
| 151 }; | 198 }; | 
| 152 | 199 | 
| 153 /** | 200 /** | 
| 154 * @param {!Event} event | 201 * @param {!Event} event | 
| 155 */ | 202 */ | 
| 156 WebInspector._elementDragMove = function(event) | 203 WebInspector.DragHandler.prototype._elementDragMove = function(event) | 
| 157 { | 204 { | 
| 158 if (event.buttons !== 1) { | 205 if (event.buttons !== 1) { | 
| 159 WebInspector._elementDragEnd(event); | 206 this._elementDragEnd(event); | 
| 160 return; | 207 return; | 
| 161 } | 208 } | 
| 162 | 209 if (this._elementDraggingEventListener(/** @type {!MouseEvent} */ (event))) | 
| 163 if (WebInspector._elementDraggingEventListener(/** @type {!MouseEvent} */ (e vent))) | 210 this._cancelDragEvents(event); | 
| 164 WebInspector._cancelDragEvents(event); | |
| 165 }; | 211 }; | 
| 166 | 212 | 
| 167 /** | 213 /** | 
| 168 * @param {!Event} event | 214 * @param {!Event} event | 
| 169 */ | 215 */ | 
| 170 WebInspector._cancelDragEvents = function(event) | 216 WebInspector.DragHandler.prototype._cancelDragEvents = function(event) | 
| 171 { | 217 { | 
| 172 WebInspector._unregisterDragEvents(); | 218 this._unregisterDragEvents(); | 
| 173 WebInspector._unregisterMouseOutWhileDragging(); | 219 this._unregisterMouseOutWhileDragging(); | 
| 174 | 220 | 
| 175 if (WebInspector._restoreCursorAfterDrag) | 221 if (this._restoreCursorAfterDrag) | 
| 176 WebInspector._restoreCursorAfterDrag(); | 222 this._restoreCursorAfterDrag(); | 
| 177 | 223 | 
| 178 if (WebInspector._elementDraggingGlassPane) | 224 this._disposeGlassPane(); | 
| 179 WebInspector._elementDraggingGlassPane.dispose(); | |
| 180 | 225 | 
| 181 delete WebInspector._elementDraggingGlassPane; | 226 delete this._elementDraggingEventListener; | 
| 182 delete WebInspector._elementDraggingEventListener; | 227 delete this._elementEndDraggingEventListener; | 
| 183 delete WebInspector._elementEndDraggingEventListener; | |
| 184 }; | 228 }; | 
| 185 | 229 | 
| 186 /** | 230 /** | 
| 187 * @param {!Event} event | 231 * @param {!Event} event | 
| 188 */ | 232 */ | 
| 189 WebInspector._elementDragEnd = function(event) | 233 WebInspector.DragHandler.prototype._elementDragEnd = function(event) | 
| 190 { | 234 { | 
| 191 var elementDragEnd = WebInspector._elementEndDraggingEventListener; | 235 var elementDragEnd = this._elementEndDraggingEventListener; | 
| 192 | 236 this._cancelDragEvents(/** @type {!MouseEvent} */ (event)); | 
| 193 WebInspector._cancelDragEvents(/** @type {!MouseEvent} */ (event)); | |
| 194 | |
| 195 event.preventDefault(); | 237 event.preventDefault(); | 
| 196 if (elementDragEnd) | 238 if (elementDragEnd) | 
| 197 elementDragEnd(/** @type {!MouseEvent} */ (event)); | 239 elementDragEnd(/** @type {!MouseEvent} */ (event)); | 
| 198 }; | 240 }; | 
| 199 | 241 | 
| 200 /** | 242 /** | 
| 201 * @param {!Element} element | 243 * @param {!Element} element | 
| 202 * @param {function(number, number, !MouseEvent): boolean} elementDragStart | 244 * @param {function(number, number, !MouseEvent): boolean} elementDragStart | 
| 203 * @param {function(number, number)} elementDrag | 245 * @param {function(number, number)} elementDrag | 
| 204 * @param {function(number, number)} elementDragEnd | 246 * @param {function(number, number)} elementDragEnd | 
| (...skipping 1733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1938 * @param {string} title | 1980 * @param {string} title | 
| 1939 * @return {!Element} | 1981 * @return {!Element} | 
| 1940 */ | 1982 */ | 
| 1941 WebInspector.linkifyDocumentationURLAsNode = function(article, title) | 1983 WebInspector.linkifyDocumentationURLAsNode = function(article, title) | 
| 1942 { | 1984 { | 
| 1943 return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool s/chrome-devtools/" + article, title, undefined, true); | 1985 return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool s/chrome-devtools/" + article, title, undefined, true); | 
| 1944 }; | 1986 }; | 
| 1945 | 1987 | 
| 1946 /** @type {!WebInspector.ThemeSupport} */ | 1988 /** @type {!WebInspector.ThemeSupport} */ | 
| 1947 WebInspector.themeSupport; | 1989 WebInspector.themeSupport; | 
| OLD | NEW |