Reviewed by Darin.
authorthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 May 2006 04:43:00 +0000 (04:43 +0000)
committerthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 May 2006 04:43:00 +0000 (04:43 +0000)
        Bug 8856: Web Inspector should show the Xpath for the selected node
        http://bugzilla.opendarwin.org/show_bug.cgi?id=8856

        Adds an Xpath area to the Node panel.

        * WebInspector/webInspector/inspector.css:
        * WebInspector/webInspector/inspector.html:
        * WebInspector/webInspector/inspector.js:

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

WebKit/ChangeLog
WebKit/WebInspector/webInspector/inspector.css
WebKit/WebInspector/webInspector/inspector.html
WebKit/WebInspector/webInspector/inspector.js

index 5e07ad4f5eaea137e43bbdc41006bcbd6670ff96..d92f92ae55f16ea11447df0b2092d325e33784b5 100644 (file)
@@ -1,3 +1,16 @@
+2006-05-11  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Darin.
+
+        Bug 8856: Web Inspector should show the Xpath for the selected node
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=8856
+        
+        Adds an Xpath area to the Node panel.
+
+        * WebInspector/webInspector/inspector.css:
+        * WebInspector/webInspector/inspector.html:
+        * WebInspector/webInspector/inspector.js:
+
 2006-05-11  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by Anders.
index 17da28daae173029543dec9e22c9826822e3696f..e69555bd6d20afa2334771cdac628537944b08d2 100644 (file)
@@ -645,6 +645,20 @@ button.toggle.right {
     color: rgba(255,255,255,0.6);
 }
 
+#nodeXpath {
+    margin-top: 4px;
+    height: 60px;
+}
+
+#nodeXpathValue {
+    -webkit-user-select: text;
+    -webkit-dashboard-region: dashboard-region(control rectangle);
+    word-wrap: break-word;
+    overflow: hidden;
+    text-overflow: ellipsis;
+    height: 32px;
+}
+
 #nodeContents {
     display: -webkit-box;
     -webkit-box-flex: 12;
index 1a4447c3654c839a93e10f4bb9642142757fb0b3..a03b120f7d2e4116e30998965795d35d3f4a8b54 100644 (file)
@@ -77,6 +77,12 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
             <span class="label">Namespace URI:</span>
             <span class="value"><div id="nodeNamespace"></div></span>
         </div>
+        <div id="nodeXpath">
+            <div class="infoRow header">
+                <span class="label" style="width: initial">Xpath</span>
+            </div>
+            <div id="nodeXpathValue"></div>
+        </div>
         <div id="elementAttributes">
             <div class="infoRow header">
                 <span class="label" style="width: initial">Element Attributes</span>
index c457ae7b3d5d13bb635603f67049ddd5c0c0bc6f..3cf64ea50e5b680f6e99c676127052b03531461e 100644 (file)
@@ -262,6 +262,40 @@ function nodeTypeName(node)
     return "(unknown)";
 }
 
+function xpathForNode(node)
+{
+    var path = "";
+    while (node) {
+        if (node.nodeType == Node.DOCUMENT_NODE) {
+            path = "/" + path;
+        } else {
+            if (node.nodeName == "HTML" || node.nodeName == "BODY") {
+                path = node.nodeName.toLowerCase() + (path.length ? "/" + path : "");
+            } else {
+                var index = 1;
+                var child = (node.parentNode ? node.parentNode.firstChild : null);
+                while (child) {
+                    if (node == child)
+                        break;
+                    if (child.nodeName == node.nodeName)
+                        index++;
+                    child = child.nextSibling;
+                }
+                
+                var name = node.nodeName.toLowerCase();
+                if (node.nodeType == Node.TEXT_NODE)
+                    name = "text()";
+
+                path = name + "[" + index + "]" + (path.length ? "/" + path : "");
+            }
+        }
+
+        node = node.parentNode;
+    }
+
+    return path;
+}
+
 function updatePanes()
 {
     for (var i = 0; i < tabNames.length; i++)
@@ -341,6 +375,8 @@ function updateNodePane() {
         document.getElementById("nodeContents").style.display = "none";
     }
 
+    document.getElementById("nodeXpathValue").textContent = xpathForNode(focusedNode);
+
     document.getElementById("nodeType").textContent = nodeTypeName(focusedNode);
     document.getElementById("nodeName").textContent = focusedNode.nodeName;