Makes the JavaScript syntax highlighter process lines in chunks
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jun 2008 19:26:52 +0000 (19:26 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jun 2008 19:26:52 +0000 (19:26 +0000)
        so the user interface isn't blocked for large script files.

        https://bugs.webkit.org/show_bug.cgi?id=19677

        Reviewed by Adam Roben.

        * page/inspector/SourceFrame.js:
        (WebInspector.SourceFrame.prototype._addMessageToSource): Use the cells
        property on the row instead of getElementsByTagName.
        (WebInspector.SourceFrame.prototype.syntaxHighlightJavascript): Use the
        cells property on the row instead of getElementsByTagName. Added
        a nested processChunk function that highlights 10 lines at a time
        This processChunk function is called at an interval of 25ms. The
        code is still highlighted quickly, and the user can't tell it wasn't
        highlighted all at once.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@34695 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/page/inspector/SourceFrame.js

index 95b04ff..7d87f5e 100644 (file)
@@ -1,5 +1,24 @@
 2008-06-20  Timothy Hatcher  <timothy@apple.com>
 
+        Makes the JavaScript syntax highlighter process lines in chunks
+        so the user interface isn't blocked for large script files.
+
+        https://bugs.webkit.org/show_bug.cgi?id=19677
+
+        Reviewed by Adam Roben.
+
+        * page/inspector/SourceFrame.js:
+        (WebInspector.SourceFrame.prototype._addMessageToSource): Use the cells
+        property on the row instead of getElementsByTagName.
+        (WebInspector.SourceFrame.prototype.syntaxHighlightJavascript): Use the
+        cells property on the row instead of getElementsByTagName. Added
+        a nested processChunk function that highlights 10 lines at a time
+        This processChunk function is called at an interval of 25ms. The
+        code is still highlighted quickly, and the user can't tell it wasn't
+        highlighted all at once.
+
+2008-06-20  Timothy Hatcher  <timothy@apple.com>
+
         Fixes a bug where the source view in the Resources panel had a
         couple of extra pixels at the bottom when fully scrolled.
 
index 3ddaa56..33d1faf 100644 (file)
@@ -321,7 +321,7 @@ WebInspector.SourceFrame.prototype = {
         if (!row)
             return;
 
-        var cell = row.getElementsByTagName("td")[1];
+        var cell = row.cells[1];
         if (!cell)
             return;
 
@@ -594,9 +594,11 @@ WebInspector.SourceFrame.prototype = {
         if (!table)
             return;
 
+        var i = 0;
         var rows = table.rows;
         var rowsLength = rows.length;
         var previousCell = null;
+        var processChunkInterval;
 
         function deleteContinueFlags(cell)
         {
@@ -608,16 +610,31 @@ WebInspector.SourceFrame.prototype = {
             delete cell._regexpContinues;
         }
 
-        for (var i = 0; i < rowsLength; ++i) {
-            var row = rows[i];
-            var cell = row.getElementsByTagName("td")[1];
-            if (!cell)
-                continue;
-            this._syntaxHighlightJavascriptLine(cell, previousCell);
-            deleteContinueFlags(previousCell);
-            previousCell = cell;
+        // Split up the work into chunks so we don't block the
+        // UI thread while processing.
+
+        function processChunk()
+        {
+            for (var end = Math.min(i + 10, rowsLength); i < end; ++i) {
+                var row = rows[i];
+                if (!row)
+                    continue;
+                var cell = row.cells[1];
+                if (!cell)
+                    continue;
+                this._syntaxHighlightJavascriptLine(cell, previousCell);
+                if (i < (end - 1))
+                    deleteContinueFlags(previousCell);
+                previousCell = cell;
+            }
+
+            if (i >= rowsLength && processChunkInterval) {
+                deleteContinueFlags(previousCell);
+                clearInterval(processChunkInterval);
+            }
         }
 
-        deleteContinueFlags(previousCell);
+        processChunk.call(this);
+        processChunkInterval = setInterval(processChunk.bind(this), 25);
     }
 }