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 31WebInspector.AuditResultView = function(categoryResults) 32{ 33 WebInspector.View.call(this); 34 35 this.element.id = "audit-result-view"; 36 37 function entrySortFunction(a, b) 38 { 39 var result = b.type - a.type; 40 if (!result) 41 result = (a.value || "").localeCompare(b.value || ""); 42 return result; 43 } 44 45 for (var i = 0; i < categoryResults.length; ++i) { 46 var entries = categoryResults[i].entries; 47 if (entries) { 48 entries.sort(entrySortFunction); 49 this.element.appendChild(new WebInspector.AuditCategoryResultPane(categoryResults[i]).element); 50 } 51 } 52} 53 54WebInspector.AuditResultView.prototype.__proto__ = WebInspector.View.prototype; 55 56 57WebInspector.AuditCategoryResultPane = function(categoryResult) 58{ 59 WebInspector.SidebarPane.call(this, categoryResult.title); 60 this.expand(); 61 for (var i = 0; i < categoryResult.entries.length; ++i) 62 this.bodyElement.appendChild(new WebInspector.AuditRuleResultPane(categoryResult.entries[i]).element); 63} 64 65WebInspector.AuditCategoryResultPane.prototype.__proto__ = WebInspector.SidebarPane.prototype; 66 67 68WebInspector.AuditRuleResultPane = function(ruleResult) 69{ 70 WebInspector.SidebarPane.call(this, ruleResult.value); 71 if (!ruleResult.children) 72 return; 73 74 this._decorateRuleResult(ruleResult); 75 76 for (var i = 0; i < ruleResult.children.length; ++i) { 77 var section = new WebInspector.AuditRuleResultChildSection(ruleResult.children[i]); 78 this.bodyElement.appendChild(section.element); 79 } 80} 81 82WebInspector.AuditRuleResultPane.prototype = { 83 _decorateRuleResult: function(ruleResult) 84 { 85 if (ruleResult.type == WebInspector.AuditRuleResult.Type.NA) 86 return; 87 88 var scoreElement = document.createElement("img"); 89 scoreElement.className = "score"; 90 var className = (ruleResult.type == WebInspector.AuditRuleResult.Type.Violation) ? "red" : "green"; 91 scoreElement.addStyleClass(className); 92 this.element.insertBefore(scoreElement, this.element.firstChild); 93 } 94} 95 96WebInspector.AuditRuleResultPane.prototype.__proto__ = WebInspector.SidebarPane.prototype; 97 98 99WebInspector.AuditRuleResultChildSection = function(entry) 100{ 101 WebInspector.Section.call(this, entry.value); 102 var children = entry.children; 103 this._hasChildren = !!children && children.length; 104 if (!this._hasChildren) 105 this.element.addStyleClass("blank-section"); 106 else { 107 this.contentElement = document.createElement("div"); 108 this.contentElement.addStyleClass("section-content"); 109 for (var i = 0; i < children.length; ++i) { 110 var paraElement = document.createElement("p"); 111 paraElement.innerHTML = children[i].value; 112 this.contentElement.appendChild(paraElement); 113 } 114 this.contentElement.appendChild(paraElement); 115 this.element.appendChild(this.contentElement); 116 } 117} 118 119WebInspector.AuditRuleResultChildSection.prototype = { 120 121 // title is considered pure HTML 122 set title(x) 123 { 124 if (this._title === x) 125 return; 126 this._title = x; 127 128 this.titleElement.innerHTML = x; 129 }, 130 131 expand: function() 132 { 133 if (this._hasChildren) 134 WebInspector.Section.prototype.expand.call(this); 135 } 136} 137 138WebInspector.AuditRuleResultChildSection.prototype.__proto__ = WebInspector.Section.prototype; 139