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

Side by Side 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, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 30 matching lines...) Expand all
41 this._url = contentProvider.contentURL(); 41 this._url = contentProvider.contentURL();
42 this._contentProvider = contentProvider; 42 this._contentProvider = contentProvider;
43 43
44 var textEditorDelegate = new WebInspector.TextEditorDelegateForSourceFrame(t his); 44 var textEditorDelegate = new WebInspector.TextEditorDelegateForSourceFrame(t his);
45 45
46 this._textEditor = new WebInspector.CodeMirrorTextEditor(this._url, textEdit orDelegate); 46 this._textEditor = new WebInspector.CodeMirrorTextEditor(this._url, textEdit orDelegate);
47 47
48 this._currentSearchResultIndex = -1; 48 this._currentSearchResultIndex = -1;
49 this._searchResults = []; 49 this._searchResults = [];
50 50
51 this._rowMessageBuckets = {};
52
53 this._textEditor.setReadOnly(!this.canEditSource()); 51 this._textEditor.setReadOnly(!this.canEditSource());
54 52
55 this._shortcuts = {}; 53 this._shortcuts = {};
56 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), fal se); 54 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), fal se);
57 55
58 this._sourcePosition = new WebInspector.ToolbarText("", "source-frame-cursor -position"); 56 this._sourcePosition = new WebInspector.ToolbarText("", "source-frame-cursor -position");
59
60 this._errorPopoverHelper = new WebInspector.PopoverHelper(this.element, this ._getErrorAnchor.bind(this), this._showErrorPopover.bind(this));
61 this._errorPopoverHelper.setTimeout(100, 100);
62 } 57 }
63 58
64 WebInspector.SourceFrame.Events = { 59 WebInspector.SourceFrame.Events = {
65 ScrollChanged: "ScrollChanged", 60 ScrollChanged: "ScrollChanged",
66 SelectionChanged: "SelectionChanged", 61 SelectionChanged: "SelectionChanged",
67 JumpHappened: "JumpHappened" 62 JumpHappened: "JumpHappened"
68 } 63 }
69 64
70 WebInspector.SourceFrame.prototype = { 65 WebInspector.SourceFrame.prototype = {
71 /** 66 /**
72 * @param {!Element} target
73 * @param {!Event} event
74 * @return {(!Element|undefined)}
75 */
76 _getErrorAnchor: function(target, event)
77 {
78 var element = target.enclosingNodeOrSelfWithClass("text-editor-line-deco ration-icon")
79 || target.enclosingNodeOrSelfWithClass("text-editor-line-decoration- wave");
80 if (!element)
81 return;
82 this._errorWavePopoverAnchor = new AnchorBox(event.clientX, event.client Y, 1, 1);
83 return element;
84 },
85
86 /**
87 * @param {!Element} anchor
88 * @param {!WebInspector.Popover} popover
89 */
90 _showErrorPopover: function(anchor, popover)
91 {
92 var messageBucket = anchor.enclosingNodeOrSelfWithClass("text-editor-lin e-decoration")._messageBucket;
93 var messagesOutline = messageBucket.messagesDescription();
94 var popoverAnchor = anchor.enclosingNodeOrSelfWithClass("text-editor-lin e-decoration-icon") ? anchor : this._errorWavePopoverAnchor;
95 popover.showForAnchor(messagesOutline, popoverAnchor);
96 },
97
98 /**
99 * @param {number} key 67 * @param {number} key
100 * @param {function():boolean} handler 68 * @param {function():boolean} handler
101 */ 69 */
102 addShortcut: function(key, handler) 70 addShortcut: function(key, handler)
103 { 71 {
104 this._shortcuts[key] = handler; 72 this._shortcuts[key] = handler;
105 }, 73 },
106 74
107 wasShown: function() 75 wasShown: function()
108 { 76 {
109 this._ensureContentLoaded(); 77 this._ensureContentLoaded();
110 this._textEditor.show(this.element); 78 this._textEditor.show(this.element);
111 this._editorAttached = true; 79 this._editorAttached = true;
112 // We need CodeMirrorTextEditor to be initialized prior to this call as it calls |cursorPositionToCoordinates| internally. @see crbug.com/506566
113 setImmediate(this._updateBucketDecorations.bind(this));
114 this._wasShownOrLoaded(); 80 this._wasShownOrLoaded();
115 }, 81 },
116 82
117 _updateBucketDecorations: function()
118 {
119 for (var line in this._rowMessageBuckets) {
120 var bucket = this._rowMessageBuckets[line];
121 bucket._updateDecoration();
122 }
123 },
124
125 /** 83 /**
126 * @return {boolean} 84 * @return {boolean}
127 */ 85 */
128 _isEditorShowing: function() 86 isEditorShowing: function()
129 { 87 {
130 return this.isShowing() && this._editorAttached; 88 return this.isShowing() && this._editorAttached;
131 }, 89 },
132 90
133 willHide: function() 91 willHide: function()
134 { 92 {
135 WebInspector.Widget.prototype.willHide.call(this); 93 WebInspector.Widget.prototype.willHide.call(this);
136 94
137 this._clearPositionToReveal(); 95 this._clearPositionToReveal();
138 }, 96 },
(...skipping 26 matching lines...) Expand all
165 }, 123 },
166 124
167 _ensureContentLoaded: function() 125 _ensureContentLoaded: function()
168 { 126 {
169 if (!this._contentRequested) { 127 if (!this._contentRequested) {
170 this._contentRequested = true; 128 this._contentRequested = true;
171 this._contentProvider.requestContent(this.setContent.bind(this)); 129 this._contentProvider.requestContent(this.setContent.bind(this));
172 } 130 }
173 }, 131 },
174 132
175 clearMessages: function()
176 {
177 for (var line in this._rowMessageBuckets) {
178 var bubble = this._rowMessageBuckets[line];
179 bubble.detachFromEditor();
180 }
181
182 this._rowMessageBuckets = {};
183 this._errorPopoverHelper.hidePopover();
184 },
185
186 /** 133 /**
187 * @param {number} line 0-based 134 * @param {number} line 0-based
188 * @param {number=} column 135 * @param {number=} column
189 * @param {boolean=} shouldHighlight 136 * @param {boolean=} shouldHighlight
190 */ 137 */
191 revealPosition: function(line, column, shouldHighlight) 138 revealPosition: function(line, column, shouldHighlight)
192 { 139 {
193 this._clearLineToScrollTo(); 140 this._clearLineToScrollTo();
194 this._clearSelectionToSet(); 141 this._clearSelectionToSet();
195 this._positionToReveal = { line: line, column: column, shouldHighlight: shouldHighlight }; 142 this._positionToReveal = { line: line, column: column, shouldHighlight: shouldHighlight };
196 this._innerRevealPositionIfNeeded(); 143 this._innerRevealPositionIfNeeded();
197 }, 144 },
198 145
199 _innerRevealPositionIfNeeded: function() 146 _innerRevealPositionIfNeeded: function()
200 { 147 {
201 if (!this._positionToReveal) 148 if (!this._positionToReveal)
202 return; 149 return;
203 150
204 if (!this.loaded || !this._isEditorShowing()) 151 if (!this.loaded || !this.isEditorShowing())
205 return; 152 return;
206 153
207 this._textEditor.revealPosition(this._positionToReveal.line, this._posit ionToReveal.column, this._positionToReveal.shouldHighlight); 154 this._textEditor.revealPosition(this._positionToReveal.line, this._posit ionToReveal.column, this._positionToReveal.shouldHighlight);
208 delete this._positionToReveal; 155 delete this._positionToReveal;
209 }, 156 },
210 157
211 _clearPositionToReveal: function() 158 _clearPositionToReveal: function()
212 { 159 {
213 this._textEditor.clearPositionHighlight(); 160 this._textEditor.clearPositionHighlight();
214 delete this._positionToReveal; 161 delete this._positionToReveal;
215 }, 162 },
216 163
217 /** 164 /**
218 * @param {number} line 165 * @param {number} line
219 */ 166 */
220 scrollToLine: function(line) 167 scrollToLine: function(line)
221 { 168 {
222 this._clearPositionToReveal(); 169 this._clearPositionToReveal();
223 this._lineToScrollTo = line; 170 this._lineToScrollTo = line;
224 this._innerScrollToLineIfNeeded(); 171 this._innerScrollToLineIfNeeded();
225 }, 172 },
226 173
227 _innerScrollToLineIfNeeded: function() 174 _innerScrollToLineIfNeeded: function()
228 { 175 {
229 if (typeof this._lineToScrollTo === "number") { 176 if (typeof this._lineToScrollTo === "number") {
230 if (this.loaded && this._isEditorShowing()) { 177 if (this.loaded && this.isEditorShowing()) {
231 this._textEditor.scrollToLine(this._lineToScrollTo); 178 this._textEditor.scrollToLine(this._lineToScrollTo);
232 delete this._lineToScrollTo; 179 delete this._lineToScrollTo;
233 } 180 }
234 } 181 }
235 }, 182 },
236 183
237 _clearLineToScrollTo: function() 184 _clearLineToScrollTo: function()
238 { 185 {
239 delete this._lineToScrollTo; 186 delete this._lineToScrollTo;
240 }, 187 },
(...skipping 10 matching lines...) Expand all
251 * @param {!WebInspector.TextRange} textRange 198 * @param {!WebInspector.TextRange} textRange
252 */ 199 */
253 setSelection: function(textRange) 200 setSelection: function(textRange)
254 { 201 {
255 this._selectionToSet = textRange; 202 this._selectionToSet = textRange;
256 this._innerSetSelectionIfNeeded(); 203 this._innerSetSelectionIfNeeded();
257 }, 204 },
258 205
259 _innerSetSelectionIfNeeded: function() 206 _innerSetSelectionIfNeeded: function()
260 { 207 {
261 if (this._selectionToSet && this.loaded && this._isEditorShowing()) { 208 if (this._selectionToSet && this.loaded && this.isEditorShowing()) {
262 this._textEditor.setSelection(this._selectionToSet); 209 this._textEditor.setSelection(this._selectionToSet);
263 delete this._selectionToSet; 210 delete this._selectionToSet;
264 } 211 }
265 }, 212 },
266 213
267 _clearSelectionToSet: function() 214 _clearSelectionToSet: function()
268 { 215 {
269 delete this._selectionToSet; 216 delete this._selectionToSet;
270 }, 217 },
271 218
272 _wasShownOrLoaded: function() 219 _wasShownOrLoaded: function()
273 { 220 {
274 this._innerRevealPositionIfNeeded(); 221 this._innerRevealPositionIfNeeded();
275 this._innerSetSelectionIfNeeded(); 222 this._innerSetSelectionIfNeeded();
276 this._innerScrollToLineIfNeeded(); 223 this._innerScrollToLineIfNeeded();
277 }, 224 },
278 225
279 onTextChanged: function(oldRange, newRange) 226 onTextChanged: function(oldRange, newRange)
280 { 227 {
281 if (this._searchResultsChangedCallback) 228 if (this._searchResultsChangedCallback)
282 this._searchResultsChangedCallback(); 229 this._searchResultsChangedCallback();
283 this.clearMessages();
284 }, 230 },
285 231
286 /** 232 /**
287 * @param {string} content 233 * @param {string} content
288 * @param {string} mimeType 234 * @param {string} mimeType
289 * @return {string} 235 * @return {string}
290 */ 236 */
291 _simplifyMimeType: function(content, mimeType) 237 _simplifyMimeType: function(content, mimeType)
292 { 238 {
293 if (!mimeType) 239 if (!mimeType)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 this._textEditor.markClean(); 276 this._textEditor.markClean();
331 } else { 277 } else {
332 var firstLine = this._textEditor.firstVisibleLine(); 278 var firstLine = this._textEditor.firstVisibleLine();
333 var selection = this._textEditor.selection(); 279 var selection = this._textEditor.selection();
334 this._textEditor.setText(content || ""); 280 this._textEditor.setText(content || "");
335 this._textEditor.scrollToLine(firstLine); 281 this._textEditor.scrollToLine(firstLine);
336 this._textEditor.setSelection(selection); 282 this._textEditor.setSelection(selection);
337 } 283 }
338 284
339 this._updateHighlighterType(content || ""); 285 this._updateHighlighterType(content || "");
340 this.clearMessages();
341 this._wasShownOrLoaded(); 286 this._wasShownOrLoaded();
342 287
343 if (this._delayedFindSearchMatches) { 288 if (this._delayedFindSearchMatches) {
344 this._delayedFindSearchMatches(); 289 this._delayedFindSearchMatches();
345 delete this._delayedFindSearchMatches; 290 delete this._delayedFindSearchMatches;
346 } 291 }
347 this.onTextEditorContentLoaded(); 292 this.onTextEditorContentLoaded();
348 }, 293 },
349 294
350 onTextEditorContentLoaded: function() {}, 295 onTextEditorContentLoaded: function() {},
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 ranges.push(new WebInspector.TextRange(i, offset + match .index, i, offset + matchEndIndex)); 507 ranges.push(new WebInspector.TextRange(i, offset + match .index, i, offset + matchEndIndex));
563 offset += matchEndIndex; 508 offset += matchEndIndex;
564 line = line.substring(matchEndIndex); 509 line = line.substring(matchEndIndex);
565 } 510 }
566 } while (match && line); 511 } while (match && line);
567 } 512 }
568 return ranges; 513 return ranges;
569 }, 514 },
570 515
571 /** 516 /**
572 * @param {!WebInspector.SourceFrameMessage} message
573 */
574 addMessageToSource: function(message)
575 {
576 var lineNumber = message.lineNumber();
577 if (lineNumber >= this._textEditor.linesCount)
578 lineNumber = this._textEditor.linesCount - 1;
579 if (lineNumber < 0)
580 lineNumber = 0;
581
582 if (!this._rowMessageBuckets[lineNumber])
583 this._rowMessageBuckets[lineNumber] = new WebInspector.SourceFrame.R owMessageBucket(this, this._textEditor, lineNumber);
584 var messageBucket = this._rowMessageBuckets[lineNumber];
585 messageBucket.addMessage(message);
586 },
587
588 /**
589 * @param {!WebInspector.SourceFrameMessage} message
590 */
591 removeMessageFromSource: function(message)
592 {
593 var lineNumber = message.lineNumber();
594 if (lineNumber >= this._textEditor.linesCount)
595 lineNumber = this._textEditor.linesCount - 1;
596 if (lineNumber < 0)
597 lineNumber = 0;
598
599 var messageBucket = this._rowMessageBuckets[lineNumber];
600 if (!messageBucket)
601 return;
602 messageBucket.removeMessage(message);
603 if (!messageBucket.uniqueMessagesCount()) {
604 messageBucket.detachFromEditor();
605 delete this._rowMessageBuckets[lineNumber];
606 }
607 },
608
609 /**
610 * @return {!Promise} 517 * @return {!Promise}
611 */ 518 */
612 populateLineGutterContextMenu: function(contextMenu, lineNumber) 519 populateLineGutterContextMenu: function(contextMenu, lineNumber)
613 { 520 {
614 return Promise.resolve(); 521 return Promise.resolve();
615 }, 522 },
616 523
617 /** 524 /**
618 * @return {!Promise} 525 * @return {!Promise}
619 */ 526 */
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(e); 595 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(e);
689 var handler = this._shortcuts[shortcutKey]; 596 var handler = this._shortcuts[shortcutKey];
690 if (handler && handler()) 597 if (handler && handler())
691 e.consume(true); 598 e.consume(true);
692 }, 599 },
693 600
694 __proto__: WebInspector.VBox.prototype 601 __proto__: WebInspector.VBox.prototype
695 } 602 }
696 603
697 /** 604 /**
698 * @constructor
699 * @param {string} messageText
700 * @param {!WebInspector.SourceFrameMessage.Level} level
701 * @param {number} lineNumber
702 * @param {number=} columnNumber
703 */
704 WebInspector.SourceFrameMessage = function(messageText, level, lineNumber, colum nNumber)
705 {
706 this._messageText = messageText;
707 this._level = level;
708 this._lineNumber = lineNumber;
709 this._columnNumber = columnNumber;
710 }
711
712 /**
713 * @enum {string}
714 */
715 WebInspector.SourceFrameMessage.Level = {
716 Error: "Error",
717 Warning: "Warning"
718 }
719
720 /**
721 * @param {!WebInspector.ConsoleMessage} consoleMessage
722 * @param {number} lineNumber
723 * @param {number} columnNumber
724 * @return {!WebInspector.SourceFrameMessage}
725 */
726 WebInspector.SourceFrameMessage.fromConsoleMessage = function(consoleMessage, li neNumber, columnNumber)
727 {
728 console.assert(consoleMessage.level === WebInspector.ConsoleMessage.MessageL evel.Error || consoleMessage.level === WebInspector.ConsoleMessage.MessageLevel. Warning);
729 var level = consoleMessage.level === WebInspector.ConsoleMessage.MessageLeve l.Error ? WebInspector.SourceFrameMessage.Level.Error : WebInspector.SourceFrame Message.Level.Warning;
730 return new WebInspector.SourceFrameMessage(consoleMessage.messageText, level , lineNumber, columnNumber);
731 }
732
733 WebInspector.SourceFrameMessage.prototype = {
734 /**
735 * @return {string}
736 */
737 messageText: function()
738 {
739 return this._messageText;
740 },
741
742 /**
743 * @return {!WebInspector.SourceFrameMessage.Level}
744 */
745 level: function()
746 {
747 return this._level;
748 },
749
750 /**
751 * @return {number}
752 */
753 lineNumber: function()
754 {
755 return this._lineNumber;
756 },
757
758 /**
759 * @return {(number|undefined)}
760 */
761 columnNumber: function()
762 {
763 return this._columnNumber;
764 },
765
766 /**
767 * @param {!WebInspector.SourceFrameMessage} another
768 * @return {boolean}
769 */
770 isEqual: function(another)
771 {
772 return this.messageText() === another.messageText() && this.level() === another.level() && this.lineNumber() === another.lineNumber() && this.columnNumb er() === another.columnNumber();
773 }
774 }
775
776 WebInspector.SourceFrame._iconClassPerLevel = {};
777 WebInspector.SourceFrame._iconClassPerLevel[WebInspector.SourceFrameMessage.Leve l.Error] = "error-icon";
778 WebInspector.SourceFrame._iconClassPerLevel[WebInspector.SourceFrameMessage.Leve l.Warning] = "warning-icon";
779
780 WebInspector.SourceFrame._lineClassPerLevel = {};
781 WebInspector.SourceFrame._lineClassPerLevel[WebInspector.SourceFrameMessage.Leve l.Error] = "text-editor-line-with-error";
782 WebInspector.SourceFrame._lineClassPerLevel[WebInspector.SourceFrameMessage.Leve l.Warning] = "text-editor-line-with-warning";
783
784 /**
785 * @constructor
786 * @param {!WebInspector.SourceFrameMessage} message
787 */
788 WebInspector.SourceFrame.RowMessage = function(message)
789 {
790 this._message = message;
791 this._repeatCount = 1;
792 this.element = createElementWithClass("div", "text-editor-row-message");
793 this._icon = this.element.createChild("label", "", "dt-icon-label");
794 this._icon.type = WebInspector.SourceFrame._iconClassPerLevel[message.level( )];
795 this._repeatCountElement = this.element.createChild("span", "bubble-repeat-c ount hidden error");
796 var linesContainer = this.element.createChild("div", "text-editor-row-messag e-lines");
797 var lines = this._message.messageText().split("\n");
798 for (var i = 0; i < lines.length; ++i) {
799 var messageLine = linesContainer.createChild("div");
800 messageLine.textContent = lines[i];
801 }
802 }
803
804 WebInspector.SourceFrame.RowMessage.prototype = {
805 /**
806 * @return {!WebInspector.SourceFrameMessage}
807 */
808 message: function()
809 {
810 return this._message;
811 },
812
813 /**
814 * @return {number}
815 */
816 repeatCount: function()
817 {
818 return this._repeatCount;
819 },
820
821 setRepeatCount: function(repeatCount)
822 {
823 if (this._repeatCount === repeatCount)
824 return;
825 this._repeatCount = repeatCount;
826 this._updateMessageRepeatCount();
827 },
828
829 _updateMessageRepeatCount: function()
830 {
831 this._repeatCountElement.textContent = this._repeatCount;
832 var showRepeatCount = this._repeatCount > 1;
833 this._repeatCountElement.classList.toggle("hidden", !showRepeatCount);
834 this._icon.classList.toggle("hidden", showRepeatCount);
835 }
836 }
837
838 /**
839 * @constructor
840 * @param {!WebInspector.SourceFrame} sourceFrame
841 * @param {!WebInspector.CodeMirrorTextEditor} textEditor
842 * @param {number} lineNumber
843 */
844 WebInspector.SourceFrame.RowMessageBucket = function(sourceFrame, textEditor, li neNumber)
845 {
846 this._sourceFrame = sourceFrame;
847 this._textEditor = textEditor;
848 this._lineHandle = textEditor.textEditorPositionHandle(lineNumber, 0);
849 this._decoration = createElementWithClass("div", "text-editor-line-decoratio n");
850 this._decoration._messageBucket = this;
851 this._wave = this._decoration.createChild("div", "text-editor-line-decoratio n-wave");
852 this._icon = this._wave.createChild("label", "text-editor-line-decoration-ic on", "dt-icon-label");
853
854 this._textEditor.addDecoration(lineNumber, this._decoration);
855
856 this._messagesDescriptionElement = createElementWithClass("div", "text-edito r-messages-description-container");
857 /** @type {!Array.<!WebInspector.SourceFrame.RowMessage>} */
858 this._messages = [];
859
860 this._level = null;
861 }
862
863 WebInspector.SourceFrame.RowMessageBucket.prototype = {
864 /**
865 * @param {number} lineNumber
866 * @param {number} columnNumber
867 */
868 _updateWavePosition: function(lineNumber, columnNumber)
869 {
870 lineNumber = Math.min(lineNumber, this._textEditor.linesCount - 1);
871 var lineText = this._textEditor.line(lineNumber);
872 columnNumber = Math.min(columnNumber, lineText.length);
873 var lineIndent = WebInspector.TextUtils.lineIndent(lineText).length;
874 var base = this._textEditor.cursorPositionToCoordinates(lineNumber, 0);
875
876 var start = this._textEditor.cursorPositionToCoordinates(lineNumber, Mat h.max(columnNumber - 1, lineIndent));
877 var end = this._textEditor.cursorPositionToCoordinates(lineNumber, lineT ext.length);
878 /** @const */
879 var codeMirrorLinesLeftPadding = 4;
880 this._wave.style.left = (start.x - base.x + codeMirrorLinesLeftPadding) + "px";
881 this._wave.style.width = (end.x - start.x) + "px";
882 },
883
884 /**
885 * @return {!Element}
886 */
887 messagesDescription: function()
888 {
889 this._messagesDescriptionElement.removeChildren();
890 for (var i = 0; i < this._messages.length; ++i) {
891 this._messagesDescriptionElement.appendChild(this._messages[i].eleme nt);
892 }
893 return this._messagesDescriptionElement;
894 },
895
896 detachFromEditor: function()
897 {
898 var position = this._lineHandle.resolve();
899 if (!position)
900 return;
901 var lineNumber = position.lineNumber;
902 if (this._level)
903 this._textEditor.toggleLineClass(lineNumber, WebInspector.SourceFram e._lineClassPerLevel[this._level], false);
904 this._textEditor.removeDecoration(lineNumber, this._decoration);
905 },
906
907 /**
908 * @return {number}
909 */
910 uniqueMessagesCount: function()
911 {
912 return this._messages.length;
913 },
914
915 /**
916 * @param {!WebInspector.SourceFrameMessage} message
917 */
918 addMessage: function(message)
919 {
920 for (var i = 0; i < this._messages.length; ++i) {
921 var rowMessage = this._messages[i];
922 if (rowMessage.message().isEqual(message)) {
923 rowMessage.setRepeatCount(rowMessage.repeatCount() + 1);
924 return;
925 }
926 }
927
928 var rowMessage = new WebInspector.SourceFrame.RowMessage(message);
929 this._messages.push(rowMessage);
930 this._updateDecoration();
931 },
932
933 /**
934 * @param {!WebInspector.SourceFrameMessage} message
935 */
936 removeMessage: function(message)
937 {
938 for (var i = 0; i < this._messages.length; ++i) {
939 var rowMessage = this._messages[i];
940 if (!rowMessage.message().isEqual(message))
941 continue;
942 rowMessage.setRepeatCount(rowMessage.repeatCount() - 1);
943 if (!rowMessage.repeatCount())
944 this._messages.splice(i, 1);
945 this._updateDecoration();
946 return;
947 }
948 },
949
950 _updateDecoration: function()
951 {
952 if (!this._sourceFrame._isEditorShowing())
953 return;
954 if (!this._messages.length)
955 return;
956 var position = this._lineHandle.resolve();
957 if (!position)
958 return;
959
960 var lineNumber = position.lineNumber;
961 var columnNumber = Number.MAX_VALUE;
962 var maxMessage = null;
963 for (var i = 0; i < this._messages.length; ++i) {
964 var message = this._messages[i].message();
965 columnNumber = Math.min(columnNumber, message.columnNumber());
966 if (!maxMessage || WebInspector.SourceFrameMessage.messageLevelCompa rator(maxMessage, message) < 0)
967 maxMessage = message;
968 }
969 this._updateWavePosition(lineNumber, columnNumber);
970
971 if (this._level) {
972 this._textEditor.toggleLineClass(lineNumber, WebInspector.SourceFram e._lineClassPerLevel[this._level], false);
973 this._icon.type = "";
974 }
975 this._level = maxMessage.level();
976 if (!this._level)
977 return;
978 this._textEditor.toggleLineClass(lineNumber, WebInspector.SourceFrame._l ineClassPerLevel[this._level], true);
979 this._icon.type = WebInspector.SourceFrame._iconClassPerLevel[this._leve l];
980 }
981 }
982
983 /**
984 * @implements {WebInspector.TextEditorDelegate} 605 * @implements {WebInspector.TextEditorDelegate}
985 * @constructor 606 * @constructor
986 */ 607 */
987 WebInspector.TextEditorDelegateForSourceFrame = function(sourceFrame) 608 WebInspector.TextEditorDelegateForSourceFrame = function(sourceFrame)
988 { 609 {
989 this._sourceFrame = sourceFrame; 610 this._sourceFrame = sourceFrame;
990 } 611 }
991 612
992 WebInspector.TextEditorDelegateForSourceFrame.prototype = { 613 WebInspector.TextEditorDelegateForSourceFrame.prototype = {
993 /** 614 /**
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 /** 671 /**
1051 * @override 672 * @override
1052 * @param {?WebInspector.TextRange} from 673 * @param {?WebInspector.TextRange} from
1053 * @param {?WebInspector.TextRange} to 674 * @param {?WebInspector.TextRange} to
1054 */ 675 */
1055 onJumpToPosition: function(from, to) 676 onJumpToPosition: function(from, to)
1056 { 677 {
1057 this._sourceFrame.onJumpToPosition(from, to); 678 this._sourceFrame.onJumpToPosition(from, to);
1058 } 679 }
1059 } 680 }
1060
1061 WebInspector.SourceFrameMessage._messageLevelPriority = {
1062 "Warning": 3,
1063 "Error": 4
1064 };
1065
1066 /**
1067 * @param {!WebInspector.SourceFrameMessage} a
1068 * @param {!WebInspector.SourceFrameMessage} b
1069 * @return {number}
1070 */
1071 WebInspector.SourceFrameMessage.messageLevelComparator = function(a, b)
1072 {
1073 return WebInspector.SourceFrameMessage._messageLevelPriority[a.level()] - We bInspector.SourceFrameMessage._messageLevelPriority[b.level()];
1074 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698