Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/network/JSONView.js

Issue 1899893003: [Devtools] JSONView implements Searchable interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.VBox} 33 * @extends {WebInspector.VBox}
34 * @implements {WebInspector.Searchable}
34 * @param {!WebInspector.ParsedJSON} parsedJSON 35 * @param {!WebInspector.ParsedJSON} parsedJSON
35 */ 36 */
36 WebInspector.JSONView = function(parsedJSON) 37 WebInspector.JSONView = function(parsedJSON)
37 { 38 {
38 WebInspector.VBox.call(this); 39 WebInspector.VBox.call(this);
39 this._parsedJSON = parsedJSON; 40 this._parsedJSON = parsedJSON;
40 this.element.classList.add("json-view"); 41 this.element.classList.add("json-view");
42
43 /** @type {?WebInspector.SearchableView} */
44 this._searchableView;
45 /** @type {!WebInspector.ObjectPropertiesSection} */
46 this._treeOutline;
47 /** @type {number} */
48 this._currentSearchFocusIndex = 0;
49 /** @type {!Array.<!TreeElement>} */
50 this._currentSearchTreeElements = [];
51 /** @type {?RegExp} */
52 this._searchRegex = null;
41 } 53 }
42 54
43 /** 55 /**
56 * @param {!WebInspector.ParsedJSON} parsedJSON
57 * @return {!WebInspector.SearchableView}
58 */
59 WebInspector.JSONView.createSearchableView = function(parsedJSON)
60 {
61 var jsonView = new WebInspector.JSONView(parsedJSON);
62 var searchableView = new WebInspector.SearchableView(jsonView);
63 searchableView.setPlaceholder(WebInspector.UIString("Find"));
64 jsonView._searchableView = searchableView;
65 jsonView.show(searchableView.element);
66 jsonView.element.setAttribute("tabIndex", 0);
67 return searchableView;
68 }
69
70 /**
44 * @param {?string} text 71 * @param {?string} text
45 * @return {!Promise<?WebInspector.ParsedJSON>} 72 * @return {!Promise<?WebInspector.ParsedJSON>}
46 */ 73 */
47 WebInspector.JSONView.parseJSON = function(text) 74 WebInspector.JSONView.parseJSON = function(text)
48 { 75 {
49 var returnObj = null; 76 var returnObj = null;
50 if (text) 77 if (text)
51 returnObj = WebInspector.JSONView._extractJSON(/** @type {string} */ (te xt)); 78 returnObj = WebInspector.JSONView._extractJSON(/** @type {string} */ (te xt));
52 if (!returnObj) 79 if (!returnObj)
53 return Promise.resolve(/** @type {?WebInspector.ParsedJSON} */ (null)); 80 return Promise.resolve(/** @type {?WebInspector.ParsedJSON} */ (null));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 }, 145 },
119 146
120 _initialize: function() 147 _initialize: function()
121 { 148 {
122 if (this._initialized) 149 if (this._initialized)
123 return; 150 return;
124 this._initialized = true; 151 this._initialized = true;
125 152
126 var obj = WebInspector.RemoteObject.fromLocalObject(this._parsedJSON.dat a); 153 var obj = WebInspector.RemoteObject.fromLocalObject(this._parsedJSON.dat a);
127 var title = this._parsedJSON.prefix + obj.description + this._parsedJSON .suffix; 154 var title = this._parsedJSON.prefix + obj.description + this._parsedJSON .suffix;
128 var section = new WebInspector.ObjectPropertiesSection(obj, title); 155 this._treeOutline = new WebInspector.ObjectPropertiesSection(obj, title) ;
129 section.setEditable(false); 156 this._treeOutline.setEditable(false);
130 section.expand(); 157 this._treeOutline.expand();
131 this.element.appendChild(section.element); 158 this.element.appendChild(this._treeOutline.element);
159 },
160
161 /**
162 * @param {number} index
163 */
164 _jumpToMatch: function(index)
165 {
166 if (!this._searchRegex)
167 return;
168 var previousFocusElement = this._currentSearchTreeElements[this._current SearchFocusIndex];
169 if (previousFocusElement)
170 previousFocusElement.setSearchRegex(this._searchRegex);
171
172 var newFocusElement = this._currentSearchTreeElements[index];
173 if (newFocusElement) {
174 this._updateSearchIndex(index);
175 newFocusElement.setSearchRegex(this._searchRegex, WebInspector.highl ightedCurrentSearchResultClassName);
176 newFocusElement.reveal();
177 } else {
178 this._updateSearchIndex(0);
179 }
180 },
181
182 /**
183 * @param {number} count
184 */
185 _updateSearchCount: function(count)
186 {
187 if (!this._searchableView)
188 return;
189 this._searchableView.updateSearchMatchesCount(count);
190 },
191
192 /**
193 * @param {number} index
194 */
195 _updateSearchIndex: function(index)
196 {
197 this._currentSearchFocusIndex = index;
198 if (!this._searchableView)
199 return;
200 this._searchableView.updateCurrentMatchIndex(index);
201 },
202
203 /**
204 * @override
205 */
206 searchCanceled: function()
207 {
208 this._searchRegex = null;
209 this._currentSearchTreeElements = [];
210
211 for (var element = this._treeOutline.rootElement(); element; element = e lement.traverseNextTreeElement(false)) {
212 if (!(element instanceof WebInspector.ObjectPropertyTreeElement))
213 continue;
214 element.revertHighlightChanges();
215 }
216 this._updateSearchCount(0);
217 this._updateSearchIndex(0);
218 },
219
220 /**
221 * @override
222 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig
223 * @param {boolean} shouldJump
224 * @param {boolean=} jumpBackwards
225 */
226 performSearch: function(searchConfig, shouldJump, jumpBackwards)
227 {
228 var newIndex = this._currentSearchFocusIndex;
229 var previousSearchFocusElement = this._currentSearchTreeElements[newInde x];
230 this.searchCanceled();
231 this._searchRegex = searchConfig.toSearchRegex(true);
232
233 for (var element = this._treeOutline.rootElement(); element; element = e lement.traverseNextTreeElement(false)) {
234 if (!(element instanceof WebInspector.ObjectPropertyTreeElement))
235 continue;
236 var hasMatch = element.setSearchRegex(this._searchRegex);
237 if (hasMatch)
238 this._currentSearchTreeElements.push(element);
239 if (previousSearchFocusElement === element) {
240 var currentIndex = this._currentSearchTreeElements.length - 1;
241 if (hasMatch || jumpBackwards)
242 newIndex = currentIndex;
243 else
244 newIndex = currentIndex + 1;
245 }
246 }
247 this._updateSearchCount(this._currentSearchTreeElements.length);
248
249 if (!this._currentSearchTreeElements.length) {
250 this._updateSearchIndex(0);
251 return;
252 }
253 newIndex = mod(newIndex, this._currentSearchTreeElements.length);
254
255 this._jumpToMatch(newIndex);
256 },
257
258 /**
259 * @override
260 */
261 jumpToNextSearchResult: function()
262 {
263 if (!this._currentSearchTreeElements.length)
264 return;
265 var newIndex = mod(this._currentSearchFocusIndex + 1, this._currentSearc hTreeElements.length);
266 this._jumpToMatch(newIndex);
267 },
268
269 /**
270 * @override
271 */
272 jumpToPreviousSearchResult: function()
273 {
274 if (!this._currentSearchTreeElements.length)
275 return;
276 var newIndex = mod(this._currentSearchFocusIndex - 1, this._currentSearc hTreeElements.length);
277 this._jumpToMatch(newIndex);
278 },
279
280 /**
281 * @override
282 * @return {boolean}
283 */
284 supportsCaseSensitiveSearch: function()
285 {
286 return true;
287 },
288
289 /**
290 * @override
291 * @return {boolean}
292 */
293 supportsRegexSearch: function()
294 {
295 return true;
132 }, 296 },
133 297
134 __proto__: WebInspector.VBox.prototype 298 __proto__: WebInspector.VBox.prototype
135 } 299 }
136 300
137 /** 301 /**
138 * @constructor 302 * @constructor
139 * @param {*} data 303 * @param {*} data
140 * @param {string} prefix 304 * @param {string} prefix
141 * @param {string} suffix 305 * @param {string} suffix
142 */ 306 */
143 WebInspector.ParsedJSON = function(data, prefix, suffix) 307 WebInspector.ParsedJSON = function(data, prefix, suffix)
144 { 308 {
145 this.data = data; 309 this.data = data;
146 this.prefix = prefix; 310 this.prefix = prefix;
147 this.suffix = suffix; 311 this.suffix = suffix;
148 } 312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698