Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/network/JSONView.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/network/JSONView.js b/third_party/WebKit/Source/devtools/front_end/network/JSONView.js |
| index 20f9c5c9f6119dbb3a6ca78d7cac365e74b2332a..09a5f132f5f5571423a74553fad657c621cd622b 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/network/JSONView.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/network/JSONView.js |
| @@ -31,6 +31,7 @@ |
| /** |
| * @constructor |
| * @extends {WebInspector.VBox} |
| + * @implements {WebInspector.Searchable} |
| * @param {!WebInspector.ParsedJSON} parsedJSON |
| */ |
| WebInspector.JSONView = function(parsedJSON) |
| @@ -38,6 +39,17 @@ WebInspector.JSONView = function(parsedJSON) |
| WebInspector.VBox.call(this); |
| this._parsedJSON = parsedJSON; |
| this.element.classList.add("json-view"); |
| + |
| + /** @type {?WebInspector.SearchableView} */ |
| + this._searchableView; |
| + /** @type {!WebInspector.ObjectPropertiesSection} */ |
| + this._section; |
| + /** @type {number} */ |
| + this._currentSearchFocusIndex = -1; // -1 if nothing currently focused |
|
lushnikov
2016/04/22 19:43:00
let's remove comment
allada
2016/04/25 23:48:49
Done.
|
| + /** @type {!Array.<!TreeElement>} */ |
| + this._currentSearchTreeElements = []; |
| + /** @type {?RegExp} */ |
| + this._searchRegExp = null; |
|
lushnikov
2016/04/22 19:43:00
this._searchRegex
allada
2016/04/25 23:48:49
Done.
|
| } |
| /** |
| @@ -134,10 +146,176 @@ WebInspector.JSONView.prototype = { |
| var obj = WebInspector.RemoteObject.fromLocalObject(this._parsedJSON.data); |
| var title = this._parsedJSON.prefix + obj.description + this._parsedJSON.suffix; |
| - var section = new WebInspector.ObjectPropertiesSection(obj, title); |
| - section.setEditable(false); |
| - section.expand(); |
| - this.element.appendChild(section.element); |
| + this._section = new WebInspector.ObjectPropertiesSection(obj, title); |
| + this._section.setEditable(false); |
| + this._section.expand(); |
| + this.element.appendChild(this._section.element); |
| + }, |
| + |
| + /** |
| + * @return {!WebInspector.SearchableView} |
| + */ |
| + makeSearchable: function() { |
| + var searchableView = new WebInspector.SearchableView(this); |
|
lushnikov
2016/04/22 19:43:00
createSearchableView: ...
I've seen this code rec
allada
2016/04/25 23:48:49
Done.
|
| + searchableView.setPlaceholder(WebInspector.UIString("Find")); |
| + this._searchableView = searchableView; |
| + this.show(searchableView.element); |
| + this.element.setAttribute("tabIndex", 0); |
| + return searchableView; |
| + }, |
| + |
| + /** |
| + * @param {number} index |
| + */ |
| + _jumpToMatch: function(index) |
| + { |
| + if (!this._searchRegExp) |
| + return; |
| + var previousIndex = this._currentSearchFocusIndex; |
| + var newFocusElement = this._currentSearchTreeElements[index]; |
| + var previousFocusElement = this._currentSearchTreeElements[previousIndex]; |
| + |
| + if (!newFocusElement) |
| + index = -1; |
| + |
| + if (previousFocusElement) |
| + previousFocusElement.applyHighlight(this._searchRegExp); |
| + |
| + if (newFocusElement) { |
| + newFocusElement.applyHighlight(this._searchRegExp, WebInspector.highlightedCurrentSearchResultClassName); |
| + newFocusElement.reveal(); |
| + } |
| + this._updateSearchIndex(index); |
| + }, |
| + |
| + /** |
| + * @param {number} count |
| + */ |
| + _updateSearchCount: function(count) |
| + { |
| + if (!this._searchableView) |
| + return; |
| + this._searchableView.updateSearchMatchesCount(count); |
| + }, |
| + |
| + /** |
| + * @param {number} index |
| + */ |
| + _updateSearchIndex: function(index) |
| + { |
| + this._currentSearchFocusIndex = index; |
| + if (!this._searchableView) |
| + return; |
| + this._searchableView.updateCurrentMatchIndex(index); |
| + }, |
| + |
| + /** |
| + * @override |
| + */ |
| + searchCanceled: function() |
| + { |
| + var newIndex = -1; |
| + this._searchRegExp = null; |
| + this._currentSearchTreeElements = []; |
| + var currentElement = this._section.rootElement(); |
| + |
| + while (currentElement) { |
| + if (currentElement instanceof WebInspector.ObjectPropertyTreeElement) |
| + currentElement.revertHighlightChanges(); |
| + currentElement = currentElement.traverseNextTreeElement(false); |
| + } |
| + this._updateSearchCount(0); |
| + this._updateSearchIndex(newIndex); |
| + }, |
| + |
| + /** |
| + * @override |
| + * @param {!WebInspector.SearchableView.SearchConfig} searchConfig |
| + * @param {boolean} shouldJump |
| + * @param {boolean=} jumpBackwards |
| + */ |
| + performSearch: function(searchConfig, shouldJump, jumpBackwards) |
| + { |
| + var query = searchConfig.query; |
| + var newIndex = this._currentSearchFocusIndex; |
| + var previousFocusElement = this._currentSearchTreeElements[newIndex]; |
| + this.searchCanceled(); |
| + this._searchRegExp = searchConfig.toSearchRegex(true); |
| + |
| + var currentElement = this._section.rootElement(); |
| + |
| + var focusNextSearchResult = newIndex === -1 ? true : false; |
| + |
| + while (currentElement) { |
| + if (currentElement instanceof WebInspector.ObjectPropertyTreeElement) { |
| + var hasMatch = currentElement.applyHighlight(this._searchRegExp); |
| + if (hasMatch) |
| + this._currentSearchTreeElements.push(currentElement); |
| + if (previousFocusElement === currentElement) |
| + focusNextSearchResult = true; |
| + if (focusNextSearchResult && hasMatch) { |
| + focusNextSearchResult = false; |
| + if (jumpBackwards) |
| + newIndex = this._currentSearchTreeElements.length - 1; |
| + else |
| + // -2 because it will +1 inside jumpToNextSearchResult() below |
| + newIndex = this._currentSearchTreeElements.length - 2; |
| + } |
| + } |
| + currentElement = currentElement.traverseNextTreeElement(false); |
| + } |
| + this._currentSearchFocusIndex = newIndex; |
| + this._updateSearchCount(this._currentSearchTreeElements.length); |
| + if (jumpBackwards) |
| + this.jumpToPreviousSearchResult(); |
| + else |
| + this.jumpToNextSearchResult(); |
| + }, |
| + |
| + /** |
| + * @override |
| + */ |
| + jumpToNextSearchResult: function() |
| + { |
| + if (!this._currentSearchTreeElements.length) |
| + return; |
| + |
| + var currentIndex = this._currentSearchFocusIndex; |
| + if (currentIndex + 1 >= this._currentSearchTreeElements.length) |
| + currentIndex = -1; |
| + this._jumpToMatch(currentIndex + 1); |
| + }, |
| + |
| + /** |
| + * @override |
| + */ |
| + jumpToPreviousSearchResult: function() |
| + { |
| + if (!this._currentSearchTreeElements.length) |
| + return; |
| + var currentIndex = this._currentSearchFocusIndex; |
| + if (currentIndex <= 0) |
| + currentIndex = this._currentSearchTreeElements.length; |
| + |
| + this._jumpToMatch(currentIndex - 1); |
| + }, |
| + |
| + /** |
| + * @override |
| + * @return {boolean} |
| + */ |
| + supportsCaseSensitiveSearch: function() |
| + { |
| + return true; |
| + }, |
| + |
| + /** |
| + * @override |
| + * @return {boolean} |
| + */ |
| + supportsRegexSearch: function() |
| + { |
| + return true; |
| }, |
| __proto__: WebInspector.VBox.prototype |