OLD | NEW |
---|---|
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 Loading... | |
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|undefined} */ |
pfeldman
2017/02/06 22:30:52
You could assign these to null for clarity.
luoe
2017/02/07 00:50:32
Done.
| |
52 this._messageLevelIcon = null; | 52 this._timestampSlot; |
53 /** @type {!Element|undefined} */ | |
54 this._levelSlot; | |
55 /** @type {!Element|undefined} */ | |
56 this._nestingLevelMarkersSlot; | |
57 /** @type {!Element|undefined} */ | |
58 this._repeatSlot; | |
59 /** @type {!Element|undefined} */ | |
60 this._repeatCountElement; | |
53 } | 61 } |
54 | 62 |
55 /** | 63 /** |
56 * @return {?SDK.Target} | 64 * @return {?SDK.Target} |
57 */ | 65 */ |
58 _target() { | 66 _target() { |
59 return this.consoleMessage().target(); | 67 return this.consoleMessage().target(); |
60 } | 68 } |
61 | 69 |
62 /** | 70 /** |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
819 | 827 |
820 /** | 828 /** |
821 * @param {string} filter | 829 * @param {string} filter |
822 * @return {boolean} | 830 * @return {boolean} |
823 */ | 831 */ |
824 matchesFilterText(filter) { | 832 matchesFilterText(filter) { |
825 var text = this.contentElement().deepTextContent(); | 833 var text = this.contentElement().deepTextContent(); |
826 return text.toLowerCase().includes(filter.toLowerCase()); | 834 return text.toLowerCase().includes(filter.toLowerCase()); |
827 } | 835 } |
828 | 836 |
829 updateTimestamp() { | 837 rebuildTimestamp() { |
830 if (!this._contentElement) | 838 if (!this._timestampSlot) |
pfeldman
2017/02/06 22:30:52
This should never happen.
luoe
2017/02/07 00:50:32
Done.
| |
831 return; | 839 return; |
832 | |
833 var format = Common.moduleSetting('consoleTimestampFormat').get(); | 840 var format = Common.moduleSetting('consoleTimestampFormat').get(); |
834 if (format !== Console.ConsoleViewMessage.TimestampFormat.None) { | 841 if (format !== Console.ConsoleViewMessage.TimestampFormat.None) { |
835 var timestampText = formatTimestamp(this._message.timestamp, format); | 842 var timestampText = formatTimestamp(this._message.timestamp, format); |
836 if (!this._timestampElement) | 843 this._timestampSlot.textContent = timestampText + ' '; |
837 this._timestampElement = createElementWithClass('span', 'console-timesta mp'); | 844 this._timestampSlot.title = timestampText; |
838 this._timestampElement.textContent = timestampText + ' '; | 845 } else { |
839 this._timestampElement.title = timestampText; | 846 this._timestampSlot.removeChildren(); |
840 this._contentElement.insertBefore(this._timestampElement, this._contentEle ment.firstChild); | 847 this._timestampSlot.title = ''; |
841 } else if (this._timestampElement) { | |
842 this._timestampElement.remove(); | |
843 delete this._timestampElement; | |
844 } | 848 } |
845 | 849 |
846 /** | 850 /** |
847 * @param {number} timestamp | 851 * @param {number} timestamp |
848 * @param {!Console.ConsoleViewMessage.TimestampFormat} format | 852 * @param {!Console.ConsoleViewMessage.TimestampFormat} format |
849 * @return {string} | 853 * @return {string} |
850 */ | 854 */ |
851 function formatTimestamp(timestamp, format) { | 855 function formatTimestamp(timestamp, format) { |
852 var date = new Date(timestamp); | 856 var date = new Date(timestamp); |
853 var yymmdd = date.getFullYear() + '-' + leadZero(date.getMonth() + 1, 2) + '-' + leadZero(date.getDate(), 2); | 857 var yymmdd = date.getFullYear() + '-' + leadZero(date.getMonth() + 1, 2) + '-' + leadZero(date.getDate(), 2); |
(...skipping 28 matching lines...) Expand all Loading... | |
882 return; | 886 return; |
883 this._closeGroupDecorationCount = 0; | 887 this._closeGroupDecorationCount = 0; |
884 this._updateCloseGroupDecorations(); | 888 this._updateCloseGroupDecorations(); |
885 } | 889 } |
886 | 890 |
887 incrementCloseGroupDecorationCount() { | 891 incrementCloseGroupDecorationCount() { |
888 ++this._closeGroupDecorationCount; | 892 ++this._closeGroupDecorationCount; |
889 this._updateCloseGroupDecorations(); | 893 this._updateCloseGroupDecorations(); |
890 } | 894 } |
891 | 895 |
896 _rebuildNestingLevelMarkers() { | |
pfeldman
2017/02/06 22:30:52
You only call it once, call it _buildNestingLevelM
luoe
2017/02/07 00:50:32
After refactoring, it was small enough that I inli
| |
897 if (!this._nestingLevelMarkersSlot) | |
pfeldman
2017/02/06 22:30:52
ditto
luoe
2017/02/07 00:50:32
Done.
| |
898 return; | |
899 this._nestingLevelMarkersSlot.removeChildren(); | |
900 this._nestingLevelMarkers = []; | |
901 for (var i = 0; i < this._nestingLevel; ++i) | |
902 this._nestingLevelMarkers.push(this._nestingLevelMarkersSlot.createChild(' div', 'message-nesting-level-marker')); | |
903 this._updateCloseGroupDecorations(); | |
904 } | |
905 | |
892 _updateCloseGroupDecorations() { | 906 _updateCloseGroupDecorations() { |
893 if (!this._nestingLevelMarkers) | 907 if (!this._nestingLevelMarkers) |
894 return; | 908 return; |
895 for (var i = 0, n = this._nestingLevelMarkers.length; i < n; ++i) { | 909 for (var i = 0, n = this._nestingLevelMarkers.length; i < n; ++i) { |
896 var marker = this._nestingLevelMarkers[i]; | 910 var marker = this._nestingLevelMarkers[i]; |
897 marker.classList.toggle('group-closed', n - i <= this._closeGroupDecoratio nCount); | 911 marker.classList.toggle('group-closed', n - i <= this._closeGroupDecoratio nCount); |
898 } | 912 } |
899 } | 913 } |
900 | 914 |
901 /** | 915 /** |
902 * @return {!Element} | 916 * @return {!Element} |
903 */ | 917 */ |
904 contentElement() { | 918 contentElement() { |
905 if (this._contentElement) | 919 if (this._contentElement) |
906 return this._contentElement; | 920 return this._contentElement; |
907 | 921 |
908 var contentElement = createElementWithClass('div', 'console-message'); | 922 var contentElement = createElementWithClass('div', 'console-message'); |
909 if (this._messageLevelIcon) | |
910 contentElement.appendChild(this._messageLevelIcon); | |
911 this._contentElement = contentElement; | 923 this._contentElement = contentElement; |
912 if (this._message.type === SDK.ConsoleMessage.MessageType.StartGroup || | 924 if (this._message.type === SDK.ConsoleMessage.MessageType.StartGroup || |
913 this._message.type === SDK.ConsoleMessage.MessageType.StartGroupCollapse d) | 925 this._message.type === SDK.ConsoleMessage.MessageType.StartGroupCollapse d) |
914 contentElement.classList.add('console-group-title'); | 926 contentElement.classList.add('console-group-title'); |
927 else if (this._message.type === SDK.ConsoleMessage.MessageType.Result) | |
928 contentElement.classList.add('console-user-command-result'); | |
915 | 929 |
916 var formattedMessage; | 930 var formattedMessage; |
917 var consoleMessage = this._message; | 931 var consoleMessage = this._message; |
918 var target = consoleMessage.target(); | 932 var target = consoleMessage.target(); |
919 var shouldIncludeTrace = | 933 var shouldIncludeTrace = |
920 !!consoleMessage.stackTrace && (consoleMessage.source === SDK.ConsoleMes sage.MessageSource.Network || | 934 !!consoleMessage.stackTrace && (consoleMessage.source === SDK.ConsoleMes sage.MessageSource.Network || |
921 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Error || | 935 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Error || |
922 consoleMessage.type === SDK.ConsoleMessa ge.MessageType.Trace || | 936 consoleMessage.type === SDK.ConsoleMessa ge.MessageType.Trace || |
923 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Warning); | 937 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Warning); |
924 if (target && shouldIncludeTrace) | 938 if (target && shouldIncludeTrace) |
925 formattedMessage = this._buildMessageWithStackTrace(consoleMessage, target , this._linkifier); | 939 formattedMessage = this._buildMessageWithStackTrace(consoleMessage, target , this._linkifier); |
926 else if (this._message.type === SDK.ConsoleMessage.MessageType.Table) | 940 else if (this._message.type === SDK.ConsoleMessage.MessageType.Table) |
927 formattedMessage = this._buildTableMessage(this._message); | 941 formattedMessage = this._buildTableMessage(this._message); |
928 else | 942 else |
929 formattedMessage = this._buildMessage(consoleMessage); | 943 formattedMessage = this._buildMessage(consoleMessage); |
930 contentElement.appendChild(formattedMessage); | 944 contentElement.appendChild(formattedMessage); |
931 | 945 |
932 this.updateTimestamp(); | |
933 return this._contentElement; | 946 return this._contentElement; |
934 } | 947 } |
935 | 948 |
936 /** | 949 /** |
937 * @return {!Element} | 950 * @return {!Element} |
938 */ | 951 */ |
939 toMessageElement() { | 952 toMessageElement() { |
940 if (this._element) | 953 if (this._element) |
941 return this._element; | 954 return this._element; |
942 | 955 |
943 this._element = createElement('div'); | 956 this._element = createElement('div'); |
944 this.updateMessageElement(); | 957 this.updateMessageElement(); |
945 return this._element; | 958 return this._element; |
946 } | 959 } |
947 | 960 |
948 updateMessageElement() { | 961 updateMessageElement() { |
949 if (!this._element) | 962 if (!this._element) |
950 return; | 963 return; |
951 | 964 |
952 this._element.className = 'console-message-wrapper'; | 965 this._element.className = 'console-message-wrapper'; |
953 this._element.removeChildren(); | 966 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; | 967 this._element.message = this; |
960 | 968 |
961 switch (this._message.level) { | 969 switch (this._message.level) { |
962 case SDK.ConsoleMessage.MessageLevel.Verbose: | 970 case SDK.ConsoleMessage.MessageLevel.Verbose: |
963 this._element.classList.add('console-verbose-level'); | 971 this._element.classList.add('console-verbose-level'); |
964 this._updateMessageLevelIcon(''); | |
965 break; | 972 break; |
966 case SDK.ConsoleMessage.MessageLevel.Info: | 973 case SDK.ConsoleMessage.MessageLevel.Info: |
967 this._element.classList.add('console-info-level'); | 974 this._element.classList.add('console-info-level'); |
968 break; | 975 break; |
969 case SDK.ConsoleMessage.MessageLevel.Warning: | 976 case SDK.ConsoleMessage.MessageLevel.Warning: |
970 this._element.classList.add('console-warning-level'); | 977 this._element.classList.add('console-warning-level'); |
971 this._updateMessageLevelIcon('smallicon-warning'); | |
972 break; | 978 break; |
973 case SDK.ConsoleMessage.MessageLevel.Error: | 979 case SDK.ConsoleMessage.MessageLevel.Error: |
974 this._element.classList.add('console-error-level'); | 980 this._element.classList.add('console-error-level'); |
975 this._updateMessageLevelIcon('smallicon-error'); | |
976 break; | 981 break; |
977 } | 982 } |
978 | 983 |
979 // Render verbose and info deprecations, interventions and violations with w arning background. | 984 // Render verbose and info deprecations, interventions and violations with w arning background. |
980 if (this._message.level === SDK.ConsoleMessage.MessageLevel.Verbose || | 985 if (this._message.level === SDK.ConsoleMessage.MessageLevel.Verbose || |
981 this._message.level === SDK.ConsoleMessage.MessageLevel.Info) { | 986 this._message.level === SDK.ConsoleMessage.MessageLevel.Info) { |
982 switch (this._message.source) { | 987 switch (this._message.source) { |
983 case SDK.ConsoleMessage.MessageSource.Violation: | 988 case SDK.ConsoleMessage.MessageSource.Violation: |
984 case SDK.ConsoleMessage.MessageSource.Deprecation: | 989 case SDK.ConsoleMessage.MessageSource.Deprecation: |
985 case SDK.ConsoleMessage.MessageSource.Intervention: | 990 case SDK.ConsoleMessage.MessageSource.Intervention: |
986 this._element.classList.add('console-warning-level'); | 991 this._element.classList.add('console-warning-level'); |
987 break; | 992 break; |
988 } | 993 } |
989 } | 994 } |
990 | 995 |
996 this._timestampSlot = this._element.createChild('span', 'message-timestamp-s lot'); | |
997 this._levelSlot = this._element.createChild('span', 'message-level-slot'); | |
998 this._nestingLevelMarkersSlot = this._element.createChild('span', 'message-n esting-level-markers-slot'); | |
999 this._repeatSlot = this._element.createChild('span', 'message-repeat-count-s lot'); | |
991 this._element.appendChild(this.contentElement()); | 1000 this._element.appendChild(this.contentElement()); |
992 if (this._repeatCount > 1) | 1001 |
993 this._showRepeatCountElement(); | 1002 this.rebuildTimestamp(); |
1003 this._rebuildLevelIcon(); | |
1004 this._rebuildNestingLevelMarkers(); | |
1005 this._rebuildRepeatCountElement(); | |
1006 } | |
1007 | |
1008 _rebuildLevelIcon() { | |
1009 if (!this._levelSlot) | |
pfeldman
2017/02/06 22:30:52
ditto, also don't see that you call it more than o
luoe
2017/02/07 00:50:32
Done.
| |
1010 return; | |
1011 var iconType = ''; | |
1012 if (this._message.level === SDK.ConsoleMessage.MessageLevel.Warning) | |
1013 iconType = 'smallicon-warning'; | |
1014 else if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error) | |
1015 iconType = 'smallicon-error'; | |
1016 else if (this._message.type === SDK.ConsoleMessage.MessageType.Command) | |
1017 iconType = 'smallicon-user-command'; | |
1018 else if (this._message.type === SDK.ConsoleMessage.MessageType.Result) | |
1019 iconType = 'smallicon-command-result'; | |
1020 this._levelSlot.removeChildren(); | |
1021 if (iconType) | |
1022 this._levelSlot.appendChild(UI.Icon.create(iconType)); | |
994 } | 1023 } |
995 | 1024 |
996 /** | 1025 /** |
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} | 1026 * @return {number} |
1012 */ | 1027 */ |
1013 repeatCount() { | 1028 repeatCount() { |
1014 return this._repeatCount || 1; | 1029 return this._repeatCount || 1; |
1015 } | 1030 } |
1016 | 1031 |
1017 resetIncrementRepeatCount() { | 1032 resetIncrementRepeatCount() { |
1018 this._repeatCount = 1; | 1033 this._repeatCount = 1; |
1019 if (!this._repeatCountElement) | 1034 this._rebuildRepeatCountElement(); |
1020 return; | |
1021 | |
1022 this._repeatCountElement.remove(); | |
1023 if (this._contentElement) | |
1024 this._contentElement.classList.remove('repeated-message'); | |
1025 delete this._repeatCountElement; | |
1026 } | 1035 } |
1027 | 1036 |
1028 incrementRepeatCount() { | 1037 incrementRepeatCount() { |
1029 this._repeatCount++; | 1038 this._repeatCount++; |
1030 this._showRepeatCountElement(); | 1039 this._rebuildRepeatCountElement(); |
1031 } | 1040 } |
1032 | 1041 |
1033 _showRepeatCountElement() { | 1042 _rebuildRepeatCountElement() { |
1034 if (!this._contentElement) | 1043 if (!this._repeatSlot) |
1035 return; | 1044 return; |
1036 | 1045 if (this._repeatCount > 1) { |
1037 if (!this._repeatCountElement) { | 1046 if (!this._repeatCountElement) |
1038 this._repeatCountElement = createElementWithClass('label', 'console-messag e-repeat-count', 'dt-small-bubble'); | 1047 this._repeatCountElement = this._repeatSlot.createChild('label', 'messag e-repeat-count', 'dt-small-bubble'); |
1039 switch (this._message.level) { | 1048 switch (this._message.level) { |
1040 case SDK.ConsoleMessage.MessageLevel.Warning: | 1049 case SDK.ConsoleMessage.MessageLevel.Warning: |
1041 this._repeatCountElement.type = 'warning'; | 1050 this._repeatCountElement.type = 'warning'; |
1042 break; | 1051 break; |
1043 case SDK.ConsoleMessage.MessageLevel.Error: | 1052 case SDK.ConsoleMessage.MessageLevel.Error: |
1044 this._repeatCountElement.type = 'error'; | 1053 this._repeatCountElement.type = 'error'; |
1045 break; | 1054 break; |
1046 case SDK.ConsoleMessage.MessageLevel.Verbose: | 1055 case SDK.ConsoleMessage.MessageLevel.Verbose: |
1047 this._repeatCountElement.type = 'verbose'; | 1056 this._repeatCountElement.type = 'verbose'; |
1048 break; | 1057 break; |
1049 default: | 1058 default: |
1050 this._repeatCountElement.type = 'info'; | 1059 this._repeatCountElement.type = 'info'; |
1051 } | 1060 } |
1052 this._element.insertBefore(this._repeatCountElement, this._contentElement) ; | 1061 this._repeatCountElement.textContent = this._repeatCount; |
1053 this._contentElement.classList.add('repeated-message'); | 1062 } else if (this._repeatCountElement) { |
1063 this._repeatCountElement.remove(); | |
1064 delete this._repeatCountElement; | |
1054 } | 1065 } |
1055 this._repeatCountElement.textContent = this._repeatCount; | 1066 if (this._element) |
1067 this._element.classList.toggle('repeated-message', this._repeatCount > 1); | |
1056 } | 1068 } |
1057 | 1069 |
1058 get text() { | 1070 get text() { |
1059 return this._message.messageText; | 1071 return this._message.messageText; |
1060 } | 1072 } |
1061 | 1073 |
1062 /** | 1074 /** |
1063 * @return {string} | 1075 * @return {string} |
1064 */ | 1076 */ |
1065 toExportString() { | 1077 toExportString() { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1256 toMessageElement() { | 1268 toMessageElement() { |
1257 if (!this._element) { | 1269 if (!this._element) { |
1258 super.toMessageElement(); | 1270 super.toMessageElement(); |
1259 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); | 1271 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); |
1260 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); | 1272 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); |
1261 this.setCollapsed(this._collapsed); | 1273 this.setCollapsed(this._collapsed); |
1262 } | 1274 } |
1263 return this._element; | 1275 return this._element; |
1264 } | 1276 } |
1265 }; | 1277 }; |
OLD | NEW |