• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
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
13 * distribution.
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.
17 *
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.
29 */
30
31/**
32 * @constructor
33 * @extends {WebInspector.SidebarPaneStack}
34 * @param {!Array.<!WebInspector.AuditCategoryResult>} categoryResults
35 */
36WebInspector.AuditResultView = function(categoryResults)
37{
38    WebInspector.SidebarPaneStack.call(this);
39    this.setMinimumSize(100, 25);
40    this.element.classList.add("audit-result-view", "fill");
41
42    function categorySorter(a, b) {
43        return (a.title || "").localeCompare(b.title || "");
44    }
45    categoryResults.sort(categorySorter);
46    for (var i = 0; i < categoryResults.length; ++i)
47        this.addPane(new WebInspector.AuditCategoryResultPane(categoryResults[i]));
48}
49
50WebInspector.AuditResultView.prototype = {
51    __proto__: WebInspector.SidebarPaneStack.prototype
52}
53
54/**
55 * @constructor
56 * @extends {WebInspector.SidebarPane}
57 * @param {!WebInspector.AuditCategoryResult} categoryResult
58 */
59WebInspector.AuditCategoryResultPane = function(categoryResult)
60{
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);
65
66    this._treeOutline = new TreeOutline(treeOutlineElement);
67    this._treeOutline.expandTreeElementsWhenArrowing = true;
68
69    function ruleSorter(a, b)
70    {
71        var result = WebInspector.AuditRule.SeverityOrder[a.severity || 0] - WebInspector.AuditRule.SeverityOrder[b.severity || 0];
72        if (!result)
73            result = (a.value || "").localeCompare(b.value || "");
74        return result;
75    }
76
77    categoryResult.ruleResults.sort(ruleSorter);
78
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");
83    }
84    this.expand();
85}
86
87WebInspector.AuditCategoryResultPane.prototype = {
88    /**
89     * @param {(!TreeOutline|!TreeElement)} parentTreeElement
90     * @param {!WebInspector.AuditRuleResult} result
91     * @param {?WebInspector.AuditRule.Severity=} severity
92     */
93    _appendResult: function(parentTreeElement, result, severity)
94    {
95        var title = "";
96
97        if (typeof result.value === "string") {
98            title = result.value;
99            if (result.violationCount)
100                title = String.sprintf("%s (%d)", title, result.violationCount);
101        }
102
103        var titleFragment = document.createDocumentFragment();
104        if (severity) {
105            var severityElement = document.createElement("div");
106            severityElement.className = "severity-" + severity;
107            titleFragment.appendChild(severityElement);
108        }
109        titleFragment.appendChild(document.createTextNode(title));
110
111        var treeElement = new TreeElement(titleFragment, null, !!result.children);
112        parentTreeElement.appendChild(treeElement);
113
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));
118
119        if (result.children) {
120            for (var i = 0; i < result.children.length; ++i)
121                this._appendResult(treeElement, result.children[i]);
122        }
123        if (result.expanded) {
124            treeElement.listItemElement.classList.remove("parent");
125            treeElement.listItemElement.classList.add("parent-expanded");
126            treeElement.expand();
127        }
128        return treeElement;
129    },
130
131    __proto__: WebInspector.SidebarPane.prototype
132}
133