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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 _disposeGlassPane: function() | 108 _disposeGlassPane: function() |
109 { | 109 { |
110 if (!this._glassPaneInUse) | 110 if (!this._glassPaneInUse) |
111 return; | 111 return; |
112 this._glassPaneInUse = false; | 112 this._glassPaneInUse = false; |
113 if (--WebInspector.DragHandler._glassPaneUsageCount) | 113 if (--WebInspector.DragHandler._glassPaneUsageCount) |
114 return; | 114 return; |
115 WebInspector.DragHandler._glassPane.dispose(); | 115 WebInspector.DragHandler._glassPane.dispose(); |
116 delete WebInspector.DragHandler._glassPane; | 116 delete WebInspector.DragHandler._glassPane; |
117 delete WebInspector.DragHandler._documentForMouseOut; | 117 delete WebInspector.DragHandler._documentForMouseOut; |
| 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 elementDragStart: function(targetElement, elementDragStart, elementDrag, ele
mentDragEnd, cursor, event) |
| 129 { |
| 130 // Only drag upon left button. Right will likely cause a context menu. S
o will ctrl-click on mac. |
| 131 if (event.button || (WebInspector.isMac() && event.ctrlKey)) |
| 132 return; |
| 133 |
| 134 if (this._elementDraggingEventListener) |
| 135 return; |
| 136 |
| 137 if (elementDragStart && !elementDragStart(/** @type {!MouseEvent} */ (ev
ent))) |
| 138 return; |
| 139 |
| 140 var targetDocument = event.target.ownerDocument; |
| 141 this._elementDraggingEventListener = elementDrag; |
| 142 this._elementEndDraggingEventListener = elementDragEnd; |
| 143 console.assert((WebInspector.DragHandler._documentForMouseOut || targetD
ocument) === targetDocument, |
| 144 "Dragging on multiple documents."); |
| 145 WebInspector.DragHandler._documentForMouseOut = targetDocument; |
| 146 this._dragEventsTargetDocument = targetDocument; |
| 147 this._dragEventsTargetDocumentTop = targetDocument.defaultView.top.docum
ent; |
| 148 |
| 149 targetDocument.addEventListener("mousemove", this._elementDragMove, true
); |
| 150 targetDocument.addEventListener("mouseup", this._elementDragEnd, true); |
| 151 targetDocument.addEventListener("mouseout", this._mouseOutWhileDragging,
true); |
| 152 if (targetDocument !== this._dragEventsTargetDocumentTop) |
| 153 this._dragEventsTargetDocumentTop.addEventListener("mouseup", this._
elementDragEnd, true); |
| 154 |
| 155 if (typeof cursor === "string") { |
| 156 this._restoreCursorAfterDrag = restoreCursor.bind(this, targetElemen
t.style.cursor); |
| 157 targetElement.style.cursor = cursor; |
| 158 targetDocument.body.style.cursor = cursor; |
| 159 } |
| 160 /** |
| 161 * @param {string} oldCursor |
| 162 * @this {WebInspector.DragHandler} |
| 163 */ |
| 164 function restoreCursor(oldCursor) |
| 165 { |
| 166 targetDocument.body.style.removeProperty("cursor"); |
| 167 targetElement.style.cursor = oldCursor; |
| 168 this._restoreCursorAfterDrag = null; |
| 169 } |
| 170 event.preventDefault(); |
| 171 }, |
| 172 |
| 173 _mouseOutWhileDragging: function() |
| 174 { |
| 175 this._unregisterMouseOutWhileDragging(); |
| 176 this._createGlassPane(); |
| 177 }, |
| 178 |
| 179 _unregisterMouseOutWhileDragging: function() |
| 180 { |
| 181 if (!WebInspector.DragHandler._documentForMouseOut) |
| 182 return; |
| 183 WebInspector.DragHandler._documentForMouseOut.removeEventListener("mouse
out", this._mouseOutWhileDragging, true); |
| 184 }, |
| 185 |
| 186 _unregisterDragEvents: function() |
| 187 { |
| 188 if (!this._dragEventsTargetDocument) |
| 189 return; |
| 190 this._dragEventsTargetDocument.removeEventListener("mousemove", this._el
ementDragMove, true); |
| 191 this._dragEventsTargetDocument.removeEventListener("mouseup", this._elem
entDragEnd, true); |
| 192 if (this._dragEventsTargetDocument !== this._dragEventsTargetDocumentTop
) |
| 193 this._dragEventsTargetDocumentTop.removeEventListener("mouseup", thi
s._elementDragEnd, true); |
| 194 delete this._dragEventsTargetDocument; |
| 195 delete this._dragEventsTargetDocumentTop; |
| 196 }, |
| 197 |
| 198 /** |
| 199 * @param {!Event} event |
| 200 */ |
| 201 _elementDragMove: function(event) |
| 202 { |
| 203 if (event.buttons !== 1) { |
| 204 this._elementDragEnd(event); |
| 205 return; |
| 206 } |
| 207 if (this._elementDraggingEventListener(/** @type {!MouseEvent} */ (event
))) |
| 208 this._cancelDragEvents(event); |
| 209 }, |
| 210 |
| 211 /** |
| 212 * @param {!Event} event |
| 213 */ |
| 214 _cancelDragEvents: function(event) |
| 215 { |
| 216 this._unregisterDragEvents(); |
| 217 this._unregisterMouseOutWhileDragging(); |
| 218 |
| 219 if (this._restoreCursorAfterDrag) |
| 220 this._restoreCursorAfterDrag(); |
| 221 |
| 222 this._disposeGlassPane(); |
| 223 |
| 224 delete this._elementDraggingEventListener; |
| 225 delete this._elementEndDraggingEventListener; |
| 226 }, |
| 227 |
| 228 /** |
| 229 * @param {!Event} event |
| 230 */ |
| 231 _elementDragEnd: function(event) |
| 232 { |
| 233 var elementDragEnd = this._elementEndDraggingEventListener; |
| 234 this._cancelDragEvents(/** @type {!MouseEvent} */ (event)); |
| 235 event.preventDefault(); |
| 236 if (elementDragEnd) |
| 237 elementDragEnd(/** @type {!MouseEvent} */ (event)); |
118 } | 238 } |
119 }; | 239 }; |
120 | 240 |
121 /** | 241 /** |
122 * @param {!Element} targetElement | |
123 * @param {?function(!MouseEvent):boolean} elementDragStart | |
124 * @param {function(!MouseEvent)} elementDrag | |
125 * @param {?function(!MouseEvent)} elementDragEnd | |
126 * @param {string} cursor | |
127 * @param {!Event} event | |
128 */ | |
129 WebInspector.DragHandler.prototype.elementDragStart = function(targetElement, el
ementDragStart, elementDrag, elementDragEnd, cursor, event) | |
130 { | |
131 // Only drag upon left button. Right will likely cause a context menu. So wi
ll ctrl-click on mac. | |
132 if (event.button || (WebInspector.isMac() && event.ctrlKey)) | |
133 return; | |
134 | |
135 if (this._elementDraggingEventListener) | |
136 return; | |
137 | |
138 if (elementDragStart && !elementDragStart(/** @type {!MouseEvent} */ (event)
)) | |
139 return; | |
140 | |
141 var targetDocument = event.target.ownerDocument; | |
142 this._elementDraggingEventListener = elementDrag; | |
143 this._elementEndDraggingEventListener = elementDragEnd; | |
144 console.assert((WebInspector.DragHandler._documentForMouseOut || targetDocum
ent) === targetDocument, | |
145 "Dragging on multiple documents."); | |
146 WebInspector.DragHandler._documentForMouseOut = targetDocument; | |
147 this._dragEventsTargetDocument = targetDocument; | |
148 this._dragEventsTargetDocumentTop = targetDocument.defaultView.top.document; | |
149 | |
150 targetDocument.addEventListener("mousemove", this._elementDragMove, true); | |
151 targetDocument.addEventListener("mouseup", this._elementDragEnd, true); | |
152 targetDocument.addEventListener("mouseout", this._mouseOutWhileDragging, tru
e); | |
153 if (targetDocument !== this._dragEventsTargetDocumentTop) | |
154 this._dragEventsTargetDocumentTop.addEventListener("mouseup", this._elem
entDragEnd, true); | |
155 | |
156 if (typeof cursor === "string") { | |
157 this._restoreCursorAfterDrag = restoreCursor.bind(this, targetElement.st
yle.cursor); | |
158 targetElement.style.cursor = cursor; | |
159 targetDocument.body.style.cursor = cursor; | |
160 } | |
161 /** | |
162 * @param {string} oldCursor | |
163 * @this {WebInspector.DragHandler} | |
164 */ | |
165 function restoreCursor(oldCursor) | |
166 { | |
167 targetDocument.body.style.removeProperty("cursor"); | |
168 targetElement.style.cursor = oldCursor; | |
169 this._restoreCursorAfterDrag = null; | |
170 } | |
171 event.preventDefault(); | |
172 }; | |
173 | |
174 WebInspector.DragHandler.prototype._mouseOutWhileDragging = function() | |
175 { | |
176 this._unregisterMouseOutWhileDragging(); | |
177 this._createGlassPane(); | |
178 }; | |
179 | |
180 WebInspector.DragHandler.prototype._unregisterMouseOutWhileDragging = function() | |
181 { | |
182 if (!WebInspector.DragHandler._documentForMouseOut) | |
183 return; | |
184 WebInspector.DragHandler._documentForMouseOut.removeEventListener("mouseout"
, this._mouseOutWhileDragging, true); | |
185 }; | |
186 | |
187 WebInspector.DragHandler.prototype._unregisterDragEvents = function() | |
188 { | |
189 if (!this._dragEventsTargetDocument) | |
190 return; | |
191 this._dragEventsTargetDocument.removeEventListener("mousemove", this._elemen
tDragMove, true); | |
192 this._dragEventsTargetDocument.removeEventListener("mouseup", this._elementD
ragEnd, true); | |
193 if (this._dragEventsTargetDocument !== this._dragEventsTargetDocumentTop) | |
194 this._dragEventsTargetDocumentTop.removeEventListener("mouseup", this._e
lementDragEnd, true); | |
195 delete this._dragEventsTargetDocument; | |
196 delete this._dragEventsTargetDocumentTop; | |
197 }; | |
198 | |
199 /** | |
200 * @param {!Event} event | |
201 */ | |
202 WebInspector.DragHandler.prototype._elementDragMove = function(event) | |
203 { | |
204 if (event.buttons !== 1) { | |
205 this._elementDragEnd(event); | |
206 return; | |
207 } | |
208 if (this._elementDraggingEventListener(/** @type {!MouseEvent} */ (event))) | |
209 this._cancelDragEvents(event); | |
210 }; | |
211 | |
212 /** | |
213 * @param {!Event} event | |
214 */ | |
215 WebInspector.DragHandler.prototype._cancelDragEvents = function(event) | |
216 { | |
217 this._unregisterDragEvents(); | |
218 this._unregisterMouseOutWhileDragging(); | |
219 | |
220 if (this._restoreCursorAfterDrag) | |
221 this._restoreCursorAfterDrag(); | |
222 | |
223 this._disposeGlassPane(); | |
224 | |
225 delete this._elementDraggingEventListener; | |
226 delete this._elementEndDraggingEventListener; | |
227 }; | |
228 | |
229 /** | |
230 * @param {!Event} event | |
231 */ | |
232 WebInspector.DragHandler.prototype._elementDragEnd = function(event) | |
233 { | |
234 var elementDragEnd = this._elementEndDraggingEventListener; | |
235 this._cancelDragEvents(/** @type {!MouseEvent} */ (event)); | |
236 event.preventDefault(); | |
237 if (elementDragEnd) | |
238 elementDragEnd(/** @type {!MouseEvent} */ (event)); | |
239 }; | |
240 | |
241 /** | |
242 * @param {!Element} element | 242 * @param {!Element} element |
243 * @param {function(number, number, !MouseEvent): boolean} elementDragStart | 243 * @param {function(number, number, !MouseEvent): boolean} elementDragStart |
244 * @param {function(number, number)} elementDrag | 244 * @param {function(number, number)} elementDrag |
245 * @param {function(number, number)} elementDragEnd | 245 * @param {function(number, number)} elementDragEnd |
246 * @param {string} cursor | 246 * @param {string} cursor |
247 * @param {?string=} hoverCursor | 247 * @param {?string=} hoverCursor |
248 * @param {number=} startDelay | 248 * @param {number=} startDelay |
249 * @param {number=} friction | 249 * @param {number=} friction |
250 */ | 250 */ |
251 WebInspector.installInertialDragHandle = function(element, elementDragStart, ele
mentDrag, elementDragEnd, cursor, hoverCursor, startDelay, friction) | 251 WebInspector.installInertialDragHandle = function(element, elementDragStart, ele
mentDrag, elementDragEnd, cursor, hoverCursor, startDelay, friction) |
(...skipping 1741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1993 return new Promise(fulfill => { | 1993 return new Promise(fulfill => { |
1994 var image = new Image(); | 1994 var image = new Image(); |
1995 image.addEventListener("load", () => fulfill(image)); | 1995 image.addEventListener("load", () => fulfill(image)); |
1996 image.addEventListener("error", () => fulfill(null)); | 1996 image.addEventListener("error", () => fulfill(null)); |
1997 image.src = url; | 1997 image.src = url; |
1998 }); | 1998 }); |
1999 }; | 1999 }; |
2000 | 2000 |
2001 /** @type {!WebInspector.ThemeSupport} */ | 2001 /** @type {!WebInspector.ThemeSupport} */ |
2002 WebInspector.themeSupport; | 2002 WebInspector.themeSupport; |
OLD | NEW |