Title: [108331] trunk/Source/WebCore
Revision
108331
Author
pfeld...@chromium.org
Date
2012-02-21 03:30:30 -0800 (Tue, 21 Feb 2012)

Log Message

Web Inspector: evaluate on hover does not work for large files.
https://bugs.webkit.org/show_bug.cgi?id=79015

Patch by Pavel Feldman <pfeld...@chomium.org> on 2012-02-21
Reviewed by Yury Semikhatsky.

* inspector/front-end/_javascript_SourceFrame.js:
(WebInspector._javascript_SourceFrame.prototype._getPopoverAnchor):
(WebInspector._javascript_SourceFrame.prototype._highlightExpression):
* inspector/front-end/Popover.js:
(WebInspector.PopoverHelper.prototype._handleMouseAction):
* inspector/front-end/SourceJavaScriptTokenizer.js:
(WebInspector.SourceJavaScriptTokenizer):
(WebInspector.SourceJavaScriptTokenizer.prototype.nextToken):
* inspector/front-end/SourceJavaScriptTokenizer.re2js:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (108330 => 108331)


--- trunk/Source/WebCore/ChangeLog	2012-02-21 11:28:47 UTC (rev 108330)
+++ trunk/Source/WebCore/ChangeLog	2012-02-21 11:30:30 UTC (rev 108331)
@@ -1,3 +1,20 @@
+2012-02-21  Pavel Feldman  <pfeld...@chomium.org>
+
+        Web Inspector: evaluate on hover does not work for large files.
+        https://bugs.webkit.org/show_bug.cgi?id=79015
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/front-end/_javascript_SourceFrame.js:
+        (WebInspector._javascript_SourceFrame.prototype._getPopoverAnchor):
+        (WebInspector._javascript_SourceFrame.prototype._highlightExpression):
+        * inspector/front-end/Popover.js:
+        (WebInspector.PopoverHelper.prototype._handleMouseAction):
+        * inspector/front-end/SourceJavaScriptTokenizer.js:
+        (WebInspector.SourceJavaScriptTokenizer):
+        (WebInspector.SourceJavaScriptTokenizer.prototype.nextToken):
+        * inspector/front-end/SourceJavaScriptTokenizer.re2js:
+
 2012-02-21  Pavel Feldman  <pfeld...@google.com>
 
         Web Inspector: add "show paint rectangles" setting.

Modified: trunk/Source/WebCore/inspector/front-end/_javascript_SourceFrame.js (108330 => 108331)


--- trunk/Source/WebCore/inspector/front-end/_javascript_SourceFrame.js	2012-02-21 11:28:47 UTC (rev 108330)
+++ trunk/Source/WebCore/inspector/front-end/_javascript_SourceFrame.js	2012-02-21 11:30:30 UTC (rev 108331)
@@ -254,28 +254,51 @@
         delete this._javaScriptSourceFrameState;
     },
 
-    // Popover callbacks
-    _shouldShowPopover: function(element)
+    _getPopoverAnchor: function(element, event)
     {
         if (!this._model.paused)
-            return false;
-        if (!element.enclosingNodeOrSelfWithClass("webkit-line-content"))
-            return false;
+            return null;
         if (window.getSelection().type === "Range")
-            return false;
+            return null;
+        var lineElement = element.enclosingNodeOrSelfWithClass("webkit-line-content");
+        if (!lineElement)
+            return null;
 
+        if (element.hasStyleClass("webkit-_javascript_-ident"))
+            return element;
+
+        if (element.hasStyleClass("source-frame-token"))
+            return element;
+
         // We are interested in identifiers and "this" keyword.
         if (element.hasStyleClass("webkit-_javascript_-keyword"))
-            return element.textContent === "this";
+            return element.textContent === "this" ? element : null;
 
-        return element.hasStyleClass("webkit-_javascript_-ident");
-    },
+        if (element !== lineElement || element.querySelectorAll(".source-frame-token").length)
+            return null;
 
-    _getPopoverAnchor: function(element)
-    {
-        if (!this._shouldShowPopover(element))
-            return;
-        return element;
+        // Handle non-highlighted case
+        // 1. Collect ranges of identifier suspects
+        var lineContent = lineElement.textContent;
+        var ranges = [];
+        var regex = new RegExp("[a-zA-Z_\$0-9]+", "g");
+        var match;
+        while (regex.lastIndex < lineContent.length && (match = regex.exec(lineContent)))
+            ranges.push({offset: match.index, length: regex.lastIndex - match.index});
+
+        // 2. 'highlight' them with artificial style to detect word boundaries
+        var changes = [];
+        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"))
+                continue;
+            if (event.x > lineOffsetLeft + child.offsetLeft && event.x < lineOffsetLeft + child.offsetLeft + child.offsetWidth) {
+                var text = child.textContent;
+                return (text === "this" || !WebInspector.SourceJavaScriptTokenizer.Keywords[text]) ? child : null;
+            }
+        }
+        return null;
     },
 
     _resolveObjectForPopover: function(element, showCallback, objectGroupName)
@@ -328,7 +351,7 @@
         // Collect tokens belonging to evaluated _expression_.
         var tokens = [ element ];
         var token = element.previousSibling;
-        while (token && (token.className === "webkit-_javascript_-ident" || token.className === "webkit-_javascript_-keyword" || token.textContent.trim() === ".")) {
+        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;
         }

Modified: trunk/Source/WebCore/inspector/front-end/Popover.js (108330 => 108331)


--- trunk/Source/WebCore/inspector/front-end/Popover.js	2012-02-21 11:28:47 UTC (rev 108330)
+++ trunk/Source/WebCore/inspector/front-end/Popover.js	2012-02-21 11:30:30 UTC (rev 108331)
@@ -246,7 +246,7 @@
         this._resetHoverTimer();
         if (event.which && this._disableOnClick)
             return;
-        this._hoverElement = this._getAnchor(event.target);
+        this._hoverElement = this._getAnchor(event.target, event);
         if (!this._hoverElement)
             return;
         const toolTipDelay = isMouseDown ? 0 : (this._popup ? this._timeout * 0.6 : this._timeout);

Modified: trunk/Source/WebCore/inspector/front-end/SourceJavaScriptTokenizer.js (108330 => 108331)


--- trunk/Source/WebCore/inspector/front-end/SourceJavaScriptTokenizer.js	2012-02-21 11:28:47 UTC (rev 108330)
+++ trunk/Source/WebCore/inspector/front-end/SourceJavaScriptTokenizer.js	2012-02-21 11:30:30 UTC (rev 108331)
@@ -50,13 +50,6 @@
 {
     WebInspector.SourceTokenizer.call(this);
 
-    this._keywords = [
-        "null", "true", "false", "break", "case", "catch", "const", "default", "finally", "for",
-        "instanceof", "new", "var", "continue", "function", "return", "void", "delete", "if",
-        "this", "do", "while", "else", "in", "switch", "throw", "try", "typeof", "debugger",
-        "class", "enum", "export", "extends", "import", "super", "get", "set", "with"
-    ].keySet();
-
     this._lexConditions = {
         DIV: 0,
         NODIV: 1,
@@ -76,6 +69,13 @@
     this.condition = this.createInitialCondition();
 }
 
+WebInspector.SourceJavaScriptTokenizer.Keywords = [
+        "null", "true", "false", "break", "case", "catch", "const", "default", "finally", "for",
+        "instanceof", "new", "var", "continue", "function", "return", "void", "delete", "if",
+        "this", "do", "while", "else", "in", "switch", "throw", "try", "typeof", "debugger",
+        "class", "enum", "export", "extends", "import", "super", "get", "set", "with"
+    ].keySet();
+
 WebInspector.SourceJavaScriptTokenizer.prototype = {
     createInitialCondition: function()
     {
@@ -257,7 +257,7 @@
 case 21:
             {
                     var token = this._line.substring(cursorOnEnter, cursor);
-                    if (this._keywords[token] === true && token !== "__proto__")
+                    if (WebInspector.SourceJavaScriptTokenizer.Keywords[token] === true && token !== "__proto__")
                         this.tokenType = "_javascript_-keyword";
                     else
                         this.tokenType = "_javascript_-ident";
@@ -1189,7 +1189,7 @@
             this.setLexCondition(this._lexConditions.DIV);
             {
                     var token = this._line.substring(cursorOnEnter, cursor);
-                    if (this._keywords[token] === true && token !== "__proto__")
+                    if (WebInspector.SourceJavaScriptTokenizer.Keywords[token] === true && token !== "__proto__")
                         this.tokenType = "_javascript_-keyword";
                     else
                         this.tokenType = "_javascript_-ident";

Modified: trunk/Source/WebCore/inspector/front-end/SourceJavaScriptTokenizer.re2js (108330 => 108331)


--- trunk/Source/WebCore/inspector/front-end/SourceJavaScriptTokenizer.re2js	2012-02-21 11:28:47 UTC (rev 108330)
+++ trunk/Source/WebCore/inspector/front-end/SourceJavaScriptTokenizer.re2js	2012-02-21 11:30:30 UTC (rev 108331)
@@ -49,13 +49,6 @@
 {
     WebInspector.SourceTokenizer.call(this);
 
-    this._keywords = [
-        "null", "true", "false", "break", "case", "catch", "const", "default", "finally", "for",
-        "instanceof", "new", "var", "continue", "function", "return", "void", "delete", "if",
-        "this", "do", "while", "else", "in", "switch", "throw", "try", "typeof", "debugger",
-        "class", "enum", "export", "extends", "import", "super", "get", "set", "with"
-    ].keySet();
-
     this._lexConditions = {
         DIV: 0,
         NODIV: 1,
@@ -75,6 +68,13 @@
     this.condition = this.createInitialCondition();
 }
 
+WebInspector.SourceJavaScriptTokenizer.Keywords = [
+        "null", "true", "false", "break", "case", "catch", "const", "default", "finally", "for",
+        "instanceof", "new", "var", "continue", "function", "return", "void", "delete", "if",
+        "this", "do", "while", "else", "in", "switch", "throw", "try", "typeof", "debugger",
+        "class", "enum", "export", "extends", "import", "super", "get", "set", "with"
+    ].keySet();
+
 WebInspector.SourceJavaScriptTokenizer.prototype = {
     createInitialCondition: function()
     {
@@ -170,7 +170,7 @@
                 <DIV,NODIV> Identifier => DIV
                 {
                     var token = this._line.substring(cursorOnEnter, cursor);
-                    if (this._keywords[token] === true && token !== "__proto__")
+                    if (WebInspector.SourceJavaScriptTokenizer.Keywords[token] === true && token !== "__proto__")
                         this.tokenType = "_javascript_-keyword";
                     else
                         this.tokenType = "_javascript_-ident";
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to