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

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: rebase and update Created 3 years, 7 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);
590 this.textEditor.removeDecoration(this._decoration, lineNumber); 591 var columnChanged = this._decorationStartColumn !== startColumn;
591 this._hasDecoration = true; 592 if (columnChanged) {
dgozman 2017/04/26 00:03:55 if (this._decorationStartColumn === startColumn)
luoe 2017/04/26 00:12:38 Done.
592 this.textEditor.addDecoration(this._decoration, lineNumber, Math.max(columnN umber - 1, lineIndent)); 593 if (this._decorationStartColumn !== null)
594 this.textEditor.removeDecoration(this._decoration, lineNumber);
595 this.textEditor.addDecoration(this._decoration, lineNumber, startColumn);
596 this._decorationStartColumn = startColumn;
597 }
593 } 598 }
594 599
595 /** 600 /**
596 * @return {!Element} 601 * @return {!Element}
597 */ 602 */
598 messagesDescription() { 603 messagesDescription() {
599 this._messagesDescriptionElement.removeChildren(); 604 this._messagesDescriptionElement.removeChildren();
600 UI.appendStyle(this._messagesDescriptionElement, 'source_frame/messagesPopov er.css'); 605 UI.appendStyle(this._messagesDescriptionElement, 'source_frame/messagesPopov er.css');
601 for (var i = 0; i < this._messages.length; ++i) 606 for (var i = 0; i < this._messages.length; ++i)
602 this._messagesDescriptionElement.appendChild(this._messages[i].element); 607 this._messagesDescriptionElement.appendChild(this._messages[i].element);
603 608
604 return this._messagesDescriptionElement; 609 return this._messagesDescriptionElement;
605 } 610 }
606 611
607 detachFromEditor() { 612 detachFromEditor() {
608 var position = this._lineHandle.resolve(); 613 var position = this._lineHandle.resolve();
609 if (!position) 614 if (!position)
610 return; 615 return;
611 var lineNumber = position.lineNumber; 616 var lineNumber = position.lineNumber;
612 if (this._level) 617 if (this._level)
613 this.textEditor.toggleLineClass(lineNumber, SourceFrame.UISourceCodeFrame. _lineClassPerLevel[this._level], false); 618 this.textEditor.toggleLineClass(lineNumber, SourceFrame.UISourceCodeFrame. _lineClassPerLevel[this._level], false);
614 if (this._hasDecoration) 619 if (this._decorationStartColumn !== null) {
615 this.textEditor.removeDecoration(this._decoration, lineNumber); 620 this.textEditor.removeDecoration(this._decoration, lineNumber);
616 this._hasDecoration = false; 621 this._decorationStartColumn = null;
622 }
617 } 623 }
618 624
619 /** 625 /**
620 * @return {number} 626 * @return {number}
621 */ 627 */
622 uniqueMessagesCount() { 628 uniqueMessagesCount() {
623 return this._messages.length; 629 return this._messages.length;
624 } 630 }
625 631
626 /** 632 /**
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 var columnNumber = Number.MAX_VALUE; 675 var columnNumber = Number.MAX_VALUE;
670 var maxMessage = null; 676 var maxMessage = null;
671 for (var i = 0; i < this._messages.length; ++i) { 677 for (var i = 0; i < this._messages.length; ++i) {
672 var message = this._messages[i].message(); 678 var message = this._messages[i].message();
673 columnNumber = Math.min(columnNumber, message.columnNumber()); 679 columnNumber = Math.min(columnNumber, message.columnNumber());
674 if (!maxMessage || Workspace.UISourceCode.Message.messageLevelComparator(m axMessage, message) < 0) 680 if (!maxMessage || Workspace.UISourceCode.Message.messageLevelComparator(m axMessage, message) < 0)
675 maxMessage = message; 681 maxMessage = message;
676 } 682 }
677 this._updateWavePosition(lineNumber, columnNumber); 683 this._updateWavePosition(lineNumber, columnNumber);
678 684
679 if (this._level) { 685 var newLevel = maxMessage.level();
680 this.textEditor.toggleLineClass(lineNumber, SourceFrame.UISourceCodeFrame. _lineClassPerLevel[this._level], false); 686 var wasLevelChanged = newLevel !== this._level;
681 this._icon.type = ''; 687 if (wasLevelChanged) {
dgozman 2017/04/26 00:03:55 I think we can leave previous code intact and just
luoe 2017/04/26 00:12:38 Done.
688 if (this._level) {
689 var oldLineClass = SourceFrame.UISourceCodeFrame._lineClassPerLevel[this ._level];
690 this.textEditor.toggleLineClass(lineNumber, oldLineClass, false);
691 }
692 if (newLevel) {
693 var newLineClass = SourceFrame.UISourceCodeFrame._lineClassPerLevel[newL evel];
694 this.textEditor.toggleLineClass(lineNumber, newLineClass, true);
695 this._icon.type = SourceFrame.UISourceCodeFrame._iconClassPerLevel[newLe vel];
696 } else {
697 this._icon.type = '';
698 }
699 this._level = newLevel;
682 } 700 }
683 this._level = maxMessage.level();
684 if (!this._level)
685 return;
686 this.textEditor.toggleLineClass(lineNumber, SourceFrame.UISourceCodeFrame._l ineClassPerLevel[this._level], true);
687 this._icon.type = SourceFrame.UISourceCodeFrame._iconClassPerLevel[this._lev el];
688 } 701 }
689 }; 702 };
690 703
691 Workspace.UISourceCode.Message._messageLevelPriority = { 704 Workspace.UISourceCode.Message._messageLevelPriority = {
692 'Warning': 3, 705 'Warning': 3,
693 'Error': 4 706 'Error': 4
694 }; 707 };
695 708
696 /** 709 /**
697 * @param {!Workspace.UISourceCode.Message} a 710 * @param {!Workspace.UISourceCode.Message} a
698 * @param {!Workspace.UISourceCode.Message} b 711 * @param {!Workspace.UISourceCode.Message} b
699 * @return {number} 712 * @return {number}
700 */ 713 */
701 Workspace.UISourceCode.Message.messageLevelComparator = function(a, b) { 714 Workspace.UISourceCode.Message.messageLevelComparator = function(a, b) {
702 return Workspace.UISourceCode.Message._messageLevelPriority[a.level()] - 715 return Workspace.UISourceCode.Message._messageLevelPriority[a.level()] -
703 Workspace.UISourceCode.Message._messageLevelPriority[b.level()]; 716 Workspace.UISourceCode.Message._messageLevelPriority[b.level()];
704 }; 717 };
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