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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js

Issue 2373113003: DevTools: ConsoleViewMessage isolate _formatMessageAsTable() and single dataGrid (Closed)
Patch Set: Created 4 years, 2 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2009 Joseph Pecoraro 4 * Copyright (C) 2009 Joseph Pecoraro
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 25 matching lines...) Expand all
36 * @param {number} nestingLevel 36 * @param {number} nestingLevel
37 */ 37 */
38 WebInspector.ConsoleViewMessage = function(consoleMessage, linkifier, nestingLev el) 38 WebInspector.ConsoleViewMessage = function(consoleMessage, linkifier, nestingLev el)
39 { 39 {
40 this._message = consoleMessage; 40 this._message = consoleMessage;
41 this._linkifier = linkifier; 41 this._linkifier = linkifier;
42 this._repeatCount = 1; 42 this._repeatCount = 1;
43 this._closeGroupDecorationCount = 0; 43 this._closeGroupDecorationCount = 0;
44 this._nestingLevel = nestingLevel; 44 this._nestingLevel = nestingLevel;
45 45
46 /** @type {!Array.<!WebInspector.DataGrid>} */ 46 /** @type {?WebInspector.DataGrid} */
47 this._dataGrids = []; 47 this._dataGrid = null;
lushnikov 2016/09/28 20:52:35 whoa, nice!
luoe 2016/09/29 21:31:13 Done.
48 48
49 /** @type {!Object.<string, function(!WebInspector.RemoteObject, !Element, b oolean=)>} */ 49 /** @type {!Object.<string, function(!WebInspector.RemoteObject, !Element, b oolean=)>} */
50 this._customFormatters = { 50 this._customFormatters = {
51 "array": this._formatParameterAsArray, 51 "array": this._formatParameterAsArray,
52 "typedarray": this._formatParameterAsArray, 52 "typedarray": this._formatParameterAsArray,
53 "error": this._formatParameterAsError, 53 "error": this._formatParameterAsError,
54 "function": this._formatParameterAsFunction, 54 "function": this._formatParameterAsFunction,
55 "generator": this._formatParameterAsObject, 55 "generator": this._formatParameterAsObject,
56 "iterator": this._formatParameterAsObject, 56 "iterator": this._formatParameterAsObject,
57 "map": this._formatParameterAsObject, 57 "map": this._formatParameterAsObject,
(...skipping 24 matching lines...) Expand all
82 element: function() 82 element: function()
83 { 83 {
84 return this.toMessageElement(); 84 return this.toMessageElement();
85 }, 85 },
86 86
87 /** 87 /**
88 * @override 88 * @override
89 */ 89 */
90 wasShown: function() 90 wasShown: function()
91 { 91 {
92 for (var i = 0; this._dataGrids && i < this._dataGrids.length; ++i) 92 if (this._datagrid)
93 this._dataGrids[i].updateWidths(); 93 this._dataGrid.updateWidths();
94 this._isVisible = true; 94 this._isVisible = true;
95 }, 95 },
96 96
97 onResize: function() 97 onResize: function()
98 { 98 {
99 if (!this._isVisible) 99 if (!this._isVisible)
100 return; 100 return;
101 for (var i = 0; this._dataGrids && i < this._dataGrids.length; ++i) 101 if (this._datagrid)
102 this._dataGrids[i].onResize(); 102 this._dataGrid.onResize();
103 }, 103 },
104 104
105 /** 105 /**
106 * @override 106 * @override
107 */ 107 */
108 willHide: function() 108 willHide: function()
109 { 109 {
110 this._isVisible = false; 110 this._isVisible = false;
111 this._cachedHeight = this.contentElement().offsetHeight; 111 this._cachedHeight = this.contentElement().offsetHeight;
112 }, 112 },
(...skipping 27 matching lines...) Expand all
140 /** 140 /**
141 * @return {!Element} 141 * @return {!Element}
142 */ 142 */
143 _formatMessage: function() 143 _formatMessage: function()
144 { 144 {
145 var formattedMessage = createElement("span"); 145 var formattedMessage = createElement("span");
146 WebInspector.appendStyle(formattedMessage, "components/objectValue.css") ; 146 WebInspector.appendStyle(formattedMessage, "components/objectValue.css") ;
147 formattedMessage.className = "console-message-text source-code"; 147 formattedMessage.className = "console-message-text source-code";
148 148
149 var consoleMessage = this._message; 149 var consoleMessage = this._message;
150 var messageElement = this._buildMessage(consoleMessage); 150 var messageElement;
151 if (this._message.type === WebInspector.ConsoleMessage.MessageType.Table )
152 messageElement = this._formatMessageAsTable(consoleMessage);
153 else
154 messageElement = this._buildMessage(consoleMessage);
151 formattedMessage.appendChild(messageElement); 155 formattedMessage.appendChild(messageElement);
152 156
153 var anchorElement = this._buildAnchor(consoleMessage); 157 var anchorElement = this._buildAnchor(consoleMessage);
154 if (anchorElement) { 158 if (anchorElement) {
155 // Append a space to prevent the anchor text from being glued to the console message when the user selects and copies the console messages. 159 // Append a space to prevent the anchor text from being glued to the console message when the user selects and copies the console messages.
156 anchorElement.appendChild(createTextNode(" ")); 160 anchorElement.appendChild(createTextNode(" "));
157 formattedMessage.insertBefore(anchorElement, formattedMessage.firstC hild); 161 formattedMessage.insertBefore(anchorElement, formattedMessage.firstC hild);
158 } 162 }
159 163
160 var dumpStackTrace = !!consoleMessage.stackTrace && (consoleMessage.sour ce === WebInspector.ConsoleMessage.MessageSource.Network || consoleMessage.level === WebInspector.ConsoleMessage.MessageLevel.Error || consoleMessage.level === WebInspector.ConsoleMessage.MessageLevel.RevokedError || consoleMessage.type === WebInspector.ConsoleMessage.MessageType.Trace || consoleMessage.level === WebIn spector.ConsoleMessage.MessageLevel.Warning); 164 var dumpStackTrace = !!consoleMessage.stackTrace && (consoleMessage.sour ce === WebInspector.ConsoleMessage.MessageSource.Network || consoleMessage.level === WebInspector.ConsoleMessage.MessageLevel.Error || consoleMessage.level === WebInspector.ConsoleMessage.MessageLevel.RevokedError || consoleMessage.type === WebInspector.ConsoleMessage.MessageType.Trace || consoleMessage.level === WebIn spector.ConsoleMessage.MessageLevel.Warning);
161 var target = this._target(); 165 var target = this._target();
162 if (dumpStackTrace && target) { 166 if (dumpStackTrace && target) {
163 var stackTracePreview = WebInspector.DOMPresentationUtils.buildStack TracePreviewContents(target, this._linkifier, consoleMessage.stackTrace); 167 var stackTracePreview = WebInspector.DOMPresentationUtils.buildStack TracePreviewContents(target, this._linkifier, consoleMessage.stackTrace);
164 var autoExpand = consoleMessage.type === WebInspector.ConsoleMessage .MessageType.Trace; 168 var autoExpand = consoleMessage.type === WebInspector.ConsoleMessage .MessageType.Trace;
165 formattedMessage = this._wrapStackTraceFormatting(formattedMessage, stackTracePreview, autoExpand); 169 formattedMessage = this._wrapStackTraceFormatting(formattedMessage, stackTracePreview, autoExpand);
166 } 170 }
167 171
168 return formattedMessage; 172 return formattedMessage;
169 }, 173 },
170 174
171 /** 175 /**
172 * @param {!WebInspector.ConsoleMessage} consoleMessage 176 * @param {!WebInspector.ConsoleMessage} consoleMessage
173 * @return {!Element} 177 * @return {!Element}
174 */ 178 */
179 _formatMessageAsTable: function(consoleMessage)
180 {
181 var formattedResult = createElement("span");
182 if (!consoleMessage.parameters || !consoleMessage.parameters.length)
183 return formattedResult;
184
185 var table = this._parameterToRemoteObject(consoleMessage.parameters[0], this._target());
186 this._dataGrid = this._buildTableDataGrid(table);
187 if (!this._dataGrid)
188 return formattedResult;
189
190 var tableElement = formattedResult.createChild("div", "console-message-f ormatted-table");
191 var dataGridContainer = tableElement.createChild("span");
192 tableElement.appendChild(this._formatParameter(table, true, false));
193 this._dataGrid.renderInline();
194 dataGridContainer.appendChild(this._dataGrid.element);
195
196 return formattedResult;
197 },
198
199 /**
200 * @param {!WebInspector.ConsoleMessage} consoleMessage
201 * @return {!Element}
202 */
175 _buildMessage: function(consoleMessage) 203 _buildMessage: function(consoleMessage)
176 { 204 {
177 var messageElement; 205 var messageElement;
178 if (consoleMessage.source === WebInspector.ConsoleMessage.MessageSource. ConsoleAPI) { 206 if (consoleMessage.source === WebInspector.ConsoleMessage.MessageSource. ConsoleAPI) {
179 switch (consoleMessage.type) { 207 switch (consoleMessage.type) {
180 case WebInspector.ConsoleMessage.MessageType.Trace: 208 case WebInspector.ConsoleMessage.MessageType.Trace:
181 messageElement = this._format(consoleMessage.parameters || ["con sole.trace"]); 209 messageElement = this._format(consoleMessage.parameters || ["con sole.trace"]);
182 break; 210 break;
183 case WebInspector.ConsoleMessage.MessageType.Clear: 211 case WebInspector.ConsoleMessage.MessageType.Clear:
184 messageElement = createElementWithClass("span", "console-info"); 212 messageElement = createElementWithClass("span", "console-info");
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 var shouldFormatMessage = WebInspector.RemoteObject.type((/** @type {!Ar ray.<!WebInspector.RemoteObject>} **/ (parameters))[0]) === "string" && (this._m essage.type !== WebInspector.ConsoleMessage.MessageType.Result || this._message. level === WebInspector.ConsoleMessage.MessageLevel.Error || this._message.level === WebInspector.ConsoleMessage.MessageLevel.RevokedError); 419 var shouldFormatMessage = WebInspector.RemoteObject.type((/** @type {!Ar ray.<!WebInspector.RemoteObject>} **/ (parameters))[0]) === "string" && (this._m essage.type !== WebInspector.ConsoleMessage.MessageType.Result || this._message. level === WebInspector.ConsoleMessage.MessageLevel.Error || this._message.level === WebInspector.ConsoleMessage.MessageLevel.RevokedError);
392 420
393 // Multiple parameters with the first being a format string. Save unused substitutions. 421 // Multiple parameters with the first being a format string. Save unused substitutions.
394 if (shouldFormatMessage) { 422 if (shouldFormatMessage) {
395 var result = this._formatWithSubstitutionString(/** @type {string} * */ (parameters[0].description), parameters.slice(1), formattedResult); 423 var result = this._formatWithSubstitutionString(/** @type {string} * */ (parameters[0].description), parameters.slice(1), formattedResult);
396 parameters = result.unusedSubstitutions; 424 parameters = result.unusedSubstitutions;
397 if (parameters.length) 425 if (parameters.length)
398 formattedResult.createTextChild(" "); 426 formattedResult.createTextChild(" ");
399 } 427 }
400 428
401 if (this._message.type === WebInspector.ConsoleMessage.MessageType.Table ) {
402 formattedResult.appendChild(this._formatParameterAsTable(parameters) );
403 return formattedResult;
404 }
405
406 // Single parameter, or unused substitutions from above. 429 // Single parameter, or unused substitutions from above.
407 for (var i = 0; i < parameters.length; ++i) { 430 for (var i = 0; i < parameters.length; ++i) {
408 // Inline strings when formatting. 431 // Inline strings when formatting.
409 if (shouldFormatMessage && parameters[i].type === "string") 432 if (shouldFormatMessage && parameters[i].type === "string")
410 formattedResult.appendChild(WebInspector.linkifyStringAsFragment (parameters[i].description)); 433 formattedResult.appendChild(WebInspector.linkifyStringAsFragment (parameters[i].description));
411 else 434 else
412 formattedResult.appendChild(this._formatParameter(parameters[i], false, true)); 435 formattedResult.appendChild(this._formatParameter(parameters[i], false, true));
413 if (i < parameters.length - 1) 436 if (i < parameters.length - 1)
414 formattedResult.createTextChild(" "); 437 formattedResult.createTextChild(" ");
415 } 438 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 _formatParameterAsArray: function(array, elem) 602 _formatParameterAsArray: function(array, elem)
580 { 603 {
581 var maxFlatArrayLength = 100; 604 var maxFlatArrayLength = 100;
582 if (this.useArrayPreviewInFormatter(array) || array.arrayLength() > maxF latArrayLength) 605 if (this.useArrayPreviewInFormatter(array) || array.arrayLength() > maxF latArrayLength)
583 this._formatParameterAsArrayOrObject(array, elem, this.useArrayPrevi ewInFormatter(array) || array.arrayLength() <= maxFlatArrayLength); 606 this._formatParameterAsArrayOrObject(array, elem, this.useArrayPrevi ewInFormatter(array) || array.arrayLength() <= maxFlatArrayLength);
584 else 607 else
585 array.getAllProperties(false, this._printArrayResult.bind(this, arra y, elem)); 608 array.getAllProperties(false, this._printArrayResult.bind(this, arra y, elem));
586 }, 609 },
587 610
588 /** 611 /**
589 * @param {!Array.<!WebInspector.RemoteObject>} parameters 612 * @param {!WebInspector.RemoteObject} table
590 * @return {!Element} 613 * @return {?WebInspector.SortableDataGrid}
591 */ 614 */
592 _formatParameterAsTable: function(parameters) 615 _buildTableDataGrid: function(table)
lushnikov 2016/09/28 20:52:35 maybe join this with _formatMessageAsTable?
luoe 2016/09/29 21:31:55 Done.
593 { 616 {
594 var element = createElementWithClass("div", "console-message-formatted-t able"); 617 if (!table.preview)
595 var table = parameters[0]; 618 return null;
596 if (!table || !table.preview)
597 return element;
598 619
599 var columnNames = []; 620 var columnNames = [];
600 var preview = table.preview; 621 var preview = table.preview;
601 var rows = []; 622 var rows = [];
602 for (var i = 0; i < preview.properties.length; ++i) { 623 for (var i = 0; i < preview.properties.length; ++i) {
603 var rowProperty = preview.properties[i]; 624 var rowProperty = preview.properties[i];
604 var rowPreview = rowProperty.valuePreview; 625 var rowPreview = rowProperty.valuePreview;
605 if (!rowPreview) 626 if (!rowPreview)
606 continue; 627 continue;
607 628
(...skipping 19 matching lines...) Expand all
627 } 648 }
628 649
629 var flatValues = []; 650 var flatValues = [];
630 for (var i = 0; i < rows.length; ++i) { 651 for (var i = 0; i < rows.length; ++i) {
631 var rowName = rows[i][0]; 652 var rowName = rows[i][0];
632 var rowValue = rows[i][1]; 653 var rowValue = rows[i][1];
633 flatValues.push(rowName); 654 flatValues.push(rowName);
634 for (var j = 0; j < columnNames.length; ++j) 655 for (var j = 0; j < columnNames.length; ++j)
635 flatValues.push(rowValue[columnNames[j]]); 656 flatValues.push(rowValue[columnNames[j]]);
636 } 657 }
658 columnNames.unshift(WebInspector.UIString("(index)"));
637 659
638 var dataGridContainer = element.createChild("span");
639 element.appendChild(this._formatParameter(table, true, false));
640 if (!flatValues.length) 660 if (!flatValues.length)
641 return element; 661 return null;
642 662
643 columnNames.unshift(WebInspector.UIString("(index)")); 663 return WebInspector.SortableDataGrid.create(columnNames, flatValues);
644 var dataGrid = WebInspector.SortableDataGrid.create(columnNames, flatVal ues);
645 dataGrid.renderInline();
646 dataGridContainer.appendChild(dataGrid.element);
647 this._dataGrids.push(dataGrid);
648 return element;
649 }, 664 },
650 665
651 /** 666 /**
652 * @param {!WebInspector.RemoteObject} output 667 * @param {!WebInspector.RemoteObject} output
653 * @param {!Element} elem 668 * @param {!Element} elem
654 */ 669 */
655 _formatParameterAsString: function(output, elem) 670 _formatParameterAsString: function(output, elem)
656 { 671 {
657 var span = createElement("span"); 672 var span = createElement("span");
658 span.className = "object-value-string source-code"; 673 span.className = "object-value-string source-code";
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 { 1288 {
1274 if (!this._element) { 1289 if (!this._element) {
1275 WebInspector.ConsoleViewMessage.prototype.toMessageElement.call(this ); 1290 WebInspector.ConsoleViewMessage.prototype.toMessageElement.call(this );
1276 this._element.classList.toggle("collapsed", this._collapsed); 1291 this._element.classList.toggle("collapsed", this._collapsed);
1277 } 1292 }
1278 return this._element; 1293 return this._element;
1279 }, 1294 },
1280 1295
1281 __proto__: WebInspector.ConsoleViewMessage.prototype 1296 __proto__: WebInspector.ConsoleViewMessage.prototype
1282 } 1297 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698