diff options
author | serya@google.com <serya@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 09:12:46 +0000 |
---|---|---|
committer | serya@google.com <serya@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 09:12:46 +0000 |
commit | ab8048755fd3349eb593f455488555fe8918d42c (patch) | |
tree | 699d7dee4920a8e50bdbb7d88bf106c78831c0a7 /webkit | |
parent | a1a0df059f8145a73231752cefde82c3ddf3853a (diff) | |
download | chromium_src-ab8048755fd3349eb593f455488555fe8918d42c.zip chromium_src-ab8048755fd3349eb593f455488555fe8918d42c.tar.gz chromium_src-ab8048755fd3349eb593f455488555fe8918d42c.tar.bz2 |
Implemented navigation through the search results (jump to next/next)
Review URL: http://codereview.chromium.org/45062
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13411 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/devtools/js/devtools.js | 51 | ||||
-rw-r--r-- | webkit/glue/devtools/js/dom_agent.js | 52 |
2 files changed, 83 insertions, 20 deletions
diff --git a/webkit/glue/devtools/js/devtools.js b/webkit/glue/devtools/js/devtools.js index 4454213..9e14e6f 100644 --- a/webkit/glue/devtools/js/devtools.js +++ b/webkit/glue/devtools/js/devtools.js @@ -218,12 +218,24 @@ WebInspector.ElementsTreeElement.prototype.updateChildren = function() { */ WebInspector.ElementsPanel.prototype.performSearch = function(query) { this.searchCanceled(); - var self = this; - devtools.tools.getDomAgent().performSearch(query, function(node) { - var treeElement = self.treeOutline.findTreeElement(node); + devtools.tools.getDomAgent().performSearch(query, + goog.bind(this.performSearchCallback_, this)); +}; + + +WebInspector.ElementsPanel.prototype.performSearchCallback_ = function(nodes) { + for (var i = 0; i < nodes.length; ++i) { + var treeElement = this.treeOutline.findTreeElement(nodes[i]); if (treeElement) treeElement.highlighted = true; - }); + } + + if (nodes.length) { + this.currentSearchResultIndex_ = 0; + this.focusedDOMNode = nodes[0]; + } + + this.searchResultCount_ = nodes.length; }; @@ -231,12 +243,19 @@ WebInspector.ElementsPanel.prototype.performSearch = function(query) { * @override */ WebInspector.ElementsPanel.prototype.searchCanceled = function() { - var self = this; - devtools.tools.getDomAgent().searchCanceled(function(node) { - var treeElement = self.treeOutline.findTreeElement(node); + this.currentSearchResultIndex_ = 0; + this.searchResultCount_ = 0; + devtools.tools.getDomAgent().searchCanceled( + goog.bind(this.searchCanceledCallback_, this)); +}; + + +WebInspector.ElementsPanel.prototype.searchCanceledCallback_ = function(nodes) { + for (var i = 0; i < nodes.length; i++) { + var treeElement = this.treeOutline.findTreeElement(nodes[i]); if (treeElement) treeElement.highlighted = false; - }); + } }; @@ -244,6 +263,14 @@ WebInspector.ElementsPanel.prototype.searchCanceled = function() { * @override */ WebInspector.ElementsPanel.prototype.jumpToNextSearchResult = function() { + if (!this.searchResultCount_) + return; + + if (++this.currentSearchResultIndex_ >= this.searchResultCount_) + this.currentSearchResultIndex_ = 0; + + this.focusedDOMNode = devtools.tools.getDomAgent(). + getSearchResultNode(this.currentSearchResultIndex_); }; @@ -251,6 +278,14 @@ WebInspector.ElementsPanel.prototype.jumpToNextSearchResult = function() { * @override */ WebInspector.ElementsPanel.prototype.jumpToPreviousSearchResult = function() { + if (!this.searchResultCount_) + return; + + if (--this.currentSearchResultIndex_ < 0) + this.currentSearchResultIndex_ = this.searchResultCount_ - 1; + + this.focusedDOMNode = devtools.tools.getDomAgent(). + getSearchResultNode(this.currentSearchResultIndex_); }; diff --git a/webkit/glue/devtools/js/dom_agent.js b/webkit/glue/devtools/js/dom_agent.js index c33b03f..2e4b547 100644 --- a/webkit/glue/devtools/js/dom_agent.js +++ b/webkit/glue/devtools/js/dom_agent.js @@ -780,40 +780,68 @@ devtools.DomAgent.prototype.childNodeRemoved = function( * @see DomAgentDelegate. * {@inheritDoc}. */ -devtools.DomAgent.prototype.performSearch = function(query, forEach) { +devtools.DomAgent.prototype.performSearch = function(query, callback) { + this.searchResults_ = []; RemoteDomAgent.PerformSearch( devtools.Callback.wrap( - goog.bind(this.performSearchCallback_, this, forEach)), + goog.bind(this.performSearchCallback_, this, callback, + this.searchResults_)), query); }; /** - * Invokes callback for each node that needs to clear highlighting. - * @param {function(devtools.DomNode):undefined} forEach callback to call. + * Invokes callback for nodes that needs to clear highlighting. + * @param {function(Array.<devtools.DomNode>)} callback to accept the result. */ -devtools.DomAgent.prototype.searchCanceled = function(forEach) { +devtools.DomAgent.prototype.searchCanceled = function(callback) { + if (!this.searchResults_) + return; + + var nodes = []; for (var i = 0; i < this.searchResults_.length; ++i) { var nodeId = this.searchResults_[i]; var node = this.idToDomNode_[nodeId]; - forEach(node); + nodes.push(node); } + + callback(nodes); + this.searchResults_ = null; }; /** * Invokes callback for each node that needs to gain highlighting. - * @param {function(devtools.DomNode):undefined} forEach callback to call. + * @param {function(Array.<devtools.DomNode>)} callback to accept the result. + * @param {Array.<number>} searchResults to be populated. * @param {Array.<number>} nodeIds Ids to highlight. */ -devtools.DomAgent.prototype.performSearchCallback_ = function(forEach, - nodeIds) { - this.searchResults_ = []; +devtools.DomAgent.prototype.performSearchCallback_ = function(callback, + searchResults, nodeIds) { + + if (this.searchResults_ !== searchResults) + return; // another search has requested and this results are obsolete + + var nodes = []; + for (var i = 0; i < nodeIds.length; ++i) { var node = this.idToDomNode_[nodeIds[i]]; - this.searchResults_.push(nodeIds[i]); - forEach(node); + searchResults.push(nodeIds[i]); + nodes.push(node); } + + callback(nodes); +}; + + +/** + * Returns a node by index from the actual search results + * (last performSearch). + * @param {number} index in the results. + * @return {devtools.DomNode} + */ +devtools.DomAgent.prototype.getSearchResultNode = function(index) { + return this.idToDomNode_[this.searchResults_[index]]; }; |