Fix Bug 16234: Inspector should support searching for elements by CSS selectors
authoraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jan 2008 21:35:07 +0000 (21:35 +0000)
committeraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jan 2008 21:35:07 +0000 (21:35 +0000)
        <http://bugs.webkit.org/show_bugs.cgi?id=16234>
        <rdar://5712862>

        Reviewed by Tim.

        * page/inspector/inspector.js: Use Document.querySelectorAll to search
        for elements by CSS selector. Also store a custom property on nodes
        being added to the search results to avoid showing the same node more
        than once.

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

WebCore/ChangeLog
WebCore/page/inspector/inspector.js

index e64058b..6b0bf03 100644 (file)
@@ -1,5 +1,19 @@
 2008-01-29  Adam Roben  <aroben@apple.com>
 
+        Fix Bug 16234: Inspector should support searching for elements by CSS selectors
+
+        <http://bugs.webkit.org/show_bugs.cgi?id=16234>
+        <rdar://5712862>
+
+        Reviewed by Tim.
+
+        * page/inspector/inspector.js: Use Document.querySelectorAll to search
+        for elements by CSS selector. Also store a custom property on nodes
+        being added to the search results to avoid showing the same node more
+        than once.
+
+2008-01-29  Adam Roben  <aroben@apple.com>
+
         Fix <rdar://5711136> Full-screen Flash on 1up.com is unresponsive
 
         Reviewed by Anders and Darin.
index 380c038..f65febf 100644 (file)
@@ -869,15 +869,37 @@ WebInspector.performSearch = function(query)
         }
 
         var domResults = [];
+        const searchResultsProperty = "__includedInInspectorSearchResults";
+        function addNodesToDOMResults(nodes, length, getItem)
+        {
+            for (var i = 0; i < length; ++i) {
+                var node = getItem(nodes, i);
+                if (searchResultsProperty in node)
+                    continue;
+                node[searchResultsProperty] = true;
+                domResults.push(node);
+            }
+        }
+
+        function cleanUpDOMResultsNodes()
+        {
+            for (var i = 0; i < domResults.length; ++i)
+                delete domResults[i][searchResultsProperty];
+        }
+
         if (resource.category === this.resourceCategories.documents) {
+            var doc = resource.documentNode;
             try {
-                var doc = resource.documentNode;
-                var nodeList = doc.evaluate(xpathQuery, doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE);
-                for (var j = 0; j < nodeList.snapshotLength; ++j)
-                    domResults.push(nodeList.snapshotItem(i));
+                var result = doc.evaluate(xpathQuery, doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE);
+                addNodesToDOMResults(result, result.snapshotLength, function(l, i) { return l.snapshotItem(i); });
             } catch(err) {
                 // ignore any exceptions. the query might be malformed, but we allow that.
             }
+
+            var result = doc.querySelectorAll(query);
+            addNodesToDOMResults(result, result.length, function(l, i) { return l.item(i); });
+
+            cleanUpDOMResultsNodes();
         }
 
         if ((!sourceResults || !sourceResults.length) && !domResults.length)