Web Inspector: Add Context Menus to Object Tree properties
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Mar 2015 19:32:49 +0000 (19:32 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Mar 2015 19:32:49 +0000 (19:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142125

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

* inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::functionDetails):
Update to include columnNumber.

Source/WebInspectorUI:

* Localizations/en.lproj/localizedStrings.js:
* UserInterface/Views/ObjectPropertiesSection.js:
(WebInspector.ObjectPropertyTreeElement.prototype._functionContextMenuEventFired):
(WebInspector.ObjectPropertyTreeElement.prototype._functionContextMenuEventFired.revealFunction):
Fix legacy implementation.

* UserInterface/Views/ObjectTreeArrayIndexTreeElement.js:
* UserInterface/Views/ObjectTreePropertyTreeElement.js:
(WebInspector.ObjectTreePropertyTreeElement.prototype._createTitlePrototype):
Give prototype buttons a tooltip.

(WebInspector.ObjectTreePropertyTreeElement.prototype.oncontextmenu):
(WebInspector.ObjectTreePropertyTreeElement.prototype._contextMenuHandler):
(WebInspector.ObjectTreePropertyTreeElement.prototype._appendMenusItemsForObject):
Context Menus based on the selected object.

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js
Source/WebInspectorUI/UserInterface/Views/ObjectPropertiesSection.js
Source/WebInspectorUI/UserInterface/Views/ObjectTreeArrayIndexTreeElement.js
Source/WebInspectorUI/UserInterface/Views/ObjectTreePropertyTreeElement.js

index e5acb3c..ef2471f 100644 (file)
@@ -1,3 +1,14 @@
+2015-03-02  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Add Context Menus to Object Tree properties
+        https://bugs.webkit.org/show_bug.cgi?id=142125
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/JSInjectedScriptHost.cpp:
+        (Inspector::JSInjectedScriptHost::functionDetails):
+        Update to include columnNumber.
+
 2015-03-01  Filip Pizlo  <fpizlo@apple.com>
 
         BytecodeGenerator shouldn't emit op_resolve_scope as a roundabout way of returning the scopeRegister
index 5b3d3e6..d29d36f 100644 (file)
@@ -166,19 +166,26 @@ JSValue JSInjectedScriptHost::functionDetails(ExecState* exec)
     if (!value.asCell()->inherits(JSFunction::info()))
         return jsUndefined();
 
+    // FIXME: This should provide better details for JSBoundFunctions.
+
     JSFunction* function = jsCast<JSFunction*>(value);
     const SourceCode* sourceCode = function->sourceCode();
     if (!sourceCode)
         return jsUndefined();
 
+    // In the inspector protocol all positions are 0-based while in SourceCode they are 1-based
     int lineNumber = sourceCode->firstLine();
     if (lineNumber)
-        lineNumber -= 1; // In the inspector protocol all positions are 0-based while in SourceCode they are 1-based
+        lineNumber -= 1;
+    int columnNumber = sourceCode->startColumn();
+    if (columnNumber)
+        columnNumber -= 1;
 
     String scriptID = String::number(sourceCode->provider()->asID());
     JSObject* location = constructEmptyObject(exec);
-    location->putDirect(exec->vm(), Identifier(exec, "lineNumber"), jsNumber(lineNumber));
     location->putDirect(exec->vm(), Identifier(exec, "scriptId"), jsString(exec, scriptID));
+    location->putDirect(exec->vm(), Identifier(exec, "lineNumber"), jsNumber(lineNumber));
+    location->putDirect(exec->vm(), Identifier(exec, "columnNumber"), jsNumber(columnNumber));
 
     JSObject* result = constructEmptyObject(exec);
     result->putDirect(exec->vm(), Identifier(exec, "location"), location);
index 7d33e97..1016b63 100644 (file)
@@ -1,3 +1,26 @@
+2015-03-02  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Add Context Menus to Object Tree properties
+        https://bugs.webkit.org/show_bug.cgi?id=142125
+
+        Reviewed by Timothy Hatcher.
+
+        * Localizations/en.lproj/localizedStrings.js:
+        * UserInterface/Views/ObjectPropertiesSection.js:
+        (WebInspector.ObjectPropertyTreeElement.prototype._functionContextMenuEventFired):
+        (WebInspector.ObjectPropertyTreeElement.prototype._functionContextMenuEventFired.revealFunction):
+        Fix legacy implementation.
+
+        * UserInterface/Views/ObjectTreeArrayIndexTreeElement.js:
+        * UserInterface/Views/ObjectTreePropertyTreeElement.js:
+        (WebInspector.ObjectTreePropertyTreeElement.prototype._createTitlePrototype):
+        Give prototype buttons a tooltip.
+
+        (WebInspector.ObjectTreePropertyTreeElement.prototype.oncontextmenu):
+        (WebInspector.ObjectTreePropertyTreeElement.prototype._contextMenuHandler):
+        (WebInspector.ObjectTreePropertyTreeElement.prototype._appendMenusItemsForObject):
+        Context Menus based on the selected object.
+
 2015-02-27  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Use Maps in ResourceCollection instead of objects
index c60752b..6423a4d 100644 (file)
Binary files a/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js and b/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js differ
index 284ae42..63d0b96 100644 (file)
@@ -257,20 +257,25 @@ WebInspector.ObjectPropertyTreeElement.prototype = {
     {
         function didGetLocation(error, response)
         {
-            if (error) {
-                console.error(error);
+            if (error)
                 return;
-            }
-            WebInspector.panels.scripts.showFunctionDefinition(response);
+
+            var location = response.location;
+            var sourceCode = WebInspector.debuggerManager.scriptForIdentifier(location.scriptId);
+            if (!sourceCode)
+                return;
+
+            var sourceCodeLocation = sourceCode.createSourceCodeLocation(location.lineNumber, location.columnNumber || 0);
+            WebInspector.resourceSidebarPanel.showSourceCodeLocation(sourceCodeLocation);
         }
 
         function revealFunction()
         {
-            DebuggerAgent.getFunctionLocation(this.property.value.objectId, didGetLocation.bind(this));
+            DebuggerAgent.getFunctionDetails(this.property.value.objectId, didGetLocation);
         }
 
         var contextMenu = new WebInspector.ContextMenu(event);
-        contextMenu.appendItem(WebInspector.UIString("Show function definition"), revealFunction.bind(this));
+        contextMenu.appendItem(WebInspector.UIString("Jump to Definition"), revealFunction.bind(this));
         contextMenu.show();
     },
 
index 082b23b..0a58baa 100644 (file)
@@ -23,7 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-// FIXME: This should share more code with ObjectTreePropertyTreeElement.
+// FIXME: This should share more code with ObjectTreePropertyTreeElement. (getters, resolved values, context menus)
 
 WebInspector.ObjectTreeArrayIndexTreeElement = function(property, propertyPath)
 {
index d2f7df0..4d72009 100644 (file)
@@ -88,6 +88,11 @@ WebInspector.ObjectTreePropertyTreeElement.prototype = {
             this._previewView.showPreview();
     },
 
+    oncontextmenu: function(event)
+    {
+        this._contextMenuHandler(event);
+    },
+
     // Private
 
     _resolvedValue: function()
@@ -185,6 +190,7 @@ WebInspector.ObjectTreePropertyTreeElement.prototype = {
         var nameElement = document.createElement("span");
         nameElement.className = "prototype-name";
         nameElement.textContent = WebInspector.UIString("%s Prototype").format(this._sanitizedPrototypeString(this._property.value));
+        nameElement.title = this._propertyPathString(this._thisPropertyPath());
         return nameElement;
     },
 
@@ -219,7 +225,6 @@ WebInspector.ObjectTreePropertyTreeElement.prototype = {
                     valueOrGetterElement.textContent = this._functionPropertyString();
             }
 
-            // FIXME: Context Menu for Value. (See ObjectPropertiesSection).
             // FIXME: Option+Click for Value.
         } else {
             valueOrGetterElement = document.createElement("span");
@@ -466,5 +471,61 @@ WebInspector.ObjectTreePropertyTreeElement.prototype = {
             var emptyMessageElement = WebInspector.ObjectTreeView.emptyMessageElement(WebInspector.UIString("No Properties."));
             this.appendChild(new TreeElement(emptyMessageElement, null, false));
         }
+    },
+
+    _contextMenuHandler: function(event)
+    {
+        var resolvedValue = this._resolvedValue();
+        if (!resolvedValue)
+            return;
+
+        var contextMenu = new WebInspector.ContextMenu(event);
+
+        var propertyPath = this._resolvedValuePropertyPath();
+        if (propertyPath && !propertyPath.isFullPathImpossible()) {
+            contextMenu.appendItem(WebInspector.UIString("Copy Path to Property"), function() {
+                InspectorFrontendHost.copyText(propertyPath.displayPath(WebInspector.PropertyPath.Type.Value));
+            }.bind(this));
+        }
+
+        contextMenu.appendSeparator();
+
+        this._appendMenusItemsForObject(contextMenu, resolvedValue);
+
+        if (!contextMenu.isEmpty())
+            contextMenu.show();
+    },
+
+    _appendMenusItemsForObject: function(contextMenu, resolvedValue)
+    {
+        if (resolvedValue.type === "function") {
+            // FIXME: We should better handle bound functions.
+            if (!isFunctionStringNativeCode(resolvedValue.description)) {
+                contextMenu.appendItem(WebInspector.UIString("Jump to Definition"), function() {
+                    DebuggerAgent.getFunctionDetails(resolvedValue.objectId, function(error, response) {
+                        if (error)
+                            return;
+
+                        var location = response.location;
+                        var sourceCode = WebInspector.debuggerManager.scriptForIdentifier(location.scriptId);
+                        if (!sourceCode)
+                            return;
+
+                        var sourceCodeLocation = sourceCode.createSourceCodeLocation(location.lineNumber, location.columnNumber || 0);
+                        WebInspector.resourceSidebarPanel.showSourceCodeLocation(sourceCodeLocation);
+                    });
+                });
+            }
+            return;
+        }
+
+        if (resolvedValue.subtype === "node") {
+            contextMenu.appendItem(WebInspector.UIString("Reveal in DOM Tree"), function() {
+                resolvedValue.pushNodeToFrontend(function(nodeId) {
+                    WebInspector.domTreeManager.inspectElement(nodeId);
+                });
+            });
+            return;
+        }
     }
 };