Title: [141244] trunk
Revision
141244
Author
commit-qu...@webkit.org
Date
2013-01-30 03:49:40 -0800 (Wed, 30 Jan 2013)

Log Message

Web Inspector: do not repaint all lines in highlight regex API in DTE
https://bugs.webkit.org/show_bug.cgi?id=108081

Patch by Andrey Lushnikov <lushni...@chromium.org> on 2013-01-30
Reviewed by Pavel Feldman.

Source/WebCore:

Implement repaintLineRowsAffectedByHighlightDescriptor method that
will go through the visible lineRows and repaint only those of them
which were outdated by highlight change.

Improved test: inspector/editor/text-editor-highlight-regexp.html

* inspector/front-end/DefaultTextEditor.js:
(WebInspector.TextEditorMainPanel.prototype.highlightRegex):
(WebInspector.TextEditorMainPanel.prototype.removeRegexHighlight):
(WebInspector.TextEditorMainPanel.prototype._repaintLineRowsAffectedByHighlightDescriptor):
(WebInspector.TextEditorMainPanel.prototype._paintLines):
(WebInspector.TextEditorMainPanel.prototype._paintLineRows):

LayoutTests:

Modify layout test to add a verification that highlight does not
repaint more DefaultTextEditor line rows than it needs to.

* inspector/editor/text-editor-highlight-regexp-expected.txt:
* inspector/editor/text-editor-highlight-regexp.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (141243 => 141244)


--- trunk/LayoutTests/ChangeLog	2013-01-30 11:20:31 UTC (rev 141243)
+++ trunk/LayoutTests/ChangeLog	2013-01-30 11:49:40 UTC (rev 141244)
@@ -1,3 +1,16 @@
+2013-01-30  Andrey Lushnikov  <lushni...@chromium.org>
+
+        Web Inspector: do not repaint all lines in highlight regex API in DTE
+        https://bugs.webkit.org/show_bug.cgi?id=108081
+
+        Reviewed by Pavel Feldman.
+
+        Modify layout test to add a verification that highlight does not
+        repaint more DefaultTextEditor line rows than it needs to.
+
+        * inspector/editor/text-editor-highlight-regexp-expected.txt:
+        * inspector/editor/text-editor-highlight-regexp.html:
+
 2013-01-30  Tien-Ren Chen  <trc...@chromium.org>
 
         REGRESSION (r139282): Caret repainting is broken for text-align: center'd <input>

Modified: trunk/LayoutTests/inspector/editor/text-editor-highlight-regexp-expected.txt (141243 => 141244)


--- trunk/LayoutTests/inspector/editor/text-editor-highlight-regexp-expected.txt	2013-01-30 11:20:31 UTC (rev 141243)
+++ trunk/LayoutTests/inspector/editor/text-editor-highlight-regexp-expected.txt	2013-01-30 11:49:40 UTC (rev 141244)
@@ -14,6 +14,7 @@
 <div class="webkit-line-content">some_other_foo_X</div></div>
 
 Add highlight for regexp /foo_./
+Lines repainted: 2
 
 <div class="inner-container" tabindex="0">
 <div class="webkit-line-content">foo();</div>
@@ -24,6 +25,7 @@
 <div class="webkit-line-content">some_other_foo_X<span class="some-css-class text-editor-overlay-highlight" style="left: 76px; width: 37px;"> </span></div></div>
 
 Remove highlight for regexp /foo_./
+Lines repainted: 2
 
 <div class="inner-container" tabindex="0">
 <div class="webkit-line-content">foo();</div>

Modified: trunk/LayoutTests/inspector/editor/text-editor-highlight-regexp.html (141243 => 141244)


--- trunk/LayoutTests/inspector/editor/text-editor-highlight-regexp.html	2013-01-30 11:20:31 UTC (rev 141243)
+++ trunk/LayoutTests/inspector/editor/text-editor-highlight-regexp.html	2013-01-30 11:49:40 UTC (rev 141244)
@@ -19,13 +19,22 @@
             ];
             var textEditor = InspectorTest.createTestEditor();
             textEditor.setText(text.join("\n"));
+            var paintLineCalls = 0;
+            function paintLineCounter()
+            {
+                ++paintLineCalls;
+            }
+            InspectorTest.addSniffer(textEditor._mainPanel, "_paintLine", paintLineCounter, true);
             InspectorTest.addResult("\nBefore highlight");
             InspectorTest.dumpEditorHTML(textEditor, true);
             var highlightDescriptor = textEditor.highlightRegex("foo_.", "some-css-class");
             InspectorTest.addResult("\nAdd highlight for regexp /foo_./");
+            InspectorTest.addResult("Lines repainted: " + paintLineCalls);
+            paintLineCalls = 0;
             InspectorTest.dumpEditorHTML(textEditor, true);
             InspectorTest.addResult("\nRemove highlight for regexp /foo_./");
             textEditor.removeRegexHighlight(highlightDescriptor);
+            InspectorTest.addResult("Lines repainted: " + paintLineCalls);
             InspectorTest.dumpEditorHTML(textEditor, true);
             next();
         },

Modified: trunk/Source/WebCore/ChangeLog (141243 => 141244)


--- trunk/Source/WebCore/ChangeLog	2013-01-30 11:20:31 UTC (rev 141243)
+++ trunk/Source/WebCore/ChangeLog	2013-01-30 11:49:40 UTC (rev 141244)
@@ -1,3 +1,23 @@
+2013-01-30  Andrey Lushnikov  <lushni...@chromium.org>
+
+        Web Inspector: do not repaint all lines in highlight regex API in DTE
+        https://bugs.webkit.org/show_bug.cgi?id=108081
+
+        Reviewed by Pavel Feldman.
+
+        Implement repaintLineRowsAffectedByHighlightDescriptor method that
+        will go through the visible lineRows and repaint only those of them
+        which were outdated by highlight change.
+
+        Improved test: inspector/editor/text-editor-highlight-regexp.html
+
+        * inspector/front-end/DefaultTextEditor.js:
+        (WebInspector.TextEditorMainPanel.prototype.highlightRegex):
+        (WebInspector.TextEditorMainPanel.prototype.removeRegexHighlight):
+        (WebInspector.TextEditorMainPanel.prototype._repaintLineRowsAffectedByHighlightDescriptor):
+        (WebInspector.TextEditorMainPanel.prototype._paintLines):
+        (WebInspector.TextEditorMainPanel.prototype._paintLineRows):
+
 2013-01-30  Tien-Ren Chen  <trc...@chromium.org>
 
         REGRESSION (r139282): Caret repainting is broken for text-align: center'd <input>

Modified: trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js (141243 => 141244)


--- trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js	2013-01-30 11:20:31 UTC (rev 141243)
+++ trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js	2013-01-30 11:49:40 UTC (rev 141244)
@@ -1378,7 +1378,7 @@
     {
         var highlightDescriptor = new WebInspector.TextEditorMainPanel.RegexHighlightDescriptor(new RegExp(regex, "g"), cssClass);
         this._highlightDescriptors.push(highlightDescriptor);
-        this._repaintVisibleChunks();
+        this._repaintLineRowsAffectedByHighlightDescriptor(highlightDescriptor);
         return highlightDescriptor;
     },
 
@@ -1388,21 +1388,35 @@
     removeRegexHighlight: function(highlightDescriptor)
     {
         this._highlightDescriptors.remove(highlightDescriptor);
-        this._repaintVisibleChunks();
+        this._repaintLineRowsAffectedByHighlightDescriptor(highlightDescriptor);
     },
 
-    _repaintVisibleChunks: function()
+    /**
+     * @param {WebInspector.TextEditorMainPanel.HighlightDescriptor} highlightDescriptor
+     */
+    _repaintLineRowsAffectedByHighlightDescriptor: function(highlightDescriptor)
     {
         var visibleFrom = this.scrollTop();
         var visibleTo = visibleFrom + this.clientHeight();
 
         var visibleChunks = this.findVisibleChunks(visibleFrom, visibleTo);
-        var selection = this.selection();
 
-        for(var i = visibleChunks.start; i < visibleChunks.end; ++i) {
+        var affectedLineRows = [];
+        for (var i = visibleChunks.start; i < visibleChunks.end; ++i) {
             var chunk = this._textChunks[i];
-            this._paintLines(chunk._startLine, chunk._startLine + chunk.linesCount);
+            if (!chunk.expanded())
+                continue;
+            for (var lineNumber = chunk.startLine; lineNumber < chunk.startLine + chunk.linesCount; ++lineNumber) {
+                var lineRow = chunk.expandedLineRow(lineNumber);
+                var line = this._textModel.line(lineNumber);
+                if (highlightDescriptor.affectsLine(lineNumber, line))
+                    affectedLineRows.push(lineRow);
+            }
         }
+        if (affectedLineRows.length === 0)
+            return;
+        var selection = this.selection();
+        this._paintLineRows(affectedLineRows);
         this._restoreSelection(selection);
     },
 
@@ -1795,20 +1809,34 @@
      */
     _paintLines: function(fromLine, toLine, restoreSelection)
     {
+        var lineRows = [];
         var chunk;
-        var selection;
-        var lineRows = [];
         for (var lineNumber = fromLine; lineNumber < toLine; ++lineNumber) {
             if (!chunk || lineNumber < chunk.startLine || lineNumber >= chunk.startLine + chunk.linesCount)
                 chunk = this.chunkForLine(lineNumber);
             var lineRow = chunk.expandedLineRow(lineNumber);
             if (!lineRow)
                 continue;
-            if (restoreSelection && !selection)
-                selection = this.selection();
             lineRows.push(lineRow);
         }
+        if (lineRows.length === 0)
+            return;
 
+        var selection;
+        if (restoreSelection)
+            selection = this.selection();
+
+        this._paintLineRows(lineRows);
+
+        if (restoreSelection)
+            this._restoreSelection(selection);
+    },
+
+    /**
+     * @param {Array.<Element>} lineRows
+     */
+    _paintLineRows: function(lineRows)
+    {
         var highlight = {};
         this.beginDomUpdates();
         for(var i = 0; i < this._highlightDescriptors.length; ++i) {
@@ -1820,9 +1848,6 @@
             this._paintLine(lineRows[i], highlight[lineRows[i].lineNumber]);
 
         this.endDomUpdates();
-
-        if (restoreSelection)
-            this._restoreSelection(selection);
     },
 
     /**
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to