Changeset 80346 in webkit


Ignore:
Timestamp:
Mar 4, 2011 6:20:01 AM (13 years ago)
Author:
podivilov@chromium.org
Message:

2011-03-04 Andrey Adaikin <aandrey@google.com>

Reviewed by Pavel Feldman.

Web Inspector: [Text editor] DOMNodeRemoved events are missing
https://bugs.webkit.org/show_bug.cgi?id=55769

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r80345 r80346  
     12011-03-04  Andrey Adaikin  <aandrey@google.com>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: [Text editor] DOMNodeRemoved events are missing
     6        https://bugs.webkit.org/show_bug.cgi?id=55769
     7
     8        * inspector/front-end/TextViewer.js:
     9        (WebInspector.TextEditorMainPanel):
     10        (WebInspector.TextEditorMainPanel.prototype._handleDOMUpdates):
     11        (WebInspector.TextEditorMainChunk):
     12        (WebInspector.TextEditorMainChunk.prototype._createRow):
     13
    1142011-03-04  Ilya Tikhonovsky  <loislo@chromium.org>
    215
  • trunk/Source/WebCore/inspector/front-end/TextViewer.js

    r80119 r80346  
    678678    this.element = document.createElement("div");
    679679    this.element.className = "text-editor-contents";
     680    this.element.tabIndex = 0;
    680681
    681682    this._container = document.createElement("div");
     
    690691        this._container.addEventListener("keydown", this._handleKeyDown.bind(this), false);
    691692
    692     var handleDOMUpdates = this._handleDOMUpdates.bind(this);
    693     this._container.addEventListener("DOMCharacterDataModified", handleDOMUpdates, false);
    694     this._container.addEventListener("DOMNodeInserted", handleDOMUpdates, false);
    695     this._container.addEventListener("DOMNodeRemoved", handleDOMUpdates, false);
    696     // For some reasons, in a few corner cases the events above are not able to catch the editings.
    697     // To workaround that we also listen to a more general event as a backup.
    698     this._container.addEventListener("DOMSubtreeModified", this._handleDOMSubtreeModified.bind(this), false);
     693    // In WebKit the DOMNodeRemoved event is fired AFTER the node is removed, thus it should be
     694    // attached to all DOM nodes that we want to track. Instead, we attach the DOMNodeRemoved
     695    // listeners only on the line rows, and use DOMSubtreeModified to track node removals inside
     696    // the line rows. For more info see: https://bugs.webkit.org/show_bug.cgi?id=55666
     697    this._handleDOMUpdatesCallback = this._handleDOMUpdates.bind(this);
     698    this._container.addEventListener("DOMCharacterDataModified", this._handleDOMUpdatesCallback, false);
     699    this._container.addEventListener("DOMNodeInserted", this._handleDOMUpdatesCallback, false);
     700    this._container.addEventListener("DOMSubtreeModified", this._handleDOMUpdatesCallback, false);
    699701
    700702    this.freeCachedElements();
     
    11281130            return;
    11291131
    1130         if (lineRow.decorationsElement && lineRow.decorationsElement.isAncestor(target)) {
    1131             if (this._syncDecorationsForLineListener) {
    1132                 // Wait until this event is processed and only then sync the sizes. This is necessary in
    1133                 // case of the DOMNodeRemoved event, because it is dispatched before the removal takes place.
    1134                 setTimeout(function() {
    1135                     this._syncDecorationsForLineListener(lineRow.lineNumber);
    1136                 }.bind(this), 0);
    1137             }
     1132        if (lineRow.decorationsElement && (lineRow.decorationsElement === target || lineRow.decorationsElement.isAncestor(target))) {
     1133            if (this._syncDecorationsForLineListener)
     1134                this._syncDecorationsForLineListener(lineRow.lineNumber);
    11381135            return;
    11391136        }
     
    11421139            return;
    11431140
    1144         if (target === lineRow && (e.type === "DOMNodeInserted" || e.type === "DOMNodeRemoved")) {
    1145             // The "lineNumber" (if any) is no longer valid for a line being removed or inserted.
    1146             delete lineRow.lineNumber;
    1147         }
    1148 
    1149         var startLine = 0;
    1150         for (var row = lineRow; row; row = row.previousSibling) {
    1151             if (typeof row.lineNumber === "number") {
    1152                 startLine = row.lineNumber;
    1153                 break;
    1154             }
    1155         }
    1156 
    1157         var endLine = this._textModel.linesCount;
    1158         for (var row = lineRow.nextSibling; row; row = row.nextSibling) {
    1159             if (typeof row.lineNumber === "number") {
    1160                 endLine = row.lineNumber;
    1161                 break;
    1162             }
    1163         }
    1164 
    1165         this._markDirtyLines(startLine, endLine);
    1166     },
    1167 
    1168     _handleDOMSubtreeModified: function(e)
    1169     {
    1170         if (this._domUpdateCoalescingLevel || this._readOnly || e.target !== this._container)
    1171             return;
    1172 
    1173         // Proceed only when other events failed to catch the DOM updates, otherwise it is not necessary.
    1174         if (this._dirtyLines)
    1175             return;
    1176 
    1177         var selection = this._getSelection();
    1178         if (!selection)
    1179             return;
    1180 
    1181         var startLine = Math.min(selection.startLine, selection.endLine);
    1182         var endLine = Math.max(selection.startLine, selection.endLine) + 1;
    1183         endLine = Math.min(this._textModel.linesCount, endLine);
    1184 
    1185         this._markDirtyLines(startLine, endLine);
    1186     },
    1187 
    1188     _markDirtyLines: function(startLine, endLine)
    1189     {
     1141        var lineNumber = lineRow.lineNumber;
    11901142        if (this._dirtyLines) {
    1191             this._dirtyLines.start = Math.min(this._dirtyLines.start, startLine);
    1192             this._dirtyLines.end = Math.max(this._dirtyLines.end, endLine);
     1143            this._dirtyLines.start = Math.min(this._dirtyLines.start, lineNumber);
     1144            this._dirtyLines.end = Math.max(this._dirtyLines.end, lineNumber + 1);
    11931145        } else {
    1194             this._dirtyLines = { start: startLine, end: endLine };
     1146            this._dirtyLines = { start: lineNumber, end: lineNumber + 1 };
    11951147            setTimeout(this._applyDomUpdates.bind(this), 0);
    11961148            // Remove marked ranges, if any.
     
    14501402    this.element.lineNumber = startLine;
    14511403    this.element.className = "webkit-line-content";
     1404    this.element.addEventListener("DOMNodeRemoved", this._textViewer._handleDOMUpdatesCallback, false);
    14521405
    14531406    this._startLine = startLine;
     
    15801533        lineRow.lineNumber = lineNumber;
    15811534        lineRow.className = "webkit-line-content";
     1535        lineRow.addEventListener("DOMNodeRemoved", this._textViewer._handleDOMUpdatesCallback, false);
    15821536        lineRow.textContent = this._textModel.line(lineNumber);
    15831537        if (!lineRow.textContent)
Note: See TracChangeset for help on using the changeset viewer.