Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/audits/AuditFormatters.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 WebInspector.AuditFormatters = class { 34 Audits.AuditFormatters = class {
35 /** 35 /**
36 * @param {string|boolean|number|!Object} value 36 * @param {string|boolean|number|!Object} value
37 * @return {!Node} 37 * @return {!Node}
38 */ 38 */
39 apply(value) { 39 apply(value) {
40 var formatter; 40 var formatter;
41 var type = typeof value; 41 var type = typeof value;
42 var args; 42 var args;
43 43
44 switch (type) { 44 switch (type) {
45 case 'string': 45 case 'string':
46 case 'boolean': 46 case 'boolean':
47 case 'number': 47 case 'number':
48 formatter = WebInspector.AuditFormatters.Registry.text; 48 formatter = Audits.AuditFormatters.Registry.text;
49 args = [value.toString()]; 49 args = [value.toString()];
50 break; 50 break;
51 51
52 case 'object': 52 case 'object':
53 if (value instanceof Node) 53 if (value instanceof Node)
54 return value; 54 return value;
55 if (Array.isArray(value)) { 55 if (Array.isArray(value)) {
56 formatter = WebInspector.AuditFormatters.Registry.concat; 56 formatter = Audits.AuditFormatters.Registry.concat;
57 args = value; 57 args = value;
58 } else if (value.type && value.arguments) { 58 } else if (value.type && value.arguments) {
59 formatter = WebInspector.AuditFormatters.Registry[value.type]; 59 formatter = Audits.AuditFormatters.Registry[value.type];
60 args = value.arguments; 60 args = value.arguments;
61 } 61 }
62 } 62 }
63 if (!formatter) 63 if (!formatter)
64 throw 'Invalid value or formatter: ' + type + JSON.stringify(value); 64 throw 'Invalid value or formatter: ' + type + JSON.stringify(value);
65 65
66 return formatter.apply(null, args); 66 return formatter.apply(null, args);
67 } 67 }
68 68
69 /** 69 /**
70 * @param {!Object} formatters 70 * @param {!Object} formatters
71 * @param {?Object} thisArgument 71 * @param {?Object} thisArgument
72 * @param {string|boolean|number|!Object} value 72 * @param {string|boolean|number|!Object} value
73 * @return {*} 73 * @return {*}
74 */ 74 */
75 partiallyApply(formatters, thisArgument, value) { 75 partiallyApply(formatters, thisArgument, value) {
76 if (Array.isArray(value)) 76 if (Array.isArray(value))
77 return value.map(this.partiallyApply.bind(this, formatters, thisArgument)) ; 77 return value.map(this.partiallyApply.bind(this, formatters, thisArgument)) ;
78 if (typeof value === 'object' && typeof formatters[value.type] === 'function ' && value.arguments) 78 if (typeof value === 'object' && typeof formatters[value.type] === 'function ' && value.arguments)
79 return formatters[value.type].apply(thisArgument, value.arguments); 79 return formatters[value.type].apply(thisArgument, value.arguments);
80 return value; 80 return value;
81 } 81 }
82 }; 82 };
83 83
84 WebInspector.AuditFormatters.Registry = { 84 Audits.AuditFormatters.Registry = {
85 85
86 /** 86 /**
87 * @param {string} text 87 * @param {string} text
88 * @return {!Text} 88 * @return {!Text}
89 */ 89 */
90 text: function(text) { 90 text: function(text) {
91 return createTextNode(text); 91 return createTextNode(text);
92 }, 92 },
93 93
94 /** 94 /**
95 * @param {string} snippetText 95 * @param {string} snippetText
96 * @return {!Element} 96 * @return {!Element}
97 */ 97 */
98 snippet: function(snippetText) { 98 snippet: function(snippetText) {
99 var div = createElement('div'); 99 var div = createElement('div');
100 div.textContent = snippetText; 100 div.textContent = snippetText;
101 div.className = 'source-code'; 101 div.className = 'source-code';
102 return div; 102 return div;
103 }, 103 },
104 104
105 /** 105 /**
106 * @return {!Element} 106 * @return {!Element}
107 */ 107 */
108 concat: function() { 108 concat: function() {
109 var parent = createElement('span'); 109 var parent = createElement('span');
110 for (var arg = 0; arg < arguments.length; ++arg) 110 for (var arg = 0; arg < arguments.length; ++arg)
111 parent.appendChild(WebInspector.auditFormatters.apply(arguments[arg])); 111 parent.appendChild(Audits.auditFormatters.apply(arguments[arg]));
112 return parent; 112 return parent;
113 }, 113 },
114 114
115 /** 115 /**
116 * @param {string} url 116 * @param {string} url
117 * @param {string=} displayText 117 * @param {string=} displayText
118 * @return {!Element} 118 * @return {!Element}
119 */ 119 */
120 url: function(url, displayText) { 120 url: function(url, displayText) {
121 return WebInspector.linkifyURLAsNode(url, displayText, undefined, true); 121 return UI.linkifyURLAsNode(url, displayText, undefined, true);
122 }, 122 },
123 123
124 /** 124 /**
125 * @param {string} url 125 * @param {string} url
126 * @param {number=} line 126 * @param {number=} line
127 * @return {!Element} 127 * @return {!Element}
128 */ 128 */
129 resourceLink: function(url, line) { 129 resourceLink: function(url, line) {
130 // FIXME: use WebInspector.Linkifier 130 // FIXME: use Components.Linkifier
131 return WebInspector.linkifyResourceAsNode(url, line, undefined, 'resource-ur l webkit-html-resource-link'); 131 return Components.linkifyResourceAsNode(url, line, undefined, 'resource-url webkit-html-resource-link');
132 } 132 }
133 }; 133 };
134 134
135 WebInspector.auditFormatters = new WebInspector.AuditFormatters(); 135 Audits.auditFormatters = new Audits.AuditFormatters();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698