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");
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 this._treeOutline
= new TreeOutlineInShadow();
63 this._treeOutline
.registerRequiredCSS("audits/auditResultTree.css");
64 this._treeOutline
.element
.classList
.add("audit-result-tree");
65 this.element
.appendChild(this._treeOutline
.element
);
66 this._treeOutline
.expandTreeElementsWhenArrowing
= true;
68 function ruleSorter(a
, b
)
70 var result
= WebInspector
.AuditRule
.SeverityOrder
[a
.severity
|| 0] - WebInspector
.AuditRule
.SeverityOrder
[b
.severity
|| 0];
72 result
= (a
.value
|| "").localeCompare(b
.value
|| "");
76 categoryResult
.ruleResults
.sort(ruleSorter
);
78 for (var i
= 0; i
< categoryResult
.ruleResults
.length
; ++i
) {
79 var ruleResult
= categoryResult
.ruleResults
[i
];
80 var treeElement
= this._appendResult(this._treeOutline
.rootElement(), ruleResult
, ruleResult
.severity
);
81 treeElement
.listItemElement
.classList
.add("audit-result");
86 WebInspector
.AuditCategoryResultPane
.prototype = {
88 * @param {!TreeElement} parentTreeNode
89 * @param {!WebInspector.AuditRuleResult} result
90 * @param {?WebInspector.AuditRule.Severity=} severity
92 _appendResult: function(parentTreeNode
, result
, severity
)
96 if (typeof result
.value
=== "string") {
98 if (result
.violationCount
)
99 title
= String
.sprintf("%s (%d)", title
, result
.violationCount
);
102 var titleFragment
= createDocumentFragment();
104 var severityElement
= createElement("div");
105 severityElement
.classList
.add("severity", severity
);
106 titleFragment
.appendChild(severityElement
);
108 titleFragment
.createTextChild(title
);
110 var treeElement
= new TreeElement(titleFragment
, !!result
.children
);
111 treeElement
.selectable
= false;
112 parentTreeNode
.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