2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
33 * @extends {WebInspector.SidebarPaneStack}
34 * @param {!Array.<!WebInspector.AuditCategoryResult>} categoryResults
36 WebInspector.AuditResultView = function(categoryResults)
38 WebInspector.SidebarPaneStack.call(this);
39 this.setMinimumSize(100, 25);
40 this.element.classList.add("audit-result-view", "fill");
42 function categorySorter(a, b) {
43 return (a.title || "").localeCompare(b.title || "");
45 categoryResults.sort(categorySorter);
46 for (var i = 0; i < categoryResults.length; ++i)
47 this.addPane(new WebInspector.AuditCategoryResultPane(categoryResults[i]));
50 WebInspector.AuditResultView.prototype = {
51 __proto__: WebInspector.SidebarPaneStack.prototype
56 * @extends {WebInspector.SidebarPane}
57 * @param {!WebInspector.AuditCategoryResult} categoryResult
59 WebInspector.AuditCategoryResultPane = function(categoryResult)
61 WebInspector.SidebarPane.call(this, categoryResult.title);
62 var treeOutlineElement = document.createElement("ol");
63 this.bodyElement.classList.add("audit-result-tree");
64 this.bodyElement.appendChild(treeOutlineElement);
66 this._treeOutline = new TreeOutline(treeOutlineElement);
67 this._treeOutline.expandTreeElementsWhenArrowing = true;
69 function ruleSorter(a, b)
71 var result = WebInspector.AuditRule.SeverityOrder[a.severity || 0] - WebInspector.AuditRule.SeverityOrder[b.severity || 0];
73 result = (a.value || "").localeCompare(b.value || "");
77 categoryResult.ruleResults.sort(ruleSorter);
79 for (var i = 0; i < categoryResult.ruleResults.length; ++i) {
80 var ruleResult = categoryResult.ruleResults[i];
81 var treeElement = this._appendResult(this._treeOutline, ruleResult, ruleResult.severity);
82 treeElement.listItemElement.classList.add("audit-result");
87 WebInspector.AuditCategoryResultPane.prototype = {
89 * @param {(!TreeOutline|!TreeElement)} parentTreeElement
90 * @param {!WebInspector.AuditRuleResult} result
91 * @param {?WebInspector.AuditRule.Severity=} severity
93 _appendResult: function(parentTreeElement, result, severity)
97 if (typeof result.value === "string") {
99 if (result.violationCount)
100 title = String.sprintf("%s (%d)", title, result.violationCount);
103 var titleFragment = document.createDocumentFragment();
105 var severityElement = document.createElement("div");
106 severityElement.className = "severity-" + severity;
107 titleFragment.appendChild(severityElement);
109 titleFragment.appendChild(document.createTextNode(title));
111 var treeElement = new TreeElement(titleFragment, null, !!result.children);
112 parentTreeElement.appendChild(treeElement);
114 if (result.className)
115 treeElement.listItemElement.classList.add(result.className);
116 if (typeof result.value !== "string")
117 treeElement.listItemElement.appendChild(WebInspector.auditFormatters.apply(result.value));
119 if (result.children) {
120 for (var i = 0; i < result.children.length; ++i)
121 this._appendResult(treeElement, result.children[i]);
123 if (result.expanded) {
124 treeElement.listItemElement.classList.remove("parent");
125 treeElement.listItemElement.classList.add("parent-expanded");
126 treeElement.expand();
131 __proto__: WebInspector.SidebarPane.prototype