Changeset 141244 in webkit


Ignore:
Timestamp:
Jan 30, 2013 3:49:40 AM (11 years ago)
Author:
commit-queue@webkit.org
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 <lushnikov@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:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r141243 r141244  
     12013-01-30  Andrey Lushnikov  <lushnikov@chromium.org>
     2
     3        Web Inspector: do not repaint all lines in highlight regex API in DTE
     4        https://bugs.webkit.org/show_bug.cgi?id=108081
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Modify layout test to add a verification that highlight does not
     9        repaint more DefaultTextEditor line rows than it needs to.
     10
     11        * inspector/editor/text-editor-highlight-regexp-expected.txt:
     12        * inspector/editor/text-editor-highlight-regexp.html:
     13
    1142013-01-30  Tien-Ren Chen  <trchen@chromium.org>
    215
  • trunk/LayoutTests/inspector/editor/text-editor-highlight-regexp-expected.txt

    r140556 r141244  
    1515
    1616Add highlight for regexp /foo_./
     17Lines repainted: 2
    1718
    1819<div class="inner-container" tabindex="0">
     
    2526
    2627Remove highlight for regexp /foo_./
     28Lines repainted: 2
    2729
    2830<div class="inner-container" tabindex="0">
  • trunk/LayoutTests/inspector/editor/text-editor-highlight-regexp.html

    r141111 r141244  
    2020            var textEditor = InspectorTest.createTestEditor();
    2121            textEditor.setText(text.join("\n"));
     22            var paintLineCalls = 0;
     23            function paintLineCounter()
     24            {
     25                ++paintLineCalls;
     26            }
     27            InspectorTest.addSniffer(textEditor._mainPanel, "_paintLine", paintLineCounter, true);
    2228            InspectorTest.addResult("\nBefore highlight");
    2329            InspectorTest.dumpEditorHTML(textEditor, true);
    2430            var highlightDescriptor = textEditor.highlightRegex("foo_.", "some-css-class");
    2531            InspectorTest.addResult("\nAdd highlight for regexp /foo_./");
     32            InspectorTest.addResult("Lines repainted: " + paintLineCalls);
     33            paintLineCalls = 0;
    2634            InspectorTest.dumpEditorHTML(textEditor, true);
    2735            InspectorTest.addResult("\nRemove highlight for regexp /foo_./");
    2836            textEditor.removeRegexHighlight(highlightDescriptor);
     37            InspectorTest.addResult("Lines repainted: " + paintLineCalls);
    2938            InspectorTest.dumpEditorHTML(textEditor, true);
    3039            next();
  • trunk/Source/WebCore/ChangeLog

    r141243 r141244  
     12013-01-30  Andrey Lushnikov  <lushnikov@chromium.org>
     2
     3        Web Inspector: do not repaint all lines in highlight regex API in DTE
     4        https://bugs.webkit.org/show_bug.cgi?id=108081
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Implement repaintLineRowsAffectedByHighlightDescriptor method that
     9        will go through the visible lineRows and repaint only those of them
     10        which were outdated by highlight change.
     11
     12        Improved test: inspector/editor/text-editor-highlight-regexp.html
     13
     14        * inspector/front-end/DefaultTextEditor.js:
     15        (WebInspector.TextEditorMainPanel.prototype.highlightRegex):
     16        (WebInspector.TextEditorMainPanel.prototype.removeRegexHighlight):
     17        (WebInspector.TextEditorMainPanel.prototype._repaintLineRowsAffectedByHighlightDescriptor):
     18        (WebInspector.TextEditorMainPanel.prototype._paintLines):
     19        (WebInspector.TextEditorMainPanel.prototype._paintLineRows):
     20
    1212013-01-30  Tien-Ren Chen  <trchen@chromium.org>
    222
  • trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js

    r141230 r141244  
    13791379        var highlightDescriptor = new WebInspector.TextEditorMainPanel.RegexHighlightDescriptor(new RegExp(regex, "g"), cssClass);
    13801380        this._highlightDescriptors.push(highlightDescriptor);
    1381         this._repaintVisibleChunks();
     1381        this._repaintLineRowsAffectedByHighlightDescriptor(highlightDescriptor);
    13821382        return highlightDescriptor;
    13831383    },
     
    13891389    {
    13901390        this._highlightDescriptors.remove(highlightDescriptor);
    1391         this._repaintVisibleChunks();
    1392     },
    1393 
    1394     _repaintVisibleChunks: function()
     1391        this._repaintLineRowsAffectedByHighlightDescriptor(highlightDescriptor);
     1392    },
     1393
     1394    /**
     1395     * @param {WebInspector.TextEditorMainPanel.HighlightDescriptor} highlightDescriptor
     1396     */
     1397    _repaintLineRowsAffectedByHighlightDescriptor: function(highlightDescriptor)
    13951398    {
    13961399        var visibleFrom = this.scrollTop();
     
    13981401
    13991402        var visibleChunks = this.findVisibleChunks(visibleFrom, visibleTo);
     1403
     1404        var affectedLineRows = [];
     1405        for (var i = visibleChunks.start; i < visibleChunks.end; ++i) {
     1406            var chunk = this._textChunks[i];
     1407            if (!chunk.expanded())
     1408                continue;
     1409            for (var lineNumber = chunk.startLine; lineNumber < chunk.startLine + chunk.linesCount; ++lineNumber) {
     1410                var lineRow = chunk.expandedLineRow(lineNumber);
     1411                var line = this._textModel.line(lineNumber);
     1412                if (highlightDescriptor.affectsLine(lineNumber, line))
     1413                    affectedLineRows.push(lineRow);
     1414            }
     1415        }
     1416        if (affectedLineRows.length === 0)
     1417            return;
    14001418        var selection = this.selection();
    1401 
    1402         for(var i = visibleChunks.start; i < visibleChunks.end; ++i) {
    1403             var chunk = this._textChunks[i];
    1404             this._paintLines(chunk._startLine, chunk._startLine + chunk.linesCount);
    1405         }
     1419        this._paintLineRows(affectedLineRows);
    14061420        this._restoreSelection(selection);
    14071421    },
     
    17961810    _paintLines: function(fromLine, toLine, restoreSelection)
    17971811    {
     1812        var lineRows = [];
    17981813        var chunk;
    1799         var selection;
    1800         var lineRows = [];
    18011814        for (var lineNumber = fromLine; lineNumber < toLine; ++lineNumber) {
    18021815            if (!chunk || lineNumber < chunk.startLine || lineNumber >= chunk.startLine + chunk.linesCount)
     
    18051818            if (!lineRow)
    18061819                continue;
    1807             if (restoreSelection && !selection)
    1808                 selection = this.selection();
    18091820            lineRows.push(lineRow);
    18101821        }
    1811 
     1822        if (lineRows.length === 0)
     1823            return;
     1824
     1825        var selection;
     1826        if (restoreSelection)
     1827            selection = this.selection();
     1828
     1829        this._paintLineRows(lineRows);
     1830
     1831        if (restoreSelection)
     1832            this._restoreSelection(selection);
     1833    },
     1834
     1835    /**
     1836     * @param {Array.<Element>} lineRows
     1837     */
     1838    _paintLineRows: function(lineRows)
     1839    {
    18121840        var highlight = {};
    18131841        this.beginDomUpdates();
     
    18211849
    18221850        this.endDomUpdates();
    1823 
    1824         if (restoreSelection)
    1825             this._restoreSelection(selection);
    18261851    },
    18271852
Note: See TracChangeset for help on using the changeset viewer.