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

Unified Diff: third_party/WebKit/Source/devtools/front_end/source_frame/SourceFrame.js

Issue 1427653002: DevTools: move ui messages from SourceFrame to UISourceCodeFrame (step1) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 5 years, 2 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/source_frame/SourceFrame.js
diff --git a/third_party/WebKit/Source/devtools/front_end/source_frame/SourceFrame.js b/third_party/WebKit/Source/devtools/front_end/source_frame/SourceFrame.js
index 0208af4961bc67e40edbcde2fbb6a782c229f5c2..083df1be2334451a63df8eb4b7a41426160a49fb 100644
--- a/third_party/WebKit/Source/devtools/front_end/source_frame/SourceFrame.js
+++ b/third_party/WebKit/Source/devtools/front_end/source_frame/SourceFrame.js
@@ -48,17 +48,12 @@ WebInspector.SourceFrame = function(contentProvider)
this._currentSearchResultIndex = -1;
this._searchResults = [];
- this._rowMessageBuckets = {};
-
this._textEditor.setReadOnly(!this.canEditSource());
this._shortcuts = {};
this.element.addEventListener("keydown", this._handleKeyDown.bind(this), false);
this._sourcePosition = new WebInspector.ToolbarText("", "source-frame-cursor-position");
-
- this._errorPopoverHelper = new WebInspector.PopoverHelper(this.element, this._getErrorAnchor.bind(this), this._showErrorPopover.bind(this));
- this._errorPopoverHelper.setTimeout(100, 100);
}
WebInspector.SourceFrame.Events = {
@@ -69,33 +64,6 @@ WebInspector.SourceFrame.Events = {
WebInspector.SourceFrame.prototype = {
/**
- * @param {!Element} target
- * @param {!Event} event
- * @return {(!Element|undefined)}
- */
- _getErrorAnchor: function(target, event)
- {
- var element = target.enclosingNodeOrSelfWithClass("text-editor-line-decoration-icon")
- || target.enclosingNodeOrSelfWithClass("text-editor-line-decoration-wave");
- if (!element)
- return;
- this._errorWavePopoverAnchor = new AnchorBox(event.clientX, event.clientY, 1, 1);
- return element;
- },
-
- /**
- * @param {!Element} anchor
- * @param {!WebInspector.Popover} popover
- */
- _showErrorPopover: function(anchor, popover)
- {
- var messageBucket = anchor.enclosingNodeOrSelfWithClass("text-editor-line-decoration")._messageBucket;
- var messagesOutline = messageBucket.messagesDescription();
- var popoverAnchor = anchor.enclosingNodeOrSelfWithClass("text-editor-line-decoration-icon") ? anchor : this._errorWavePopoverAnchor;
- popover.showForAnchor(messagesOutline, popoverAnchor);
- },
-
- /**
* @param {number} key
* @param {function():boolean} handler
*/
@@ -109,23 +77,13 @@ WebInspector.SourceFrame.prototype = {
this._ensureContentLoaded();
this._textEditor.show(this.element);
this._editorAttached = true;
- // We need CodeMirrorTextEditor to be initialized prior to this call as it calls |cursorPositionToCoordinates| internally. @see crbug.com/506566
- setImmediate(this._updateBucketDecorations.bind(this));
this._wasShownOrLoaded();
},
- _updateBucketDecorations: function()
- {
- for (var line in this._rowMessageBuckets) {
- var bucket = this._rowMessageBuckets[line];
- bucket._updateDecoration();
- }
- },
-
/**
* @return {boolean}
*/
- _isEditorShowing: function()
+ isEditorShowing: function()
{
return this.isShowing() && this._editorAttached;
},
@@ -172,17 +130,6 @@ WebInspector.SourceFrame.prototype = {
}
},
- clearMessages: function()
- {
- for (var line in this._rowMessageBuckets) {
- var bubble = this._rowMessageBuckets[line];
- bubble.detachFromEditor();
- }
-
- this._rowMessageBuckets = {};
- this._errorPopoverHelper.hidePopover();
- },
-
/**
* @param {number} line 0-based
* @param {number=} column
@@ -201,7 +148,7 @@ WebInspector.SourceFrame.prototype = {
if (!this._positionToReveal)
return;
- if (!this.loaded || !this._isEditorShowing())
+ if (!this.loaded || !this.isEditorShowing())
return;
this._textEditor.revealPosition(this._positionToReveal.line, this._positionToReveal.column, this._positionToReveal.shouldHighlight);
@@ -227,7 +174,7 @@ WebInspector.SourceFrame.prototype = {
_innerScrollToLineIfNeeded: function()
{
if (typeof this._lineToScrollTo === "number") {
- if (this.loaded && this._isEditorShowing()) {
+ if (this.loaded && this.isEditorShowing()) {
this._textEditor.scrollToLine(this._lineToScrollTo);
delete this._lineToScrollTo;
}
@@ -258,7 +205,7 @@ WebInspector.SourceFrame.prototype = {
_innerSetSelectionIfNeeded: function()
{
- if (this._selectionToSet && this.loaded && this._isEditorShowing()) {
+ if (this._selectionToSet && this.loaded && this.isEditorShowing()) {
this._textEditor.setSelection(this._selectionToSet);
delete this._selectionToSet;
}
@@ -280,7 +227,6 @@ WebInspector.SourceFrame.prototype = {
{
if (this._searchResultsChangedCallback)
this._searchResultsChangedCallback();
- this.clearMessages();
},
/**
@@ -337,7 +283,6 @@ WebInspector.SourceFrame.prototype = {
}
this._updateHighlighterType(content || "");
- this.clearMessages();
this._wasShownOrLoaded();
if (this._delayedFindSearchMatches) {
@@ -569,44 +514,6 @@ WebInspector.SourceFrame.prototype = {
},
/**
- * @param {!WebInspector.SourceFrameMessage} message
- */
- addMessageToSource: function(message)
- {
- var lineNumber = message.lineNumber();
- if (lineNumber >= this._textEditor.linesCount)
- lineNumber = this._textEditor.linesCount - 1;
- if (lineNumber < 0)
- lineNumber = 0;
-
- if (!this._rowMessageBuckets[lineNumber])
- this._rowMessageBuckets[lineNumber] = new WebInspector.SourceFrame.RowMessageBucket(this, this._textEditor, lineNumber);
- var messageBucket = this._rowMessageBuckets[lineNumber];
- messageBucket.addMessage(message);
- },
-
- /**
- * @param {!WebInspector.SourceFrameMessage} message
- */
- removeMessageFromSource: function(message)
- {
- var lineNumber = message.lineNumber();
- if (lineNumber >= this._textEditor.linesCount)
- lineNumber = this._textEditor.linesCount - 1;
- if (lineNumber < 0)
- lineNumber = 0;
-
- var messageBucket = this._rowMessageBuckets[lineNumber];
- if (!messageBucket)
- return;
- messageBucket.removeMessage(message);
- if (!messageBucket.uniqueMessagesCount()) {
- messageBucket.detachFromEditor();
- delete this._rowMessageBuckets[lineNumber];
- }
- },
-
- /**
* @return {!Promise}
*/
populateLineGutterContextMenu: function(contextMenu, lineNumber)
@@ -695,292 +602,6 @@ WebInspector.SourceFrame.prototype = {
}
/**
- * @constructor
- * @param {string} messageText
- * @param {!WebInspector.SourceFrameMessage.Level} level
- * @param {number} lineNumber
- * @param {number=} columnNumber
- */
-WebInspector.SourceFrameMessage = function(messageText, level, lineNumber, columnNumber)
-{
- this._messageText = messageText;
- this._level = level;
- this._lineNumber = lineNumber;
- this._columnNumber = columnNumber;
-}
-
-/**
- * @enum {string}
- */
-WebInspector.SourceFrameMessage.Level = {
- Error: "Error",
- Warning: "Warning"
-}
-
-/**
- * @param {!WebInspector.ConsoleMessage} consoleMessage
- * @param {number} lineNumber
- * @param {number} columnNumber
- * @return {!WebInspector.SourceFrameMessage}
- */
-WebInspector.SourceFrameMessage.fromConsoleMessage = function(consoleMessage, lineNumber, columnNumber)
-{
- console.assert(consoleMessage.level === WebInspector.ConsoleMessage.MessageLevel.Error || consoleMessage.level === WebInspector.ConsoleMessage.MessageLevel.Warning);
- var level = consoleMessage.level === WebInspector.ConsoleMessage.MessageLevel.Error ? WebInspector.SourceFrameMessage.Level.Error : WebInspector.SourceFrameMessage.Level.Warning;
- return new WebInspector.SourceFrameMessage(consoleMessage.messageText, level, lineNumber, columnNumber);
-}
-
-WebInspector.SourceFrameMessage.prototype = {
- /**
- * @return {string}
- */
- messageText: function()
- {
- return this._messageText;
- },
-
- /**
- * @return {!WebInspector.SourceFrameMessage.Level}
- */
- level: function()
- {
- return this._level;
- },
-
- /**
- * @return {number}
- */
- lineNumber: function()
- {
- return this._lineNumber;
- },
-
- /**
- * @return {(number|undefined)}
- */
- columnNumber: function()
- {
- return this._columnNumber;
- },
-
- /**
- * @param {!WebInspector.SourceFrameMessage} another
- * @return {boolean}
- */
- isEqual: function(another)
- {
- return this.messageText() === another.messageText() && this.level() === another.level() && this.lineNumber() === another.lineNumber() && this.columnNumber() === another.columnNumber();
- }
-}
-
-WebInspector.SourceFrame._iconClassPerLevel = {};
-WebInspector.SourceFrame._iconClassPerLevel[WebInspector.SourceFrameMessage.Level.Error] = "error-icon";
-WebInspector.SourceFrame._iconClassPerLevel[WebInspector.SourceFrameMessage.Level.Warning] = "warning-icon";
-
-WebInspector.SourceFrame._lineClassPerLevel = {};
-WebInspector.SourceFrame._lineClassPerLevel[WebInspector.SourceFrameMessage.Level.Error] = "text-editor-line-with-error";
-WebInspector.SourceFrame._lineClassPerLevel[WebInspector.SourceFrameMessage.Level.Warning] = "text-editor-line-with-warning";
-
-/**
- * @constructor
- * @param {!WebInspector.SourceFrameMessage} message
- */
-WebInspector.SourceFrame.RowMessage = function(message)
-{
- this._message = message;
- this._repeatCount = 1;
- this.element = createElementWithClass("div", "text-editor-row-message");
- this._icon = this.element.createChild("label", "", "dt-icon-label");
- this._icon.type = WebInspector.SourceFrame._iconClassPerLevel[message.level()];
- this._repeatCountElement = this.element.createChild("span", "bubble-repeat-count hidden error");
- var linesContainer = this.element.createChild("div", "text-editor-row-message-lines");
- var lines = this._message.messageText().split("\n");
- for (var i = 0; i < lines.length; ++i) {
- var messageLine = linesContainer.createChild("div");
- messageLine.textContent = lines[i];
- }
-}
-
-WebInspector.SourceFrame.RowMessage.prototype = {
- /**
- * @return {!WebInspector.SourceFrameMessage}
- */
- message: function()
- {
- return this._message;
- },
-
- /**
- * @return {number}
- */
- repeatCount: function()
- {
- return this._repeatCount;
- },
-
- setRepeatCount: function(repeatCount)
- {
- if (this._repeatCount === repeatCount)
- return;
- this._repeatCount = repeatCount;
- this._updateMessageRepeatCount();
- },
-
- _updateMessageRepeatCount: function()
- {
- this._repeatCountElement.textContent = this._repeatCount;
- var showRepeatCount = this._repeatCount > 1;
- this._repeatCountElement.classList.toggle("hidden", !showRepeatCount);
- this._icon.classList.toggle("hidden", showRepeatCount);
- }
-}
-
-/**
- * @constructor
- * @param {!WebInspector.SourceFrame} sourceFrame
- * @param {!WebInspector.CodeMirrorTextEditor} textEditor
- * @param {number} lineNumber
- */
-WebInspector.SourceFrame.RowMessageBucket = function(sourceFrame, textEditor, lineNumber)
-{
- this._sourceFrame = sourceFrame;
- this._textEditor = textEditor;
- this._lineHandle = textEditor.textEditorPositionHandle(lineNumber, 0);
- this._decoration = createElementWithClass("div", "text-editor-line-decoration");
- this._decoration._messageBucket = this;
- this._wave = this._decoration.createChild("div", "text-editor-line-decoration-wave");
- this._icon = this._wave.createChild("label", "text-editor-line-decoration-icon", "dt-icon-label");
-
- this._textEditor.addDecoration(lineNumber, this._decoration);
-
- this._messagesDescriptionElement = createElementWithClass("div", "text-editor-messages-description-container");
- /** @type {!Array.<!WebInspector.SourceFrame.RowMessage>} */
- this._messages = [];
-
- this._level = null;
-}
-
-WebInspector.SourceFrame.RowMessageBucket.prototype = {
- /**
- * @param {number} lineNumber
- * @param {number} columnNumber
- */
- _updateWavePosition: function(lineNumber, columnNumber)
- {
- lineNumber = Math.min(lineNumber, this._textEditor.linesCount - 1);
- var lineText = this._textEditor.line(lineNumber);
- columnNumber = Math.min(columnNumber, lineText.length);
- var lineIndent = WebInspector.TextUtils.lineIndent(lineText).length;
- var base = this._textEditor.cursorPositionToCoordinates(lineNumber, 0);
-
- var start = this._textEditor.cursorPositionToCoordinates(lineNumber, Math.max(columnNumber - 1, lineIndent));
- var end = this._textEditor.cursorPositionToCoordinates(lineNumber, lineText.length);
- /** @const */
- var codeMirrorLinesLeftPadding = 4;
- this._wave.style.left = (start.x - base.x + codeMirrorLinesLeftPadding) + "px";
- this._wave.style.width = (end.x - start.x) + "px";
- },
-
- /**
- * @return {!Element}
- */
- messagesDescription: function()
- {
- this._messagesDescriptionElement.removeChildren();
- for (var i = 0; i < this._messages.length; ++i) {
- this._messagesDescriptionElement.appendChild(this._messages[i].element);
- }
- return this._messagesDescriptionElement;
- },
-
- detachFromEditor: function()
- {
- var position = this._lineHandle.resolve();
- if (!position)
- return;
- var lineNumber = position.lineNumber;
- if (this._level)
- this._textEditor.toggleLineClass(lineNumber, WebInspector.SourceFrame._lineClassPerLevel[this._level], false);
- this._textEditor.removeDecoration(lineNumber, this._decoration);
- },
-
- /**
- * @return {number}
- */
- uniqueMessagesCount: function()
- {
- return this._messages.length;
- },
-
- /**
- * @param {!WebInspector.SourceFrameMessage} message
- */
- addMessage: function(message)
- {
- for (var i = 0; i < this._messages.length; ++i) {
- var rowMessage = this._messages[i];
- if (rowMessage.message().isEqual(message)) {
- rowMessage.setRepeatCount(rowMessage.repeatCount() + 1);
- return;
- }
- }
-
- var rowMessage = new WebInspector.SourceFrame.RowMessage(message);
- this._messages.push(rowMessage);
- this._updateDecoration();
- },
-
- /**
- * @param {!WebInspector.SourceFrameMessage} message
- */
- removeMessage: function(message)
- {
- for (var i = 0; i < this._messages.length; ++i) {
- var rowMessage = this._messages[i];
- if (!rowMessage.message().isEqual(message))
- continue;
- rowMessage.setRepeatCount(rowMessage.repeatCount() - 1);
- if (!rowMessage.repeatCount())
- this._messages.splice(i, 1);
- this._updateDecoration();
- return;
- }
- },
-
- _updateDecoration: function()
- {
- if (!this._sourceFrame._isEditorShowing())
- return;
- if (!this._messages.length)
- return;
- var position = this._lineHandle.resolve();
- if (!position)
- return;
-
- var lineNumber = position.lineNumber;
- var columnNumber = Number.MAX_VALUE;
- var maxMessage = null;
- for (var i = 0; i < this._messages.length; ++i) {
- var message = this._messages[i].message();
- columnNumber = Math.min(columnNumber, message.columnNumber());
- if (!maxMessage || WebInspector.SourceFrameMessage.messageLevelComparator(maxMessage, message) < 0)
- maxMessage = message;
- }
- this._updateWavePosition(lineNumber, columnNumber);
-
- if (this._level) {
- this._textEditor.toggleLineClass(lineNumber, WebInspector.SourceFrame._lineClassPerLevel[this._level], false);
- this._icon.type = "";
- }
- this._level = maxMessage.level();
- if (!this._level)
- return;
- this._textEditor.toggleLineClass(lineNumber, WebInspector.SourceFrame._lineClassPerLevel[this._level], true);
- this._icon.type = WebInspector.SourceFrame._iconClassPerLevel[this._level];
- }
-}
-
-/**
* @implements {WebInspector.TextEditorDelegate}
* @constructor
*/
@@ -1057,18 +678,3 @@ WebInspector.TextEditorDelegateForSourceFrame.prototype = {
this._sourceFrame.onJumpToPosition(from, to);
}
}
-
-WebInspector.SourceFrameMessage._messageLevelPriority = {
- "Warning": 3,
- "Error": 4
-};
-
-/**
- * @param {!WebInspector.SourceFrameMessage} a
- * @param {!WebInspector.SourceFrameMessage} b
- * @return {number}
- */
-WebInspector.SourceFrameMessage.messageLevelComparator = function(a, b)
-{
- return WebInspector.SourceFrameMessage._messageLevelPriority[a.level()] - WebInspector.SourceFrameMessage._messageLevelPriority[b.level()];
-}

Powered by Google App Engine
This is Rietveld 408576698