 Chromium Code Reviews
 Chromium Code Reviews Issue 2623143002:
  DevTools: insert console message decorations in order
    
  
    Issue 2623143002:
  DevTools: insert console message decorations in order 
  | 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} */ | 
| 52 this._messageLevelIcon = null; | 52 this._timestampElement = null; | 
| 53 /** @type {?Element} */ | |
| 54 this._levelIcon = null; | |
| 55 /** @type {?Element} */ | |
| 56 this._nestingLevelMarkersSlot = null; | |
| 57 /** @type {?Element} */ | |
| 58 this._repeatCountElement = null; | |
| 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 /** | 
| 63 * @override | 69 * @override | 
| 64 * @return {!Element} | 70 * @return {!Element} | 
| 65 */ | 71 */ | 
| 66 element() { | 72 element() { | 
| 67 return this.toMessageElement(); | 73 return this.toMessageElement(); | 
| 68 } | 74 } | 
| 69 | 75 | 
| 70 /** | 76 /** | 
| 71 * @override | 77 * @override | 
| 72 */ | 78 */ | 
| 73 wasShown() { | 79 wasShown() { | 
| 74 if (this._dataGrid) | 80 if (this._dataGrid) | 
| 75 this._dataGrid.updateWidths(); | 81 this._dataGrid.updateWidths(); | 
| 82 this._rebuildTimestamp(); | |
| 
pfeldman
2017/02/07 01:11:35
Why would we rebuild these slots over and over as
 
luoe
2017/02/07 17:33:05
As discussed offline, it should not be too expensi
 | |
| 83 this._rebuildLevelIcon(); | |
| 84 this._rebuildRepeatCountElement(); | |
| 76 this._isVisible = true; | 85 this._isVisible = true; | 
| 77 } | 86 } | 
| 78 | 87 | 
| 79 onResize() { | 88 onResize() { | 
| 80 if (!this._isVisible) | 89 if (!this._isVisible) | 
| 81 return; | 90 return; | 
| 82 if (this._dataGrid) | 91 if (this._dataGrid) | 
| 83 this._dataGrid.onResize(); | 92 this._dataGrid.onResize(); | 
| 84 } | 93 } | 
| 85 | 94 | 
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 | 828 | 
| 820 /** | 829 /** | 
| 821 * @param {string} filter | 830 * @param {string} filter | 
| 822 * @return {boolean} | 831 * @return {boolean} | 
| 823 */ | 832 */ | 
| 824 matchesFilterText(filter) { | 833 matchesFilterText(filter) { | 
| 825 var text = this.contentElement().deepTextContent(); | 834 var text = this.contentElement().deepTextContent(); | 
| 826 return text.toLowerCase().includes(filter.toLowerCase()); | 835 return text.toLowerCase().includes(filter.toLowerCase()); | 
| 827 } | 836 } | 
| 828 | 837 | 
| 829 updateTimestamp() { | 838 _rebuildTimestamp() { | 
| 
pfeldman
2017/02/07 01:11:35
I don't see how timestamp becomes visible upon tog
 
luoe
2017/02/07 17:33:05
Done.
 | |
| 830 if (!this._contentElement) | |
| 831 return; | |
| 832 | |
| 833 var format = Common.moduleSetting('consoleTimestampFormat').get(); | 839 var format = Common.moduleSetting('consoleTimestampFormat').get(); | 
| 834 if (format !== Console.ConsoleViewMessage.TimestampFormat.None) { | 840 var show = format !== Console.ConsoleViewMessage.TimestampFormat.None; | 
| 841 if (show) { | |
| 835 var timestampText = formatTimestamp(this._message.timestamp, format); | 842 var timestampText = formatTimestamp(this._message.timestamp, format); | 
| 836 if (!this._timestampElement) | |
| 837 this._timestampElement = createElementWithClass('span', 'console-timesta mp'); | |
| 838 this._timestampElement.textContent = timestampText + ' '; | 843 this._timestampElement.textContent = timestampText + ' '; | 
| 839 this._timestampElement.title = timestampText; | 844 this._timestampElement.title = timestampText; | 
| 840 this._contentElement.insertBefore(this._timestampElement, this._contentEle ment.firstChild); | 845 } else { | 
| 841 } else if (this._timestampElement) { | 846 this._timestampElement.textContent = ''; | 
| 842 this._timestampElement.remove(); | 847 this._timestampElement.title = ''; | 
| 843 delete this._timestampElement; | |
| 844 } | 848 } | 
| 849 this._timestampElement.hidden = !show; | |
| 
pfeldman
2017/02/07 01:11:35
.classList.toggle('hidden', !show)
 
luoe
2017/02/07 17:33:05
Done.
 | |
| 845 | 850 | 
| 846 /** | 851 /** | 
| 847 * @param {number} timestamp | 852 * @param {number} timestamp | 
| 848 * @param {!Console.ConsoleViewMessage.TimestampFormat} format | 853 * @param {!Console.ConsoleViewMessage.TimestampFormat} format | 
| 849 * @return {string} | 854 * @return {string} | 
| 850 */ | 855 */ | 
| 851 function formatTimestamp(timestamp, format) { | 856 function formatTimestamp(timestamp, format) { | 
| 852 var date = new Date(timestamp); | 857 var date = new Date(timestamp); | 
| 853 var yymmdd = date.getFullYear() + '-' + leadZero(date.getMonth() + 1, 2) + '-' + leadZero(date.getDate(), 2); | 858 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) + ':' + | 859 var hhmmssfff = leadZero(date.getHours(), 2) + ':' + leadZero(date.getMinu tes(), 2) + ':' + | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 899 } | 904 } | 
| 900 | 905 | 
| 901 /** | 906 /** | 
| 902 * @return {!Element} | 907 * @return {!Element} | 
| 903 */ | 908 */ | 
| 904 contentElement() { | 909 contentElement() { | 
| 905 if (this._contentElement) | 910 if (this._contentElement) | 
| 906 return this._contentElement; | 911 return this._contentElement; | 
| 907 | 912 | 
| 908 var contentElement = createElementWithClass('div', 'console-message'); | 913 var contentElement = createElementWithClass('div', 'console-message'); | 
| 909 if (this._messageLevelIcon) | |
| 910 contentElement.appendChild(this._messageLevelIcon); | |
| 911 this._contentElement = contentElement; | 914 this._contentElement = contentElement; | 
| 912 if (this._message.type === SDK.ConsoleMessage.MessageType.StartGroup || | 915 if (this._message.type === SDK.ConsoleMessage.MessageType.StartGroup || | 
| 913 this._message.type === SDK.ConsoleMessage.MessageType.StartGroupCollapse d) | 916 this._message.type === SDK.ConsoleMessage.MessageType.StartGroupCollapse d) | 
| 914 contentElement.classList.add('console-group-title'); | 917 contentElement.classList.add('console-group-title'); | 
| 918 else if (this._message.type === SDK.ConsoleMessage.MessageType.Result) | |
| 919 contentElement.classList.add('console-user-command-result'); | |
| 915 | 920 | 
| 916 var formattedMessage; | 921 var formattedMessage; | 
| 917 var consoleMessage = this._message; | 922 var consoleMessage = this._message; | 
| 918 var target = consoleMessage.target(); | 923 var target = consoleMessage.target(); | 
| 919 var shouldIncludeTrace = | 924 var shouldIncludeTrace = | 
| 920 !!consoleMessage.stackTrace && (consoleMessage.source === SDK.ConsoleMes sage.MessageSource.Network || | 925 !!consoleMessage.stackTrace && (consoleMessage.source === SDK.ConsoleMes sage.MessageSource.Network || | 
| 921 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Error || | 926 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Error || | 
| 922 consoleMessage.type === SDK.ConsoleMessa ge.MessageType.Trace || | 927 consoleMessage.type === SDK.ConsoleMessa ge.MessageType.Trace || | 
| 923 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Warning); | 928 consoleMessage.level === SDK.ConsoleMess age.MessageLevel.Warning); | 
| 924 if (target && shouldIncludeTrace) | 929 if (target && shouldIncludeTrace) | 
| 925 formattedMessage = this._buildMessageWithStackTrace(consoleMessage, target , this._linkifier); | 930 formattedMessage = this._buildMessageWithStackTrace(consoleMessage, target , this._linkifier); | 
| 926 else if (this._message.type === SDK.ConsoleMessage.MessageType.Table) | 931 else if (this._message.type === SDK.ConsoleMessage.MessageType.Table) | 
| 927 formattedMessage = this._buildTableMessage(this._message); | 932 formattedMessage = this._buildTableMessage(this._message); | 
| 928 else | 933 else | 
| 929 formattedMessage = this._buildMessage(consoleMessage); | 934 formattedMessage = this._buildMessage(consoleMessage); | 
| 930 contentElement.appendChild(formattedMessage); | 935 contentElement.appendChild(formattedMessage); | 
| 931 | 936 | 
| 932 this.updateTimestamp(); | |
| 933 return this._contentElement; | 937 return this._contentElement; | 
| 934 } | 938 } | 
| 935 | 939 | 
| 936 /** | 940 /** | 
| 937 * @return {!Element} | 941 * @return {!Element} | 
| 938 */ | 942 */ | 
| 939 toMessageElement() { | 943 toMessageElement() { | 
| 940 if (this._element) | 944 if (this._element) | 
| 941 return this._element; | 945 return this._element; | 
| 942 | 946 | 
| 943 this._element = createElement('div'); | 947 this._element = createElement('div'); | 
| 944 this.updateMessageElement(); | 948 this.updateMessageElement(); | 
| 945 return this._element; | 949 return this._element; | 
| 946 } | 950 } | 
| 947 | 951 | 
| 948 updateMessageElement() { | 952 updateMessageElement() { | 
| 949 if (!this._element) | 953 if (!this._element) | 
| 950 return; | 954 return; | 
| 951 | 955 | 
| 952 this._element.className = 'console-message-wrapper'; | 956 this._element.className = 'console-message-wrapper'; | 
| 953 this._element.removeChildren(); | 957 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; | 958 this._element.message = this; | 
| 960 | 959 | 
| 961 switch (this._message.level) { | 960 switch (this._message.level) { | 
| 962 case SDK.ConsoleMessage.MessageLevel.Verbose: | 961 case SDK.ConsoleMessage.MessageLevel.Verbose: | 
| 963 this._element.classList.add('console-verbose-level'); | 962 this._element.classList.add('console-verbose-level'); | 
| 964 this._updateMessageLevelIcon(''); | |
| 965 break; | 963 break; | 
| 966 case SDK.ConsoleMessage.MessageLevel.Info: | 964 case SDK.ConsoleMessage.MessageLevel.Info: | 
| 967 this._element.classList.add('console-info-level'); | 965 this._element.classList.add('console-info-level'); | 
| 968 break; | 966 break; | 
| 969 case SDK.ConsoleMessage.MessageLevel.Warning: | 967 case SDK.ConsoleMessage.MessageLevel.Warning: | 
| 970 this._element.classList.add('console-warning-level'); | 968 this._element.classList.add('console-warning-level'); | 
| 971 this._updateMessageLevelIcon('smallicon-warning'); | |
| 972 break; | 969 break; | 
| 973 case SDK.ConsoleMessage.MessageLevel.Error: | 970 case SDK.ConsoleMessage.MessageLevel.Error: | 
| 974 this._element.classList.add('console-error-level'); | 971 this._element.classList.add('console-error-level'); | 
| 975 this._updateMessageLevelIcon('smallicon-error'); | |
| 976 break; | 972 break; | 
| 977 } | 973 } | 
| 978 | 974 | 
| 979 // Render verbose and info deprecations, interventions and violations with w arning background. | 975 // Render verbose and info deprecations, interventions and violations with w arning background. | 
| 980 if (this._message.level === SDK.ConsoleMessage.MessageLevel.Verbose || | 976 if (this._message.level === SDK.ConsoleMessage.MessageLevel.Verbose || | 
| 981 this._message.level === SDK.ConsoleMessage.MessageLevel.Info) { | 977 this._message.level === SDK.ConsoleMessage.MessageLevel.Info) { | 
| 982 switch (this._message.source) { | 978 switch (this._message.source) { | 
| 983 case SDK.ConsoleMessage.MessageSource.Violation: | 979 case SDK.ConsoleMessage.MessageSource.Violation: | 
| 984 case SDK.ConsoleMessage.MessageSource.Deprecation: | 980 case SDK.ConsoleMessage.MessageSource.Deprecation: | 
| 985 case SDK.ConsoleMessage.MessageSource.Intervention: | 981 case SDK.ConsoleMessage.MessageSource.Intervention: | 
| 986 this._element.classList.add('console-warning-level'); | 982 this._element.classList.add('console-warning-level'); | 
| 987 break; | 983 break; | 
| 988 } | 984 } | 
| 989 } | 985 } | 
| 990 | 986 | 
| 987 this._timestampElement = this._element.createChild('span', 'message-timestam p'); | |
| 988 this._levelIcon = UI.Icon.create('', 'message-level-icon'); | |
| 989 this._element.appendChild(this._levelIcon); | |
| 990 this._nestingLevelMarkersSlot = this._element.createChild('span', 'message-n esting-level-markers-slot'); | |
| 991 this._repeatCountElement = this._element.createChild('label', 'message-repea t-count', 'dt-small-bubble'); | |
| 991 this._element.appendChild(this.contentElement()); | 992 this._element.appendChild(this.contentElement()); | 
| 992 if (this._repeatCount > 1) | 993 | 
| 993 this._showRepeatCountElement(); | 994 this._nestingLevelMarkers = []; | 
| 995 for (var i = 0; i < this._nestingLevel; ++i) | |
| 996 this._nestingLevelMarkers.push(this._nestingLevelMarkersSlot.createChild(' div', 'message-nesting-level-marker')); | |
| 997 this._updateCloseGroupDecorations(); | |
| 998 } | |
| 999 | |
| 1000 _rebuildLevelIcon() { | |
| 1001 var iconType = ''; | |
| 1002 if (this._message.level === SDK.ConsoleMessage.MessageLevel.Warning) | |
| 1003 iconType = 'smallicon-warning'; | |
| 1004 else if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error) | |
| 1005 iconType = 'smallicon-error'; | |
| 1006 else if (this._message.type === SDK.ConsoleMessage.MessageType.Command) | |
| 1007 iconType = 'smallicon-user-command'; | |
| 1008 else if (this._message.type === SDK.ConsoleMessage.MessageType.Result) | |
| 1009 iconType = 'smallicon-command-result'; | |
| 1010 this._levelIcon.setIconType(iconType); | |
| 994 } | 1011 } | 
| 995 | 1012 | 
| 996 /** | 1013 /** | 
| 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} | 1014 * @return {number} | 
| 1012 */ | 1015 */ | 
| 1013 repeatCount() { | 1016 repeatCount() { | 
| 1014 return this._repeatCount || 1; | 1017 return this._repeatCount || 1; | 
| 1015 } | 1018 } | 
| 1016 | 1019 | 
| 1017 resetIncrementRepeatCount() { | 1020 resetIncrementRepeatCount() { | 
| 1018 this._repeatCount = 1; | 1021 this._repeatCount = 1; | 
| 1019 if (!this._repeatCountElement) | 1022 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 } | 1023 } | 
| 1027 | 1024 | 
| 1028 incrementRepeatCount() { | 1025 incrementRepeatCount() { | 
| 1029 this._repeatCount++; | 1026 this._repeatCount++; | 
| 1030 this._showRepeatCountElement(); | 1027 this._rebuildRepeatCountElement(); | 
| 1031 } | 1028 } | 
| 1032 | 1029 | 
| 1033 _showRepeatCountElement() { | 1030 _rebuildRepeatCountElement() { | 
| 1034 if (!this._contentElement) | 1031 // Repeat counter may be updated before a message is rendered. | 
| 1032 if (!this._repeatCountElement) | |
| 1035 return; | 1033 return; | 
| 1036 | 1034 var show = this._repeatCount > 1; | 
| 1037 if (!this._repeatCountElement) { | 1035 if (show) { | 
| 1038 this._repeatCountElement = createElementWithClass('label', 'console-messag e-repeat-count', 'dt-small-bubble'); | |
| 1039 switch (this._message.level) { | 1036 switch (this._message.level) { | 
| 1040 case SDK.ConsoleMessage.MessageLevel.Warning: | 1037 case SDK.ConsoleMessage.MessageLevel.Warning: | 
| 1041 this._repeatCountElement.type = 'warning'; | 1038 this._repeatCountElement.type = 'warning'; | 
| 1042 break; | 1039 break; | 
| 1043 case SDK.ConsoleMessage.MessageLevel.Error: | 1040 case SDK.ConsoleMessage.MessageLevel.Error: | 
| 1044 this._repeatCountElement.type = 'error'; | 1041 this._repeatCountElement.type = 'error'; | 
| 1045 break; | 1042 break; | 
| 1046 case SDK.ConsoleMessage.MessageLevel.Verbose: | 1043 case SDK.ConsoleMessage.MessageLevel.Verbose: | 
| 1047 this._repeatCountElement.type = 'verbose'; | 1044 this._repeatCountElement.type = 'verbose'; | 
| 1048 break; | 1045 break; | 
| 1049 default: | 1046 default: | 
| 1050 this._repeatCountElement.type = 'info'; | 1047 this._repeatCountElement.type = 'info'; | 
| 1051 } | 1048 } | 
| 1052 this._element.insertBefore(this._repeatCountElement, this._contentElement) ; | 1049 this._repeatCountElement.textContent = this._repeatCount; | 
| 1053 this._contentElement.classList.add('repeated-message'); | 1050 } else { | 
| 1051 this._repeatCountElement.textContent = ''; | |
| 1054 } | 1052 } | 
| 1055 this._repeatCountElement.textContent = this._repeatCount; | 1053 this._repeatCountElement.hidden = !show; | 
| 1054 if (this._element) | |
| 1055 this._element.classList.toggle('repeated-message', show); | |
| 1056 } | 1056 } | 
| 1057 | 1057 | 
| 1058 get text() { | 1058 get text() { | 
| 1059 return this._message.messageText; | 1059 return this._message.messageText; | 
| 1060 } | 1060 } | 
| 1061 | 1061 | 
| 1062 /** | 1062 /** | 
| 1063 * @return {string} | 1063 * @return {string} | 
| 1064 */ | 1064 */ | 
| 1065 toExportString() { | 1065 toExportString() { | 
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1256 toMessageElement() { | 1256 toMessageElement() { | 
| 1257 if (!this._element) { | 1257 if (!this._element) { | 
| 1258 super.toMessageElement(); | 1258 super.toMessageElement(); | 
| 1259 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); | 1259 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); | 
| 1260 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); | 1260 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); | 
| 1261 this.setCollapsed(this._collapsed); | 1261 this.setCollapsed(this._collapsed); | 
| 1262 } | 1262 } | 
| 1263 return this._element; | 1263 return this._element; | 
| 1264 } | 1264 } | 
| 1265 }; | 1265 }; | 
| OLD | NEW |