| OLD | NEW |
| 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 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.Widget} | 7 * @extends {WebInspector.Widget} |
| 8 * @implements {WebInspector.Searchable} | 8 * @implements {WebInspector.Searchable} |
| 9 * @param {!Document} parsedXML | 9 * @param {!Document} parsedXML |
| 10 */ | 10 */ |
| 11 WebInspector.XMLView = function(parsedXML) | 11 WebInspector.XMLView = function(parsedXML) |
| 12 { | 12 { |
| 13 WebInspector.Widget.call(this, true); | 13 WebInspector.Widget.call(this, 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 {?WebInspector.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 {?WebInspector.SearchableView.SearchConfig} */ |
| 27 this._searchConfig; | 27 this._searchConfig; |
| 28 | 28 |
| 29 WebInspector.XMLView.Node.populate(this._treeOutline, parsedXML, this); | 29 WebInspector.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 {!WebInspector.SearchableView} |
| 35 */ | 35 */ |
| 36 WebInspector.XMLView.createSearchableView = function(parsedXML) | 36 WebInspector.XMLView.createSearchableView = function(parsedXML) |
| 37 { | 37 { |
| 38 var xmlView = new WebInspector.XMLView(parsedXML); | 38 var xmlView = new WebInspector.XMLView(parsedXML); |
| 39 var searchableView = new WebInspector.SearchableView(xmlView); | 39 var searchableView = new WebInspector.SearchableView(xmlView); |
| 40 searchableView.setPlaceholder(WebInspector.UIString("Find")); | 40 searchableView.setPlaceholder(WebInspector.UIString("Find")); |
| 41 xmlView._searchableView = searchableView; | 41 xmlView._searchableView = searchableView; |
| 42 xmlView.show(searchableView.element); | 42 xmlView.show(searchableView.element); |
| 43 xmlView.contentElement.setAttribute("tabIndex", 0); | 43 xmlView.contentElement.setAttribute("tabIndex", 0); |
| 44 return searchableView; | 44 return searchableView; |
| 45 } | 45 }; |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * @param {string} text | 48 * @param {string} text |
| 49 * @param {string} mimeType | 49 * @param {string} mimeType |
| 50 * @return {?Document} | 50 * @return {?Document} |
| 51 */ | 51 */ |
| 52 WebInspector.XMLView.parseXML = function(text, mimeType) | 52 WebInspector.XMLView.parseXML = function(text, mimeType) |
| 53 { | 53 { |
| 54 var parsedXML; | 54 var parsedXML; |
| 55 try { | 55 try { |
| 56 parsedXML = (new DOMParser()).parseFromString(text, mimeType); | 56 parsedXML = (new DOMParser()).parseFromString(text, mimeType); |
| 57 } catch (e) { | 57 } catch (e) { |
| 58 return null; | 58 return null; |
| 59 } | 59 } |
| 60 if (parsedXML.body) | 60 if (parsedXML.body) |
| 61 return null; | 61 return null; |
| 62 return parsedXML; | 62 return parsedXML; |
| 63 } | 63 }; |
| 64 | 64 |
| 65 WebInspector.XMLView.prototype = { | 65 WebInspector.XMLView.prototype = { |
| 66 /** | 66 /** |
| 67 * @param {number} index | 67 * @param {number} index |
| 68 * @param {boolean} shouldJump | 68 * @param {boolean} shouldJump |
| 69 */ | 69 */ |
| 70 _jumpToMatch: function(index, shouldJump) | 70 _jumpToMatch: function(index, shouldJump) |
| 71 { | 71 { |
| 72 if (!this._searchConfig) | 72 if (!this._searchConfig) |
| 73 return; | 73 return; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 /** | 216 /** |
| 217 * @override | 217 * @override |
| 218 * @return {boolean} | 218 * @return {boolean} |
| 219 */ | 219 */ |
| 220 supportsRegexSearch: function() | 220 supportsRegexSearch: function() |
| 221 { | 221 { |
| 222 return true; | 222 return true; |
| 223 }, | 223 }, |
| 224 | 224 |
| 225 __proto__: WebInspector.Widget.prototype | 225 __proto__: WebInspector.Widget.prototype |
| 226 } | 226 }; |
| 227 | 227 |
| 228 /** | 228 /** |
| 229 * @constructor | 229 * @constructor |
| 230 * @extends {TreeElement} | 230 * @extends {TreeElement} |
| 231 * @param {!Node} node | 231 * @param {!Node} node |
| 232 * @param {boolean} closeTag | 232 * @param {boolean} closeTag |
| 233 * @param {!WebInspector.XMLView} xmlView | 233 * @param {!WebInspector.XMLView} xmlView |
| 234 */ | 234 */ |
| 235 WebInspector.XMLView.Node = function(node, closeTag, xmlView) | 235 WebInspector.XMLView.Node = function(node, closeTag, xmlView) |
| 236 { | 236 { |
| 237 TreeElement.call(this, "", !closeTag && !!node.childElementCount); | 237 TreeElement.call(this, "", !closeTag && !!node.childElementCount); |
| 238 this._node = node; | 238 this._node = node; |
| 239 this._closeTag = closeTag; | 239 this._closeTag = closeTag; |
| 240 this.selectable = false; | 240 this.selectable = false; |
| 241 /** @type {!Array.<!Object>} */ | 241 /** @type {!Array.<!Object>} */ |
| 242 this._highlightChanges = []; | 242 this._highlightChanges = []; |
| 243 this._xmlView = xmlView; | 243 this._xmlView = xmlView; |
| 244 this._updateTitle(); | 244 this._updateTitle(); |
| 245 } | 245 }; |
| 246 | 246 |
| 247 /** | 247 /** |
| 248 * @param {!TreeOutline|!TreeElement} root | 248 * @param {!TreeOutline|!TreeElement} root |
| 249 * @param {!Node} xmlNode | 249 * @param {!Node} xmlNode |
| 250 * @param {!WebInspector.XMLView} xmlView | 250 * @param {!WebInspector.XMLView} xmlView |
| 251 */ | 251 */ |
| 252 WebInspector.XMLView.Node.populate = function(root, xmlNode, xmlView) | 252 WebInspector.XMLView.Node.populate = function(root, xmlNode, xmlView) |
| 253 { | 253 { |
| 254 var node = xmlNode.firstChild; | 254 var node = xmlNode.firstChild; |
| 255 while (node) { | 255 while (node) { |
| 256 var currentNode = node; | 256 var currentNode = node; |
| 257 node = node.nextSibling; | 257 node = node.nextSibling; |
| 258 var nodeType = currentNode.nodeType; | 258 var nodeType = currentNode.nodeType; |
| 259 // ignore empty TEXT | 259 // ignore empty TEXT |
| 260 if (nodeType === 3 && currentNode.nodeValue.match(/\s+/)) | 260 if (nodeType === 3 && currentNode.nodeValue.match(/\s+/)) |
| 261 continue; | 261 continue; |
| 262 // ignore ATTRIBUTE, ENTITY_REFERENCE, ENTITY, DOCUMENT, DOCUMENT_TYPE,
DOCUMENT_FRAGMENT, NOTATION | 262 // ignore ATTRIBUTE, ENTITY_REFERENCE, ENTITY, DOCUMENT, DOCUMENT_TYPE,
DOCUMENT_FRAGMENT, NOTATION |
| 263 if ((nodeType !== 1) && (nodeType !== 3) && (nodeType !== 4) && (nodeTyp
e !== 7) && (nodeType !== 8)) | 263 if ((nodeType !== 1) && (nodeType !== 3) && (nodeType !== 4) && (nodeTyp
e !== 7) && (nodeType !== 8)) |
| 264 continue; | 264 continue; |
| 265 root.appendChild(new WebInspector.XMLView.Node(currentNode, false, xmlVi
ew)); | 265 root.appendChild(new WebInspector.XMLView.Node(currentNode, false, xmlVi
ew)); |
| 266 } | 266 } |
| 267 } | 267 }; |
| 268 | 268 |
| 269 WebInspector.XMLView.Node.prototype = { | 269 WebInspector.XMLView.Node.prototype = { |
| 270 /** | 270 /** |
| 271 * @param {?RegExp} regex | 271 * @param {?RegExp} regex |
| 272 * @param {string=} additionalCssClassName | 272 * @param {string=} additionalCssClassName |
| 273 * @return {boolean} | 273 * @return {boolean} |
| 274 */ | 274 */ |
| 275 setSearchRegex: function(regex, additionalCssClassName) | 275 setSearchRegex: function(regex, additionalCssClassName) |
| 276 { | 276 { |
| 277 this.revertHighlightChanges(); | 277 this.revertHighlightChanges(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 313 } |
| 314 var titleItems = ["<" + tag, "shadow-xml-view-tag"]; | 314 var titleItems = ["<" + tag, "shadow-xml-view-tag"]; |
| 315 var attributes = node.attributes; | 315 var attributes = node.attributes; |
| 316 for (var i = 0; i < attributes.length; ++i) { | 316 for (var i = 0; i < attributes.length; ++i) { |
| 317 var attributeNode = attributes.item(i); | 317 var attributeNode = attributes.item(i); |
| 318 titleItems.push( | 318 titleItems.push( |
| 319 "\u00a0", "shadow-xml-view-tag", | 319 "\u00a0", "shadow-xml-view-tag", |
| 320 attributeNode.name, "shadow-xml-view-attribute-name", | 320 attributeNode.name, "shadow-xml-view-attribute-name", |
| 321 "=\"", "shadow-xml-view-tag", | 321 "=\"", "shadow-xml-view-tag", |
| 322 attributeNode.value, "shadow-xml-view-attribute-value", | 322 attributeNode.value, "shadow-xml-view-attribute-value", |
| 323 "\"", "shadow-xml-view-tag") | 323 "\"", "shadow-xml-view-tag"); |
| 324 } | 324 } |
| 325 if (!this.expanded) { | 325 if (!this.expanded) { |
| 326 if (node.childElementCount) { | 326 if (node.childElementCount) { |
| 327 titleItems.push( | 327 titleItems.push( |
| 328 ">", "shadow-xml-view-tag", | 328 ">", "shadow-xml-view-tag", |
| 329 "\u2026", "shadow-xml-view-comment", | 329 "\u2026", "shadow-xml-view-comment", |
| 330 "</" + tag, "shadow-xml-view-tag"); | 330 "</" + tag, "shadow-xml-view-tag"); |
| 331 } else if (this._node.textContent) { | 331 } else if (this._node.textContent) { |
| 332 titleItems.push( | 332 titleItems.push( |
| 333 ">", "shadow-xml-view-tag", | 333 ">", "shadow-xml-view-tag", |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 this._updateTitle(); | 385 this._updateTitle(); |
| 386 }, | 386 }, |
| 387 | 387 |
| 388 onpopulate: function() | 388 onpopulate: function() |
| 389 { | 389 { |
| 390 WebInspector.XMLView.Node.populate(this, this._node, this._xmlView); | 390 WebInspector.XMLView.Node.populate(this, this._node, this._xmlView); |
| 391 this.appendChild(new WebInspector.XMLView.Node(this._node, true, this._x
mlView)); | 391 this.appendChild(new WebInspector.XMLView.Node(this._node, true, this._x
mlView)); |
| 392 }, | 392 }, |
| 393 | 393 |
| 394 __proto__: TreeElement.prototype | 394 __proto__: TreeElement.prototype |
| 395 } | 395 }; |
| OLD | NEW |