| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 /** |
| 5 * @unrestricted |
| 6 */ |
| 7 WebInspector.ReportView = class extends WebInspector.VBox { |
| 8 /** |
| 9 * @param {string} title |
| 10 */ |
| 11 constructor(title) { |
| 12 super(true); |
| 13 this.registerRequiredCSS('ui/reportView.css'); |
| 4 | 14 |
| 5 /** | 15 var contentBox = this.contentElement.createChild('div', 'report-content-box'
); |
| 6 * @constructor | 16 this._headerElement = contentBox.createChild('div', 'report-header vbox'); |
| 7 * @extends {WebInspector.VBox} | 17 this._headerElement.createChild('div', 'report-title').textContent = title; |
| 8 * @param {string} title | |
| 9 */ | |
| 10 WebInspector.ReportView = function(title) | |
| 11 { | |
| 12 WebInspector.VBox.call(this, true); | |
| 13 this.registerRequiredCSS("ui/reportView.css"); | |
| 14 | 18 |
| 15 var contentBox = this.contentElement.createChild("div", "report-content-box"
); | 19 this._sectionList = contentBox.createChild('div', 'vbox'); |
| 16 this._headerElement = contentBox.createChild("div", "report-header vbox"); | 20 } |
| 17 this._headerElement.createChild("div", "report-title").textContent = title; | |
| 18 | 21 |
| 19 this._sectionList = contentBox.createChild("div", "vbox"); | 22 /** |
| 20 }; | 23 * @param {string} subtitle |
| 24 */ |
| 25 setSubtitle(subtitle) { |
| 26 if (this._subtitleElement && this._subtitleElement.textContent === subtitle) |
| 27 return; |
| 28 if (!this._subtitleElement) |
| 29 this._subtitleElement = this._headerElement.createChild('div', 'report-sub
title'); |
| 30 this._subtitleElement.textContent = subtitle; |
| 31 } |
| 21 | 32 |
| 22 WebInspector.ReportView.prototype = { | 33 /** |
| 23 /** | 34 * @param {?string} url |
| 24 * @param {string} subtitle | 35 */ |
| 25 */ | 36 setURL(url) { |
| 26 setSubtitle: function(subtitle) | 37 if (this._url === url) |
| 27 { | 38 return; |
| 28 if (this._subtitleElement && this._subtitleElement.textContent === subti
tle) | 39 if (!this._urlElement) |
| 29 return; | 40 this._urlElement = this._headerElement.createChild('div', 'report-url link
'); |
| 30 if (!this._subtitleElement) | |
| 31 this._subtitleElement = this._headerElement.createChild("div", "repo
rt-subtitle"); | |
| 32 this._subtitleElement.textContent = subtitle; | |
| 33 }, | |
| 34 | 41 |
| 35 /** | 42 this._url = url; |
| 36 * @param {?string} url | 43 this._urlElement.removeChildren(); |
| 37 */ | 44 if (url) |
| 38 setURL: function(url) | 45 this._urlElement.appendChild(WebInspector.linkifyURLAsNode(url)); |
| 39 { | 46 } |
| 40 if (this._url === url) | |
| 41 return; | |
| 42 if (!this._urlElement) | |
| 43 this._urlElement = this._headerElement.createChild("div", "report-ur
l link"); | |
| 44 | 47 |
| 45 this._url = url; | 48 /** |
| 46 this._urlElement.removeChildren(); | 49 * @return {!WebInspector.Toolbar} |
| 47 if (url) | 50 */ |
| 48 this._urlElement.appendChild(WebInspector.linkifyURLAsNode(url)); | 51 createToolbar() { |
| 49 }, | 52 var toolbar = new WebInspector.Toolbar(''); |
| 53 this._headerElement.appendChild(toolbar.element); |
| 54 return toolbar; |
| 55 } |
| 50 | 56 |
| 51 /** | 57 /** |
| 52 * @return {!WebInspector.Toolbar} | 58 * @param {string} title |
| 53 */ | 59 * @param {string=} className |
| 54 createToolbar: function() | 60 * @return {!WebInspector.ReportView.Section} |
| 55 { | 61 */ |
| 56 var toolbar = new WebInspector.Toolbar(""); | 62 appendSection(title, className) { |
| 57 this._headerElement.appendChild(toolbar.element); | 63 var section = new WebInspector.ReportView.Section(title, className); |
| 58 return toolbar; | 64 section.show(this._sectionList); |
| 59 }, | 65 return section; |
| 66 } |
| 60 | 67 |
| 61 /** | 68 removeAllSection() { |
| 62 * @param {string} title | 69 this._sectionList.removeChildren(); |
| 63 * @param {string=} className | 70 } |
| 64 * @return {!WebInspector.ReportView.Section} | |
| 65 */ | |
| 66 appendSection: function(title, className) | |
| 67 { | |
| 68 var section = new WebInspector.ReportView.Section(title, className); | |
| 69 section.show(this._sectionList); | |
| 70 return section; | |
| 71 }, | |
| 72 | |
| 73 removeAllSection: function() | |
| 74 { | |
| 75 this._sectionList.removeChildren(); | |
| 76 }, | |
| 77 | |
| 78 __proto__: WebInspector.VBox.prototype | |
| 79 }; | 71 }; |
| 80 | 72 |
| 81 /** | 73 /** |
| 82 * @constructor | 74 * @unrestricted |
| 83 * @extends {WebInspector.VBox} | |
| 84 * @param {string} title | |
| 85 * @param {string=} className | |
| 86 */ | 75 */ |
| 87 WebInspector.ReportView.Section = function(title, className) | 76 WebInspector.ReportView.Section = class extends WebInspector.VBox { |
| 88 { | 77 /** |
| 89 WebInspector.VBox.call(this); | 78 * @param {string} title |
| 90 this.element.classList.add("report-section"); | 79 * @param {string=} className |
| 80 */ |
| 81 constructor(title, className) { |
| 82 super(); |
| 83 this.element.classList.add('report-section'); |
| 91 if (className) | 84 if (className) |
| 92 this.element.classList.add(className); | 85 this.element.classList.add(className); |
| 93 this._headerElement = this.element.createChild("div", "report-section-header
"); | 86 this._headerElement = this.element.createChild('div', 'report-section-header
'); |
| 94 this._titleElement = this._headerElement.createChild("div", "report-section-
title"); | 87 this._titleElement = this._headerElement.createChild('div', 'report-section-
title'); |
| 95 this._titleElement.textContent = title; | 88 this._titleElement.textContent = title; |
| 96 this._fieldList = this.element.createChild("div", "vbox"); | 89 this._fieldList = this.element.createChild('div', 'vbox'); |
| 97 /** @type {!Map.<string, !Element>} */ | 90 /** @type {!Map.<string, !Element>} */ |
| 98 this._fieldMap = new Map(); | 91 this._fieldMap = new Map(); |
| 92 } |
| 93 |
| 94 /** |
| 95 * @param {string} title |
| 96 */ |
| 97 setTitle(title) { |
| 98 if (this._titleElement.textContent !== title) |
| 99 this._titleElement.textContent = title; |
| 100 } |
| 101 |
| 102 /** |
| 103 * @return {!WebInspector.Toolbar} |
| 104 */ |
| 105 createToolbar() { |
| 106 var toolbar = new WebInspector.Toolbar(''); |
| 107 this._headerElement.appendChild(toolbar.element); |
| 108 return toolbar; |
| 109 } |
| 110 |
| 111 /** |
| 112 * @param {string} title |
| 113 * @param {string=} textValue |
| 114 * @return {!Element} |
| 115 */ |
| 116 appendField(title, textValue) { |
| 117 var row = this._fieldMap.get(title); |
| 118 if (!row) { |
| 119 row = this._fieldList.createChild('div', 'report-field'); |
| 120 row.createChild('div', 'report-field-name').textContent = title; |
| 121 this._fieldMap.set(title, row); |
| 122 row.createChild('div', 'report-field-value'); |
| 123 } |
| 124 if (textValue) |
| 125 row.lastElementChild.textContent = textValue; |
| 126 return /** @type {!Element} */ (row.lastElementChild); |
| 127 } |
| 128 |
| 129 remove() { |
| 130 this.element.remove(); |
| 131 } |
| 132 |
| 133 /** |
| 134 * @param {string} title |
| 135 */ |
| 136 removeField(title) { |
| 137 var row = this._fieldMap.get(title); |
| 138 if (row) |
| 139 row.remove(); |
| 140 this._fieldMap.delete(title); |
| 141 } |
| 142 |
| 143 /** |
| 144 * @param {string} title |
| 145 * @param {boolean} visible |
| 146 */ |
| 147 setFieldVisible(title, visible) { |
| 148 var row = this._fieldMap.get(title); |
| 149 if (row) |
| 150 row.classList.toggle('hidden', !visible); |
| 151 } |
| 152 |
| 153 /** |
| 154 * @param {string} title |
| 155 * @return {?Element} |
| 156 */ |
| 157 fieldValue(title) { |
| 158 var row = this._fieldMap.get(title); |
| 159 return row ? row.lastElementChild : null; |
| 160 } |
| 161 |
| 162 /** |
| 163 * @return {!Element} |
| 164 */ |
| 165 appendRow() { |
| 166 return this._fieldList.createChild('div', 'report-row'); |
| 167 } |
| 168 |
| 169 clearContent() { |
| 170 this._fieldList.removeChildren(); |
| 171 this._fieldMap.clear(); |
| 172 } |
| 99 }; | 173 }; |
| 100 | |
| 101 WebInspector.ReportView.Section.prototype = { | |
| 102 /** | |
| 103 * @param {string} title | |
| 104 */ | |
| 105 setTitle: function(title) | |
| 106 { | |
| 107 if (this._titleElement.textContent !== title) | |
| 108 this._titleElement.textContent = title; | |
| 109 }, | |
| 110 | |
| 111 /** | |
| 112 * @return {!WebInspector.Toolbar} | |
| 113 */ | |
| 114 createToolbar: function() | |
| 115 { | |
| 116 var toolbar = new WebInspector.Toolbar(""); | |
| 117 this._headerElement.appendChild(toolbar.element); | |
| 118 return toolbar; | |
| 119 }, | |
| 120 | |
| 121 /** | |
| 122 * @param {string} title | |
| 123 * @param {string=} textValue | |
| 124 * @return {!Element} | |
| 125 */ | |
| 126 appendField: function(title, textValue) | |
| 127 { | |
| 128 var row = this._fieldMap.get(title); | |
| 129 if (!row) { | |
| 130 row = this._fieldList.createChild("div", "report-field"); | |
| 131 row.createChild("div", "report-field-name").textContent = title; | |
| 132 this._fieldMap.set(title, row); | |
| 133 row.createChild("div", "report-field-value"); | |
| 134 } | |
| 135 if (textValue) | |
| 136 row.lastElementChild.textContent = textValue; | |
| 137 return /** @type {!Element} */ (row.lastElementChild); | |
| 138 }, | |
| 139 | |
| 140 remove: function() | |
| 141 { | |
| 142 this.element.remove(); | |
| 143 }, | |
| 144 | |
| 145 /** | |
| 146 * @param {string} title | |
| 147 */ | |
| 148 removeField: function(title) | |
| 149 { | |
| 150 var row = this._fieldMap.get(title); | |
| 151 if (row) | |
| 152 row.remove(); | |
| 153 this._fieldMap.delete(title); | |
| 154 }, | |
| 155 | |
| 156 /** | |
| 157 * @param {string} title | |
| 158 * @param {boolean} visible | |
| 159 */ | |
| 160 setFieldVisible: function(title, visible) | |
| 161 { | |
| 162 var row = this._fieldMap.get(title); | |
| 163 if (row) | |
| 164 row.classList.toggle("hidden", !visible); | |
| 165 }, | |
| 166 | |
| 167 /** | |
| 168 * @param {string} title | |
| 169 * @return {?Element} | |
| 170 */ | |
| 171 fieldValue: function(title) | |
| 172 { | |
| 173 var row = this._fieldMap.get(title); | |
| 174 return row ? row.lastElementChild : null; | |
| 175 }, | |
| 176 | |
| 177 /** | |
| 178 * @return {!Element} | |
| 179 */ | |
| 180 appendRow: function() | |
| 181 { | |
| 182 return this._fieldList.createChild("div", "report-row"); | |
| 183 }, | |
| 184 | |
| 185 clearContent: function() | |
| 186 { | |
| 187 this._fieldList.removeChildren(); | |
| 188 this._fieldMap.clear(); | |
| 189 }, | |
| 190 | |
| 191 __proto__: WebInspector.VBox.prototype | |
| 192 }; | |
| OLD | NEW |