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 {!UI.Icon|undefined} */ |
52 this._messageLevelIcon = null; | 52 this._messageLevelIcon; |
53 /** @type {!Element|undefined} */ | |
54 this._nestingLevelMarkersElement; | |
55 /** @type {!Element|undefined} */ | |
56 this._repeatCountElement; | |
57 /** @type {!Element|undefined} */ | |
58 this._timestampElement; | |
53 } | 59 } |
54 | 60 |
55 /** | 61 /** |
56 * @return {?SDK.Target} | 62 * @return {?SDK.Target} |
57 */ | 63 */ |
58 _target() { | 64 _target() { |
59 return this.consoleMessage().target(); | 65 return this.consoleMessage().target(); |
60 } | 66 } |
61 | 67 |
62 /** | 68 /** |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
820 /** | 826 /** |
821 * @param {string} filter | 827 * @param {string} filter |
822 * @return {boolean} | 828 * @return {boolean} |
823 */ | 829 */ |
824 matchesFilterText(filter) { | 830 matchesFilterText(filter) { |
825 var text = this.contentElement().deepTextContent(); | 831 var text = this.contentElement().deepTextContent(); |
826 return text.toLowerCase().includes(filter.toLowerCase()); | 832 return text.toLowerCase().includes(filter.toLowerCase()); |
827 } | 833 } |
828 | 834 |
829 updateTimestamp() { | 835 updateTimestamp() { |
830 if (!this._contentElement) | |
831 return; | |
832 | |
833 var format = Common.moduleSetting('consoleTimestampFormat').get(); | 836 var format = Common.moduleSetting('consoleTimestampFormat').get(); |
834 if (format !== Console.ConsoleViewMessage.TimestampFormat.None) { | 837 if (format !== Console.ConsoleViewMessage.TimestampFormat.None) { |
835 var timestampText = formatTimestamp(this._message.timestamp, format); | 838 var timestampText = formatTimestamp(this._message.timestamp, format); |
836 if (!this._timestampElement) | 839 if (!this._timestampElement) |
837 this._timestampElement = createElementWithClass('span', 'console-timesta mp'); | 840 this._timestampElement = createElementWithClass('span', 'console-timesta mp'); |
838 this._timestampElement.textContent = timestampText + ' '; | 841 this._timestampElement.textContent = timestampText + ' '; |
839 this._timestampElement.title = timestampText; | 842 this._timestampElement.title = timestampText; |
840 this._contentElement.insertBefore(this._timestampElement, this._contentEle ment.firstChild); | |
841 } else if (this._timestampElement) { | 843 } else if (this._timestampElement) { |
842 this._timestampElement.remove(); | 844 this._timestampElement.remove(); |
843 delete this._timestampElement; | 845 delete this._timestampElement; |
844 } | 846 } |
847 this._insertDecorationsInOrder(); | |
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); |
854 var hhmmssfff = leadZero(date.getHours(), 2) + ':' + leadZero(date.getMinu tes(), 2) + ':' + | 858 var hhmmssfff = leadZero(date.getHours(), 2) + ':' + leadZero(date.getMinu tes(), 2) + ':' + |
(...skipping 27 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 _updateNestingLevelMarkers() { | |
897 if (!this._nestingLevelMarkersElement && this._nestingLevel > 0) { | |
898 this._nestingLevelMarkersElement = createElementWithClass('span', 'nesting -level-markers-wrapper'); | |
899 this._nestingLevelMarkers = []; | |
900 for (var i = 0; i < this._nestingLevel; ++i) | |
901 this._nestingLevelMarkers.push(this._nestingLevelMarkersElement.createCh ild('div', 'nesting-level-marker')); | |
902 this._updateCloseGroupDecorations(); | |
903 } | |
904 this._insertDecorationsInOrder(); | |
905 } | |
906 | |
892 _updateCloseGroupDecorations() { | 907 _updateCloseGroupDecorations() { |
893 if (!this._nestingLevelMarkers) | 908 if (!this._nestingLevelMarkers) |
894 return; | 909 return; |
895 for (var i = 0, n = this._nestingLevelMarkers.length; i < n; ++i) { | 910 for (var i = 0, n = this._nestingLevelMarkers.length; i < n; ++i) { |
896 var marker = this._nestingLevelMarkers[i]; | 911 var marker = this._nestingLevelMarkers[i]; |
897 marker.classList.toggle('group-closed', n - i <= this._closeGroupDecoratio nCount); | 912 marker.classList.toggle('group-closed', n - i <= this._closeGroupDecoratio nCount); |
898 } | 913 } |
899 } | 914 } |
900 | 915 |
901 /** | 916 /** |
902 * @return {!Element} | 917 * @return {!Element} |
903 */ | 918 */ |
904 contentElement() { | 919 contentElement() { |
905 if (this._contentElement) | 920 if (this._contentElement) |
906 return this._contentElement; | 921 return this._contentElement; |
907 | 922 |
908 var contentElement = createElementWithClass('div', 'console-message'); | 923 var contentElement = createElementWithClass('div', 'console-message'); |
909 if (this._messageLevelIcon) | |
910 contentElement.appendChild(this._messageLevelIcon); | |
911 this._contentElement = contentElement; | 924 this._contentElement = contentElement; |
912 if (this._message.type === SDK.ConsoleMessage.MessageType.StartGroup || | 925 if (this._message.type === SDK.ConsoleMessage.MessageType.StartGroup || |
913 this._message.type === SDK.ConsoleMessage.MessageType.StartGroupCollapse d) | 926 this._message.type === SDK.ConsoleMessage.MessageType.StartGroupCollapse d) |
914 contentElement.classList.add('console-group-title'); | 927 contentElement.classList.add('console-group-title'); |
928 else if (this._message.type === SDK.ConsoleMessage.MessageType.Result) | |
929 contentElement.classList.add('console-user-command-result'); | |
915 | 930 |
916 var formattedMessage; | 931 var formattedMessage; |
917 var consoleMessage = this._message; | 932 var consoleMessage = this._message; |
918 var target = consoleMessage.target(); | 933 var target = consoleMessage.target(); |
919 var shouldIncludeTrace = | 934 var shouldIncludeTrace = |
920 !!consoleMessage.stackTrace && (consoleMessage.source === SDK.ConsoleMes sage.MessageSource.Network || | 935 !!consoleMessage.stackTrace && (consoleMessage.source === SDK.ConsoleMes sage.MessageSource.Network || |
921 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Error || | 936 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Error || |
922 consoleMessage.type === SDK.ConsoleMessa ge.MessageType.Trace || | 937 consoleMessage.type === SDK.ConsoleMessa ge.MessageType.Trace || |
923 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Warning); | 938 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Warning); |
924 if (target && shouldIncludeTrace) | 939 if (target && shouldIncludeTrace) |
925 formattedMessage = this._buildMessageWithStackTrace(consoleMessage, target , this._linkifier); | 940 formattedMessage = this._buildMessageWithStackTrace(consoleMessage, target , this._linkifier); |
926 else if (this._message.type === SDK.ConsoleMessage.MessageType.Table) | 941 else if (this._message.type === SDK.ConsoleMessage.MessageType.Table) |
927 formattedMessage = this._buildTableMessage(this._message); | 942 formattedMessage = this._buildTableMessage(this._message); |
928 else | 943 else |
929 formattedMessage = this._buildMessage(consoleMessage); | 944 formattedMessage = this._buildMessage(consoleMessage); |
930 contentElement.appendChild(formattedMessage); | 945 contentElement.appendChild(formattedMessage); |
931 | 946 |
932 this.updateTimestamp(); | |
933 return this._contentElement; | 947 return this._contentElement; |
934 } | 948 } |
935 | 949 |
936 /** | 950 /** |
937 * @return {!Element} | 951 * @return {!Element} |
938 */ | 952 */ |
939 toMessageElement() { | 953 toMessageElement() { |
940 if (this._element) | 954 if (this._element) |
941 return this._element; | 955 return this._element; |
942 | 956 |
943 this._element = createElement('div'); | 957 this._element = createElement('div'); |
944 this.updateMessageElement(); | 958 this.updateMessageElement(); |
945 return this._element; | 959 return this._element; |
946 } | 960 } |
947 | 961 |
948 updateMessageElement() { | 962 updateMessageElement() { |
949 if (!this._element) | 963 if (!this._element) |
950 return; | 964 return; |
951 | 965 |
952 this._element.className = 'console-message-wrapper'; | 966 this._element.className = 'console-message-wrapper'; |
953 this._element.removeChildren(); | 967 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; | 968 this._element.message = this; |
960 | 969 |
961 switch (this._message.level) { | 970 switch (this._message.level) { |
962 case SDK.ConsoleMessage.MessageLevel.Verbose: | 971 case SDK.ConsoleMessage.MessageLevel.Verbose: |
963 this._element.classList.add('console-verbose-level'); | 972 this._element.classList.add('console-verbose-level'); |
964 this._updateMessageLevelIcon(''); | |
965 break; | 973 break; |
966 case SDK.ConsoleMessage.MessageLevel.Info: | 974 case SDK.ConsoleMessage.MessageLevel.Info: |
967 this._element.classList.add('console-info-level'); | 975 this._element.classList.add('console-info-level'); |
968 break; | 976 break; |
969 case SDK.ConsoleMessage.MessageLevel.Warning: | 977 case SDK.ConsoleMessage.MessageLevel.Warning: |
970 this._element.classList.add('console-warning-level'); | 978 this._element.classList.add('console-warning-level'); |
971 this._updateMessageLevelIcon('smallicon-warning'); | |
972 break; | 979 break; |
973 case SDK.ConsoleMessage.MessageLevel.Error: | 980 case SDK.ConsoleMessage.MessageLevel.Error: |
974 this._element.classList.add('console-error-level'); | 981 this._element.classList.add('console-error-level'); |
975 this._updateMessageLevelIcon('smallicon-error'); | |
976 break; | 982 break; |
977 } | 983 } |
978 | 984 |
979 // Render verbose and info deprecations, interventions and violations with w arning background. | 985 // Render verbose and info deprecations, interventions and violations with w arning background. |
980 if (this._message.level === SDK.ConsoleMessage.MessageLevel.Verbose || | 986 if (this._message.level === SDK.ConsoleMessage.MessageLevel.Verbose || |
981 this._message.level === SDK.ConsoleMessage.MessageLevel.Info) { | 987 this._message.level === SDK.ConsoleMessage.MessageLevel.Info) { |
982 switch (this._message.source) { | 988 switch (this._message.source) { |
983 case SDK.ConsoleMessage.MessageSource.Violation: | 989 case SDK.ConsoleMessage.MessageSource.Violation: |
984 case SDK.ConsoleMessage.MessageSource.Deprecation: | 990 case SDK.ConsoleMessage.MessageSource.Deprecation: |
985 case SDK.ConsoleMessage.MessageSource.Intervention: | 991 case SDK.ConsoleMessage.MessageSource.Intervention: |
986 this._element.classList.add('console-warning-level'); | 992 this._element.classList.add('console-warning-level'); |
987 break; | 993 break; |
988 } | 994 } |
989 } | 995 } |
990 | 996 |
991 this._element.appendChild(this.contentElement()); | 997 this._element.appendChild(this.contentElement()); |
992 if (this._repeatCount > 1) | 998 this.updateMessageLevelIcon(); |
993 this._showRepeatCountElement(); | 999 this.updateTimestamp(); |
1000 this._updateNestingLevelMarkers(); | |
1001 this._updateRepeatCountElement(); | |
1002 } | |
1003 | |
1004 _insertDecorationsInOrder() { | |
1005 if (!this._contentElement || this._contentElement.parentElement !== this._el ement) | |
1006 return; | |
1007 var leftMostElement = this._contentElement; | |
1008 var addElementIfNeededBound = addElementIfNeeded.bind(this); | |
1009 addElementIfNeededBound(this._repeatCountElement); | |
1010 addElementIfNeededBound(this._nestingLevelMarkersElement); | |
1011 addElementIfNeededBound(this._messageLevelIcon); | |
1012 addElementIfNeededBound(this._timestampElement); | |
1013 | |
1014 /** | |
1015 * @this {!Console.ConsoleViewMessage} | |
1016 * @param {!Element|undefined} elementToAdd | |
1017 */ | |
1018 function addElementIfNeeded(elementToAdd) { | |
1019 if (!elementToAdd) | |
1020 return; | |
1021 if (elementToAdd.parentElement !== this._element) | |
1022 this._element.insertBefore(elementToAdd, leftMostElement); | |
1023 leftMostElement = elementToAdd; | |
1024 } | |
1025 } | |
1026 | |
1027 updateMessageLevelIcon() { | |
dgozman
2017/02/03 21:16:42
Make it private?
luoe
2017/02/03 22:45:04
Done.
| |
1028 if (!this._messageLevelIcon) | |
1029 this._messageLevelIcon = UI.Icon.create('', 'message-level-icon'); | |
1030 | |
1031 var iconType = ''; | |
1032 if (this._message.level === SDK.ConsoleMessage.MessageLevel.Warning) { | |
1033 iconType = 'smallicon-warning'; | |
1034 } else if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error) { | |
1035 iconType = 'smallicon-error'; | |
1036 } else { | |
1037 if (this._message.type === SDK.ConsoleMessage.MessageType.Command) | |
1038 iconType = 'smallicon-user-command'; | |
1039 else if (this._message.type === SDK.ConsoleMessage.MessageType.Result) | |
1040 iconType = 'smallicon-command-result'; | |
1041 } | |
1042 this._messageLevelIcon.setIconType(iconType); | |
1043 this._insertDecorationsInOrder(); | |
994 } | 1044 } |
995 | 1045 |
996 /** | 1046 /** |
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} | 1047 * @return {number} |
1012 */ | 1048 */ |
1013 repeatCount() { | 1049 repeatCount() { |
1014 return this._repeatCount || 1; | 1050 return this._repeatCount || 1; |
1015 } | 1051 } |
1016 | 1052 |
1017 resetIncrementRepeatCount() { | 1053 resetIncrementRepeatCount() { |
1018 this._repeatCount = 1; | 1054 this._repeatCount = 1; |
1019 if (!this._repeatCountElement) | 1055 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 } | 1056 } |
1027 | 1057 |
1028 incrementRepeatCount() { | 1058 incrementRepeatCount() { |
1029 this._repeatCount++; | 1059 this._repeatCount++; |
1030 this._showRepeatCountElement(); | 1060 this._updateRepeatCountElement(); |
1031 } | 1061 } |
1032 | 1062 |
1033 _showRepeatCountElement() { | 1063 _updateRepeatCountElement() { |
1034 if (!this._contentElement) | 1064 if (this._repeatCount > 1) { |
1035 return; | 1065 if (!this._repeatCountElement) |
1036 | 1066 this._repeatCountElement = createElementWithClass('label', 'console-mess age-repeat-count', 'dt-small-bubble'); |
1037 if (!this._repeatCountElement) { | |
1038 this._repeatCountElement = createElementWithClass('label', 'console-messag e-repeat-count', 'dt-small-bubble'); | |
1039 switch (this._message.level) { | 1067 switch (this._message.level) { |
1040 case SDK.ConsoleMessage.MessageLevel.Warning: | 1068 case SDK.ConsoleMessage.MessageLevel.Warning: |
1041 this._repeatCountElement.type = 'warning'; | 1069 this._repeatCountElement.type = 'warning'; |
1042 break; | 1070 break; |
1043 case SDK.ConsoleMessage.MessageLevel.Error: | 1071 case SDK.ConsoleMessage.MessageLevel.Error: |
1044 this._repeatCountElement.type = 'error'; | 1072 this._repeatCountElement.type = 'error'; |
1045 break; | 1073 break; |
1046 case SDK.ConsoleMessage.MessageLevel.Verbose: | 1074 case SDK.ConsoleMessage.MessageLevel.Verbose: |
1047 this._repeatCountElement.type = 'verbose'; | 1075 this._repeatCountElement.type = 'verbose'; |
1048 break; | 1076 break; |
1049 default: | 1077 default: |
1050 this._repeatCountElement.type = 'info'; | 1078 this._repeatCountElement.type = 'info'; |
1051 } | 1079 } |
1052 this._element.insertBefore(this._repeatCountElement, this._contentElement) ; | 1080 this._repeatCountElement.textContent = this._repeatCount; |
1053 this._contentElement.classList.add('repeated-message'); | 1081 } else if (this._repeatCountElement) { |
1082 this._repeatCountElement.remove(); | |
1083 delete this._repeatCountElement; | |
1054 } | 1084 } |
1055 this._repeatCountElement.textContent = this._repeatCount; | 1085 if (this._element) |
1086 this._element.classList.toggle('repeated-message', this._repeatCount > 1); | |
1087 this._insertDecorationsInOrder(); | |
1056 } | 1088 } |
1057 | 1089 |
1058 get text() { | 1090 get text() { |
1059 return this._message.messageText; | 1091 return this._message.messageText; |
1060 } | 1092 } |
1061 | 1093 |
1062 /** | 1094 /** |
1063 * @return {string} | 1095 * @return {string} |
1064 */ | 1096 */ |
1065 toExportString() { | 1097 toExportString() { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1256 toMessageElement() { | 1288 toMessageElement() { |
1257 if (!this._element) { | 1289 if (!this._element) { |
1258 super.toMessageElement(); | 1290 super.toMessageElement(); |
1259 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); | 1291 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); |
1260 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); | 1292 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); |
1261 this.setCollapsed(this._collapsed); | 1293 this.setCollapsed(this._collapsed); |
1262 } | 1294 } |
1263 return this._element; | 1295 return this._element; |
1264 } | 1296 } |
1265 }; | 1297 }; |
OLD | NEW |