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

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

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 /** 4 /**
5 * @implements {WebInspector.Searchable} 5 * @implements {UI.Searchable}
6 * @unrestricted 6 * @unrestricted
7 */ 7 */
8 WebInspector.XMLView = class extends WebInspector.Widget { 8 Network.XMLView = class extends UI.Widget {
9 /** 9 /**
10 * @param {!Document} parsedXML 10 * @param {!Document} parsedXML
11 */ 11 */
12 constructor(parsedXML) { 12 constructor(parsedXML) {
13 super(true); 13 super(true);
14 this.registerRequiredCSS('network/xmlView.css'); 14 this.registerRequiredCSS('network/xmlView.css');
15 this.contentElement.classList.add('shadow-xml-view', 'source-code'); 15 this.contentElement.classList.add('shadow-xml-view', 'source-code');
16 this._treeOutline = new TreeOutlineInShadow(); 16 this._treeOutline = new TreeOutlineInShadow();
17 this._treeOutline.registerRequiredCSS('network/xmlTree.css'); 17 this._treeOutline.registerRequiredCSS('network/xmlTree.css');
18 this.contentElement.appendChild(this._treeOutline.element); 18 this.contentElement.appendChild(this._treeOutline.element);
19 19
20 /** @type {?WebInspector.SearchableView} */ 20 /** @type {?UI.SearchableView} */
21 this._searchableView; 21 this._searchableView;
22 /** @type {number} */ 22 /** @type {number} */
23 this._currentSearchFocusIndex = 0; 23 this._currentSearchFocusIndex = 0;
24 /** @type {!Array.<!TreeElement>} */ 24 /** @type {!Array.<!TreeElement>} */
25 this._currentSearchTreeElements = []; 25 this._currentSearchTreeElements = [];
26 /** @type {?WebInspector.SearchableView.SearchConfig} */ 26 /** @type {?UI.SearchableView.SearchConfig} */
27 this._searchConfig; 27 this._searchConfig;
28 28
29 WebInspector.XMLView.Node.populate(this._treeOutline, parsedXML, this); 29 Network.XMLView.Node.populate(this._treeOutline, parsedXML, this);
30 } 30 }
31 31
32 /** 32 /**
33 * @param {!Document} parsedXML 33 * @param {!Document} parsedXML
34 * @return {!WebInspector.SearchableView} 34 * @return {!UI.SearchableView}
35 */ 35 */
36 static createSearchableView(parsedXML) { 36 static createSearchableView(parsedXML) {
37 var xmlView = new WebInspector.XMLView(parsedXML); 37 var xmlView = new Network.XMLView(parsedXML);
38 var searchableView = new WebInspector.SearchableView(xmlView); 38 var searchableView = new UI.SearchableView(xmlView);
39 searchableView.setPlaceholder(WebInspector.UIString('Find')); 39 searchableView.setPlaceholder(Common.UIString('Find'));
40 xmlView._searchableView = searchableView; 40 xmlView._searchableView = searchableView;
41 xmlView.show(searchableView.element); 41 xmlView.show(searchableView.element);
42 xmlView.contentElement.setAttribute('tabIndex', 0); 42 xmlView.contentElement.setAttribute('tabIndex', 0);
43 return searchableView; 43 return searchableView;
44 } 44 }
45 45
46 /** 46 /**
47 * @param {string} text 47 * @param {string} text
48 * @param {string} mimeType 48 * @param {string} mimeType
49 * @return {?Document} 49 * @return {?Document}
(...skipping 20 matching lines...) Expand all
70 var regex = this._searchConfig.toSearchRegex(true); 70 var regex = this._searchConfig.toSearchRegex(true);
71 var previousFocusElement = this._currentSearchTreeElements[this._currentSear chFocusIndex]; 71 var previousFocusElement = this._currentSearchTreeElements[this._currentSear chFocusIndex];
72 if (previousFocusElement) 72 if (previousFocusElement)
73 previousFocusElement.setSearchRegex(regex); 73 previousFocusElement.setSearchRegex(regex);
74 74
75 var newFocusElement = this._currentSearchTreeElements[index]; 75 var newFocusElement = this._currentSearchTreeElements[index];
76 if (newFocusElement) { 76 if (newFocusElement) {
77 this._updateSearchIndex(index); 77 this._updateSearchIndex(index);
78 if (shouldJump) 78 if (shouldJump)
79 newFocusElement.reveal(true); 79 newFocusElement.reveal(true);
80 newFocusElement.setSearchRegex(regex, WebInspector.highlightedCurrentSearc hResultClassName); 80 newFocusElement.setSearchRegex(regex, UI.highlightedCurrentSearchResultCla ssName);
81 } else { 81 } else {
82 this._updateSearchIndex(0); 82 this._updateSearchIndex(0);
83 } 83 }
84 } 84 }
85 85
86 /** 86 /**
87 * @param {number} count 87 * @param {number} count
88 */ 88 */
89 _updateSearchCount(count) { 89 _updateSearchCount(count) {
90 if (!this._searchableView) 90 if (!this._searchableView)
(...skipping 18 matching lines...) Expand all
109 _innerPerformSearch(shouldJump, jumpBackwards) { 109 _innerPerformSearch(shouldJump, jumpBackwards) {
110 if (!this._searchConfig) 110 if (!this._searchConfig)
111 return; 111 return;
112 var newIndex = this._currentSearchFocusIndex; 112 var newIndex = this._currentSearchFocusIndex;
113 var previousSearchFocusElement = this._currentSearchTreeElements[newIndex]; 113 var previousSearchFocusElement = this._currentSearchTreeElements[newIndex];
114 this._innerSearchCanceled(); 114 this._innerSearchCanceled();
115 this._currentSearchTreeElements = []; 115 this._currentSearchTreeElements = [];
116 var regex = this._searchConfig.toSearchRegex(true); 116 var regex = this._searchConfig.toSearchRegex(true);
117 117
118 for (var element = this._treeOutline.rootElement(); element; element = eleme nt.traverseNextTreeElement(false)) { 118 for (var element = this._treeOutline.rootElement(); element; element = eleme nt.traverseNextTreeElement(false)) {
119 if (!(element instanceof WebInspector.XMLView.Node)) 119 if (!(element instanceof Network.XMLView.Node))
120 continue; 120 continue;
121 var hasMatch = element.setSearchRegex(regex); 121 var hasMatch = element.setSearchRegex(regex);
122 if (hasMatch) 122 if (hasMatch)
123 this._currentSearchTreeElements.push(element); 123 this._currentSearchTreeElements.push(element);
124 if (previousSearchFocusElement === element) { 124 if (previousSearchFocusElement === element) {
125 var currentIndex = this._currentSearchTreeElements.length - 1; 125 var currentIndex = this._currentSearchTreeElements.length - 1;
126 if (hasMatch || jumpBackwards) 126 if (hasMatch || jumpBackwards)
127 newIndex = currentIndex; 127 newIndex = currentIndex;
128 else 128 else
129 newIndex = currentIndex + 1; 129 newIndex = currentIndex + 1;
130 } 130 }
131 } 131 }
132 this._updateSearchCount(this._currentSearchTreeElements.length); 132 this._updateSearchCount(this._currentSearchTreeElements.length);
133 133
134 if (!this._currentSearchTreeElements.length) { 134 if (!this._currentSearchTreeElements.length) {
135 this._updateSearchIndex(0); 135 this._updateSearchIndex(0);
136 return; 136 return;
137 } 137 }
138 newIndex = mod(newIndex, this._currentSearchTreeElements.length); 138 newIndex = mod(newIndex, this._currentSearchTreeElements.length);
139 139
140 this._jumpToMatch(newIndex, shouldJump); 140 this._jumpToMatch(newIndex, shouldJump);
141 } 141 }
142 142
143 _innerSearchCanceled() { 143 _innerSearchCanceled() {
144 for (var element = this._treeOutline.rootElement(); element; element = eleme nt.traverseNextTreeElement(false)) { 144 for (var element = this._treeOutline.rootElement(); element; element = eleme nt.traverseNextTreeElement(false)) {
145 if (!(element instanceof WebInspector.XMLView.Node)) 145 if (!(element instanceof Network.XMLView.Node))
146 continue; 146 continue;
147 element.revertHighlightChanges(); 147 element.revertHighlightChanges();
148 } 148 }
149 this._updateSearchCount(0); 149 this._updateSearchCount(0);
150 this._updateSearchIndex(0); 150 this._updateSearchIndex(0);
151 } 151 }
152 152
153 /** 153 /**
154 * @override 154 * @override
155 */ 155 */
156 searchCanceled() { 156 searchCanceled() {
157 this._searchConfig = null; 157 this._searchConfig = null;
158 this._currentSearchTreeElements = []; 158 this._currentSearchTreeElements = [];
159 this._innerSearchCanceled(); 159 this._innerSearchCanceled();
160 } 160 }
161 161
162 /** 162 /**
163 * @override 163 * @override
164 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig 164 * @param {!UI.SearchableView.SearchConfig} searchConfig
165 * @param {boolean} shouldJump 165 * @param {boolean} shouldJump
166 * @param {boolean=} jumpBackwards 166 * @param {boolean=} jumpBackwards
167 */ 167 */
168 performSearch(searchConfig, shouldJump, jumpBackwards) { 168 performSearch(searchConfig, shouldJump, jumpBackwards) {
169 this._searchConfig = searchConfig; 169 this._searchConfig = searchConfig;
170 this._innerPerformSearch(shouldJump, jumpBackwards); 170 this._innerPerformSearch(shouldJump, jumpBackwards);
171 } 171 }
172 172
173 /** 173 /**
174 * @override 174 * @override
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 */ 206 */
207 supportsRegexSearch() { 207 supportsRegexSearch() {
208 return true; 208 return true;
209 } 209 }
210 }; 210 };
211 211
212 212
213 /** 213 /**
214 * @unrestricted 214 * @unrestricted
215 */ 215 */
216 WebInspector.XMLView.Node = class extends TreeElement { 216 Network.XMLView.Node = class extends TreeElement {
217 /** 217 /**
218 * @param {!Node} node 218 * @param {!Node} node
219 * @param {boolean} closeTag 219 * @param {boolean} closeTag
220 * @param {!WebInspector.XMLView} xmlView 220 * @param {!Network.XMLView} xmlView
221 */ 221 */
222 constructor(node, closeTag, xmlView) { 222 constructor(node, closeTag, xmlView) {
223 super('', !closeTag && !!node.childElementCount); 223 super('', !closeTag && !!node.childElementCount);
224 this._node = node; 224 this._node = node;
225 this._closeTag = closeTag; 225 this._closeTag = closeTag;
226 this.selectable = false; 226 this.selectable = false;
227 /** @type {!Array.<!Object>} */ 227 /** @type {!Array.<!Object>} */
228 this._highlightChanges = []; 228 this._highlightChanges = [];
229 this._xmlView = xmlView; 229 this._xmlView = xmlView;
230 this._updateTitle(); 230 this._updateTitle();
231 } 231 }
232 232
233 /** 233 /**
234 * @param {!TreeOutline|!TreeElement} root 234 * @param {!TreeOutline|!TreeElement} root
235 * @param {!Node} xmlNode 235 * @param {!Node} xmlNode
236 * @param {!WebInspector.XMLView} xmlView 236 * @param {!Network.XMLView} xmlView
237 */ 237 */
238 static populate(root, xmlNode, xmlView) { 238 static populate(root, xmlNode, xmlView) {
239 var node = xmlNode.firstChild; 239 var node = xmlNode.firstChild;
240 while (node) { 240 while (node) {
241 var currentNode = node; 241 var currentNode = node;
242 node = node.nextSibling; 242 node = node.nextSibling;
243 var nodeType = currentNode.nodeType; 243 var nodeType = currentNode.nodeType;
244 // ignore empty TEXT 244 // ignore empty TEXT
245 if (nodeType === 3 && currentNode.nodeValue.match(/\s+/)) 245 if (nodeType === 3 && currentNode.nodeValue.match(/\s+/))
246 continue; 246 continue;
247 // ignore ATTRIBUTE, ENTITY_REFERENCE, ENTITY, DOCUMENT, DOCUMENT_TYPE, DO CUMENT_FRAGMENT, NOTATION 247 // ignore ATTRIBUTE, ENTITY_REFERENCE, ENTITY, DOCUMENT, DOCUMENT_TYPE, DO CUMENT_FRAGMENT, NOTATION
248 if ((nodeType !== 1) && (nodeType !== 3) && (nodeType !== 4) && (nodeType !== 7) && (nodeType !== 8)) 248 if ((nodeType !== 1) && (nodeType !== 3) && (nodeType !== 4) && (nodeType !== 7) && (nodeType !== 8))
249 continue; 249 continue;
250 root.appendChild(new WebInspector.XMLView.Node(currentNode, false, xmlView )); 250 root.appendChild(new Network.XMLView.Node(currentNode, false, xmlView));
251 } 251 }
252 } 252 }
253 253
254 /** 254 /**
255 * @param {?RegExp} regex 255 * @param {?RegExp} regex
256 * @param {string=} additionalCssClassName 256 * @param {string=} additionalCssClassName
257 * @return {boolean} 257 * @return {boolean}
258 */ 258 */
259 setSearchRegex(regex, additionalCssClassName) { 259 setSearchRegex(regex, additionalCssClassName) {
260 this.revertHighlightChanges(); 260 this.revertHighlightChanges();
261 if (!regex) 261 if (!regex)
262 return false; 262 return false;
263 if (this._closeTag && this.parent && !this.parent.expanded) 263 if (this._closeTag && this.parent && !this.parent.expanded)
264 return false; 264 return false;
265 regex.lastIndex = 0; 265 regex.lastIndex = 0;
266 var cssClasses = WebInspector.highlightedSearchResultClassName; 266 var cssClasses = UI.highlightedSearchResultClassName;
267 if (additionalCssClassName) 267 if (additionalCssClassName)
268 cssClasses += ' ' + additionalCssClassName; 268 cssClasses += ' ' + additionalCssClassName;
269 var content = this.listItemElement.textContent.replace(/\xA0/g, ' '); 269 var content = this.listItemElement.textContent.replace(/\xA0/g, ' ');
270 var match = regex.exec(content); 270 var match = regex.exec(content);
271 var ranges = []; 271 var ranges = [];
272 while (match) { 272 while (match) {
273 ranges.push(new WebInspector.SourceRange(match.index, match[0].length)); 273 ranges.push(new Common.SourceRange(match.index, match[0].length));
274 match = regex.exec(content); 274 match = regex.exec(content);
275 } 275 }
276 if (ranges.length) 276 if (ranges.length)
277 WebInspector.highlightRangesWithStyleClass(this.listItemElement, ranges, c ssClasses, this._highlightChanges); 277 UI.highlightRangesWithStyleClass(this.listItemElement, ranges, cssClasses, this._highlightChanges);
278 return !!this._highlightChanges.length; 278 return !!this._highlightChanges.length;
279 } 279 }
280 280
281 revertHighlightChanges() { 281 revertHighlightChanges() {
282 WebInspector.revertDomChanges(this._highlightChanges); 282 UI.revertDomChanges(this._highlightChanges);
283 this._highlightChanges = []; 283 this._highlightChanges = [];
284 } 284 }
285 285
286 _updateTitle() { 286 _updateTitle() {
287 var node = this._node; 287 var node = this._node;
288 switch (node.nodeType) { 288 switch (node.nodeType) {
289 case 1: // ELEMENT 289 case 1: // ELEMENT
290 var tag = node.tagName; 290 var tag = node.tagName;
291 if (this._closeTag) { 291 if (this._closeTag) {
292 this._setTitle(['</' + tag + '>', 'shadow-xml-view-tag']); 292 this._setTitle(['</' + tag + '>', 'shadow-xml-view-tag']);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 * @override 362 * @override
363 */ 363 */
364 oncollapse() { 364 oncollapse() {
365 this._updateTitle(); 365 this._updateTitle();
366 } 366 }
367 367
368 /** 368 /**
369 * @override 369 * @override
370 */ 370 */
371 onpopulate() { 371 onpopulate() {
372 WebInspector.XMLView.Node.populate(this, this._node, this._xmlView); 372 Network.XMLView.Node.populate(this, this._node, this._xmlView);
373 this.appendChild(new WebInspector.XMLView.Node(this._node, true, this._xmlVi ew)); 373 this.appendChild(new Network.XMLView.Node(this._node, true, this._xmlView));
374 } 374 }
375 }; 375 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698