Changeset 29849 in webkit


Ignore:
Timestamp:
Jan 29, 2008, 1:35:07 PM (17 years ago)
Author:
Adam Roben
Message:

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.
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r29847 r29849  
     12008-01-29  Adam Roben  <aroben@apple.com>
     2
     3        Fix Bug 16234: Inspector should support searching for elements by CSS selectors
     4
     5        <http://bugs.webkit.org/show_bugs.cgi?id=16234>
     6        <rdar://5712862>
     7
     8        Reviewed by Tim.
     9
     10        * page/inspector/inspector.js: Use Document.querySelectorAll to search
     11        for elements by CSS selector. Also store a custom property on nodes
     12        being added to the search results to avoid showing the same node more
     13        than once.
     14
    1152008-01-29  Adam Roben  <aroben@apple.com>
    216
  • trunk/WebCore/page/inspector/inspector.js

    r29179 r29849  
    870870
    871871        var domResults = [];
     872        const searchResultsProperty = "__includedInInspectorSearchResults";
     873        function addNodesToDOMResults(nodes, length, getItem)
     874        {
     875            for (var i = 0; i < length; ++i) {
     876                var node = getItem(nodes, i);
     877                if (searchResultsProperty in node)
     878                    continue;
     879                node[searchResultsProperty] = true;
     880                domResults.push(node);
     881            }
     882        }
     883
     884        function cleanUpDOMResultsNodes()
     885        {
     886            for (var i = 0; i < domResults.length; ++i)
     887                delete domResults[i][searchResultsProperty];
     888        }
     889
    872890        if (resource.category === this.resourceCategories.documents) {
     891            var doc = resource.documentNode;
    873892            try {
    874                 var doc = resource.documentNode;
    875                 var nodeList = doc.evaluate(xpathQuery, doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE);
    876                 for (var j = 0; j < nodeList.snapshotLength; ++j)
    877                     domResults.push(nodeList.snapshotItem(i));
     893                var result = doc.evaluate(xpathQuery, doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE);
     894                addNodesToDOMResults(result, result.snapshotLength, function(l, i) { return l.snapshotItem(i); });
    878895            } catch(err) {
    879896                // ignore any exceptions. the query might be malformed, but we allow that.
    880897            }
     898
     899            var result = doc.querySelectorAll(query);
     900            addNodesToDOMResults(result, result.length, function(l, i) { return l.item(i); });
     901
     902            cleanUpDOMResultsNodes();
    881903        }
    882904
Note: See TracChangeset for help on using the changeset viewer.