Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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._section; | |
| 47 /** @type {number} */ | |
| 48 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.
| |
| 49 /** @type {!Array.<!TreeElement>} */ | |
| 50 this._currentSearchTreeElements = []; | |
| 51 /** @type {?RegExp} */ | |
| 52 this._searchRegExp = null; | |
|
lushnikov
2016/04/22 19:43:00
this._searchRegex
allada
2016/04/25 23:48:49
Done.
| |
| 41 } | 53 } |
| 42 | 54 |
| 43 /** | 55 /** |
| 44 * @param {?string} text | 56 * @param {?string} text |
| 45 * @return {!Promise<?WebInspector.ParsedJSON>} | 57 * @return {!Promise<?WebInspector.ParsedJSON>} |
| 46 */ | 58 */ |
| 47 WebInspector.JSONView.parseJSON = function(text) | 59 WebInspector.JSONView.parseJSON = function(text) |
| 48 { | 60 { |
| 49 var returnObj = null; | 61 var returnObj = null; |
| 50 if (text) | 62 if (text) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 }, | 139 }, |
| 128 | 140 |
| 129 _initialize: function() | 141 _initialize: function() |
| 130 { | 142 { |
| 131 if (this._initialized) | 143 if (this._initialized) |
| 132 return; | 144 return; |
| 133 this._initialized = true; | 145 this._initialized = true; |
| 134 | 146 |
| 135 var obj = WebInspector.RemoteObject.fromLocalObject(this._parsedJSON.dat a); | 147 var obj = WebInspector.RemoteObject.fromLocalObject(this._parsedJSON.dat a); |
| 136 var title = this._parsedJSON.prefix + obj.description + this._parsedJSON .suffix; | 148 var title = this._parsedJSON.prefix + obj.description + this._parsedJSON .suffix; |
| 137 var section = new WebInspector.ObjectPropertiesSection(obj, title); | 149 this._section = new WebInspector.ObjectPropertiesSection(obj, title); |
| 138 section.setEditable(false); | 150 this._section.setEditable(false); |
| 139 section.expand(); | 151 this._section.expand(); |
| 140 this.element.appendChild(section.element); | 152 this.element.appendChild(this._section.element); |
| 153 }, | |
| 154 | |
| 155 /** | |
| 156 * @return {!WebInspector.SearchableView} | |
| 157 */ | |
| 158 makeSearchable: function() { | |
| 159 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.
| |
| 160 searchableView.setPlaceholder(WebInspector.UIString("Find")); | |
| 161 this._searchableView = searchableView; | |
| 162 this.show(searchableView.element); | |
| 163 this.element.setAttribute("tabIndex", 0); | |
| 164 return searchableView; | |
| 165 }, | |
| 166 | |
| 167 /** | |
| 168 * @param {number} index | |
| 169 */ | |
| 170 _jumpToMatch: function(index) | |
| 171 { | |
| 172 if (!this._searchRegExp) | |
| 173 return; | |
| 174 var previousIndex = this._currentSearchFocusIndex; | |
| 175 var newFocusElement = this._currentSearchTreeElements[index]; | |
| 176 var previousFocusElement = this._currentSearchTreeElements[previousIndex ]; | |
| 177 | |
| 178 if (!newFocusElement) | |
| 179 index = -1; | |
| 180 | |
| 181 if (previousFocusElement) | |
| 182 previousFocusElement.applyHighlight(this._searchRegExp); | |
| 183 | |
| 184 if (newFocusElement) { | |
| 185 newFocusElement.applyHighlight(this._searchRegExp, WebInspector.high lightedCurrentSearchResultClassName); | |
| 186 newFocusElement.reveal(); | |
| 187 } | |
| 188 this._updateSearchIndex(index); | |
| 189 }, | |
| 190 | |
| 191 /** | |
| 192 * @param {number} count | |
| 193 */ | |
| 194 _updateSearchCount: function(count) | |
| 195 { | |
| 196 if (!this._searchableView) | |
| 197 return; | |
| 198 this._searchableView.updateSearchMatchesCount(count); | |
| 199 }, | |
| 200 | |
| 201 /** | |
| 202 * @param {number} index | |
| 203 */ | |
| 204 _updateSearchIndex: function(index) | |
| 205 { | |
| 206 this._currentSearchFocusIndex = index; | |
| 207 if (!this._searchableView) | |
| 208 return; | |
| 209 this._searchableView.updateCurrentMatchIndex(index); | |
| 210 }, | |
| 211 | |
| 212 /** | |
| 213 * @override | |
| 214 */ | |
| 215 searchCanceled: function() | |
| 216 { | |
| 217 var newIndex = -1; | |
| 218 this._searchRegExp = null; | |
| 219 this._currentSearchTreeElements = []; | |
| 220 var currentElement = this._section.rootElement(); | |
| 221 | |
| 222 while (currentElement) { | |
| 223 if (currentElement instanceof WebInspector.ObjectPropertyTreeElement ) | |
| 224 currentElement.revertHighlightChanges(); | |
| 225 currentElement = currentElement.traverseNextTreeElement(false); | |
| 226 } | |
| 227 this._updateSearchCount(0); | |
| 228 this._updateSearchIndex(newIndex); | |
| 229 }, | |
| 230 | |
| 231 /** | |
| 232 * @override | |
| 233 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig | |
| 234 * @param {boolean} shouldJump | |
| 235 * @param {boolean=} jumpBackwards | |
| 236 */ | |
| 237 performSearch: function(searchConfig, shouldJump, jumpBackwards) | |
| 238 { | |
| 239 var query = searchConfig.query; | |
| 240 var newIndex = this._currentSearchFocusIndex; | |
| 241 var previousFocusElement = this._currentSearchTreeElements[newIndex]; | |
| 242 this.searchCanceled(); | |
| 243 this._searchRegExp = searchConfig.toSearchRegex(true); | |
| 244 | |
| 245 var currentElement = this._section.rootElement(); | |
| 246 | |
| 247 var focusNextSearchResult = newIndex === -1 ? true : false; | |
| 248 | |
| 249 while (currentElement) { | |
| 250 if (currentElement instanceof WebInspector.ObjectPropertyTreeElement ) { | |
| 251 var hasMatch = currentElement.applyHighlight(this._searchRegExp) ; | |
| 252 if (hasMatch) | |
| 253 this._currentSearchTreeElements.push(currentElement); | |
| 254 if (previousFocusElement === currentElement) | |
| 255 focusNextSearchResult = true; | |
| 256 if (focusNextSearchResult && hasMatch) { | |
| 257 focusNextSearchResult = false; | |
| 258 if (jumpBackwards) | |
| 259 newIndex = this._currentSearchTreeElements.length - 1; | |
| 260 else | |
| 261 // -2 because it will +1 inside jumpToNextSearchResult() below | |
| 262 newIndex = this._currentSearchTreeElements.length - 2; | |
| 263 } | |
| 264 } | |
| 265 currentElement = currentElement.traverseNextTreeElement(false); | |
| 266 } | |
| 267 this._currentSearchFocusIndex = newIndex; | |
| 268 this._updateSearchCount(this._currentSearchTreeElements.length); | |
| 269 if (jumpBackwards) | |
| 270 this.jumpToPreviousSearchResult(); | |
| 271 else | |
| 272 this.jumpToNextSearchResult(); | |
| 273 }, | |
| 274 | |
| 275 /** | |
| 276 * @override | |
| 277 */ | |
| 278 jumpToNextSearchResult: function() | |
| 279 { | |
| 280 if (!this._currentSearchTreeElements.length) | |
| 281 return; | |
| 282 | |
| 283 var currentIndex = this._currentSearchFocusIndex; | |
| 284 if (currentIndex + 1 >= this._currentSearchTreeElements.length) | |
| 285 currentIndex = -1; | |
| 286 this._jumpToMatch(currentIndex + 1); | |
| 287 }, | |
| 288 | |
| 289 /** | |
| 290 * @override | |
| 291 */ | |
| 292 jumpToPreviousSearchResult: function() | |
| 293 { | |
| 294 if (!this._currentSearchTreeElements.length) | |
| 295 return; | |
| 296 var currentIndex = this._currentSearchFocusIndex; | |
| 297 if (currentIndex <= 0) | |
| 298 currentIndex = this._currentSearchTreeElements.length; | |
| 299 | |
| 300 this._jumpToMatch(currentIndex - 1); | |
| 301 }, | |
| 302 | |
| 303 /** | |
| 304 * @override | |
| 305 * @return {boolean} | |
| 306 */ | |
| 307 supportsCaseSensitiveSearch: function() | |
| 308 { | |
| 309 return true; | |
| 310 }, | |
| 311 | |
| 312 /** | |
| 313 * @override | |
| 314 * @return {boolean} | |
| 315 */ | |
| 316 supportsRegexSearch: function() | |
| 317 { | |
| 318 return true; | |
| 141 }, | 319 }, |
| 142 | 320 |
| 143 __proto__: WebInspector.VBox.prototype | 321 __proto__: WebInspector.VBox.prototype |
| 144 } | 322 } |
| 145 | 323 |
| 146 /** | 324 /** |
| 147 * @constructor | 325 * @constructor |
| 148 * @param {*} data | 326 * @param {*} data |
| 149 * @param {string} prefix | 327 * @param {string} prefix |
| 150 * @param {string} suffix | 328 * @param {string} suffix |
| 151 */ | 329 */ |
| 152 WebInspector.ParsedJSON = function(data, prefix, suffix) | 330 WebInspector.ParsedJSON = function(data, prefix, suffix) |
| 153 { | 331 { |
| 154 this.data = data; | 332 this.data = data; |
| 155 this.prefix = prefix; | 333 this.prefix = prefix; |
| 156 this.suffix = suffix; | 334 this.suffix = suffix; |
| 157 } | 335 } |
| OLD | NEW |