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

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

Issue 2623143002: DevTools: insert console message decorations in order
Patch Set: a 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js
diff --git a/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js b/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js
index c4c5aea90db9c7cb8a8bd3cb1c525277f428f532..46d9f8a53e979a995974135ad1740870d5935c26 100644
--- a/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js
+++ b/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js
@@ -48,8 +48,16 @@ Console.ConsoleViewMessage = class {
this._dataGrid = null;
this._previewFormatter = new Components.RemoteObjectPreviewFormatter();
this._searchRegex = null;
- /** @type {?UI.Icon} */
- this._messageLevelIcon = null;
+ /** @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.
+ this._timestampSlot;
+ /** @type {!Element|undefined} */
+ this._levelSlot;
+ /** @type {!Element|undefined} */
+ this._nestingLevelMarkersSlot;
+ /** @type {!Element|undefined} */
+ this._repeatSlot;
+ /** @type {!Element|undefined} */
+ this._repeatCountElement;
}
/**
@@ -826,21 +834,17 @@ Console.ConsoleViewMessage = class {
return text.toLowerCase().includes(filter.toLowerCase());
}
- updateTimestamp() {
- if (!this._contentElement)
+ rebuildTimestamp() {
+ if (!this._timestampSlot)
pfeldman 2017/02/06 22:30:52 This should never happen.
luoe 2017/02/07 00:50:32 Done.
return;
-
var format = Common.moduleSetting('consoleTimestampFormat').get();
if (format !== Console.ConsoleViewMessage.TimestampFormat.None) {
var timestampText = formatTimestamp(this._message.timestamp, format);
- if (!this._timestampElement)
- this._timestampElement = createElementWithClass('span', 'console-timestamp');
- this._timestampElement.textContent = timestampText + ' ';
- this._timestampElement.title = timestampText;
- this._contentElement.insertBefore(this._timestampElement, this._contentElement.firstChild);
- } else if (this._timestampElement) {
- this._timestampElement.remove();
- delete this._timestampElement;
+ this._timestampSlot.textContent = timestampText + ' ';
+ this._timestampSlot.title = timestampText;
+ } else {
+ this._timestampSlot.removeChildren();
+ this._timestampSlot.title = '';
}
/**
@@ -889,6 +893,16 @@ Console.ConsoleViewMessage = class {
this._updateCloseGroupDecorations();
}
+ _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
+ if (!this._nestingLevelMarkersSlot)
pfeldman 2017/02/06 22:30:52 ditto
luoe 2017/02/07 00:50:32 Done.
+ return;
+ this._nestingLevelMarkersSlot.removeChildren();
+ this._nestingLevelMarkers = [];
+ for (var i = 0; i < this._nestingLevel; ++i)
+ this._nestingLevelMarkers.push(this._nestingLevelMarkersSlot.createChild('div', 'message-nesting-level-marker'));
+ this._updateCloseGroupDecorations();
+ }
+
_updateCloseGroupDecorations() {
if (!this._nestingLevelMarkers)
return;
@@ -906,12 +920,12 @@ Console.ConsoleViewMessage = class {
return this._contentElement;
var contentElement = createElementWithClass('div', 'console-message');
- if (this._messageLevelIcon)
- contentElement.appendChild(this._messageLevelIcon);
this._contentElement = contentElement;
if (this._message.type === SDK.ConsoleMessage.MessageType.StartGroup ||
this._message.type === SDK.ConsoleMessage.MessageType.StartGroupCollapsed)
contentElement.classList.add('console-group-title');
+ else if (this._message.type === SDK.ConsoleMessage.MessageType.Result)
+ contentElement.classList.add('console-user-command-result');
var formattedMessage;
var consoleMessage = this._message;
@@ -929,7 +943,6 @@ Console.ConsoleViewMessage = class {
formattedMessage = this._buildMessage(consoleMessage);
contentElement.appendChild(formattedMessage);
- this.updateTimestamp();
return this._contentElement;
}
@@ -951,28 +964,20 @@ Console.ConsoleViewMessage = class {
this._element.className = 'console-message-wrapper';
this._element.removeChildren();
-
- this._nestingLevelMarkers = [];
- for (var i = 0; i < this._nestingLevel; ++i)
- this._nestingLevelMarkers.push(this._element.createChild('div', 'nesting-level-marker'));
- this._updateCloseGroupDecorations();
this._element.message = this;
switch (this._message.level) {
case SDK.ConsoleMessage.MessageLevel.Verbose:
this._element.classList.add('console-verbose-level');
- this._updateMessageLevelIcon('');
break;
case SDK.ConsoleMessage.MessageLevel.Info:
this._element.classList.add('console-info-level');
break;
case SDK.ConsoleMessage.MessageLevel.Warning:
this._element.classList.add('console-warning-level');
- this._updateMessageLevelIcon('smallicon-warning');
break;
case SDK.ConsoleMessage.MessageLevel.Error:
this._element.classList.add('console-error-level');
- this._updateMessageLevelIcon('smallicon-error');
break;
}
@@ -988,23 +993,33 @@ Console.ConsoleViewMessage = class {
}
}
+ this._timestampSlot = this._element.createChild('span', 'message-timestamp-slot');
+ this._levelSlot = this._element.createChild('span', 'message-level-slot');
+ this._nestingLevelMarkersSlot = this._element.createChild('span', 'message-nesting-level-markers-slot');
+ this._repeatSlot = this._element.createChild('span', 'message-repeat-count-slot');
this._element.appendChild(this.contentElement());
- if (this._repeatCount > 1)
- this._showRepeatCountElement();
+
+ this.rebuildTimestamp();
+ this._rebuildLevelIcon();
+ this._rebuildNestingLevelMarkers();
+ this._rebuildRepeatCountElement();
}
- /**
- * @param {string} iconType
- */
- _updateMessageLevelIcon(iconType) {
- if (!iconType && !this._messageLevelIcon)
+ _rebuildLevelIcon() {
+ 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.
return;
- if (iconType && !this._messageLevelIcon) {
- this._messageLevelIcon = UI.Icon.create('', 'message-level-icon');
- if (this._contentElement)
- this._contentElement.insertBefore(this._messageLevelIcon, this._contentElement.firstChild);
- }
- this._messageLevelIcon.setIconType(iconType);
+ var iconType = '';
+ if (this._message.level === SDK.ConsoleMessage.MessageLevel.Warning)
+ iconType = 'smallicon-warning';
+ else if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error)
+ iconType = 'smallicon-error';
+ else if (this._message.type === SDK.ConsoleMessage.MessageType.Command)
+ iconType = 'smallicon-user-command';
+ else if (this._message.type === SDK.ConsoleMessage.MessageType.Result)
+ iconType = 'smallicon-command-result';
+ this._levelSlot.removeChildren();
+ if (iconType)
+ this._levelSlot.appendChild(UI.Icon.create(iconType));
}
/**
@@ -1016,26 +1031,20 @@ Console.ConsoleViewMessage = class {
resetIncrementRepeatCount() {
this._repeatCount = 1;
- if (!this._repeatCountElement)
- return;
-
- this._repeatCountElement.remove();
- if (this._contentElement)
- this._contentElement.classList.remove('repeated-message');
- delete this._repeatCountElement;
+ this._rebuildRepeatCountElement();
}
incrementRepeatCount() {
this._repeatCount++;
- this._showRepeatCountElement();
+ this._rebuildRepeatCountElement();
}
- _showRepeatCountElement() {
- if (!this._contentElement)
+ _rebuildRepeatCountElement() {
+ if (!this._repeatSlot)
return;
-
- if (!this._repeatCountElement) {
- this._repeatCountElement = createElementWithClass('label', 'console-message-repeat-count', 'dt-small-bubble');
+ if (this._repeatCount > 1) {
+ if (!this._repeatCountElement)
+ this._repeatCountElement = this._repeatSlot.createChild('label', 'message-repeat-count', 'dt-small-bubble');
switch (this._message.level) {
case SDK.ConsoleMessage.MessageLevel.Warning:
this._repeatCountElement.type = 'warning';
@@ -1049,10 +1058,13 @@ Console.ConsoleViewMessage = class {
default:
this._repeatCountElement.type = 'info';
}
- this._element.insertBefore(this._repeatCountElement, this._contentElement);
- this._contentElement.classList.add('repeated-message');
+ this._repeatCountElement.textContent = this._repeatCount;
+ } else if (this._repeatCountElement) {
+ this._repeatCountElement.remove();
+ delete this._repeatCountElement;
}
- this._repeatCountElement.textContent = this._repeatCount;
+ if (this._element)
+ this._element.classList.toggle('repeated-message', this._repeatCount > 1);
}
get text() {

Powered by Google App Engine
This is Rietveld 408576698