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

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

Issue 2623143002: DevTools: insert console message decorations in order
Patch Set: address comment Created 3 years, 10 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
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 30 matching lines...) Expand all
41 this._message = consoleMessage; 41 this._message = consoleMessage;
42 this._linkifier = linkifier; 42 this._linkifier = linkifier;
43 this._repeatCount = 1; 43 this._repeatCount = 1;
44 this._closeGroupDecorationCount = 0; 44 this._closeGroupDecorationCount = 0;
45 this._nestingLevel = nestingLevel; 45 this._nestingLevel = nestingLevel;
46 46
47 /** @type {?DataGrid.DataGrid} */ 47 /** @type {?DataGrid.DataGrid} */
48 this._dataGrid = null; 48 this._dataGrid = null;
49 this._previewFormatter = new Components.RemoteObjectPreviewFormatter(); 49 this._previewFormatter = new Components.RemoteObjectPreviewFormatter();
50 this._searchRegex = null; 50 this._searchRegex = null;
51 /** @type {?UI.Icon} */ 51 /** @type {?Element} */
52 this._messageLevelIcon = null; 52 this._decorationWrapper = null;
53 /** @type {?Element} */
54 this._repeatCountElement = null;
53 } 55 }
54 56
55 /** 57 /**
56 * @return {?SDK.Target} 58 * @return {?SDK.Target}
57 */ 59 */
58 _target() { 60 _target() {
59 return this.consoleMessage().target(); 61 return this.consoleMessage().target();
60 } 62 }
61 63
62 /** 64 /**
63 * @override 65 * @override
64 * @return {!Element} 66 * @return {!Element}
65 */ 67 */
66 element() { 68 element() {
67 return this.toMessageElement(); 69 return this.toMessageElement();
68 } 70 }
69 71
70 /** 72 /**
71 * @override 73 * @override
72 */ 74 */
73 wasShown() { 75 wasShown() {
74 if (this._dataGrid) 76 if (this._dataGrid)
75 this._dataGrid.updateWidths(); 77 this._dataGrid.updateWidths();
78 this._rebuildDecorations();
76 this._isVisible = true; 79 this._isVisible = true;
77 } 80 }
78 81
79 onResize() { 82 onResize() {
80 if (!this._isVisible) 83 if (!this._isVisible)
81 return; 84 return;
82 if (this._dataGrid) 85 if (this._dataGrid)
83 this._dataGrid.onResize(); 86 this._dataGrid.onResize();
84 } 87 }
85 88
86 /** 89 /**
87 * @override 90 * @override
88 */ 91 */
89 willHide() { 92 willHide() {
90 this._isVisible = false; 93 this._isVisible = false;
91 this._cachedHeight = this.contentElement().offsetHeight; 94 this._cachedHeight = this.contentElement().offsetHeight;
92 } 95 }
93 96
97 _rebuildDecorations() {
98 if (!this._decorationWrapper)
99 return;
100 this._decorationWrapper.removeChildren();
101
102 // Console viewport text selection logic requires every element that can be
103 // the start/end of a selection to have a text node.
104 this._decorationWrapper.createTextChild('');
105
106 // Build timestamp.
107 if (Common.moduleSetting('consoleTimestampsEnabled').get()) {
108 var timestampElement = this._decorationWrapper.createChild('span', 'messag e-timestamp');
109 timestampElement.textContent = formatTimestamp(this._message.timestamp, fa lse) + ' ';
110 timestampElement.title = formatTimestamp(this._message.timestamp, true);
111 }
112
113 // Build level icon.
114 var iconType = '';
115 if (this._message.level === SDK.ConsoleMessage.MessageLevel.Warning)
116 iconType = 'smallicon-warning';
117 else if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error)
118 iconType = 'smallicon-error';
119 else if (this._message.type === SDK.ConsoleMessage.MessageType.Command)
120 iconType = 'smallicon-user-command';
121 else if (this._message.type === SDK.ConsoleMessage.MessageType.Result)
122 iconType = 'smallicon-command-result';
123 this._decorationWrapper.appendChild(UI.Icon.create(iconType, 'message-level- icon'));
124
125 // Timestamps may affect repeat counter.
126 this._updateRepeatCountElement();
127
128 /**
129 * @param {number} timestamp
130 * @param {boolean} full
131 * @return {string}
132 */
133 function formatTimestamp(timestamp, full) {
134 var date = new Date(timestamp);
135 var yymmdd = date.getFullYear() + '-' + leadZero(date.getMonth() + 1, 2) + '-' + leadZero(date.getDate(), 2);
136 var hhmmssfff = leadZero(date.getHours(), 2) + ':' + leadZero(date.getMinu tes(), 2) + ':' +
137 leadZero(date.getSeconds(), 2) + '.' + leadZero(date.getMilliseconds() , 3);
138 return full ? (yymmdd + ' ' + hhmmssfff) : hhmmssfff;
139
140 /**
141 * @param {number} value
142 * @param {number} length
143 * @return {string}
144 */
145 function leadZero(value, length) {
146 var valueString = value.toString();
147 var padding = length - valueString.length;
148 return padding <= 0 ? valueString : '0'.repeat(padding) + valueString;
149 }
150 }
151 }
152
94 /** 153 /**
95 * @return {number} 154 * @return {number}
96 */ 155 */
97 fastHeight() { 156 fastHeight() {
98 if (this._cachedHeight) 157 if (this._cachedHeight)
99 return this._cachedHeight; 158 return this._cachedHeight;
100 // This value reflects the 18px min-height of .console-message, plus the 159 // This value reflects the 18px min-height of .console-message, plus the
101 // 1px border of .console-message-wrapper. Keep in sync with consoleView.css . 160 // 1px border of .console-message-wrapper. Keep in sync with consoleView.css .
102 const defaultConsoleRowHeight = 19; 161 const defaultConsoleRowHeight = 19;
103 if (this._message.type === SDK.ConsoleMessage.MessageType.Table) { 162 if (this._message.type === SDK.ConsoleMessage.MessageType.Table) {
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 882
824 /** 883 /**
825 * @param {string} filter 884 * @param {string} filter
826 * @return {boolean} 885 * @return {boolean}
827 */ 886 */
828 matchesFilterText(filter) { 887 matchesFilterText(filter) {
829 var text = this.contentElement().deepTextContent(); 888 var text = this.contentElement().deepTextContent();
830 return text.toLowerCase().includes(filter.toLowerCase()); 889 return text.toLowerCase().includes(filter.toLowerCase());
831 } 890 }
832 891
833 updateTimestamp() {
834 if (!this._contentElement)
835 return;
836
837 if (Common.moduleSetting('consoleTimestampsEnabled').get()) {
838 if (!this._timestampElement)
839 this._timestampElement = createElementWithClass('span', 'console-timesta mp');
840 this._timestampElement.textContent = formatTimestamp(this._message.timesta mp, false) + ' ';
841 this._timestampElement.title = formatTimestamp(this._message.timestamp, tr ue);
842 this._contentElement.insertBefore(this._timestampElement, this._contentEle ment.firstChild);
843 } else if (this._timestampElement) {
844 this._timestampElement.remove();
845 delete this._timestampElement;
846 }
847
848 /**
849 * @param {number} timestamp
850 * @param {boolean} full
851 * @return {string}
852 */
853 function formatTimestamp(timestamp, full) {
854 var date = new Date(timestamp);
855 var yymmdd = date.getFullYear() + '-' + leadZero(date.getMonth() + 1, 2) + '-' + leadZero(date.getDate(), 2);
856 var hhmmssfff = leadZero(date.getHours(), 2) + ':' + leadZero(date.getMinu tes(), 2) + ':' +
857 leadZero(date.getSeconds(), 2) + '.' + leadZero(date.getMilliseconds() , 3);
858 return full ? (yymmdd + ' ' + hhmmssfff) : hhmmssfff;
859
860 /**
861 * @param {number} value
862 * @param {number} length
863 * @return {string}
864 */
865 function leadZero(value, length) {
866 var valueString = value.toString();
867 var padding = length - valueString.length;
868 return padding <= 0 ? valueString : '0'.repeat(padding) + valueString;
869 }
870 }
871 }
872
873 /** 892 /**
874 * @return {number} 893 * @return {number}
875 */ 894 */
876 nestingLevel() { 895 nestingLevel() {
877 return this._nestingLevel; 896 return this._nestingLevel;
878 } 897 }
879 898
880 resetCloseGroupDecorationCount() { 899 resetCloseGroupDecorationCount() {
881 if (!this._closeGroupDecorationCount) 900 if (!this._closeGroupDecorationCount)
882 return; 901 return;
(...skipping 16 matching lines...) Expand all
899 } 918 }
900 919
901 /** 920 /**
902 * @return {!Element} 921 * @return {!Element}
903 */ 922 */
904 contentElement() { 923 contentElement() {
905 if (this._contentElement) 924 if (this._contentElement)
906 return this._contentElement; 925 return this._contentElement;
907 926
908 var contentElement = createElementWithClass('div', 'console-message'); 927 var contentElement = createElementWithClass('div', 'console-message');
909 if (this._messageLevelIcon)
910 contentElement.appendChild(this._messageLevelIcon);
911 this._contentElement = contentElement; 928 this._contentElement = contentElement;
912 if (this._message.type === SDK.ConsoleMessage.MessageType.StartGroup || 929 if (this._message.type === SDK.ConsoleMessage.MessageType.StartGroup ||
913 this._message.type === SDK.ConsoleMessage.MessageType.StartGroupCollapse d) 930 this._message.type === SDK.ConsoleMessage.MessageType.StartGroupCollapse d)
914 contentElement.classList.add('console-group-title'); 931 contentElement.classList.add('console-group-title');
932 else if (this._message.type === SDK.ConsoleMessage.MessageType.Result)
933 contentElement.classList.add('console-user-command-result');
915 934
916 var formattedMessage; 935 var formattedMessage;
917 var consoleMessage = this._message; 936 var consoleMessage = this._message;
918 var target = consoleMessage.target(); 937 var target = consoleMessage.target();
919 var shouldIncludeTrace = 938 var shouldIncludeTrace =
920 !!consoleMessage.stackTrace && (consoleMessage.source === SDK.ConsoleMes sage.MessageSource.Network || 939 !!consoleMessage.stackTrace && (consoleMessage.source === SDK.ConsoleMes sage.MessageSource.Network ||
921 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Error || 940 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Error ||
922 consoleMessage.type === SDK.ConsoleMessa ge.MessageType.Trace || 941 consoleMessage.type === SDK.ConsoleMessa ge.MessageType.Trace ||
923 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Warning); 942 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Warning);
924 if (target && shouldIncludeTrace) 943 if (target && shouldIncludeTrace)
925 formattedMessage = this._buildMessageWithStackTrace(consoleMessage, target , this._linkifier); 944 formattedMessage = this._buildMessageWithStackTrace(consoleMessage, target , this._linkifier);
926 else if (this._message.type === SDK.ConsoleMessage.MessageType.Table) 945 else if (this._message.type === SDK.ConsoleMessage.MessageType.Table)
927 formattedMessage = this._buildTableMessage(this._message); 946 formattedMessage = this._buildTableMessage(this._message);
928 else 947 else
929 formattedMessage = this._buildMessage(consoleMessage); 948 formattedMessage = this._buildMessage(consoleMessage);
930 contentElement.appendChild(formattedMessage); 949 contentElement.appendChild(formattedMessage);
931 950
932 this.updateTimestamp();
933 return this._contentElement; 951 return this._contentElement;
934 } 952 }
935 953
936 /** 954 /**
937 * @return {!Element} 955 * @return {!Element}
938 */ 956 */
939 toMessageElement() { 957 toMessageElement() {
940 if (this._element) 958 if (this._element)
941 return this._element; 959 return this._element;
942 960
943 this._element = createElement('div'); 961 this._element = createElement('div');
944 this.updateMessageElement(); 962 this.updateMessageElement();
945 return this._element; 963 return this._element;
946 } 964 }
947 965
948 updateMessageElement() { 966 updateMessageElement() {
949 if (!this._element) 967 if (!this._element)
950 return; 968 return;
951 969
952 this._element.className = 'console-message-wrapper'; 970 this._element.className = 'console-message-wrapper';
953 this._element.removeChildren(); 971 this._element.removeChildren();
954
955 this._nestingLevelMarkers = [];
956 for (var i = 0; i < this._nestingLevel; ++i)
957 this._nestingLevelMarkers.push(this._element.createChild('div', 'nesting-l evel-marker'));
958 this._updateCloseGroupDecorations();
959 this._element.message = this; 972 this._element.message = this;
960 973
961 switch (this._message.level) { 974 switch (this._message.level) {
962 case SDK.ConsoleMessage.MessageLevel.Verbose: 975 case SDK.ConsoleMessage.MessageLevel.Verbose:
963 this._element.classList.add('console-verbose-level'); 976 this._element.classList.add('console-verbose-level');
964 this._updateMessageLevelIcon('');
965 break; 977 break;
966 case SDK.ConsoleMessage.MessageLevel.Info: 978 case SDK.ConsoleMessage.MessageLevel.Info:
967 this._element.classList.add('console-info-level'); 979 this._element.classList.add('console-info-level');
968 break; 980 break;
969 case SDK.ConsoleMessage.MessageLevel.Warning: 981 case SDK.ConsoleMessage.MessageLevel.Warning:
970 this._element.classList.add('console-warning-level'); 982 this._element.classList.add('console-warning-level');
971 this._updateMessageLevelIcon('smallicon-warning');
972 break; 983 break;
973 case SDK.ConsoleMessage.MessageLevel.Error: 984 case SDK.ConsoleMessage.MessageLevel.Error:
974 this._element.classList.add('console-error-level'); 985 this._element.classList.add('console-error-level');
975 this._updateMessageLevelIcon('smallicon-error');
976 break; 986 break;
977 } 987 }
978 988
979 // Render verbose and info deprecations, interventions and violations with w arning background. 989 // Render verbose and info deprecations, interventions and violations with w arning background.
980 if (this._message.level === SDK.ConsoleMessage.MessageLevel.Verbose || 990 if (this._message.level === SDK.ConsoleMessage.MessageLevel.Verbose ||
981 this._message.level === SDK.ConsoleMessage.MessageLevel.Info) { 991 this._message.level === SDK.ConsoleMessage.MessageLevel.Info) {
982 switch (this._message.source) { 992 switch (this._message.source) {
983 case SDK.ConsoleMessage.MessageSource.Violation: 993 case SDK.ConsoleMessage.MessageSource.Violation:
984 case SDK.ConsoleMessage.MessageSource.Deprecation: 994 case SDK.ConsoleMessage.MessageSource.Deprecation:
985 case SDK.ConsoleMessage.MessageSource.Intervention: 995 case SDK.ConsoleMessage.MessageSource.Intervention:
986 this._element.classList.add('console-warning-level'); 996 this._element.classList.add('console-warning-level');
987 break; 997 break;
988 } 998 }
989 } 999 }
990 1000
1001 this._decorationWrapper = this._element.createChild('span', 'message-decorat ion-wrapper');
1002 this._nestingLevelMarkers = [];
1003 for (var i = 0; i < this._nestingLevel; ++i)
1004 this._nestingLevelMarkers.push(this._element.createChild('div', 'message-n esting-level-marker'));
1005 this._updateCloseGroupDecorations();
1006 this._repeatCountElement = this._element.createChild('label', 'message-repea t-count', 'dt-small-bubble');
1007 switch (this._message.level) {
1008 case SDK.ConsoleMessage.MessageLevel.Warning:
pfeldman 2017/02/22 00:10:45 How come it is in a different location from updati
1009 this._repeatCountElement.type = 'warning';
1010 break;
1011 case SDK.ConsoleMessage.MessageLevel.Error:
1012 this._repeatCountElement.type = 'error';
1013 break;
1014 case SDK.ConsoleMessage.MessageLevel.Verbose:
1015 this._repeatCountElement.type = 'verbose';
1016 break;
1017 default:
1018 this._repeatCountElement.type = 'info';
1019 }
1020 this._rebuildDecorations();
991 this._element.appendChild(this.contentElement()); 1021 this._element.appendChild(this.contentElement());
992 if (this._repeatCount > 1)
993 this._showRepeatCountElement();
994 } 1022 }
995 1023
996 /** 1024 /**
997 * @param {string} iconType
998 */
999 _updateMessageLevelIcon(iconType) {
1000 if (!iconType && !this._messageLevelIcon)
1001 return;
1002 if (iconType && !this._messageLevelIcon) {
1003 this._messageLevelIcon = UI.Icon.create('', 'message-level-icon');
1004 if (this._contentElement)
1005 this._contentElement.insertBefore(this._messageLevelIcon, this._contentE lement.firstChild);
1006 }
1007 this._messageLevelIcon.setIconType(iconType);
1008 }
1009
1010 /**
1011 * @return {number} 1025 * @return {number}
1012 */ 1026 */
1013 repeatCount() { 1027 repeatCount() {
1014 return this._repeatCount || 1; 1028 return this._repeatCount || 1;
1015 } 1029 }
1016 1030
1017 resetIncrementRepeatCount() { 1031 resetIncrementRepeatCount() {
1018 this._repeatCount = 1; 1032 this._repeatCount = 1;
1019 if (!this._repeatCountElement) 1033 this._updateRepeatCountElement();
1020 return;
1021
1022 this._repeatCountElement.remove();
1023 if (this._contentElement)
1024 this._contentElement.classList.remove('repeated-message');
1025 delete this._repeatCountElement;
1026 } 1034 }
1027 1035
1028 incrementRepeatCount() { 1036 incrementRepeatCount() {
1029 this._repeatCount++; 1037 this._repeatCount++;
1030 this._showRepeatCountElement(); 1038 this._updateRepeatCountElement();
1031 } 1039 }
1032 1040
1033 _showRepeatCountElement() { 1041 _updateRepeatCountElement() {
1034 if (!this._element) 1042 if (!this._repeatCountElement)
1035 return; 1043 return;
1036 1044 var show = this._repeatCount > 1;
1037 if (!this._repeatCountElement) { 1045 this._repeatCountElement.textContent = show ? this._repeatCount : '';
1038 this._repeatCountElement = createElementWithClass('label', 'console-messag e-repeat-count', 'dt-small-bubble'); 1046 this._repeatCountElement.classList.toggle('hidden', !show);
1039 switch (this._message.level) { 1047 if (this._element)
1040 case SDK.ConsoleMessage.MessageLevel.Warning: 1048 this._element.classList.toggle('repeated-message', show);
1041 this._repeatCountElement.type = 'warning';
1042 break;
1043 case SDK.ConsoleMessage.MessageLevel.Error:
1044 this._repeatCountElement.type = 'error';
1045 break;
1046 case SDK.ConsoleMessage.MessageLevel.Verbose:
1047 this._repeatCountElement.type = 'verbose';
1048 break;
1049 default:
1050 this._repeatCountElement.type = 'info';
1051 }
1052 this._element.insertBefore(this._repeatCountElement, this._contentElement) ;
1053 this._contentElement.classList.add('repeated-message');
1054 }
1055 this._repeatCountElement.textContent = this._repeatCount;
1056 } 1049 }
1057 1050
1058 get text() { 1051 get text() {
1059 return this._message.messageText; 1052 return this._message.messageText;
1060 } 1053 }
1061 1054
1062 /** 1055 /**
1063 * @return {string} 1056 * @return {string}
1064 */ 1057 */
1065 toExportString() { 1058 toExportString() {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 toMessageElement() { 1240 toMessageElement() {
1248 if (!this._element) { 1241 if (!this._element) {
1249 super.toMessageElement(); 1242 super.toMessageElement();
1250 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); 1243 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon');
1251 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); 1244 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild);
1252 this.setCollapsed(this._collapsed); 1245 this.setCollapsed(this._collapsed);
1253 } 1246 }
1254 return this._element; 1247 return this._element;
1255 } 1248 }
1256 }; 1249 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698