| 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(Web
      Inspector.DragHandler._documentForMouseOut); | 
 |   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         delete WebInspector.DragHandler._documentForMouseOut; | 
 |   118     } | 
 |   119 }; | 
 |   120  | 
 |   121 /** | 
 |   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 { | 
|    83     // Only drag upon left button. Right will likely cause a context menu. So wi
      ll ctrl-click on mac. |   131     // 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)) |   132     if (event.button || (WebInspector.isMac() && event.ctrlKey)) | 
|    85         return; |   133         return; | 
|    86  |   134  | 
|    87     if (WebInspector._elementDraggingEventListener) |   135     if (this._elementDraggingEventListener) | 
|    88         return; |   136         return; | 
|    89  |   137  | 
|    90     if (elementDragStart && !elementDragStart(/** @type {!MouseEvent} */ (event)
      )) |   138     if (elementDragStart && !elementDragStart(/** @type {!MouseEvent} */ (event)
      )) | 
|    91         return; |   139         return; | 
|    92  |   140  | 
|    93     if (WebInspector._elementDraggingGlassPane) { |   141     var targetDocument = event.target.ownerDocument; | 
|    94         WebInspector._elementDraggingGlassPane.dispose(); |   142     this._elementDraggingEventListener = elementDrag; | 
|    95         delete WebInspector._elementDraggingGlassPane; |   143     this._elementEndDraggingEventListener = elementDragEnd; | 
|    96     } |   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; | 
|    97  |   149  | 
|    98     var targetDocument = event.target.ownerDocument; |   150     targetDocument.addEventListener("mousemove", this._elementDragMove, true); | 
|    99  |   151     targetDocument.addEventListener("mouseup", this._elementDragEnd, true); | 
|   100     WebInspector._elementDraggingEventListener = elementDrag; |   152     targetDocument.addEventListener("mouseout", this._mouseOutWhileDragging, tru
      e); | 
|   101     WebInspector._elementEndDraggingEventListener = elementDragEnd; |   153     if (targetDocument !== this._dragEventsTargetDocumentTop) | 
|   102     WebInspector._mouseOutWhileDraggingTargetDocument = targetDocument; |   154         this._dragEventsTargetDocumentTop.addEventListener("mouseup", this._elem
      entDragEnd, true); | 
|   103     WebInspector._dragEventsTargetDocument = targetDocument; |  | 
|   104     WebInspector._dragEventsTargetDocumentTop = targetDocument.defaultView.top.d
      ocument; |  | 
|   105  |  | 
|   106     targetDocument.addEventListener("mousemove", WebInspector._elementDragMove, 
      true); |  | 
|   107     targetDocument.addEventListener("mouseup", WebInspector._elementDragEnd, tru
      e); |  | 
|   108     targetDocument.addEventListener("mouseout", WebInspector._mouseOutWhileDragg
      ing, true); |  | 
|   109     if (targetDocument !== WebInspector._dragEventsTargetDocumentTop) |  | 
|   110         WebInspector._dragEventsTargetDocumentTop.addEventListener("mouseup", We
      bInspector._elementDragEnd, 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 (!WebInspector.DragHandler._documentForMouseOut) | 
|   136         return; |   183         return; | 
|   137     WebInspector._mouseOutWhileDraggingTargetDocument.removeEventListener("mouse
      out", WebInspector._mouseOutWhileDragging, true); |   184     WebInspector.DragHandler._documentForMouseOut.removeEventListener("mouseout"
      , this._mouseOutWhileDragging, true); | 
|   138     delete WebInspector._mouseOutWhileDraggingTargetDocument; |  | 
|   139 }; |   185 }; | 
|   140  |   186  | 
|   141 WebInspector._unregisterDragEvents = function() |   187 WebInspector.DragHandler.prototype._unregisterDragEvents = function() | 
|   142 { |   188 { | 
|   143     if (!WebInspector._dragEventsTargetDocument) |   189     if (!this._dragEventsTargetDocument) | 
|   144         return; |   190         return; | 
|   145     WebInspector._dragEventsTargetDocument.removeEventListener("mousemove", WebI
      nspector._elementDragMove, true); |   191     this._dragEventsTargetDocument.removeEventListener("mousemove", this._elemen
      tDragMove, true); | 
|   146     WebInspector._dragEventsTargetDocument.removeEventListener("mouseup", WebIns
      pector._elementDragEnd, true); |   192     this._dragEventsTargetDocument.removeEventListener("mouseup", this._elementD
      ragEnd, true); | 
|   147     if (WebInspector._dragEventsTargetDocument !== WebInspector._dragEventsTarge
      tDocumentTop) |   193     if (this._dragEventsTargetDocument !== this._dragEventsTargetDocumentTop) | 
|   148         WebInspector._dragEventsTargetDocumentTop.removeEventListener("mouseup",
       WebInspector._elementDragEnd, true); |   194         this._dragEventsTargetDocumentTop.removeEventListener("mouseup", this._e
      lementDragEnd, true); | 
|   149     delete WebInspector._dragEventsTargetDocument; |   195     delete this._dragEventsTargetDocument; | 
|   150     delete WebInspector._dragEventsTargetDocumentTop; |   196     delete this._dragEventsTargetDocumentTop; | 
|   151 }; |   197 }; | 
|   152  |   198  | 
|   153 /** |   199 /** | 
|   154  * @param {!Event} event |   200  * @param {!Event} event | 
|   155  */ |   201  */ | 
|   156 WebInspector._elementDragMove = function(event) |   202 WebInspector.DragHandler.prototype._elementDragMove = function(event) | 
|   157 { |   203 { | 
|   158     if (event.buttons !== 1) { |   204     if (event.buttons !== 1) { | 
|   159         WebInspector._elementDragEnd(event); |   205         this._elementDragEnd(event); | 
|   160         return; |   206         return; | 
|   161     } |   207     } | 
|   162  |   208     if (this._elementDraggingEventListener(/** @type {!MouseEvent} */ (event))) | 
|   163     if (WebInspector._elementDraggingEventListener(/** @type {!MouseEvent} */ (e
      vent))) |   209         this._cancelDragEvents(event); | 
|   164         WebInspector._cancelDragEvents(event); |  | 
|   165 }; |   210 }; | 
|   166  |   211  | 
|   167 /** |   212 /** | 
|   168  * @param {!Event} event |   213  * @param {!Event} event | 
|   169  */ |   214  */ | 
|   170 WebInspector._cancelDragEvents = function(event) |   215 WebInspector.DragHandler.prototype._cancelDragEvents = function(event) | 
|   171 { |   216 { | 
|   172     WebInspector._unregisterDragEvents(); |   217     this._unregisterDragEvents(); | 
|   173     WebInspector._unregisterMouseOutWhileDragging(); |   218     this._unregisterMouseOutWhileDragging(); | 
|   174  |   219  | 
|   175     if (WebInspector._restoreCursorAfterDrag) |   220     if (this._restoreCursorAfterDrag) | 
|   176         WebInspector._restoreCursorAfterDrag(); |   221         this._restoreCursorAfterDrag(); | 
|   177  |   222  | 
|   178     if (WebInspector._elementDraggingGlassPane) |   223     this._disposeGlassPane(); | 
|   179         WebInspector._elementDraggingGlassPane.dispose(); |  | 
|   180  |   224  | 
|   181     delete WebInspector._elementDraggingGlassPane; |   225     delete this._elementDraggingEventListener; | 
|   182     delete WebInspector._elementDraggingEventListener; |   226     delete this._elementEndDraggingEventListener; | 
|   183     delete WebInspector._elementEndDraggingEventListener; |  | 
|   184 }; |   227 }; | 
|   185  |   228  | 
|   186 /** |   229 /** | 
|   187  * @param {!Event} event |   230  * @param {!Event} event | 
|   188  */ |   231  */ | 
|   189 WebInspector._elementDragEnd = function(event) |   232 WebInspector.DragHandler.prototype._elementDragEnd = function(event) | 
|   190 { |   233 { | 
|   191     var elementDragEnd = WebInspector._elementEndDraggingEventListener; |   234     var elementDragEnd = this._elementEndDraggingEventListener; | 
|   192  |   235     this._cancelDragEvents(/** @type {!MouseEvent} */ (event)); | 
|   193     WebInspector._cancelDragEvents(/** @type {!MouseEvent} */ (event)); |  | 
|   194  |  | 
|   195     event.preventDefault(); |   236     event.preventDefault(); | 
|   196     if (elementDragEnd) |   237     if (elementDragEnd) | 
|   197         elementDragEnd(/** @type {!MouseEvent} */ (event)); |   238         elementDragEnd(/** @type {!MouseEvent} */ (event)); | 
|   198 }; |   239 }; | 
|   199  |   240  | 
|   200 /** |   241 /** | 
|   201  * @param {!Element} element |   242  * @param {!Element} element | 
|   202  * @param {function(number, number, !MouseEvent): boolean} elementDragStart |   243  * @param {function(number, number, !MouseEvent): boolean} elementDragStart | 
|   203  * @param {function(number, number)} elementDrag |   244  * @param {function(number, number)} elementDrag | 
|   204  * @param {function(number, number)} elementDragEnd |   245  * @param {function(number, number)} elementDragEnd | 
| (...skipping 1733 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1938  * @param {string} title |  1979  * @param {string} title | 
|  1939  * @return {!Element} |  1980  * @return {!Element} | 
|  1940  */ |  1981  */ | 
|  1941 WebInspector.linkifyDocumentationURLAsNode = function(article, title) |  1982 WebInspector.linkifyDocumentationURLAsNode = function(article, title) | 
|  1942 { |  1983 { | 
|  1943     return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool
      s/chrome-devtools/" + article, title, undefined, true); |  1984     return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool
      s/chrome-devtools/" + article, title, undefined, true); | 
|  1944 }; |  1985 }; | 
|  1945  |  1986  | 
|  1946 /** @type {!WebInspector.ThemeSupport} */ |  1987 /** @type {!WebInspector.ThemeSupport} */ | 
|  1947 WebInspector.themeSupport; |  1988 WebInspector.themeSupport; | 
| OLD | NEW |