Web Inspector: drag/drop over the sidebar should load an imported file in Canvas...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Apr 2019 18:58:27 +0000 (18:58 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Apr 2019 18:58:27 +0000 (18:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196873
<rdar://problem/49858190>

Reviewed by Timothy Hatcher.

* UserInterface/Base/Main.js:
(WI.contentLoaded):
(WI._handleDragOver): Added.
(WI._handleDrop): Added.
(WI._dragOver): Deleted.
* UserInterface/Views/AuditTabContentView.js:
(WI.AuditTabContentView):
(WI.AuditTabContentView.prototype.async handleFileDrop): Added.
(WI.AuditTabContentView.prototype._handleDragOver): Deleted.
(WI.AuditTabContentView.prototype._handleDrop): Deleted.
* UserInterface/Views/CanvasTabContentView.js:
(WI.CanvasTabContentView):
(WI.CanvasTabContentView.prototype.async handleFileDrop): Added.
(WI.CanvasTabContentView.prototype._handleDragOver): Deleted.
(WI.CanvasTabContentView.prototype._handleDrop): Deleted.
* UserInterface/Views/TimelineTabContentView.js:
(WI.TimelineTabContentView.prototype.async handleFileDrop): Added.
Check whether the current tab is able to handle a file drop, and if so, don't prevent the
drag from occuring. This now allows the user to drop anywhere on the Web Inspector area to
import files, so long as the relevant tab is currently selected.

* UserInterface/Controllers/CanvasManager.js:
(WI.CanvasManager.prototype.async processJSON): Added.
(WI.CanvasManager.prototype.processJSON): Deleted.
* UserInterface/Controllers/TimelineManager.js:
(WI.TimelineManager.prototype.async processJSON): Added.
(WI.TimelineManager.prototype.processJSON): Deleted.
Make `async` to match other `processJSON` functions.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244278 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/Main.js
Source/WebInspectorUI/UserInterface/Controllers/CanvasManager.js
Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js
Source/WebInspectorUI/UserInterface/Views/AuditTabContentView.js
Source/WebInspectorUI/UserInterface/Views/CanvasTabContentView.js
Source/WebInspectorUI/UserInterface/Views/TimelineTabContentView.js

index 31306c8..f18f4ec 100644 (file)
@@ -1,5 +1,42 @@
 2019-04-15  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: drag/drop over the sidebar should load an imported file in Canvas/Audit tab
+        https://bugs.webkit.org/show_bug.cgi?id=196873
+        <rdar://problem/49858190>
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Base/Main.js:
+        (WI.contentLoaded):
+        (WI._handleDragOver): Added.
+        (WI._handleDrop): Added.
+        (WI._dragOver): Deleted.
+        * UserInterface/Views/AuditTabContentView.js:
+        (WI.AuditTabContentView):
+        (WI.AuditTabContentView.prototype.async handleFileDrop): Added.
+        (WI.AuditTabContentView.prototype._handleDragOver): Deleted.
+        (WI.AuditTabContentView.prototype._handleDrop): Deleted.
+        * UserInterface/Views/CanvasTabContentView.js:
+        (WI.CanvasTabContentView):
+        (WI.CanvasTabContentView.prototype.async handleFileDrop): Added.
+        (WI.CanvasTabContentView.prototype._handleDragOver): Deleted.
+        (WI.CanvasTabContentView.prototype._handleDrop): Deleted.
+        * UserInterface/Views/TimelineTabContentView.js:
+        (WI.TimelineTabContentView.prototype.async handleFileDrop): Added.
+        Check whether the current tab is able to handle a file drop, and if so, don't prevent the
+        drag from occuring. This now allows the user to drop anywhere on the Web Inspector area to
+        import files, so long as the relevant tab is currently selected.
+
+        * UserInterface/Controllers/CanvasManager.js:
+        (WI.CanvasManager.prototype.async processJSON): Added.
+        (WI.CanvasManager.prototype.processJSON): Deleted.
+        * UserInterface/Controllers/TimelineManager.js:
+        (WI.TimelineManager.prototype.async processJSON): Added.
+        (WI.TimelineManager.prototype.processJSON): Deleted.
+        Make `async` to match other `processJSON` functions.
+
+2019-04-15  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Heap: logging an object from a snapshot shouldn't use the "special" style if the object is reachable
         https://bugs.webkit.org/show_bug.cgi?id=196889
         <rdar://problem/49870693>
index 11c76dd..ab08d2e 100644 (file)
@@ -271,7 +271,8 @@ WI.contentLoaded = function()
     document.addEventListener("copy", WI._copy);
 
     document.addEventListener("click", WI._mouseWasClicked);
-    document.addEventListener("dragover", WI._dragOver);
+    document.addEventListener("dragover", WI._handleDragOver);
+    document.addEventListener("drop", WI._handleDrop);
     document.addEventListener("focus", WI._focusChanged, true);
 
     window.addEventListener("focus", WI._windowFocused);
@@ -1523,7 +1524,7 @@ WI._mouseWasClicked = function(event)
     WI.handlePossibleLinkClick(event);
 };
 
-WI._dragOver = function(event)
+WI._handleDragOver = function(event)
 {
     // Do nothing if another event listener handled the event already.
     if (event.defaultPrevented)
@@ -1533,11 +1534,36 @@ WI._dragOver = function(event)
     if (WI.isEventTargetAnEditableField(event))
         return;
 
-    // Prevent the drop from being accepted.
-    event.dataTransfer.dropEffect = "none";
+    let tabContentView = WI.tabBrowser.selectedTabContentView;
+    if (!tabContentView || !tabContentView.handleFileDrop || !event.dataTransfer.types.includes("Files")) {
+        // Prevent the drop from being accepted.
+        event.dataTransfer.dropEffect = "none";
+    }
+
     event.preventDefault();
 };
 
+WI._handleDrop = function(event)
+{
+    // Do nothing if another event listener handled the event already.
+    if (event.defaultPrevented)
+        return;
+
+    // Allow dropping into editable areas.
+    if (WI.isEventTargetAnEditableField(event))
+        return;
+
+    let tabContentView = WI.tabBrowser.selectedTabContentView;
+    if (tabContentView && tabContentView.handleFileDrop && event.dataTransfer.files) {
+        event.preventDefault();
+
+        tabContentView.handleFileDrop(event.dataTransfer.files)
+        .then(() => {
+            event.dataTransfer.clearData();
+        });
+    }
+};
+
 WI._debuggerDidPause = function(event)
 {
     if (WI.settings.experimentalEnableSourcesTab.value)
index 714a529..a480c1d 100644 (file)
@@ -75,7 +75,7 @@ WI.CanvasManager = class CanvasManager extends WI.Object
         return Array.from(this._shaderProgramIdentifierMap.values());
     }
 
-    processJSON({filename, json, error})
+    async processJSON({filename, json, error})
     {
         if (error) {
             WI.Recording.synthesizeError(error);
index bb52dcf..fe514c7 100644 (file)
@@ -264,7 +264,7 @@ WI.TimelineManager = class TimelineManager extends WI.Object
         this._activeRecording.stop(this._initiatedByBackendStop);
     }
 
-    processJSON({filename, json, error})
+    async processJSON({filename, json, error})
     {
         if (error) {
             WI.TimelineManager.synthesizeImportError(error);
index 9a9e68e..f0cc9cb 100644 (file)
@@ -32,9 +32,6 @@ WI.AuditTabContentView = class AuditTabContentView extends WI.ContentBrowserTabC
         this._startStopShortcut = new WI.KeyboardShortcut(null, WI.KeyboardShortcut.Key.Space, this._handleSpace.bind(this));
         this._startStopShortcut.implicitlyPreventsDefault = false;
         this._startStopShortcut.disabled = true;
-
-        this.element.addEventListener("dragover", this._handleDragOver.bind(this));
-        this.element.addEventListener("drop", this._handleDrop.bind(this));
     }
 
     // Static
@@ -86,6 +83,11 @@ WI.AuditTabContentView = class AuditTabContentView extends WI.ContentBrowserTabC
         super.hidden();
     }
 
+    async handleFileDrop(files)
+    {
+        await WI.FileUtilities.readJSON(files, (result) => WI.auditManager.processJSON(result));
+    }
+
     // Protected
 
     initialLayout()
@@ -111,25 +113,6 @@ WI.AuditTabContentView = class AuditTabContentView extends WI.ContentBrowserTabC
 
         event.preventDefault();
     }
-
-    _handleDragOver(event)
-    {
-        if (event.dataTransfer.types.includes("Files"))
-            event.preventDefault();
-    }
-
-    _handleDrop(event)
-    {
-        if (!event.dataTransfer.files || !event.dataTransfer.files.length)
-            return;
-
-        event.preventDefault();
-
-        WI.FileUtilities.readJSON(event.dataTransfer.files, (result) => WI.auditManager.processJSON(result))
-        .then(() => {
-            event.dataTransfer.clearData();
-        });
-    }
 };
 
 WI.AuditTabContentView.Type = "audit";
index 58a2ce5..b0fb128 100644 (file)
@@ -56,9 +56,6 @@ WI.CanvasTabContentView = class CanvasTabContentView extends WI.ContentBrowserTa
         this._recordSingleFrameShortcut.implicitlyPreventsDefault = false;
         this._recordSingleFrameShortcut.disabled = true;
 
-        this.element.addEventListener("dragover", this._handleDragOver.bind(this));
-        this.element.addEventListener("drop", this._handleDrop.bind(this));
-
         WI.canvasManager.enable();
     }
 
@@ -141,6 +138,11 @@ WI.CanvasTabContentView = class CanvasTabContentView extends WI.ContentBrowserTa
         // FIXME: implement once <https://webkit.org/b/177606> is complete.
     }
 
+    async handleFileDrop(files)
+    {
+        await WI.FileUtilities.readJSON(files, (result) => WI.canvasManager.processJSON(result));
+    }
+
     // Protected
 
     initialLayout()
@@ -303,25 +305,6 @@ WI.CanvasTabContentView = class CanvasTabContentView extends WI.ContentBrowserTa
 
         event.preventDefault();
     }
-
-    _handleDragOver(event)
-    {
-        if (event.dataTransfer.types.includes("Files"))
-            event.preventDefault();
-    }
-
-    _handleDrop(event)
-    {
-        if (!event.dataTransfer.files || !event.dataTransfer.files.length)
-            return;
-
-        event.preventDefault();
-
-        WI.FileUtilities.readJSON(event.dataTransfer.files, (result) => WI.canvasManager.processJSON(result))
-        .then(() => {
-            event.dataTransfer.clearData();
-        });
-    }
 };
 
 WI.CanvasTabContentView.Type = "canvas";
index 8dea771..aed5ecf 100644 (file)
@@ -343,6 +343,11 @@ WI.TimelineTabContentView = class TimelineTabContentView extends WI.ContentBrows
         return representedObject instanceof WI.TimelineRecording;
     }
 
+    async handleFileDrop(files)
+    {
+        await WI.FileUtilities.readJSON(files, (result) => WI.timelineManager.processJSON(result));
+    }
+
     // Protected
 
     restoreFromCookie(cookie)