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

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

Issue 2820253002: DevTools: avoid slowdown from unnecessary DOM, style mutations on CodeMirrorTextEditor (Closed)
Patch Set: ac Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 * @param {number} lineNumber 561 * @param {number} lineNumber
562 */ 562 */
563 constructor(sourceFrame, textEditor, lineNumber) { 563 constructor(sourceFrame, textEditor, lineNumber) {
564 this._sourceFrame = sourceFrame; 564 this._sourceFrame = sourceFrame;
565 this.textEditor = textEditor; 565 this.textEditor = textEditor;
566 this._lineHandle = textEditor.textEditorPositionHandle(lineNumber, 0); 566 this._lineHandle = textEditor.textEditorPositionHandle(lineNumber, 0);
567 this._decoration = createElementWithClass('div', 'text-editor-line-decoratio n'); 567 this._decoration = createElementWithClass('div', 'text-editor-line-decoratio n');
568 this._decoration._messageBucket = this; 568 this._decoration._messageBucket = this;
569 this._wave = this._decoration.createChild('div', 'text-editor-line-decoratio n-wave'); 569 this._wave = this._decoration.createChild('div', 'text-editor-line-decoratio n-wave');
570 this._icon = this._wave.createChild('label', 'text-editor-line-decoration-ic on', 'dt-icon-label'); 570 this._icon = this._wave.createChild('label', 'text-editor-line-decoration-ic on', 'dt-icon-label');
571 this._hasDecoration = false; 571 /** @type {?number} */
572 this._decorationStartColumn = null;
572 573
573 this._messagesDescriptionElement = createElementWithClass('div', 'text-edito r-messages-description-container'); 574 this._messagesDescriptionElement = createElementWithClass('div', 'text-edito r-messages-description-container');
574 /** @type {!Array.<!SourceFrame.UISourceCodeFrame.RowMessage>} */ 575 /** @type {!Array.<!SourceFrame.UISourceCodeFrame.RowMessage>} */
575 this._messages = []; 576 this._messages = [];
576 577
577 this._level = null; 578 this._level = null;
578 } 579 }
579 580
580 /** 581 /**
581 * @param {number} lineNumber 582 * @param {number} lineNumber
582 * @param {number} columnNumber 583 * @param {number} columnNumber
583 */ 584 */
584 _updateWavePosition(lineNumber, columnNumber) { 585 _updateWavePosition(lineNumber, columnNumber) {
585 lineNumber = Math.min(lineNumber, this.textEditor.linesCount - 1); 586 lineNumber = Math.min(lineNumber, this.textEditor.linesCount - 1);
586 var lineText = this.textEditor.line(lineNumber); 587 var lineText = this.textEditor.line(lineNumber);
587 columnNumber = Math.min(columnNumber, lineText.length); 588 columnNumber = Math.min(columnNumber, lineText.length);
588 var lineIndent = TextUtils.TextUtils.lineIndent(lineText).length; 589 var lineIndent = TextUtils.TextUtils.lineIndent(lineText).length;
589 if (this._hasDecoration) 590 var startColumn = Math.max(columnNumber - 1, lineIndent);
591 if (this._decorationStartColumn === startColumn)
592 return;
593 if (this._decorationStartColumn !== null)
590 this.textEditor.removeDecoration(this._decoration, lineNumber); 594 this.textEditor.removeDecoration(this._decoration, lineNumber);
591 this._hasDecoration = true; 595 this.textEditor.addDecoration(this._decoration, lineNumber, startColumn);
592 this.textEditor.addDecoration(this._decoration, lineNumber, Math.max(columnN umber - 1, lineIndent)); 596 this._decorationStartColumn = startColumn;
593 } 597 }
594 598
595 /** 599 /**
596 * @return {!Element} 600 * @return {!Element}
597 */ 601 */
598 messagesDescription() { 602 messagesDescription() {
599 this._messagesDescriptionElement.removeChildren(); 603 this._messagesDescriptionElement.removeChildren();
600 UI.appendStyle(this._messagesDescriptionElement, 'source_frame/messagesPopov er.css'); 604 UI.appendStyle(this._messagesDescriptionElement, 'source_frame/messagesPopov er.css');
601 for (var i = 0; i < this._messages.length; ++i) 605 for (var i = 0; i < this._messages.length; ++i)
602 this._messagesDescriptionElement.appendChild(this._messages[i].element); 606 this._messagesDescriptionElement.appendChild(this._messages[i].element);
603 607
604 return this._messagesDescriptionElement; 608 return this._messagesDescriptionElement;
605 } 609 }
606 610
607 detachFromEditor() { 611 detachFromEditor() {
608 var position = this._lineHandle.resolve(); 612 var position = this._lineHandle.resolve();
609 if (!position) 613 if (!position)
610 return; 614 return;
611 var lineNumber = position.lineNumber; 615 var lineNumber = position.lineNumber;
612 if (this._level) 616 if (this._level)
613 this.textEditor.toggleLineClass(lineNumber, SourceFrame.UISourceCodeFrame. _lineClassPerLevel[this._level], false); 617 this.textEditor.toggleLineClass(lineNumber, SourceFrame.UISourceCodeFrame. _lineClassPerLevel[this._level], false);
614 if (this._hasDecoration) 618 if (this._decorationStartColumn !== null) {
615 this.textEditor.removeDecoration(this._decoration, lineNumber); 619 this.textEditor.removeDecoration(this._decoration, lineNumber);
616 this._hasDecoration = false; 620 this._decorationStartColumn = null;
621 }
617 } 622 }
618 623
619 /** 624 /**
620 * @return {number} 625 * @return {number}
621 */ 626 */
622 uniqueMessagesCount() { 627 uniqueMessagesCount() {
623 return this._messages.length; 628 return this._messages.length;
624 } 629 }
625 630
626 /** 631 /**
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 var columnNumber = Number.MAX_VALUE; 674 var columnNumber = Number.MAX_VALUE;
670 var maxMessage = null; 675 var maxMessage = null;
671 for (var i = 0; i < this._messages.length; ++i) { 676 for (var i = 0; i < this._messages.length; ++i) {
672 var message = this._messages[i].message(); 677 var message = this._messages[i].message();
673 columnNumber = Math.min(columnNumber, message.columnNumber()); 678 columnNumber = Math.min(columnNumber, message.columnNumber());
674 if (!maxMessage || Workspace.UISourceCode.Message.messageLevelComparator(m axMessage, message) < 0) 679 if (!maxMessage || Workspace.UISourceCode.Message.messageLevelComparator(m axMessage, message) < 0)
675 maxMessage = message; 680 maxMessage = message;
676 } 681 }
677 this._updateWavePosition(lineNumber, columnNumber); 682 this._updateWavePosition(lineNumber, columnNumber);
678 683
684 if (this._level === maxMessage.level())
685 return;
679 if (this._level) { 686 if (this._level) {
680 this.textEditor.toggleLineClass(lineNumber, SourceFrame.UISourceCodeFrame. _lineClassPerLevel[this._level], false); 687 this.textEditor.toggleLineClass(lineNumber, SourceFrame.UISourceCodeFrame. _lineClassPerLevel[this._level], false);
681 this._icon.type = ''; 688 this._icon.type = '';
682 } 689 }
683 this._level = maxMessage.level(); 690 this._level = maxMessage.level();
684 if (!this._level) 691 if (!this._level)
685 return; 692 return;
686 this.textEditor.toggleLineClass(lineNumber, SourceFrame.UISourceCodeFrame._l ineClassPerLevel[this._level], true); 693 this.textEditor.toggleLineClass(lineNumber, SourceFrame.UISourceCodeFrame._l ineClassPerLevel[this._level], true);
687 this._icon.type = SourceFrame.UISourceCodeFrame._iconClassPerLevel[this._lev el]; 694 this._icon.type = SourceFrame.UISourceCodeFrame._iconClassPerLevel[this._lev el];
688 } 695 }
689 }; 696 };
690 697
691 Workspace.UISourceCode.Message._messageLevelPriority = { 698 Workspace.UISourceCode.Message._messageLevelPriority = {
692 'Warning': 3, 699 'Warning': 3,
693 'Error': 4 700 'Error': 4
694 }; 701 };
695 702
696 /** 703 /**
697 * @param {!Workspace.UISourceCode.Message} a 704 * @param {!Workspace.UISourceCode.Message} a
698 * @param {!Workspace.UISourceCode.Message} b 705 * @param {!Workspace.UISourceCode.Message} b
699 * @return {number} 706 * @return {number}
700 */ 707 */
701 Workspace.UISourceCode.Message.messageLevelComparator = function(a, b) { 708 Workspace.UISourceCode.Message.messageLevelComparator = function(a, b) {
702 return Workspace.UISourceCode.Message._messageLevelPriority[a.level()] - 709 return Workspace.UISourceCode.Message._messageLevelPriority[a.level()] -
703 Workspace.UISourceCode.Message._messageLevelPriority[b.level()]; 710 Workspace.UISourceCode.Message._messageLevelPriority[b.level()];
704 }; 711 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698