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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/UISourceCodeFrame.js

Issue 1403373013: DevTools: move ui messages from SourceFrame to UISourceCodeFrame (step2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 10 *
(...skipping 21 matching lines...) Expand all
32 * @param {!WebInspector.UISourceCode} uiSourceCode 32 * @param {!WebInspector.UISourceCode} uiSourceCode
33 */ 33 */
34 WebInspector.UISourceCodeFrame = function(uiSourceCode) 34 WebInspector.UISourceCodeFrame = function(uiSourceCode)
35 { 35 {
36 this._uiSourceCode = uiSourceCode; 36 this._uiSourceCode = uiSourceCode;
37 WebInspector.SourceFrame.call(this, this._uiSourceCode); 37 WebInspector.SourceFrame.call(this, this._uiSourceCode);
38 this.textEditor.setAutocompleteDelegate(new WebInspector.SimpleAutocompleteD elegate()); 38 this.textEditor.setAutocompleteDelegate(new WebInspector.SimpleAutocompleteD elegate());
39 this._rowMessageBuckets = {}; 39 this._rowMessageBuckets = {};
40 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working CopyChanged, this._onWorkingCopyChanged, this); 40 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working CopyChanged, this._onWorkingCopyChanged, this);
41 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working CopyCommitted, this._onWorkingCopyCommitted, this); 41 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working CopyCommitted, this._onWorkingCopyCommitted, this);
42 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Message Added, this._onMessageAdded, this);
43 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Message Removed, this._onMessageRemoved, this);
42 this._updateStyle(); 44 this._updateStyle();
43 45
44 this._errorPopoverHelper = new WebInspector.PopoverHelper(this.element, this ._getErrorAnchor.bind(this), this._showErrorPopover.bind(this)); 46 this._errorPopoverHelper = new WebInspector.PopoverHelper(this.element, this ._getErrorAnchor.bind(this), this._showErrorPopover.bind(this));
45 this._errorPopoverHelper.setTimeout(100, 100); 47 this._errorPopoverHelper.setTimeout(100, 100);
46 } 48 }
47 49
48 WebInspector.UISourceCodeFrame.prototype = { 50 WebInspector.UISourceCodeFrame.prototype = {
49 /** 51 /**
50 * @return {!WebInspector.UISourceCode} 52 * @return {!WebInspector.UISourceCode}
51 */ 53 */
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 commitEditing: function() 103 commitEditing: function()
102 { 104 {
103 if (!this._uiSourceCode.isDirty()) 105 if (!this._uiSourceCode.isDirty())
104 return; 106 return;
105 107
106 this._muteSourceCodeEvents = true; 108 this._muteSourceCodeEvents = true;
107 this._uiSourceCode.commitWorkingCopy(); 109 this._uiSourceCode.commitWorkingCopy();
108 delete this._muteSourceCodeEvents; 110 delete this._muteSourceCodeEvents;
109 }, 111 },
110 112
113 onTextEditorContentLoaded: function()
dgozman 2015/10/27 21:43:49 @override
pfeldman 2015/10/27 22:35:17 Done.
114 {
115 WebInspector.SourceFrame.prototype.onTextEditorContentLoaded.call(this);
116 this._clearMessages();
117 for (var message of this._uiSourceCode.messages())
118 this._addMessageToSource(message);
119 },
120
111 onTextChanged: function(oldRange, newRange) 121 onTextChanged: function(oldRange, newRange)
dgozman 2015/10/27 21:43:49 mind adding JSDoc?
pfeldman 2015/10/27 22:35:17 Done.
112 { 122 {
113 WebInspector.SourceFrame.prototype.onTextChanged.call(this, oldRange, ne wRange); 123 WebInspector.SourceFrame.prototype.onTextChanged.call(this, oldRange, ne wRange);
114 this.clearMessages(); 124 this._clearMessages();
dgozman 2015/10/27 21:43:49 Do we abandon old messages? If so, who will clear
pfeldman 2015/10/27 22:35:17 Good call. Let me erase all messages from uiSource
115 if (this._isSettingContent) 125 if (this._isSettingContent)
116 return; 126 return;
117 this._muteSourceCodeEvents = true; 127 this._muteSourceCodeEvents = true;
118 if (this._textEditor.isClean()) 128 if (this._textEditor.isClean())
119 this._uiSourceCode.resetWorkingCopy(); 129 this._uiSourceCode.resetWorkingCopy();
120 else 130 else
121 this._uiSourceCode.setWorkingCopyGetter(this._textEditor.text.bind(t his._textEditor)); 131 this._uiSourceCode.setWorkingCopyGetter(this._textEditor.text.bind(t his._textEditor));
122 delete this._muteSourceCodeEvents; 132 delete this._muteSourceCodeEvents;
123 }, 133 },
124 134
125 onTextEditorContentLoaded: function()
126 {
127 WebInspector.SourceFrame.prototype.onTextEditorContentLoaded.call(this);
128 this.clearMessages();
129 },
130
131 /** 135 /**
132 * @param {!WebInspector.Event} event 136 * @param {!WebInspector.Event} event
133 */ 137 */
134 _onWorkingCopyChanged: function(event) 138 _onWorkingCopyChanged: function(event)
135 { 139 {
136 if (this._muteSourceCodeEvents) 140 if (this._muteSourceCodeEvents)
137 return; 141 return;
138 this._innerSetContent(this._uiSourceCode.workingCopy()); 142 this._innerSetContent(this._uiSourceCode.workingCopy());
139 this.onUISourceCodeContentChanged(); 143 this.onUISourceCodeContentChanged();
140 }, 144 },
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 this.doResize(); 198 this.doResize();
195 }, 199 },
196 200
197 dispose: function() 201 dispose: function()
198 { 202 {
199 this._textEditor.dispose(); 203 this._textEditor.dispose();
200 this.detach(); 204 this.detach();
201 }, 205 },
202 206
203 /** 207 /**
208 * @param {!WebInspector.Event} event
209 */
210 _onMessageAdded: function(event)
211 {
212 var message = /** @type {!WebInspector.UISourceCode.Message} */ (event.d ata);
213 this._addMessageToSource(message);
214 },
215
216 /**
204 * @param {!WebInspector.UISourceCode.Message} message 217 * @param {!WebInspector.UISourceCode.Message} message
205 */ 218 */
206 addMessageToSource: function(message) 219 _addMessageToSource: function(message)
207 { 220 {
208 var lineNumber = message.lineNumber(); 221 var lineNumber = message.lineNumber();
209 if (lineNumber >= this._textEditor.linesCount) 222 if (lineNumber >= this._textEditor.linesCount)
210 lineNumber = this._textEditor.linesCount - 1; 223 lineNumber = this._textEditor.linesCount - 1;
211 if (lineNumber < 0) 224 if (lineNumber < 0)
212 lineNumber = 0; 225 lineNumber = 0;
213 226
214 if (!this._rowMessageBuckets[lineNumber]) 227 if (!this._rowMessageBuckets[lineNumber])
215 this._rowMessageBuckets[lineNumber] = new WebInspector.UISourceCodeF rame.RowMessageBucket(this, this._textEditor, lineNumber); 228 this._rowMessageBuckets[lineNumber] = new WebInspector.UISourceCodeF rame.RowMessageBucket(this, this._textEditor, lineNumber);
216 var messageBucket = this._rowMessageBuckets[lineNumber]; 229 var messageBucket = this._rowMessageBuckets[lineNumber];
217 messageBucket.addMessage(message); 230 messageBucket.addMessage(message);
218 }, 231 },
219 232
220 /** 233 /**
234 * @param {!WebInspector.Event} event
235 */
236 _onMessageRemoved: function(event)
237 {
238 var message = /** @type {!WebInspector.UISourceCode.Message} */ (event.d ata);
239 this._removeMessageFromSource(message);
240 },
241
242 /**
221 * @param {!WebInspector.UISourceCode.Message} message 243 * @param {!WebInspector.UISourceCode.Message} message
222 */ 244 */
223 removeMessageFromSource: function(message) 245 _removeMessageFromSource: function(message)
224 { 246 {
225 var lineNumber = message.lineNumber(); 247 var lineNumber = message.lineNumber();
226 if (lineNumber >= this._textEditor.linesCount) 248 if (lineNumber >= this._textEditor.linesCount)
227 lineNumber = this._textEditor.linesCount - 1; 249 lineNumber = this._textEditor.linesCount - 1;
228 if (lineNumber < 0) 250 if (lineNumber < 0)
229 lineNumber = 0; 251 lineNumber = 0;
230 252
231 var messageBucket = this._rowMessageBuckets[lineNumber]; 253 var messageBucket = this._rowMessageBuckets[lineNumber];
232 if (!messageBucket) 254 if (!messageBucket)
233 return; 255 return;
234 messageBucket.removeMessage(message); 256 messageBucket.removeMessage(message);
235 if (!messageBucket.uniqueMessagesCount()) { 257 if (!messageBucket.uniqueMessagesCount()) {
236 messageBucket.detachFromEditor(); 258 messageBucket.detachFromEditor();
237 delete this._rowMessageBuckets[lineNumber]; 259 delete this._rowMessageBuckets[lineNumber];
238 } 260 }
239 }, 261 },
240 262
241 clearMessages: function() 263 _clearMessages: function()
242 { 264 {
243 for (var line in this._rowMessageBuckets) { 265 for (var line in this._rowMessageBuckets) {
244 var bubble = this._rowMessageBuckets[line]; 266 var bubble = this._rowMessageBuckets[line];
245 bubble.detachFromEditor(); 267 bubble.detachFromEditor();
246 } 268 }
247 269
248 this._rowMessageBuckets = {}; 270 this._rowMessageBuckets = {};
249 this._errorPopoverHelper.hidePopover(); 271 this._errorPopoverHelper.hidePopover();
250 }, 272 },
251 273
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 dispose: function() 376 dispose: function()
355 { 377 {
356 this.element.remove(); 378 this.element.remove();
357 this._onResize(); 379 this._onResize();
358 delete this._uiSourceCodeFrame; 380 delete this._uiSourceCodeFrame;
359 }, 381 },
360 382
361 __proto__: WebInspector.Infobar.prototype 383 __proto__: WebInspector.Infobar.prototype
362 } 384 }
363 385
364 /**
365 * @param {!WebInspector.ConsoleMessage} consoleMessage
366 * @param {number} lineNumber
367 * @param {number} columnNumber
368 * @return {!WebInspector.UISourceCode.Message}
369 */
370 WebInspector.UISourceCodeFrame.uiMessageFromConsoleMessage = function(consoleMes sage, lineNumber, columnNumber)
371 {
372 console.assert(consoleMessage.level === WebInspector.ConsoleMessage.MessageL evel.Error || consoleMessage.level === WebInspector.ConsoleMessage.MessageLevel. Warning);
373 var level = consoleMessage.level === WebInspector.ConsoleMessage.MessageLeve l.Error ? WebInspector.UISourceCode.Message.Level.Error : WebInspector.UISourceC ode.Message.Level.Warning;
374 return new WebInspector.UISourceCode.Message(level, consoleMessage.messageTe xt, lineNumber, columnNumber);
375 }
376
377 WebInspector.UISourceCodeFrame._iconClassPerLevel = {}; 386 WebInspector.UISourceCodeFrame._iconClassPerLevel = {};
378 WebInspector.UISourceCodeFrame._iconClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Error] = "error-icon"; 387 WebInspector.UISourceCodeFrame._iconClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Error] = "error-icon";
379 WebInspector.UISourceCodeFrame._iconClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Warning] = "warning-icon"; 388 WebInspector.UISourceCodeFrame._iconClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Warning] = "warning-icon";
380 389
381 WebInspector.UISourceCodeFrame._lineClassPerLevel = {}; 390 WebInspector.UISourceCodeFrame._lineClassPerLevel = {};
382 WebInspector.UISourceCodeFrame._lineClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Error] = "text-editor-line-with-error"; 391 WebInspector.UISourceCodeFrame._lineClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Error] = "text-editor-line-with-error";
383 WebInspector.UISourceCodeFrame._lineClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Warning] = "text-editor-line-with-warning"; 392 WebInspector.UISourceCodeFrame._lineClassPerLevel[WebInspector.UISourceCode.Mess age.Level.Warning] = "text-editor-line-with-warning";
384 393
385 /** 394 /**
386 * @constructor 395 * @constructor
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 597
589 /** 598 /**
590 * @param {!WebInspector.UISourceCode.Message} a 599 * @param {!WebInspector.UISourceCode.Message} a
591 * @param {!WebInspector.UISourceCode.Message} b 600 * @param {!WebInspector.UISourceCode.Message} b
592 * @return {number} 601 * @return {number}
593 */ 602 */
594 WebInspector.UISourceCode.Message.messageLevelComparator = function(a, b) 603 WebInspector.UISourceCode.Message.messageLevelComparator = function(a, b)
595 { 604 {
596 return WebInspector.UISourceCode.Message._messageLevelPriority[a.level()] - WebInspector.UISourceCode.Message._messageLevelPriority[b.level()]; 605 return WebInspector.UISourceCode.Message._messageLevelPriority[a.level()] - WebInspector.UISourceCode.Message._messageLevelPriority[b.level()];
597 } 606 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698