Chromium Code Reviews| 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 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) | 836 if (!this._contentElement) |
| 831 return; | 837 return; |
| 832 | |
| 833 var format = Common.moduleSetting('consoleTimestampFormat').get(); | 838 var format = Common.moduleSetting('consoleTimestampFormat').get(); |
| 834 if (format !== Console.ConsoleViewMessage.TimestampFormat.None) { | 839 if (format !== Console.ConsoleViewMessage.TimestampFormat.None) { |
| 835 var timestampText = formatTimestamp(this._message.timestamp, format); | 840 var timestampText = formatTimestamp(this._message.timestamp, format); |
| 836 if (!this._timestampElement) | 841 if (!this._timestampElement) { |
| 837 this._timestampElement = createElementWithClass('span', 'console-timesta mp'); | 842 this._timestampElement = createElementWithClass('span', 'console-timesta mp'); |
| 843 this._insertDecorationsInOrder(); | |
| 844 } | |
| 838 this._timestampElement.textContent = timestampText + ' '; | 845 this._timestampElement.textContent = timestampText + ' '; |
| 839 this._timestampElement.title = timestampText; | 846 this._timestampElement.title = timestampText; |
| 840 this._contentElement.insertBefore(this._timestampElement, this._contentEle ment.firstChild); | |
| 841 } else if (this._timestampElement) { | 847 } else if (this._timestampElement) { |
| 842 this._timestampElement.remove(); | 848 this._timestampElement.remove(); |
| 843 delete this._timestampElement; | 849 delete this._timestampElement; |
| 844 } | 850 } |
| 845 | 851 |
| 846 /** | 852 /** |
| 847 * @param {number} timestamp | 853 * @param {number} timestamp |
| 848 * @param {!Console.ConsoleViewMessage.TimestampFormat} format | 854 * @param {!Console.ConsoleViewMessage.TimestampFormat} format |
| 849 * @return {string} | 855 * @return {string} |
| 850 */ | 856 */ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 882 return; | 888 return; |
| 883 this._closeGroupDecorationCount = 0; | 889 this._closeGroupDecorationCount = 0; |
| 884 this._updateCloseGroupDecorations(); | 890 this._updateCloseGroupDecorations(); |
| 885 } | 891 } |
| 886 | 892 |
| 887 incrementCloseGroupDecorationCount() { | 893 incrementCloseGroupDecorationCount() { |
| 888 ++this._closeGroupDecorationCount; | 894 ++this._closeGroupDecorationCount; |
| 889 this._updateCloseGroupDecorations(); | 895 this._updateCloseGroupDecorations(); |
| 890 } | 896 } |
| 891 | 897 |
| 898 _updateNestingLevelMarkers() { | |
| 899 if (!this._contentElement) | |
| 900 return; | |
| 901 if (!this._nestingLevelMarkersElement && this._nestingLevel > 0) { | |
|
pfeldman
2017/02/04 01:55:19
The second time _updateNestingLevelMarkers is call
luoe
2017/02/06 19:51:55
Nesting level doesn't change and messages don't gr
| |
| 902 this._nestingLevelMarkersElement = createElementWithClass('span', 'nesting -level-markers-wrapper'); | |
| 903 this._nestingLevelMarkers = []; | |
| 904 for (var i = 0; i < this._nestingLevel; ++i) | |
| 905 this._nestingLevelMarkers.push(this._nestingLevelMarkersElement.createCh ild('div', 'nesting-level-marker')); | |
| 906 this._updateCloseGroupDecorations(); | |
| 907 this._insertDecorationsInOrder(); | |
| 908 } | |
| 909 } | |
| 910 | |
| 892 _updateCloseGroupDecorations() { | 911 _updateCloseGroupDecorations() { |
| 893 if (!this._nestingLevelMarkers) | 912 if (!this._nestingLevelMarkers) |
| 894 return; | 913 return; |
| 895 for (var i = 0, n = this._nestingLevelMarkers.length; i < n; ++i) { | 914 for (var i = 0, n = this._nestingLevelMarkers.length; i < n; ++i) { |
| 896 var marker = this._nestingLevelMarkers[i]; | 915 var marker = this._nestingLevelMarkers[i]; |
| 897 marker.classList.toggle('group-closed', n - i <= this._closeGroupDecoratio nCount); | 916 marker.classList.toggle('group-closed', n - i <= this._closeGroupDecoratio nCount); |
| 898 } | 917 } |
| 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 // Update decorations after the content is generated. | |
| 991 this._element.appendChild(this.contentElement()); | 1002 this._element.appendChild(this.contentElement()); |
| 992 if (this._repeatCount > 1) | 1003 this.updateTimestamp(); |
| 993 this._showRepeatCountElement(); | 1004 this._updateMessageLevelIcon(); |
|
pfeldman
2017/02/04 01:55:19
'create' these instead of 'updating'.
luoe
2017/02/06 19:51:55
Timestamps and repeat counters can disappear after
| |
| 1005 this._updateNestingLevelMarkers(); | |
| 1006 this._updateRepeatCountElement(); | |
| 994 } | 1007 } |
| 995 | 1008 |
| 996 /** | 1009 _insertDecorationsInOrder() { |
| 997 * @param {string} iconType | 1010 if (!this._contentElement || this._contentElement.parentElement !== this._el ement) |
| 998 */ | |
| 999 _updateMessageLevelIcon(iconType) { | |
| 1000 if (!iconType && !this._messageLevelIcon) | |
| 1001 return; | 1011 return; |
| 1002 if (iconType && !this._messageLevelIcon) { | 1012 var leftMostElement = this._contentElement; |
| 1013 var addElementIfNeededBound = addElementIfNeeded.bind(this); | |
| 1014 addElementIfNeededBound(this._repeatCountElement); | |
|
pfeldman
2017/02/04 01:55:19
you can do
[a, b, c].forEach(addElementIfNeeded.
luoe
2017/02/06 19:51:55
Acknowledged.
| |
| 1015 addElementIfNeededBound(this._nestingLevelMarkersElement); | |
| 1016 addElementIfNeededBound(this._messageLevelIcon); | |
| 1017 addElementIfNeededBound(this._timestampElement); | |
| 1018 | |
| 1019 /** | |
| 1020 * @this {!Console.ConsoleViewMessage} | |
| 1021 * @param {!Element|undefined} elementToAdd | |
| 1022 */ | |
| 1023 function addElementIfNeeded(elementToAdd) { | |
| 1024 if (!elementToAdd) | |
|
pfeldman
2017/02/04 01:55:19
Why are these nullable? We want inset to be the sa
luoe
2017/02/06 19:51:55
Acknowledged.
| |
| 1025 return; | |
| 1026 if (elementToAdd.parentElement !== this._element) | |
| 1027 this._element.insertBefore(elementToAdd, leftMostElement); | |
| 1028 leftMostElement = elementToAdd; | |
| 1029 } | |
| 1030 } | |
| 1031 | |
| 1032 _updateMessageLevelIcon() { | |
| 1033 if (!this._contentElement) | |
| 1034 return; | |
| 1035 if (!this._messageLevelIcon) { | |
| 1003 this._messageLevelIcon = UI.Icon.create('', 'message-level-icon'); | 1036 this._messageLevelIcon = UI.Icon.create('', 'message-level-icon'); |
| 1004 if (this._contentElement) | 1037 this._insertDecorationsInOrder(); |
| 1005 this._contentElement.insertBefore(this._messageLevelIcon, this._contentE lement.firstChild); | 1038 } |
| 1039 | |
| 1040 var iconType = ''; | |
| 1041 if (this._message.level === SDK.ConsoleMessage.MessageLevel.Warning) { | |
| 1042 iconType = 'smallicon-warning'; | |
| 1043 } else if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error) { | |
| 1044 iconType = 'smallicon-error'; | |
| 1045 } else { | |
| 1046 if (this._message.type === SDK.ConsoleMessage.MessageType.Command) | |
| 1047 iconType = 'smallicon-user-command'; | |
| 1048 else if (this._message.type === SDK.ConsoleMessage.MessageType.Result) | |
| 1049 iconType = 'smallicon-command-result'; | |
| 1006 } | 1050 } |
| 1007 this._messageLevelIcon.setIconType(iconType); | 1051 this._messageLevelIcon.setIconType(iconType); |
| 1008 } | 1052 } |
| 1009 | 1053 |
| 1010 /** | 1054 /** |
| 1011 * @return {number} | 1055 * @return {number} |
| 1012 */ | 1056 */ |
| 1013 repeatCount() { | 1057 repeatCount() { |
| 1014 return this._repeatCount || 1; | 1058 return this._repeatCount || 1; |
| 1015 } | 1059 } |
| 1016 | 1060 |
| 1017 resetIncrementRepeatCount() { | 1061 resetIncrementRepeatCount() { |
| 1018 this._repeatCount = 1; | 1062 this._repeatCount = 1; |
| 1019 if (!this._repeatCountElement) | 1063 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 } | 1064 } |
| 1027 | 1065 |
| 1028 incrementRepeatCount() { | 1066 incrementRepeatCount() { |
| 1029 this._repeatCount++; | 1067 this._repeatCount++; |
| 1030 this._showRepeatCountElement(); | 1068 this._updateRepeatCountElement(); |
| 1031 } | 1069 } |
| 1032 | 1070 |
| 1033 _showRepeatCountElement() { | 1071 _updateRepeatCountElement() { |
| 1034 if (!this._contentElement) | 1072 if (!this._contentElement) |
| 1035 return; | 1073 return; |
| 1036 | 1074 if (this._repeatCount > 1) { |
| 1037 if (!this._repeatCountElement) { | 1075 if (!this._repeatCountElement) { |
| 1038 this._repeatCountElement = createElementWithClass('label', 'console-messag e-repeat-count', 'dt-small-bubble'); | 1076 this._repeatCountElement = createElementWithClass('label', 'console-mess age-repeat-count', 'dt-small-bubble'); |
| 1077 this._insertDecorationsInOrder(); | |
| 1078 } | |
| 1039 switch (this._message.level) { | 1079 switch (this._message.level) { |
| 1040 case SDK.ConsoleMessage.MessageLevel.Warning: | 1080 case SDK.ConsoleMessage.MessageLevel.Warning: |
| 1041 this._repeatCountElement.type = 'warning'; | 1081 this._repeatCountElement.type = 'warning'; |
| 1042 break; | 1082 break; |
| 1043 case SDK.ConsoleMessage.MessageLevel.Error: | 1083 case SDK.ConsoleMessage.MessageLevel.Error: |
| 1044 this._repeatCountElement.type = 'error'; | 1084 this._repeatCountElement.type = 'error'; |
| 1045 break; | 1085 break; |
| 1046 case SDK.ConsoleMessage.MessageLevel.Verbose: | 1086 case SDK.ConsoleMessage.MessageLevel.Verbose: |
| 1047 this._repeatCountElement.type = 'verbose'; | 1087 this._repeatCountElement.type = 'verbose'; |
| 1048 break; | 1088 break; |
| 1049 default: | 1089 default: |
| 1050 this._repeatCountElement.type = 'info'; | 1090 this._repeatCountElement.type = 'info'; |
| 1051 } | 1091 } |
| 1052 this._element.insertBefore(this._repeatCountElement, this._contentElement) ; | 1092 this._repeatCountElement.textContent = this._repeatCount; |
| 1053 this._contentElement.classList.add('repeated-message'); | 1093 } else if (this._repeatCountElement) { |
| 1094 this._repeatCountElement.remove(); | |
| 1095 delete this._repeatCountElement; | |
| 1054 } | 1096 } |
| 1055 this._repeatCountElement.textContent = this._repeatCount; | 1097 if (this._element) |
| 1098 this._element.classList.toggle('repeated-message', this._repeatCount > 1); | |
| 1056 } | 1099 } |
| 1057 | 1100 |
| 1058 get text() { | 1101 get text() { |
| 1059 return this._message.messageText; | 1102 return this._message.messageText; |
| 1060 } | 1103 } |
| 1061 | 1104 |
| 1062 /** | 1105 /** |
| 1063 * @return {string} | 1106 * @return {string} |
| 1064 */ | 1107 */ |
| 1065 toExportString() { | 1108 toExportString() { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1256 toMessageElement() { | 1299 toMessageElement() { |
| 1257 if (!this._element) { | 1300 if (!this._element) { |
| 1258 super.toMessageElement(); | 1301 super.toMessageElement(); |
| 1259 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); | 1302 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); |
| 1260 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); | 1303 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); |
| 1261 this.setCollapsed(this._collapsed); | 1304 this.setCollapsed(this._collapsed); |
| 1262 } | 1305 } |
| 1263 return this._element; | 1306 return this._element; |
| 1264 } | 1307 } |
| 1265 }; | 1308 }; |
| OLD | NEW |