| 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 | 4 |
| 5 /** | 5 /** |
| 6 * @unrestricted | 6 * @unrestricted |
| 7 */ | 7 */ |
| 8 Audits2.Audits2Panel = class extends UI.PanelWithSidebar { | 8 Audits2.Audits2Panel = class extends UI.PanelWithSidebar { |
| 9 constructor() { | 9 constructor() { |
| 10 super('audits2'); | 10 super('audits2'); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 var clearButton = new UI.ToolbarButton(Common.UIString('Clear all'), 'largei
con-clear'); | 30 var clearButton = new UI.ToolbarButton(Common.UIString('Clear all'), 'largei
con-clear'); |
| 31 toolbar.appendToolbarItem(clearButton); | 31 toolbar.appendToolbarItem(clearButton); |
| 32 clearButton.addEventListener(UI.ToolbarButton.Events.Click, this._clearAll.b
ind(this)); | 32 clearButton.addEventListener(UI.ToolbarButton.Events.Click, this._clearAll.b
ind(this)); |
| 33 | 33 |
| 34 this._treeOutline = new UI.TreeOutlineInShadow(); | 34 this._treeOutline = new UI.TreeOutlineInShadow(); |
| 35 this._treeOutline.registerRequiredCSS('audits2/lighthouse/report-styles.css'
); | 35 this._treeOutline.registerRequiredCSS('audits2/lighthouse/report-styles.css'
); |
| 36 this._treeOutline.registerRequiredCSS('audits2/audits2Tree.css'); | 36 this._treeOutline.registerRequiredCSS('audits2/audits2Tree.css'); |
| 37 this.panelSidebarElement().appendChild(this._treeOutline.element); | 37 this.panelSidebarElement().appendChild(this._treeOutline.element); |
| 38 | 38 |
| 39 this._dropTarget = new UI.DropTarget( | 39 this._dropTarget = new UI.DropTarget( |
| 40 this.contentElement, [UI.DropTarget.Types.Files], | 40 this.contentElement, [UI.DropTarget.Types.Files], Common.UIString('Drop
audit file here'), |
| 41 Common.UIString('Drop audit file here'), this._handleDrop.bind(this)); | 41 this._handleDrop.bind(this)); |
| 42 | 42 |
| 43 this._showLandingPage(); | 43 this._showLandingPage(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 _clearAll() { | 46 _clearAll() { |
| 47 this._treeOutline.removeChildren(); | 47 this._treeOutline.removeChildren(); |
| 48 if (!this._treeOutline.rootElement().childCount()) | 48 if (!this._treeOutline.rootElement().childCount()) |
| 49 this._showLandingPage(); | 49 this._showLandingPage(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 _deleteSelected() { | 52 _deleteSelected() { |
| 53 var selection = this._treeOutline.selectedTreeElement; | 53 var selection = this._treeOutline.selectedTreeElement; |
| 54 if (selection) | 54 if (selection) |
| 55 this._treeOutline.removeChild(selection); | 55 this._treeOutline.removeChild(selection); |
| 56 if (!this._treeOutline.rootElement().childCount()) | 56 if (!this._treeOutline.rootElement().childCount()) |
| 57 this._showLandingPage(); | 57 this._showLandingPage(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 _showLandingPage() { | 60 _showLandingPage() { |
| 61 this.mainElement().removeChildren(); | 61 this.mainElement().removeChildren(); |
| 62 var landingPage = this.mainElement().createChild('div', 'vbox audits2-landin
g-page'); | 62 var landingPage = this.mainElement().createChild('div', 'vbox audits2-landin
g-page'); |
| 63 var landingCenter = landingPage.createChild('div', 'vbox audits2-landing-cen
ter'); | 63 var landingCenter = landingPage.createChild('div', 'vbox audits2-landing-cen
ter'); |
| 64 landingCenter.createChild('div', 'audits2-logo'); | 64 landingCenter.createChild('div', 'audits2-logo'); |
| 65 var text = landingCenter.createChild('div', 'audits2-landing-text'); | 65 var text = landingCenter.createChild('div', 'audits2-landing-text'); |
| 66 text.createChild('span', 'audits2-landing-bold-text').textContent = Common.U
IString('Audits'); | 66 text.createChild('span', 'audits2-landing-bold-text').textContent = Common.U
IString('Audits'); |
| 67 text.createChild('span').textContent = Common.UIString(' help you identify a
nd fix common problems that affect' + | 67 text.createChild('span').textContent = Common.UIString( |
| 68 ' help you identify and fix common problems that affect' + |
| 68 ' your site\'s performance, accessibility, and user experience. '); | 69 ' your site\'s performance, accessibility, and user experience. '); |
| 69 var link = text.createChild('span', 'link'); | 70 var link = text.createChild('span', 'link'); |
| 70 link.textContent = Common.UIString('Learn more'); | 71 link.textContent = Common.UIString('Learn more'); |
| 71 link.addEventListener( | 72 link.addEventListener( |
| 72 'click', () => InspectorFrontendHost.openInNewTab('https://developers.go
ogle.com/web/tools/lighthouse/')); | 73 'click', () => InspectorFrontendHost.openInNewTab('https://developers.go
ogle.com/web/tools/lighthouse/')); |
| 73 | 74 |
| 74 var newButton = UI.createTextButton( | 75 var newButton = UI.createTextButton( |
| 75 Common.UIString('Perform an audit\u2026'), this._showLauncherUI.bind(thi
s), 'material-button default'); | 76 Common.UIString('Perform an audit\u2026'), this._showLauncherUI.bind(thi
s), 'material-button default'); |
| 76 landingCenter.appendChild(newButton); | 77 landingCenter.appendChild(newButton); |
| 77 } | 78 } |
| 78 | 79 |
| 79 _showLauncherUI() { | 80 _showLauncherUI() { |
| 80 this._dialog = new UI.Dialog(); | 81 this._dialog = new UI.Dialog(); |
| 81 this._dialog.setOutsideClickCallback(event => event.consume(true)); | 82 this._dialog.setOutsideClickCallback(event => event.consume(true)); |
| 82 var root = UI.createShadowRootWithCoreStyles(this._dialog.contentElement, 'a
udits2/audits2Dialog.css'); | 83 var root = UI.createShadowRootWithCoreStyles(this._dialog.contentElement, 'a
udits2/audits2Dialog.css'); |
| 83 var auditsViewElement = root.createChild('div', 'audits2-view'); | 84 var auditsViewElement = root.createChild('div', 'audits2-view'); |
| 84 var uiElement = auditsViewElement.createChild('div'); | 85 var uiElement = auditsViewElement.createChild('div'); |
| 85 var headerElement = uiElement.createChild('header'); | 86 var headerElement = uiElement.createChild('header'); |
| 86 headerElement.createChild('p').textContent = Common.UIString('Audits to perf
orm'); | 87 this._headerTitleElement = headerElement.createChild('p'); |
| 88 this._headerTitleElement.textContent = Common.UIString('Audits to perform'); |
| 87 uiElement.appendChild(headerElement); | 89 uiElement.appendChild(headerElement); |
| 88 | 90 |
| 89 var auditSelectorForm = uiElement.createChild('form', 'audits2-form'); | 91 this._auditSelectorForm = uiElement.createChild('form', 'audits2-form'); |
| 90 | 92 |
| 91 for (var preset of Audits2.Audits2Panel.Presets) { | 93 for (var preset of Audits2.Audits2Panel.Presets) { |
| 92 preset.setting.setTitle(preset.title); | 94 preset.setting.setTitle(preset.title); |
| 93 var checkbox = new UI.ToolbarSettingCheckbox(preset.setting); | 95 var checkbox = new UI.ToolbarSettingCheckbox(preset.setting); |
| 94 var row = auditSelectorForm.createChild('div', 'vbox audits2-launcher-row'
); | 96 var row = this._auditSelectorForm.createChild('div', 'vbox audits2-launche
r-row'); |
| 95 row.appendChild(checkbox.element); | 97 row.appendChild(checkbox.element); |
| 96 row.createChild('span', 'audits2-launcher-description dimmed').textContent
= preset.description; | 98 row.createChild('span', 'audits2-launcher-description dimmed').textContent
= preset.description; |
| 97 } | 99 } |
| 98 | 100 |
| 101 this._statusView = this._createStatusView(uiElement); |
| 102 |
| 103 var buttonsRow = uiElement.createChild('div', 'audits2-dialog-buttons hbox')
; |
| 99 this._startButton = | 104 this._startButton = |
| 100 UI.createTextButton(Common.UIString('Run audit'), this._start.bind(this)
, 'material-button default'); | 105 UI.createTextButton(Common.UIString('Run audit'), this._start.bind(this)
, 'material-button default'); |
| 101 auditSelectorForm.appendChild(this._startButton); | 106 buttonsRow.appendChild(this._startButton); |
| 102 this._cancelButton = UI.createTextButton(Common.UIString('Cancel'), this._ca
ncel.bind(this), 'material-button'); | 107 this._cancelButton = UI.createTextButton(Common.UIString('Cancel'), this._ca
ncel.bind(this), 'material-button'); |
| 103 auditSelectorForm.appendChild(this._cancelButton); | 108 buttonsRow.appendChild(this._cancelButton); |
| 104 | |
| 105 this._statusView = this._createStatusView(uiElement); | |
| 106 | 109 |
| 107 this._dialog.setSizeBehavior(UI.GlassPane.SizeBehavior.SetExactWidthMaxHeigh
t); | 110 this._dialog.setSizeBehavior(UI.GlassPane.SizeBehavior.SetExactWidthMaxHeigh
t); |
| 108 this._dialog.setMaxContentSize(new UI.Size(600, 400)); | 111 this._dialog.setMaxContentSize(new UI.Size(500, 400)); |
| 109 this._dialog.show(this.mainElement()); | 112 this._dialog.show(this.mainElement()); |
| 110 auditsViewElement.tabIndex = 0; | 113 auditsViewElement.tabIndex = 0; |
| 111 auditsViewElement.focus(); | 114 auditsViewElement.focus(); |
| 112 } | 115 } |
| 113 | 116 |
| 114 /** | 117 /** |
| 115 * @param {!Element} launcherUIElement | 118 * @param {!Element} launcherUIElement |
| 116 * @return {!Element} | 119 * @return {!Element} |
| 117 */ | 120 */ |
| 118 _createStatusView(launcherUIElement) { | 121 _createStatusView(launcherUIElement) { |
| 119 var statusView = launcherUIElement.createChild('div', 'audits2-status hbox h
idden'); | 122 var statusView = launcherUIElement.createChild('div', 'audits2-status vbox h
idden'); |
| 120 this._statusIcon = statusView.createChild('span', 'icon'); | 123 this._statusIcon = statusView.createChild('div', 'icon'); |
| 121 this._statusElement = statusView.createChild('p'); | 124 this._statusElement = statusView.createChild('div'); |
| 122 this._updateStatus(Common.UIString('Loading...')); | 125 this._updateStatus(Common.UIString('Loading...')); |
| 123 return statusView; | 126 return statusView; |
| 124 } | 127 } |
| 125 | 128 |
| 126 _start() { | 129 _start() { |
| 127 this._dialog.setCloseOnEscape(false); | 130 this._dialog.setCloseOnEscape(false); |
| 128 this._inspectedURL = SDK.targetManager.mainTarget().inspectedURL(); | 131 this._inspectedURL = SDK.targetManager.mainTarget().inspectedURL(); |
| 129 | 132 |
| 130 var categoryIDs = []; | 133 var categoryIDs = []; |
| 131 for (var preset of Audits2.Audits2Panel.Presets) { | 134 for (var preset of Audits2.Audits2Panel.Presets) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 154 _hideDialog() { | 157 _hideDialog() { |
| 155 if (!this._dialog) | 158 if (!this._dialog) |
| 156 return; | 159 return; |
| 157 this._dialog.hide(); | 160 this._dialog.hide(); |
| 158 delete this._dialog; | 161 delete this._dialog; |
| 159 delete this._statusView; | 162 delete this._statusView; |
| 160 delete this._statusIcon; | 163 delete this._statusIcon; |
| 161 delete this._statusElement; | 164 delete this._statusElement; |
| 162 delete this._startButton; | 165 delete this._startButton; |
| 163 delete this._cancelButton; | 166 delete this._cancelButton; |
| 167 delete this._auditSelectorForm; |
| 168 delete this._headerTitleElement; |
| 164 } | 169 } |
| 165 | 170 |
| 166 _cancel() { | 171 _cancel() { |
| 167 if (this._auditRunning) { | 172 if (this._auditRunning) { |
| 168 this._updateStatus(Common.UIString('Cancelling\u2026')); | 173 this._updateStatus(Common.UIString('Cancelling\u2026')); |
| 169 this._stop(); | 174 this._stop(); |
| 170 } else { | 175 } else { |
| 171 this._hideDialog(); | 176 this._hideDialog(); |
| 172 } | 177 } |
| 173 } | 178 } |
| 174 | 179 |
| 175 _updateButton() { | 180 _updateButton() { |
| 176 if (!this._dialog) | 181 if (!this._dialog) |
| 177 return; | 182 return; |
| 178 this._startButton.classList.toggle('default', !this._auditRunning); | 183 this._startButton.classList.toggle('hidden', this._auditRunning); |
| 179 this._startButton.disabled = this._auditRunning; | 184 this._startButton.disabled = this._auditRunning; |
| 180 this._statusView.classList.toggle('hidden', !this._auditRunning); | 185 this._statusView.classList.toggle('hidden', !this._auditRunning); |
| 186 this._auditSelectorForm.classList.toggle('hidden', this._auditRunning); |
| 187 if (this._auditRunning) |
| 188 this._headerTitleElement.textContent = Common.UIString('Auditing your web
page \u2026'); |
| 189 else |
| 190 this._headerTitleElement.textContent = Common.UIString('Audits to perform'
); |
| 181 } | 191 } |
| 182 | 192 |
| 183 /** | 193 /** |
| 184 * @param {string} statusMessage | 194 * @param {string} statusMessage |
| 185 */ | 195 */ |
| 186 _updateStatus(statusMessage) { | 196 _updateStatus(statusMessage) { |
| 187 if (!this._dialog) | 197 if (!this._dialog) |
| 188 return; | 198 return; |
| 189 this._statusElement.textContent = statusMessage; | 199 this._statusElement.textContent = statusMessage; |
| 190 } | 200 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 279 } |
| 270 } | 280 } |
| 271 | 281 |
| 272 /** | 282 /** |
| 273 * @param {string} profile | 283 * @param {string} profile |
| 274 */ | 284 */ |
| 275 _loadedFromFile(profile) { | 285 _loadedFromFile(profile) { |
| 276 var data = JSON.parse(profile); | 286 var data = JSON.parse(profile); |
| 277 if (!data['lighthouseVersion']) | 287 if (!data['lighthouseVersion']) |
| 278 return; | 288 return; |
| 279 this._finish(/** @type {!ReportRenderer.ReportJSON} */(data)); | 289 this._finish(/** @type {!ReportRenderer.ReportJSON} */ (data)); |
| 280 } | 290 } |
| 281 }; | 291 }; |
| 282 | 292 |
| 283 /** | 293 /** |
| 284 * @override | 294 * @override |
| 285 */ | 295 */ |
| 286 Audits2.Audits2Panel.ReportRenderer = class extends ReportRenderer { | 296 Audits2.Audits2Panel.ReportRenderer = class extends ReportRenderer { |
| 287 /** | 297 /** |
| 288 * Provides empty element for left nav | 298 * Provides empty element for left nav |
| 289 * @override | 299 * @override |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 | 495 |
| 486 _renderReport() { | 496 _renderReport() { |
| 487 this._resultsView.removeChildren(); | 497 this._resultsView.removeChildren(); |
| 488 if (this._reportContainer) { | 498 if (this._reportContainer) { |
| 489 this._resultsView.appendChild(this._reportContainer); | 499 this._resultsView.appendChild(this._reportContainer); |
| 490 return; | 500 return; |
| 491 } | 501 } |
| 492 | 502 |
| 493 this._reportContainer = this._resultsView.createChild('div', 'report-contain
er lh-root'); | 503 this._reportContainer = this._resultsView.createChild('div', 'report-contain
er lh-root'); |
| 494 | 504 |
| 495 var dom = new DOM(/** @type {!Document} */(this._resultsView.ownerDocument))
; | 505 var dom = new DOM(/** @type {!Document} */ (this._resultsView.ownerDocument)
); |
| 496 var detailsRenderer = new DetailsRenderer(dom); | 506 var detailsRenderer = new DetailsRenderer(dom); |
| 497 var categoryRenderer = new CategoryRenderer(dom, detailsRenderer); | 507 var categoryRenderer = new CategoryRenderer(dom, detailsRenderer); |
| 498 var renderer = new Audits2.Audits2Panel.ReportRenderer(dom, categoryRenderer
); | 508 var renderer = new Audits2.Audits2Panel.ReportRenderer(dom, categoryRenderer
); |
| 499 | 509 |
| 500 var templatesHTML = Runtime.cachedResources['audits2/lighthouse/templates.ht
ml']; | 510 var templatesHTML = Runtime.cachedResources['audits2/lighthouse/templates.ht
ml']; |
| 501 var templatesDOM = new DOMParser().parseFromString(templatesHTML, 'text/html
'); | 511 var templatesDOM = new DOMParser().parseFromString(templatesHTML, 'text/html
'); |
| 502 if (!templatesDOM) | 512 if (!templatesDOM) |
| 503 return; | 513 return; |
| 504 | 514 |
| 505 renderer.setTemplateContext(templatesDOM); | 515 renderer.setTemplateContext(templatesDOM); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 529 onselect() { | 539 onselect() { |
| 530 this.parent._renderReport(); | 540 this.parent._renderReport(); |
| 531 var node = this.parent._resultsView.querySelector('.lh-category[id=' + this.
_id + ']'); | 541 var node = this.parent._resultsView.querySelector('.lh-category[id=' + this.
_id + ']'); |
| 532 if (node) { | 542 if (node) { |
| 533 node.scrollIntoView(true); | 543 node.scrollIntoView(true); |
| 534 return true; | 544 return true; |
| 535 } | 545 } |
| 536 return false; | 546 return false; |
| 537 } | 547 } |
| 538 }; | 548 }; |
| OLD | NEW |