Web Inspector: evaluate on hover regressed with the editor change
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Nov 2012 22:30:02 +0000 (22:30 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Nov 2012 22:30:02 +0000 (22:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=103063

Reviewed by Vsevolod Vlasov.

We are no longer mutating the editor's dom from outside.

* inspector/front-end/DOMExtension.js:
(Element.prototype.remove):
* inspector/front-end/DefaultTextEditor.js:
(WebInspector.DefaultTextEditor.prototype.highlightRangesWithStyleClass):
(WebInspector.DefaultTextEditor.prototype.highlightExpression):
(WebInspector.DefaultTextEditor.prototype.hideHighlightedExpression):
* inspector/front-end/JavaScriptSourceFrame.js:
(WebInspector.JavaScriptSourceFrame.prototype._getPopoverAnchor):
(WebInspector.JavaScriptSourceFrame.prototype._onHidePopover):
(WebInspector.JavaScriptSourceFrame.prototype._highlightExpression):

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

Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/DOMExtension.js
Source/WebCore/inspector/front-end/DefaultTextEditor.js
Source/WebCore/inspector/front-end/JavaScriptSourceFrame.js

index 48d393f..80667e2 100644 (file)
@@ -1,3 +1,23 @@
+2012-11-22  Pavel Feldman  <pfeldman@chromium.org>
+
+        Web Inspector: evaluate on hover regressed with the editor change
+        https://bugs.webkit.org/show_bug.cgi?id=103063
+
+        Reviewed by Vsevolod Vlasov.
+
+        We are no longer mutating the editor's dom from outside.
+
+        * inspector/front-end/DOMExtension.js:
+        (Element.prototype.remove):
+        * inspector/front-end/DefaultTextEditor.js:
+        (WebInspector.DefaultTextEditor.prototype.highlightRangesWithStyleClass):
+        (WebInspector.DefaultTextEditor.prototype.highlightExpression):
+        (WebInspector.DefaultTextEditor.prototype.hideHighlightedExpression):
+        * inspector/front-end/JavaScriptSourceFrame.js:
+        (WebInspector.JavaScriptSourceFrame.prototype._getPopoverAnchor):
+        (WebInspector.JavaScriptSourceFrame.prototype._onHidePopover):
+        (WebInspector.JavaScriptSourceFrame.prototype._highlightExpression):
+
 2012-09-26  Gustavo Noronha Silva  <gns@gnome.org>
 
         [GTK] Split SVG from WebCore to work-around make limitation
index 483714a..1af5d3e 100644 (file)
@@ -200,6 +200,13 @@ Element.prototype.isScrolledToBottom = function()
     return this.scrollTop + this.clientHeight === this.scrollHeight;
 }
 
+Element.prototype.remove = function()
+{
+    if (this.parentElement)
+        this.parentElement.removeChild(this);
+}
+
+
 /**
  * @constructor
  * @param {number} width
index 21874e4..4aed782 100644 (file)
@@ -591,6 +591,67 @@ WebInspector.DefaultTextEditor.prototype = {
         this._freeCachedElements();
     },
 
+    /**
+     * @param {Element} element
+     * @param {Array.<Object>} resultRanges
+     * @param {string} styleClass
+     * @param {Array.<Object>=} changes
+     */
+    highlightRangesWithStyleClass: function(element, resultRanges, styleClass, changes)
+    {
+        this._mainPanel.beginDomUpdates();
+        WebInspector.highlightRangesWithStyleClass(element, resultRanges, styleClass, changes);
+        this._mainPanel.endDomUpdates();
+    },
+
+    /**
+     * @param {Element} element
+     * @param {Object} skipClasses
+     * @param {Object} skipTokens
+     * @return {Element}
+     */
+    highlightExpression: function(element, skipClasses, skipTokens)
+    {
+        // Collect tokens belonging to evaluated expression.
+        var tokens = [ element ];
+        var token = element.previousSibling;
+        while (token && (skipClasses[token.className] || skipTokens[token.textContent.trim()])) {
+            tokens.push(token);
+            token = token.previousSibling;
+        }
+        tokens.reverse();
+
+        // Wrap them with highlight element.
+        this._mainPanel.beginDomUpdates();
+        var parentElement = element.parentElement;
+        var nextElement = element.nextSibling;
+        var container = document.createElement("span");
+        for (var i = 0; i < tokens.length; ++i)
+            container.appendChild(tokens[i]);
+        parentElement.insertBefore(container, nextElement);
+        this._mainPanel.endDomUpdates();
+        return container;
+    },
+
+    /**
+     * @param {Element} highlightElement
+     */
+    hideHighlightedExpression: function(highlightElement)
+    {
+        this._mainPanel.beginDomUpdates();
+        var parentElement = highlightElement.parentElement;
+        if (parentElement) {
+            var child = highlightElement.firstChild;
+            while (child) {
+                var nextSibling = child.nextSibling;
+                parentElement.insertBefore(child, highlightElement);
+                child = nextSibling;
+            }
+            parentElement.removeChild(highlightElement);
+        }
+        this._mainPanel.endDomUpdates();
+    },
+
     __proto__: WebInspector.View.prototype
 }
 
index 3210c3a..58507e0 100644 (file)
@@ -289,7 +289,7 @@ WebInspector.JavaScriptSourceFrame.prototype = {
 
         // 2. 'highlight' them with artificial style to detect word boundaries
         var changes = [];
-        WebInspector.highlightRangesWithStyleClass(lineElement, ranges, "source-frame-token", changes);
+        this.textEditor.highlightRangesWithStyleClass(lineElement, ranges, "source-frame-token", changes);
         var lineOffsetLeft = lineElement.totalOffsetLeft();
         for (var child = lineElement.firstChild; child; child = child.nextSibling) {
             if (child.nodeType !== Node.ELEMENT_NODE || !child.hasStyleClass("source-frame-token"))
@@ -338,38 +338,17 @@ WebInspector.JavaScriptSourceFrame.prototype = {
             return;
         // FIXME: the text editor should maintain highlight on its own. The check below is a workaround for
         // the case when highlight element is detached from DOM by the TextEditor when re-building the DOM.
-        var parentElement = highlightElement.parentElement;
-        if (parentElement) {
-            var child = highlightElement.firstChild;
-            while (child) {
-                var nextSibling = child.nextSibling;
-                parentElement.insertBefore(child, highlightElement);
-                child = nextSibling;
-            }
-            parentElement.removeChild(highlightElement);
-        }
+        this.textEditor.hideHighlightedExpression(highlightElement);
         delete this._highlightElement;
     },
 
+    /**
+     * @param {Element} element
+     * @return {Element}
+     */
     _highlightExpression: function(element)
     {
-        // Collect tokens belonging to evaluated expression.
-        var tokens = [ element ];
-        var token = element.previousSibling;
-        while (token && (token.className === "webkit-javascript-ident" || token.className === "source-frame-token" || token.className === "webkit-javascript-keyword" || token.textContent.trim() === ".")) {
-            tokens.push(token);
-            token = token.previousSibling;
-        }
-        tokens.reverse();
-
-        // Wrap them with highlight element.
-        var parentElement = element.parentElement;
-        var nextElement = element.nextSibling;
-        var container = document.createElement("span");
-        for (var i = 0; i < tokens.length; ++i)
-            container.appendChild(tokens[i]);
-        parentElement.insertBefore(container, nextElement);
-        return container;
+        return this.textEditor.highlightExpression(element, { "webkit-javascript-ident": true, "source-frame-token": true, "webkit-javascript-keyword": true }, { ".": true });
     },
 
     /**