Web Inspector: Auto-log inspect node selected elements to the console
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Nov 2015 21:40:21 +0000 (21:40 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Nov 2015 21:40:21 +0000 (21:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151178

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2015-11-12
Reviewed by Brian Burg.

Auto-logging user selected elements to the console helps with
quick use in the console. $0 is not very discoverable, and $n
values are expendable. This also makes it convenient to use the
inspect node toolbar search option to select a few different
nodes and use each of them in the console without extra work.

* UserInterface/Controllers/DOMTreeManager.js:
(WebInspector.DOMTreeManager.prototype.inspectNodeObject.nodeAvailable):
(WebInspector.DOMTreeManager.prototype.inspectNodeObject):
Log selected nodes to the console. Treat this as a synthetic log that
will not immediately open the console like normal evaluation results.

* UserInterface/Controllers/JavaScriptLogViewController.js:
(WebInspector.JavaScriptLogViewController.prototype.appendImmediateExecutionWithResult.saveResultCallback):
(WebInspector.JavaScriptLogViewController.prototype.appendImmediateExecutionWithResult):
(WebInspector.JavaScriptLogViewController.prototype.consolePromptTextCommitted.printResult):
(WebInspector.JavaScriptLogViewController.prototype.consolePromptTextCommitted):
Initialize ConsoleCommandResultMessage's synthetic properties.

* UserInterface/Views/DOMTreeOutline.js:
(WebInspector.DOMTreeOutline.prototype._populateContextMenu.logElement):
(WebInspector.DOMTreeOutline.prototype._populateContextMenu):
* UserInterface/Controllers/RuntimeManager.js:
Create a global for the special "console" object group used in multiple places.

* UserInterface/Models/ConsoleCommandResultMessage.js:
(WebInspector.ConsoleCommandResultMessage):
(WebInspector.ConsoleCommandResultMessage.prototype.get synthetic):
Add a synthetic property.

* UserInterface/Views/LogContentView.js:
(WebInspector.LogContentView.prototype.didAppendConsoleMessageView):
When the ConsoleResult is a synthetic result, do not auto-open the console.

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/DOMTreeManager.js
Source/WebInspectorUI/UserInterface/Controllers/JavaScriptLogViewController.js
Source/WebInspectorUI/UserInterface/Controllers/RuntimeManager.js
Source/WebInspectorUI/UserInterface/Models/ConsoleCommandResultMessage.js
Source/WebInspectorUI/UserInterface/Views/DOMTreeOutline.js
Source/WebInspectorUI/UserInterface/Views/LogContentView.js

index 0b1e4c6..44ef7eb 100644 (file)
@@ -1,5 +1,46 @@
 2015-11-12  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Web Inspector: Auto-log inspect node selected elements to the console
+        https://bugs.webkit.org/show_bug.cgi?id=151178
+
+        Reviewed by Brian Burg.
+
+        Auto-logging user selected elements to the console helps with
+        quick use in the console. $0 is not very discoverable, and $n
+        values are expendable. This also makes it convenient to use the
+        inspect node toolbar search option to select a few different
+        nodes and use each of them in the console without extra work.
+
+        * UserInterface/Controllers/DOMTreeManager.js:
+        (WebInspector.DOMTreeManager.prototype.inspectNodeObject.nodeAvailable):
+        (WebInspector.DOMTreeManager.prototype.inspectNodeObject):
+        Log selected nodes to the console. Treat this as a synthetic log that
+        will not immediately open the console like normal evaluation results.
+
+        * UserInterface/Controllers/JavaScriptLogViewController.js:
+        (WebInspector.JavaScriptLogViewController.prototype.appendImmediateExecutionWithResult.saveResultCallback):
+        (WebInspector.JavaScriptLogViewController.prototype.appendImmediateExecutionWithResult):
+        (WebInspector.JavaScriptLogViewController.prototype.consolePromptTextCommitted.printResult):
+        (WebInspector.JavaScriptLogViewController.prototype.consolePromptTextCommitted):
+        Initialize ConsoleCommandResultMessage's synthetic properties.
+
+        * UserInterface/Views/DOMTreeOutline.js:
+        (WebInspector.DOMTreeOutline.prototype._populateContextMenu.logElement):
+        (WebInspector.DOMTreeOutline.prototype._populateContextMenu):
+        * UserInterface/Controllers/RuntimeManager.js:
+        Create a global for the special "console" object group used in multiple places.
+
+        * UserInterface/Models/ConsoleCommandResultMessage.js:
+        (WebInspector.ConsoleCommandResultMessage):
+        (WebInspector.ConsoleCommandResultMessage.prototype.get synthetic):
+        Add a synthetic property.
+
+        * UserInterface/Views/LogContentView.js:
+        (WebInspector.LogContentView.prototype.didAppendConsoleMessageView):
+        When the ConsoleResult is a synthetic result, do not auto-open the console.
+
+2015-11-12  Joseph Pecoraro  <pecoraro@apple.com>
+
         Web Inspector: timeline event markers are added to overview even when not capturing a timeline recording
         https://bugs.webkit.org/show_bug.cgi?id=151166
 
index 6231beb..6454fc7 100644 (file)
@@ -328,6 +328,16 @@ WebInspector.DOMTreeManager = class DOMTreeManager extends WebInspector.Object
                 return;
 
             this.inspectElement(nodeId);
+
+            // Re-resolve the node in the console's object group when adding to the console.
+            let domNode = this.nodeForId(nodeId);
+            WebInspector.RemoteObject.resolveNode(domNode, WebInspector.RuntimeManager.ConsoleObjectGroup, function(remoteObject) {
+                if (!remoteObject)
+                    return;
+                let specialLogStyles = true;
+                let synthetic = true;
+                WebInspector.consoleLogViewController.appendImmediateExecutionWithResult(WebInspector.UIString("Selected Element"), remoteObject, specialLogStyles, synthetic);
+            });
         }
 
         remoteObject.pushNodeToFrontend(nodeAvailable.bind(this));
index bfbe87c..8755b7b 100644 (file)
@@ -117,7 +117,7 @@ WebInspector.JavaScriptLogViewController = class JavaScriptLogViewController ext
         consoleSession.element.scrollIntoView();
     }
 
-    appendImmediateExecutionWithResult(text, result, addSpecialUserLogClass)
+    appendImmediateExecutionWithResult(text, result, addSpecialUserLogClass, synthetic)
     {
         console.assert(result instanceof WebInspector.RemoteObject);
 
@@ -126,8 +126,8 @@ WebInspector.JavaScriptLogViewController = class JavaScriptLogViewController ext
 
         function saveResultCallback(savedResultIndex)
         {
-            var commandResultMessage = new WebInspector.ConsoleCommandResultMessage(result, false, savedResultIndex);
-            var commandResultMessageView = new WebInspector.ConsoleMessageView(commandResultMessage);
+            let commandResultMessage = new WebInspector.ConsoleCommandResultMessage(result, false, savedResultIndex, synthetic);
+            let commandResultMessageView = new WebInspector.ConsoleMessageView(commandResultMessage);
             this._appendConsoleMessageView(commandResultMessageView, true);
         }
 
@@ -224,12 +224,13 @@ WebInspector.JavaScriptLogViewController = class JavaScriptLogViewController ext
             if (!result || this._cleared)
                 return;
 
-            var commandResultMessage = new WebInspector.ConsoleCommandResultMessage(result, wasThrown, savedResultIndex);
-            var commandResultMessageView = new WebInspector.ConsoleMessageView(commandResultMessage);
+            let synthetic = false;
+            let commandResultMessage = new WebInspector.ConsoleCommandResultMessage(result, wasThrown, savedResultIndex, synthetic);
+            let commandResultMessageView = new WebInspector.ConsoleMessageView(commandResultMessage);
             this._appendConsoleMessageView(commandResultMessageView, true);
         }
 
-        WebInspector.runtimeManager.evaluateInInspectedWindow(text, "console", true, false, false, true, true, printResult.bind(this));
+        WebInspector.runtimeManager.evaluateInInspectedWindow(text, WebInspector.RuntimeManager.ConsoleObjectGroup, true, false, false, true, true, printResult.bind(this));
     }
 
     // Private
index dcdc608..0308fc7 100644 (file)
@@ -112,3 +112,5 @@ WebInspector.RuntimeManager = class RuntimeManager extends WebInspector.Object
 WebInspector.RuntimeManager.Event = {
     DidEvaluate: "runtime-manager-did-evaluate"
 };
+
+WebInspector.RuntimeManager.ConsoleObjectGroup = "console";
index 99784ef..f736de5 100644 (file)
 
 WebInspector.ConsoleCommandResultMessage = class ConsoleCommandResult extends WebInspector.ConsoleMessage
 {
-    constructor(result, wasThrown, savedResultIndex)
+    constructor(result, wasThrown, savedResultIndex, synthetic)
     {
-        var source = WebInspector.ConsoleMessage.MessageSource.JS;
-        var level = (wasThrown ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log);
-        var type = WebInspector.ConsoleMessage.MessageType.Result;
+        let source = WebInspector.ConsoleMessage.MessageSource.JS;
+        let level = (wasThrown ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log);
+        let type = WebInspector.ConsoleMessage.MessageType.Result;
 
         super(source, level, "", type, undefined, undefined, undefined, 0, [result], undefined, undefined);
 
         this._savedResultIndex = savedResultIndex;
+        this._synthetic = synthetic || false;
 
         if (this._savedResultIndex && this._savedResultIndex > WebInspector.ConsoleCommandResultMessage.maximumSavedResultIndex)
             WebInspector.ConsoleCommandResultMessage.maximumSavedResultIndex = this._savedResultIndex;
@@ -56,6 +57,11 @@ WebInspector.ConsoleCommandResultMessage = class ConsoleCommandResult extends We
     {
         return this._savedResultIndex;
     }
+
+    get synthetic()
+    {
+        return this._synthetic;
+    }
 };
 
 WebInspector.ConsoleCommandResultMessage.maximumSavedResultIndex = 0;
index f8e5ef0..1e82a3d 100644 (file)
@@ -509,7 +509,7 @@ WebInspector.DOMTreeOutline = class DOMTreeOutline extends WebInspector.TreeOutl
 
         function logElement()
         {
-            WebInspector.RemoteObject.resolveNode(domNode, "console", function(remoteObject) {
+            WebInspector.RemoteObject.resolveNode(domNode, WebInspector.RuntimeManager.ConsoleObjectGroup, function(remoteObject) {
                 if (!remoteObject)
                     return;
                 var text = WebInspector.UIString("Selected Element");
index dd85d2f..351056e 100644 (file)
@@ -155,9 +155,9 @@ WebInspector.LogContentView = class LogContentView extends WebInspector.ContentV
         // We want to remove focusable children after those pending dispatches too.
         InspectorBackend.runAfterPendingDispatches(this._clearFocusableChildren.bind(this));
 
-        // We only auto show the console if the message is a result.
+        // We only auto show the console if the message is a non-synthetic result.
         // This is when the user evaluated something directly in the prompt.
-        if (type !== WebInspector.ConsoleMessage.MessageType.Result)
+        if (type !== WebInspector.ConsoleMessage.MessageType.Result || messageView.message.synthetic)
             return;
 
         if (!WebInspector.isShowingConsoleTab())