Title: [93789] trunk/Source/WebCore
Revision
93789
Author
ca...@chromium.org
Date
2011-08-25 08:47:41 -0700 (Thu, 25 Aug 2011)

Log Message

Web Inspector: [refactoring] use PopoverHelper to implement popup in the SourceFrame
https://bugs.webkit.org/show_bug.cgi?id=66858

Reviewed by Pavel Feldman.

* inspector/front-end/DetailedHeapshotView.js:
(WebInspector.DetailedHeapshotView.prototype._showStringContentPopover):
* inspector/front-end/NetworkPanel.js:
(WebInspector.NetworkLogView.prototype.initializeView):
(WebInspector.NetworkLogView.prototype.willHide):
(WebInspector.NetworkLogView.prototype._reset):
(WebInspector.NetworkLogView.prototype.switchToBriefView):
(WebInspector.NetworkLogView.prototype._showPopover):
* inspector/front-end/Popover.js:
(WebInspector.Popover):
(WebInspector.Popover.prototype.show):
(WebInspector.Popover.prototype.dispose):
(WebInspector.PopoverHelper):
(WebInspector.PopoverHelper.prototype._mouseMove.doHide):
(WebInspector.PopoverHelper.prototype._mouseMove):
(WebInspector.PopoverHelper.prototype.hidePopover):
(WebInspector.PopoverHelper.prototype._hidePopover):
(WebInspector.PopoverHelper.prototype._mouseHover):
(WebInspector.PopoverHelper.prototype._killHidePopupTimer):
* inspector/front-end/SourceFrame.js:
(WebInspector.SourceFrame.prototype.willHide):
(WebInspector.SourceFrame.prototype._initializeTextViewer):
(WebInspector.SourceFrame.prototype._scroll):
(WebInspector.SourceFrame.prototype._mouseDown):
(WebInspector.SourceFrame.prototype._onHidePopover):
(WebInspector.SourceFrame.prototype._shouldShowPopover):
(WebInspector.SourceFrame.prototype._getPopoverAnchor):
(WebInspector.SourceFrame.prototype._highlightExpression):
(WebInspector.SourceFrame.prototype._onShowPopover.showObjectPopover):
(WebInspector.SourceFrame.prototype._onShowPopover):
* inspector/front-end/TimelinePanel.js:
(WebInspector.TimelinePanel):
(WebInspector.TimelinePanel.prototype._showPopover):
(WebInspector.TimelinePanel.prototype._closeRecordDetails):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (93788 => 93789)


--- trunk/Source/WebCore/ChangeLog	2011-08-25 15:46:03 UTC (rev 93788)
+++ trunk/Source/WebCore/ChangeLog	2011-08-25 15:47:41 UTC (rev 93789)
@@ -1,3 +1,45 @@
+2011-08-25  Andrey Kosyakov  <ca...@chromium.org>
+
+        Web Inspector: [refactoring] use PopoverHelper to implement popup in the SourceFrame
+        https://bugs.webkit.org/show_bug.cgi?id=66858
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/front-end/DetailedHeapshotView.js:
+        (WebInspector.DetailedHeapshotView.prototype._showStringContentPopover):
+        * inspector/front-end/NetworkPanel.js:
+        (WebInspector.NetworkLogView.prototype.initializeView):
+        (WebInspector.NetworkLogView.prototype.willHide):
+        (WebInspector.NetworkLogView.prototype._reset):
+        (WebInspector.NetworkLogView.prototype.switchToBriefView):
+        (WebInspector.NetworkLogView.prototype._showPopover):
+        * inspector/front-end/Popover.js:
+        (WebInspector.Popover):
+        (WebInspector.Popover.prototype.show):
+        (WebInspector.Popover.prototype.dispose):
+        (WebInspector.PopoverHelper):
+        (WebInspector.PopoverHelper.prototype._mouseMove.doHide):
+        (WebInspector.PopoverHelper.prototype._mouseMove):
+        (WebInspector.PopoverHelper.prototype.hidePopover):
+        (WebInspector.PopoverHelper.prototype._hidePopover):
+        (WebInspector.PopoverHelper.prototype._mouseHover):
+        (WebInspector.PopoverHelper.prototype._killHidePopupTimer):
+        * inspector/front-end/SourceFrame.js:
+        (WebInspector.SourceFrame.prototype.willHide):
+        (WebInspector.SourceFrame.prototype._initializeTextViewer):
+        (WebInspector.SourceFrame.prototype._scroll):
+        (WebInspector.SourceFrame.prototype._mouseDown):
+        (WebInspector.SourceFrame.prototype._onHidePopover):
+        (WebInspector.SourceFrame.prototype._shouldShowPopover):
+        (WebInspector.SourceFrame.prototype._getPopoverAnchor):
+        (WebInspector.SourceFrame.prototype._highlightExpression):
+        (WebInspector.SourceFrame.prototype._onShowPopover.showObjectPopover):
+        (WebInspector.SourceFrame.prototype._onShowPopover):
+        * inspector/front-end/TimelinePanel.js:
+        (WebInspector.TimelinePanel):
+        (WebInspector.TimelinePanel.prototype._showPopover):
+        (WebInspector.TimelinePanel.prototype._closeRecordDetails):
+
 2011-08-25  Pavel Feldman  <pfeld...@google.com>
 
         [Qt] REGRESSION(93769): inspector/console/console-tests.html fails

Modified: trunk/Source/WebCore/inspector/front-end/DetailedHeapshotView.js (93788 => 93789)


--- trunk/Source/WebCore/inspector/front-end/DetailedHeapshotView.js	2011-08-25 15:46:03 UTC (rev 93788)
+++ trunk/Source/WebCore/inspector/front-end/DetailedHeapshotView.js	2011-08-25 15:47:41 UTC (rev 93789)
@@ -618,7 +618,7 @@
     this.helpButton = new WebInspector.StatusBarButton("", "heapshot-help-status-bar-item status-bar-item");
     this.helpButton.addEventListener("click", this._helpClicked.bind(this), false);
 
-    var popoverHelper = new WebInspector.PopoverHelper(this.element, this._getHoverAnchor.bind(this), this._showStringContentPopup.bind(this));
+    var popoverHelper = new WebInspector.PopoverHelper(this.element, this._getHoverAnchor.bind(this), this._showStringContentPopover.bind(this));
 
     this._loadProfile(this._profileUid, profileCallback.bind(this));
 
@@ -1042,21 +1042,19 @@
         this.refreshShowAsPercents();
     },
 
-    _showStringContentPopup: function(span)
+    _showStringContentPopover: function(anchor, popover)
     {
         var stringContentElement = document.createElement("span");
         stringContentElement.className = "monospace";
         stringContentElement.style.whiteSpace = "pre";
 
-        var popover = new WebInspector.Popover(stringContentElement);
         function displayString(name, className)
         {
             stringContentElement.textContent = name;
             stringContentElement.className += " " + className;
-            popover.show(span);
+            popover.show(stringContentElement, anchor);
         }
-        span.node.hoverMessage(displayString);
-        return popover;
+        anchor.node.hoverMessage(displayString);
     },
 
     _helpClicked: function(event)

Modified: trunk/Source/WebCore/inspector/front-end/NetworkPanel.js (93788 => 93789)


--- trunk/Source/WebCore/inspector/front-end/NetworkPanel.js	2011-08-25 15:46:03 UTC (rev 93788)
+++ trunk/Source/WebCore/inspector/front-end/NetworkPanel.js	2011-08-25 15:47:41 UTC (rev 93789)
@@ -80,7 +80,7 @@
             this._setLargerResources(this.useLargeRows);
 
         this._allowPopover = true;
-        this._popoverHelper = new WebInspector.PopoverHelper(this.element, this._getPopoverAnchor.bind(this), this._showPopover.bind(this), true);
+        this._popoverHelper = new WebInspector.PopoverHelper(this.element, this._getPopoverAnchor.bind(this), this._showPopover.bind(this));
         // Enable faster hint.
         this._popoverHelper.setTimeout(100);
 
@@ -643,7 +643,7 @@
     willHide: function()
     {
         WebInspector.IFrameView.prototype.willHide.call(this);
-        this._popoverHelper.hidePopup();
+        this._popoverHelper.hidePopover();
     },
 
     refresh: function()
@@ -705,7 +705,7 @@
 
         this._clearSearchMatchedList();
         if (this._popoverHelper)
-            this._popoverHelper.hidePopup();
+            this._popoverHelper.hidePopover();
 
         if (this._calculator)
             this._calculator.reset();
@@ -862,7 +862,7 @@
         widths.name = 100;
         this._dataGrid.applyColumnWidthsMap(widths);
 
-        this._popoverHelper.hidePopup();
+        this._popoverHelper.hidePopover();
     },
 
     _toggleLargerResources: function()
@@ -898,13 +898,11 @@
         return resource && resource.timing ? anchor : null;
     },
 
-    _showPopover: function(anchor)
+    _showPopover: function(anchor, popover)
     {
         var resource = anchor.parentElement.resource;
         var tableElement = WebInspector.ResourceTimingView.createTimingTable(resource);
-        var popover = new WebInspector.Popover(tableElement);
-        popover.show(anchor);
-        return popover;
+        popover.show(tableElement, anchor);
     },
 
     _toggleGridMode: function()

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


--- trunk/Source/WebCore/inspector/front-end/Popover.js	2011-08-25 15:46:03 UTC (rev 93788)
+++ trunk/Source/WebCore/inspector/front-end/Popover.js	2011-08-25 15:47:41 UTC (rev 93789)
@@ -32,7 +32,7 @@
  * @constructor
  * @param {Element} contentElement
  */
-WebInspector.Popover = function(contentElement)
+WebInspector.Popover = function()
 {
     this.element = document.createElement("div");
     this.element.className = "popover";
@@ -41,15 +41,18 @@
     this._popupArrowElement.className = "arrow";
     this.element.appendChild(this._popupArrowElement);
 
-    this.contentElement = contentElement;
     this._contentDiv = document.createElement("div");
     this._contentDiv.className = "content";
     this._visible = false;
 }
 
 WebInspector.Popover.prototype = {
-    show: function(anchor, preferredWidth, preferredHeight)
+    show: function(contentElement, anchor, preferredWidth, preferredHeight)
     {
+        if (this._disposed)
+            return;
+        this.contentElement = contentElement;
+
         // This should not happen, but we hide previous popup to be on the safe side.
         if (WebInspector.Popover._popoverElement)
             document.body.removeChild(WebInspector.Popover._popoverElement);
@@ -82,6 +85,18 @@
         return this._visible;
     },
 
+    get disposed()
+    {
+        return this._disposed;
+    },
+
+    dispose: function()
+    {
+        if (this.visible)
+            this.hide();
+        this._disposed = true;
+    },
+
     _positionElement: function(anchorElement, preferredWidth, preferredHeight)
     {
         const borderWidth = 25;
@@ -163,12 +178,11 @@
 /**
  * @constructor
  */
-WebInspector.PopoverHelper = function(panelElement, getAnchor, showPopup, showOnClick, onHide)
+WebInspector.PopoverHelper = function(panelElement, getAnchor, showPopover, onHide)
 {
     this._panelElement = panelElement;
     this._getAnchor = getAnchor;
-    this._showPopup = showPopup;
-    this._showOnClick = showOnClick;
+    this._showPopover = showPopover;
     this._onHide = onHide;
     panelElement.addEventListener("mousedown", this._mouseDown.bind(this), false);
     panelElement.addEventListener("mousemove", this._mouseMove.bind(this), false);
@@ -194,14 +208,14 @@
             return;
 
         // User has 500ms (this._timeout / 2) to reach the popup.
-        if (this._popup && !this._hidePopupTimer) {
+        if (this._popover && !this._hidePopoverTimer) {
             var self = this;
             function doHide()
             {
-                self._hidePopup();
-                delete self._hidePopupTimer;
+                self._hidePopover();
+                delete self._hidePopoverTimer;
             }
-            this._hidePopupTimer = setTimeout(doHide, this._timeout / 2);
+            this._hidePopoverTimer = setTimeout(doHide, this._timeout / 2);
         }
 
         this._handleMouseAction(event);
@@ -227,37 +241,38 @@
         }
     },
 
-    hidePopup: function()
+    hidePopover: function()
     {
         this._resetHoverTimer();
-        this._hidePopup();
+        this._hidePopover();
     },
 
-    _hidePopup: function()
+    _hidePopover: function()
     {
-        if (!this._popup)
+        delete this._popupInstanceMarker;
+        if (!this._popover)
             return;
 
         if (this._onHide)
             this._onHide();
 
-        this._popup.hide();
-        delete this._popup;
+        this._popover.dispose();
+        delete this._popover;
     },
 
     _mouseHover: function(element)
     {
         delete this._hoverTimer;
 
-        this._popup = this._showPopup(element);
-        if (this._popup)
-            this._popup.contentElement.addEventListener("mousemove", this._killHidePopupTimer.bind(this), true);
+        this._hidePopover();
+        this._popover = new WebInspector.Popover();
+        this._showPopover(element, this._popover);
     },
 
     _killHidePopupTimer: function()
     {
-        if (this._hidePopupTimer) {
-            clearTimeout(this._hidePopupTimer);
+        if (this._hidePopoverTimer) {
+            clearTimeout(this._hidePopoverTimer);
             delete this._hidePopupTimer;
 
             // We know that we reached the popup, but we might have moved over other elements.

Modified: trunk/Source/WebCore/inspector/front-end/SourceFrame.js (93788 => 93789)


--- trunk/Source/WebCore/inspector/front-end/SourceFrame.js	2011-08-25 15:46:03 UTC (rev 93788)
+++ trunk/Source/WebCore/inspector/front-end/SourceFrame.js	2011-08-25 15:47:41 UTC (rev 93789)
@@ -91,7 +91,8 @@
         if (this.loaded)
             this._textViewer.freeCachedElements();
 
-        this._hidePopup();
+        if (this._popoverHelper)
+            this._popoverHelper.hidePopover();
         this._clearLineHighlight();
     },
 
@@ -280,8 +281,9 @@
 
         var element = this._textViewer.element;
         if (this._delegate.debuggingSupported()) {
+            this._popoverHelper = new WebInspector.PopoverHelper(element,
+                this._getPopoverAnchor.bind(this), this._onShowPopover.bind(this), this._onHidePopover.bind(this));
             element.addEventListener("mousedown", this._mouseDown.bind(this), true);
-            element.addEventListener("mousemove", this._mouseMove.bind(this), true);
             element.addEventListener("scroll", this._scroll.bind(this), true);
         }
 
@@ -631,12 +633,14 @@
 
     _scroll: function(event)
     {
-        this._hidePopup();
+        if (this._popoverHelper)
+            this._popoverHelper.hidePopover();
     },
 
     _mouseDown: function(event)
     {
-        this._hidePopup();
+        if (this._popoverHelper)
+            this._popoverHelper.hidePopover();
         if (event.button != 0 || event.altKey || event.ctrlKey || event.metaKey)
             return;
         var target = event.target.enclosingNodeOrSelfWithClass("webkit-line-number");
@@ -655,79 +659,44 @@
         event.preventDefault();
     },
 
-    _mouseMove: function(event)
+    _onHidePopover: function()
     {
-        // Pretend that nothing has happened.
-        if (this._hoverElement === event.target || event.target.hasStyleClass("source-frame-eval-_expression_"))
-            return;
-
-        this._resetHoverTimer();
-        // User has 500ms to reach the popup.
-        if (this._popup) {
-            var self = this;
-            function doHide()
-            {
-                self._hidePopup();
-                delete self._hidePopupTimer;
-            }
-            if (!("_hidePopupTimer" in this))
-                this._hidePopupTimer = setTimeout(doHide, 500);
+        // Replace higlight element with its contents inplace.
+        var highlightElement = this._highlightElement;
+        var parentElement = highlightElement.parentElement;
+        var child = highlightElement.firstChild;
+        while (child) {
+            var nextSibling = child.nextSibling;
+            parentElement.insertBefore(child, highlightElement);
+            child = nextSibling;
         }
+        parentElement.removeChild(highlightElement);
+        this._delegate.releaseEvaluationResult();
+    },
 
-        this._hoverElement = event.target;
-
-        // Now that cleanup routines are set up above, leave this in case we are not on a break.
+    _shouldShowPopover: function(element)
+    {
         if (!this._delegate.debuggerPaused())
-            return;
+            return false;
+        if (!element.enclosingNodeOrSelfWithClass("webkit-line-content"))
+            return false;
 
         // We are interested in identifiers and "this" keyword.
-        if (this._hoverElement.hasStyleClass("webkit-_javascript_-keyword")) {
-            if (this._hoverElement.textContent !== "this")
-                return;
-        } else if (!this._hoverElement.hasStyleClass("webkit-_javascript_-ident"))
-            return;
+        if (element.hasStyleClass("webkit-_javascript_-keyword"))
+            return element.textContent === "this";
 
-        const toolTipDelay = this._popup ? 600 : 1000;
-        this._hoverTimer = setTimeout(this._mouseHover.bind(this, this._hoverElement), toolTipDelay);
+        return element.hasStyleClass("webkit-_javascript_-ident");
     },
 
-    _resetHoverTimer: function()
+    _getPopoverAnchor: function(element)
     {
-        if (this._hoverTimer) {
-            clearTimeout(this._hoverTimer);
-            delete this._hoverTimer;
-        }
-    },
-
-    _hidePopup: function()
-    {
-        this._resetHoverTimer();
-        if (!this._popup)
+        if (!this._shouldShowPopover(element))
             return;
-
-        // Replace higlight element with its contents inplace.
-        var parentElement = this._popup.highlightElement.parentElement;
-        var child = this._popup.highlightElement.firstChild;
-        while (child) {
-            var nextSibling = child.nextSibling;
-            parentElement.insertBefore(child, this._popup.highlightElement);
-            child = nextSibling;
-        }
-        parentElement.removeChild(this._popup.highlightElement);
-
-        this._popup.hide();
-        delete this._popup;
-        this._delegate.releaseEvaluationResult();
+        return element;
     },
 
-    _mouseHover: function(element)
+    _highlightExpression: function(element)
     {
-        delete this._hoverTimer;
-
-        var lineRow = element.enclosingNodeOrSelfWithClass("webkit-line-content");
-        if (!lineRow)
-            return;
-
         // Collect tokens belonging to evaluated exression.
         var tokens = [ element ];
         var token = element.previousSibling;
@@ -744,66 +713,52 @@
         for (var i = 0; i < tokens.length; ++i)
             container.appendChild(tokens[i]);
         parentElement.insertBefore(container, nextElement);
-        this._showPopup(container);
+        return container;
     },
 
-    _showPopup: function(element)
+    _onShowPopover: function(element, popover)
     {
-        if (!this._delegate.debuggerPaused())
-            return;
+        this._highlightElement = this._highlightExpression(element);
 
-        function killHidePopupTimer()
+        function showObjectPopover(result, wasThrown)
         {
-            if (this._hidePopupTimer) {
-                clearTimeout(this._hidePopupTimer);
-                delete this._hidePopupTimer;
-
-                // We know that we reached the popup, but we might have moved over other elements.
-                // Discard pending command.
-                this._resetHoverTimer();
-            }
-        }
-
-        function showObjectPopup(result, wasThrown)
-        {
-            if (wasThrown || !this._delegate.debuggerPaused())
+            if (popover.disposed)
                 return;
-
-            var popupContentElement = null;
+            if (wasThrown || !this._delegate.debuggerPaused()) {
+                this._popoverHelper.hidePopover();
+                return;
+            }
+            var popoverContentElement = null;
             if (result.type !== "object") {
-                popupContentElement = document.createElement("span");
-                popupContentElement.className = "monospace console-formatted-" + result.type;
-                popupContentElement.style.whiteSpace = "pre";
-                popupContentElement.textContent = result.description;
+                popoverContentElement = document.createElement("span");
+                popoverContentElement.className = "monospace console-formatted-" + result.type;
+                popoverContentElement.style.whiteSpace = "pre";
+                popoverContentElement.textContent = result.description;
                 if (result.type === "string")
-                    popupContentElement.textContent = "\"" + popupContentElement.textContent + "\"";
-                this._popup = new WebInspector.Popover(popupContentElement);
-                this._popup.show(element);
+                    popoverContentElement.textContent = "\"" + popoverContentElement.textContent + "\"";
+                popover.show(popoverContentElement, element);
             } else {
-                var popupContentElement = document.createElement("div");
+                var popoverContentElement = document.createElement("div");
 
                 var titleElement = document.createElement("div");
                 titleElement.className = "source-frame-popover-title monospace";
                 titleElement.textContent = result.description;
-                popupContentElement.appendChild(titleElement);
+                popoverContentElement.appendChild(titleElement);
 
                 var section = new WebInspector.ObjectPropertiesSection(result);
                 section.expanded = true;
                 section.element.addStyleClass("source-frame-popover-tree");
                 section.headerElement.addStyleClass("hidden");
-                popupContentElement.appendChild(section.element);
+                popoverContentElement.appendChild(section.element);
 
-                this._popup = new WebInspector.Popover(popupContentElement);
-                const popupWidth = 300;
-                const popupHeight = 250;
-                this._popup.show(element, popupWidth, popupHeight);
+                const popoverWidth = 300;
+                const popoverHeight = 250;
+                popover.show(popoverContentElement, element, popoverWidth, popoverHeight);
             }
-            this._popup.highlightElement = element;
-            this._popup.highlightElement.addStyleClass("source-frame-eval-_expression_");
-            popupContentElement.addEventListener("mousemove", killHidePopupTimer.bind(this), true);
+            this._highlightElement.addStyleClass("source-frame-eval-_expression_");
         }
 
-        this._delegate.evaluateInSelectedCallFrame(element.textContent, showObjectPopup.bind(this));
+        this._delegate.evaluateInSelectedCallFrame(this._highlightElement.textContent, showObjectPopover.bind(this));
     },
 
     _editBreakpointCondition: function(lineNumber, condition, callback)

Modified: trunk/Source/WebCore/inspector/front-end/TimelinePanel.js (93788 => 93789)


--- trunk/Source/WebCore/inspector/front-end/TimelinePanel.js	2011-08-25 15:46:03 UTC (rev 93788)
+++ trunk/Source/WebCore/inspector/front-end/TimelinePanel.js	2011-08-25 15:47:41 UTC (rev 93789)
@@ -93,7 +93,7 @@
     this._boundariesAreValid = true;
     this._scrollTop = 0;
 
-    this._popoverHelper = new WebInspector.PopoverHelper(this._containerElement, this._getPopoverAnchor.bind(this), this._showPopover.bind(this), true);
+    this._popoverHelper = new WebInspector.PopoverHelper(this._containerElement, this._getPopoverAnchor.bind(this), this._showPopover.bind(this));
     this._containerElement.addEventListener("mousemove", this._mouseMove.bind(this), false);
     this._containerElement.addEventListener("mouseout", this._mouseOut.bind(this), false);
 
@@ -748,17 +748,15 @@
         }
     },
 
-    _showPopover: function(anchor)
+    _showPopover: function(anchor, popover)
     {
         var record = anchor.row._record;
-        var popover = new WebInspector.Popover(record._generatePopupContent(this._calculator, this.categories));
-        popover.show(anchor);
-        return popover;
+        popover.show(record._generatePopupContent(this._calculator, this.categories), anchor);
     },
 
     _closeRecordDetails: function()
     {
-        this._popoverHelper.hidePopup();
+        this._popoverHelper.hidePopover();
     }
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to