Title: [141111] trunk
Revision
141111
Author
[email protected]
Date
2013-01-29 07:52:00 -0800 (Tue, 29 Jan 2013)

Log Message

Web Inspector: introduce HighlightDescriptor interface in DTE.
https://bugs.webkit.org/show_bug.cgi?id=108161

Patch by Andrey Lushnikov <[email protected]> on 2013-01-29
Reviewed by Pavel Feldman.

Source/WebCore:

Introduce new HighlightDescriptor interface and its
RegexHighlightDescriptor implementation and use it in DTE to
support overlay highlight.

No new tests: no change in behaviour.

* inspector/front-end/DefaultTextEditor.js:
(WebInspector.DefaultTextEditor.prototype.highlightRegex):
(WebInspector.DefaultTextEditor.prototype.removeRegexHighlight):
(WebInspector.TextEditorMainPanel):
(WebInspector.TextEditorMainPanel.prototype.highlightRegex):
(WebInspector.TextEditorMainPanel.prototype.removeRegexHighlight):
(WebInspector.TextEditorMainPanel.prototype._paintLines):
(WebInspector.TextEditorMainPanel.prototype._measureHighlightDescriptor):
(WebInspector.TextEditorMainPanel.HighlightDescriptor): Added.
(WebInspector.TextEditorMainPanel.HighlightDescriptor.prototype.affectsLine):
(WebInspector.TextEditorMainPanel.HighlightDescriptor.prototype.rangesForLine):
(WebInspector.TextEditorMainPanel.HighlightDescriptor.prototype.cssClass):
(WebInspector.TextEditorMainPanel.RegexHighlightDescriptor): Added.
(WebInspector.TextEditorMainPanel.RegexHighlightDescriptor.prototype.affectsLine):
(WebInspector.TextEditorMainPanel.RegexHighlightDescriptor.prototype.rangesForLine):
(WebInspector.TextEditorMainPanel.RegexHighlightDescriptor.prototype.cssClass):
(WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._highlight):
(WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._removeHighlight):
* inspector/front-end/TextEditor.js:
(WebInspector.TextEditor.prototype.removeRegexHighlight):

LayoutTests:

Correct layout test according to refactoring changes.

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

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (141110 => 141111)


--- trunk/LayoutTests/ChangeLog	2013-01-29 15:29:48 UTC (rev 141110)
+++ trunk/LayoutTests/ChangeLog	2013-01-29 15:52:00 UTC (rev 141111)
@@ -1,3 +1,14 @@
+2013-01-29  Andrey Lushnikov  <[email protected]>
+
+        Web Inspector: introduce HighlightDescriptor interface in DTE.
+        https://bugs.webkit.org/show_bug.cgi?id=108161
+
+        Reviewed by Pavel Feldman.
+
+        Correct layout test according to refactoring changes.
+
+        * inspector/editor/text-editor-highlight-regexp.html:
+
 2013-01-29  Grzegorz Czajkowski  <[email protected]>
 
         [EFL] Unified text checker implementation.

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


--- trunk/LayoutTests/inspector/editor/text-editor-highlight-regexp.html	2013-01-29 15:29:48 UTC (rev 141110)
+++ trunk/LayoutTests/inspector/editor/text-editor-highlight-regexp.html	2013-01-29 15:52:00 UTC (rev 141111)
@@ -21,11 +21,11 @@
             textEditor.setText(text.join("\n"));
             InspectorTest.addResult("\nBefore highlight");
             InspectorTest.dumpEditorHTML(textEditor, true);
-            textEditor.highlightRegex("foo_.", "some-css-class");
+            var highlightDescriptor = textEditor.highlightRegex("foo_.", "some-css-class");
             InspectorTest.addResult("\nAdd highlight for regexp /foo_./");
             InspectorTest.dumpEditorHTML(textEditor, true);
             InspectorTest.addResult("\nRemove highlight for regexp /foo_./");
-            textEditor.removeRegexHighlight("foo_.");
+            textEditor.removeRegexHighlight(highlightDescriptor);
             InspectorTest.dumpEditorHTML(textEditor, true);
             next();
         },

Modified: trunk/Source/WebCore/ChangeLog (141110 => 141111)


--- trunk/Source/WebCore/ChangeLog	2013-01-29 15:29:48 UTC (rev 141110)
+++ trunk/Source/WebCore/ChangeLog	2013-01-29 15:52:00 UTC (rev 141111)
@@ -1,3 +1,37 @@
+2013-01-29  Andrey Lushnikov  <[email protected]>
+
+        Web Inspector: introduce HighlightDescriptor interface in DTE.
+        https://bugs.webkit.org/show_bug.cgi?id=108161
+
+        Reviewed by Pavel Feldman.
+
+        Introduce new HighlightDescriptor interface and its
+        RegexHighlightDescriptor implementation and use it in DTE to
+        support overlay highlight.
+
+        No new tests: no change in behaviour.
+
+        * inspector/front-end/DefaultTextEditor.js:
+        (WebInspector.DefaultTextEditor.prototype.highlightRegex):
+        (WebInspector.DefaultTextEditor.prototype.removeRegexHighlight):
+        (WebInspector.TextEditorMainPanel):
+        (WebInspector.TextEditorMainPanel.prototype.highlightRegex):
+        (WebInspector.TextEditorMainPanel.prototype.removeRegexHighlight):
+        (WebInspector.TextEditorMainPanel.prototype._paintLines):
+        (WebInspector.TextEditorMainPanel.prototype._measureHighlightDescriptor):
+        (WebInspector.TextEditorMainPanel.HighlightDescriptor): Added.
+        (WebInspector.TextEditorMainPanel.HighlightDescriptor.prototype.affectsLine):
+        (WebInspector.TextEditorMainPanel.HighlightDescriptor.prototype.rangesForLine):
+        (WebInspector.TextEditorMainPanel.HighlightDescriptor.prototype.cssClass):
+        (WebInspector.TextEditorMainPanel.RegexHighlightDescriptor): Added.
+        (WebInspector.TextEditorMainPanel.RegexHighlightDescriptor.prototype.affectsLine):
+        (WebInspector.TextEditorMainPanel.RegexHighlightDescriptor.prototype.rangesForLine):
+        (WebInspector.TextEditorMainPanel.RegexHighlightDescriptor.prototype.cssClass):
+        (WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._highlight):
+        (WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._removeHighlight):
+        * inspector/front-end/TextEditor.js:
+        (WebInspector.TextEditor.prototype.removeRegexHighlight):
+
 2013-01-29  Grzegorz Czajkowski  <[email protected]>
 
         [EFL] Unified text checker implementation.

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


--- trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js	2013-01-29 15:29:48 UTC (rev 141110)
+++ trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js	2013-01-29 15:52:00 UTC (rev 141111)
@@ -112,19 +112,19 @@
     /**
      * @param {string} regex
      * @param {string} cssClass
+     * @return {WebInspector.TextEditorMainPanel.HighlightDescriptor}
      */
     highlightRegex: function(regex, cssClass)
     {
-        this._mainPanel.highlightRegex(regex, cssClass);
+        return this._mainPanel.highlightRegex(regex, cssClass);
     },
 
     /**
-     * @param {string} regex
-     * @return {boolean}
+     * @param {WebInspector.TextEditorMainPanel.HighlightDescriptor} highlightDescriptor
      */
-    removeRegexHighlight: function(regex)
+    removeRegexHighlight: function(highlightDescriptor)
     {
-        return this._mainPanel.removeRegexHighlight(regex);
+        this._mainPanel.removeRegexHighlight(highlightDescriptor);
     },
 
     /**
@@ -1360,7 +1360,7 @@
 
     this._container.addEventListener("focus", this._handleFocused.bind(this), false);
 
-    this._highlightRegexs = {};
+    this._highlightDescriptors = [];
 
     this._tokenHighlighter = new WebInspector.TextEditorMainPanel.TokenHighlighter(this, textModel);
 
@@ -1372,25 +1372,23 @@
     /**
      * @param {string} regex
      * @param {string} cssClass
+     * @return {WebInspector.TextEditorMainPanel.HighlightDescriptor}
      */
     highlightRegex: function(regex, cssClass)
     {
-        this._highlightRegexs[regex] = {
-            regex: new RegExp(regex, "g"),
-            cssClass: cssClass
-        };
+        var highlightDescriptor = new WebInspector.TextEditorMainPanel.RegexHighlightDescriptor(new RegExp(regex, "g"), cssClass);
+        this._highlightDescriptors.push(highlightDescriptor);
         this._repaintVisibleChunks();
+        return highlightDescriptor;
     },
 
     /**
-     * @param {string} regex
-     * @return {boolean}
+     * @param {WebInspector.TextEditorMainPanel.HighlightDescriptor} highlightDescriptor
      */
-    removeRegexHighlight: function(regex)
+    removeRegexHighlight: function(highlightDescriptor)
     {
-        var result = delete this._highlightRegexs[regex];
+        this._highlightDescriptors.remove(highlightDescriptor);
         this._repaintVisibleChunks();
-        return result;
     },
 
     _repaintVisibleChunks: function()
@@ -1813,9 +1811,9 @@
 
         var highlight = {};
         this.beginDomUpdates();
-        for(var regexString in this._highlightRegexs) {
-            var regexHighlightDescriptor = this._highlightRegexs[regexString];
-            this._measureRegexHighlight(highlight, lineRows, regexHighlightDescriptor.regex, regexHighlightDescriptor.cssClass);
+        for(var i = 0; i < this._highlightDescriptors.length; ++i) {
+            var highlightDescriptor = this._highlightDescriptors[i];
+            this._measureHighlightDescriptor(highlight, lineRows, highlightDescriptor);
         }
 
         for(var i = 0; i < lineRows.length; ++i)
@@ -1828,36 +1826,17 @@
     },
 
     /**
-     * @param {string} line
-     * @param {RegExp} regex
-     * @return {Array.<{startColumn: number, endColumn: number}>}
-     */
-    _findRegexOccurrences: function(line, regex)
-    {
-        var ranges = [];
-        var regexResult;
-        while (regexResult = regex.exec(line)) {
-            ranges.push({
-                startColumn: regexResult.index,
-                endColumn: regexResult.index + regexResult[0].length - 1
-            });
-        }
-        return ranges;
-    },
-
-    /**
      * @param {Object.<number, Array.<WebInspector.TextEditorMainPanel.LineOverlayHighlight>>} highlight
      * @param {Array.<Element>} lineRows
-     * @param {RegExp} regex
-     * @param {string} cssClass
+     * @param {WebInspector.TextEditorMainPanel.HighlightDescriptor} highlightDescriptor
      */
-    _measureRegexHighlight: function(highlight, lineRows, regex, cssClass)
+    _measureHighlightDescriptor: function(highlight, lineRows, highlightDescriptor)
     {
         var rowsToMeasure = [];
         for(var i = 0; i < lineRows.length; ++i) {
             var lineRow = lineRows[i];
             var line = this._textModel.line(lineRow.lineNumber);
-            var ranges = this._findRegexOccurrences(line, regex);
+            var ranges = highlightDescriptor.rangesForLine(lineRow.lineNumber, line);
             if (ranges.length === 0)
                 continue;
 
@@ -1873,7 +1852,7 @@
             if (!highlight[lineNumber])
                 highlight[lineNumber] = [];
 
-            highlight[lineNumber].push(new WebInspector.TextEditorMainPanel.LineOverlayHighlight(metrics, cssClass));
+            highlight[lineNumber].push(new WebInspector.TextEditorMainPanel.LineOverlayHighlight(metrics, highlightDescriptor.cssClass()));
         }
     },
 
@@ -2669,7 +2648,83 @@
 }
 
 /**
+ * @interface
+ */
+WebInspector.TextEditorMainPanel.HighlightDescriptor = function() { }
+
+WebInspector.TextEditorMainPanel.HighlightDescriptor.prototype = {
+    /**
+     * @param {number} lineNumber
+     * @param {string} line
+     * @return {boolean}
+     */
+    affectsLine: function(lineNumber, line) { return false; },
+
+    /**
+     * @param {number} lineNumber
+     * @param {string} line
+     * @return {Array.<{startColumn: number, endColumn: number}>}
+     */
+    rangesForLine: function(lineNumber, line) { return []; },
+
+    /**
+     * @return {string}
+     */
+    cssClass: function() { return ""; },
+}
+
+/**
  * @constructor
+ * @implements {WebInspector.TextEditorMainPanel.HighlightDescriptor}
+ */
+WebInspector.TextEditorMainPanel.RegexHighlightDescriptor = function(regex, cssClass)
+{
+    this._cssClass = cssClass;
+    this._regex = regex;
+}
+
+WebInspector.TextEditorMainPanel.RegexHighlightDescriptor.prototype = {
+    /**
+     * @param {number} lineNumber
+     * @param {string} line
+     * @return {boolean}
+     */
+    affectsLine: function(lineNumber, line)
+    {
+        this._regex.lastIndex = 0;
+        return this._regex.test(line);
+    },
+
+    /**
+     * @param {number} lineNumber
+     * @param {string} line
+     * @return {Array.<{startColumn: number, endColumn: number}>}
+     */
+    rangesForLine: function(lineNumber, line)
+    {
+        var ranges = [];
+        var regexResult;
+        this._regex.lastIndex = 0;
+        while (regexResult = this._regex.exec(line)) {
+            ranges.push({
+                startColumn: regexResult.index,
+                endColumn: regexResult.index + regexResult[0].length - 1
+            });
+        }
+        return ranges;
+    },
+
+    /**
+     * @return {string}
+     */
+    cssClass: function()
+    {
+        return this._cssClass;
+    }
+}
+
+/**
+ * @constructor
  * @param {Element} element
  */
 WebInspector.TextEditorMainPanel.ElementMetrics = function(element)
@@ -3009,14 +3064,15 @@
     {
         this._removeHighlight();
         this._selectedWord = selectedWord;
-        this._mainPanel.highlightRegex(this._regexString(selectedWord), "text-editor-token-highlight")
+        this._highlightDescriptor = this._mainPanel.highlightRegex(this._regexString(selectedWord), "text-editor-token-highlight")
     },
 
     _removeHighlight: function()
     {
         if (this._selectedWord) {
-            this._mainPanel.removeRegexHighlight(this._regexString(this._selectedWord));
+            this._mainPanel.removeRegexHighlight(this._highlightDescriptor);
             delete this._selectedWord;
+            delete this._highlightDescriptor;
         }
     },
 

Modified: trunk/Source/WebCore/inspector/front-end/TextEditor.js (141110 => 141111)


--- trunk/Source/WebCore/inspector/front-end/TextEditor.js	2013-01-29 15:29:48 UTC (rev 141110)
+++ trunk/Source/WebCore/inspector/front-end/TextEditor.js	2013-01-29 15:52:00 UTC (rev 141111)
@@ -63,14 +63,14 @@
     /**
      * @param {string} regex
      * @param {string} cssClass
+     * @return {WebInspector.TextEditorMainPanel.HighlightDescriptor}
      */
     highlightRegex: function(regex, cssClass) { },
 
     /**
-     * @param {string} regex
-     * @return {boolean}
+     * @param {WebInspector.TextEditorMainPanel.HighlightDescriptor} highlightDescriptor
      */
-    removeRegexHighlight: function(regex) { },
+    removeRegexHighlight: function(highlightDescriptor) { },
 
     /**
      * @param {number} lineNumber
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to