Title: [142278] trunk/Source/WebCore
Revision
142278
Author
[email protected]
Date
2013-02-08 07:44:24 -0800 (Fri, 08 Feb 2013)

Log Message

Web Inspector: refactor MemoryStatistics.js
https://bugs.webkit.org/show_bug.cgi?id=109299

Reviewed by Vsevolod Vlasov.

Extracted functionality specific to DOM counter graphs drawing into
separate methods on MemoryStatistics class.
Introduced CounterUIBase base class for DOMCounterUI that contains
functionality which can be shared with native memory graph.

* inspector/front-end/MemoryStatistics.js:
(WebInspector.MemoryStatistics):
(WebInspector.CounterUIBase):
(WebInspector.CounterUIBase.prototype.updateCurrentValue):
(WebInspector.CounterUIBase.prototype.clearCurrentValueAndMarker):
(WebInspector.CounterUIBase.prototype.get visible):
(WebInspector.DOMCounterUI):
(WebInspector.DOMCounterUI.prototype.discardImageUnderMarker):
(WebInspector.MemoryStatistics.prototype._onMouseOut):
(WebInspector.MemoryStatistics.prototype._clearCurrentValueAndMarker):
(WebInspector.MemoryStatistics.prototype._refreshCurrentValues):
(WebInspector.MemoryStatistics.prototype._updateCurrentValue):
(WebInspector.MemoryStatistics.prototype._highlightCurrentPositionOnGraphs):
(WebInspector.MemoryStatistics.prototype._restoreImageUnderMarker):
(WebInspector.MemoryStatistics.prototype._saveImageUnderMarker):
(WebInspector.MemoryStatistics.prototype._drawMarker):
(WebInspector.MemoryStatistics.prototype._clear):
(WebInspector.MemoryStatistics.prototype._discardImageUnderMarker):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (142277 => 142278)


--- trunk/Source/WebCore/ChangeLog	2013-02-08 15:36:48 UTC (rev 142277)
+++ trunk/Source/WebCore/ChangeLog	2013-02-08 15:44:24 UTC (rev 142278)
@@ -1,3 +1,34 @@
+2013-02-08  Yury Semikhatsky  <[email protected]>
+
+        Web Inspector: refactor MemoryStatistics.js
+        https://bugs.webkit.org/show_bug.cgi?id=109299
+
+        Reviewed by Vsevolod Vlasov.
+
+        Extracted functionality specific to DOM counter graphs drawing into
+        separate methods on MemoryStatistics class.
+        Introduced CounterUIBase base class for DOMCounterUI that contains
+        functionality which can be shared with native memory graph.
+
+        * inspector/front-end/MemoryStatistics.js:
+        (WebInspector.MemoryStatistics):
+        (WebInspector.CounterUIBase):
+        (WebInspector.CounterUIBase.prototype.updateCurrentValue):
+        (WebInspector.CounterUIBase.prototype.clearCurrentValueAndMarker):
+        (WebInspector.CounterUIBase.prototype.get visible):
+        (WebInspector.DOMCounterUI):
+        (WebInspector.DOMCounterUI.prototype.discardImageUnderMarker):
+        (WebInspector.MemoryStatistics.prototype._onMouseOut):
+        (WebInspector.MemoryStatistics.prototype._clearCurrentValueAndMarker):
+        (WebInspector.MemoryStatistics.prototype._refreshCurrentValues):
+        (WebInspector.MemoryStatistics.prototype._updateCurrentValue):
+        (WebInspector.MemoryStatistics.prototype._highlightCurrentPositionOnGraphs):
+        (WebInspector.MemoryStatistics.prototype._restoreImageUnderMarker):
+        (WebInspector.MemoryStatistics.prototype._saveImageUnderMarker):
+        (WebInspector.MemoryStatistics.prototype._drawMarker):
+        (WebInspector.MemoryStatistics.prototype._clear):
+        (WebInspector.MemoryStatistics.prototype._discardImageUnderMarker):
+
 2013-02-08  Mike West  <[email protected]>
 
         Add a new IGNORE_EXCEPTION helper to ignore ExceptionCodes when they are expected but uninteresting

Modified: trunk/Source/WebCore/inspector/front-end/MemoryStatistics.js (142277 => 142278)


--- trunk/Source/WebCore/inspector/front-end/MemoryStatistics.js	2013-02-08 15:36:48 UTC (rev 142277)
+++ trunk/Source/WebCore/inspector/front-end/MemoryStatistics.js	2013-02-08 15:44:24 UTC (rev 142278)
@@ -80,9 +80,9 @@
         return entry.listenerCount;
     }
     this._counterUI = [
-        new WebInspector.CounterUI(this, "Document Count", "Documents: %d", [100,0,0], getDocumentCount),
-        new WebInspector.CounterUI(this, "DOM Node Count", "Nodes: %d", [0,100,0], getNodeCount),
-        new WebInspector.CounterUI(this, "Event Listener Count", "Listeners: %d", [0,0,100], getListenerCount)
+        new WebInspector.DOMCounterUI(this, "Document Count", "Documents: %d", [100,0,0], getDocumentCount),
+        new WebInspector.DOMCounterUI(this, "DOM Node Count", "Nodes: %d", [0,100,0], getNodeCount),
+        new WebInspector.DOMCounterUI(this, "Event Listener Count", "Listeners: %d", [0,0,100], getListenerCount)
     ];
 
     TimelineAgent.setIncludeMemoryDetails(true);
@@ -134,26 +134,23 @@
 /**
  * @constructor
  */
-WebInspector.CounterUI = function(memoryCountersPane, title, currentValueLabel, rgb, valueGetter)
+WebInspector.CounterUIBase = function(memoryCountersPane, title, graphColor, valueGetter)
 {
     this._memoryCountersPane = memoryCountersPane;
     this.valueGetter = valueGetter;
     var container = memoryCountersPane._memorySidebarView.sidebarElement.createChild("div", "memory-counter-sidebar-info");
-    var swatchColor = "rgb(" + rgb.join(",") + ")";
+    var swatchColor = graphColor;
     this._swatch = new WebInspector.SwatchCheckbox(WebInspector.UIString(title), swatchColor);
     this._swatch.addEventListener(WebInspector.SwatchCheckbox.Events.Changed, this._toggleCounterGraph.bind(this));
     container.appendChild(this._swatch.element);
-    this._range = this._swatch.element.createChild("span");
 
-    this._value = memoryCountersPane._currentValuesBar.createChild("span", "memory-counter-value");
-    this._value.style.color = swatchColor;
-    this._currentValueLabel = currentValueLabel;
-
-    this.graphColor = "rgba(" + rgb.join(",") + ",0.8)";
+    this._value = null;
+    this.graphColor =graphColor;
+    this.strokeColor = graphColor;
     this.graphYValues = [];
 }
 
-WebInspector.CounterUI.prototype = {
+WebInspector.CounterUIBase.prototype = {
     _toggleCounterGraph: function(event)
     {
         if (this._swatch.checked)
@@ -163,6 +160,41 @@
         this._memoryCountersPane.refresh();
     },
 
+    updateCurrentValue: function(countersEntry)
+    {
+        this._value.textContent = Number.bytesToString(this.valueGetter(countersEntry));
+    },
+
+    clearCurrentValueAndMarker: function(ctx)
+    {
+        this._value.textContent = "";
+    },
+
+    get visible()
+    {
+        return this._swatch.checked;
+    },
+}
+
+/**
+ * @constructor
+ * @extends {WebInspector.CounterUIBase}
+ */
+WebInspector.DOMCounterUI = function(memoryCountersPane, title, currentValueLabel, rgb, valueGetter)
+{
+    var swatchColor = "rgb(" + rgb.join(",") + ")";
+    WebInspector.CounterUIBase.call(this, memoryCountersPane, title, swatchColor, valueGetter)
+    this._range = this._swatch.element.createChild("span");
+
+    this._value = memoryCountersPane._currentValuesBar.createChild("span", "memory-counter-value");
+    this._value.style.color = swatchColor;
+    this._currentValueLabel = currentValueLabel;
+
+    this.graphColor = "rgba(" + rgb.join(",") + ",0.8)";
+    this.graphYValues = [];
+}
+
+WebInspector.DOMCounterUI.prototype = {
     setRange: function(minValue, maxValue)
     {
         this._range.textContent = WebInspector.UIString("[ %d - %d ]", minValue, maxValue);
@@ -179,11 +211,6 @@
         this.restoreImageUnderMarker(ctx);
     },
 
-    get visible()
-    {
-        return this._swatch.checked;
-    },
-
     saveImageUnderMarker: function(ctx, x, y, radius)
     {
         const w = radius + 1;
@@ -206,7 +233,9 @@
     discardImageUnderMarker: function()
     {
         delete this._imageUnderMarker;
-    }
+    },
+
+    __proto__: WebInspector.CounterUIBase.prototype
 }
 
 
@@ -326,6 +355,11 @@
         delete this._markerXPosition;
 
         var ctx = this._canvas.getContext("2d");
+        this._clearCurrentValueAndMarker(ctx);
+    },
+
+    _clearCurrentValueAndMarker: function(ctx)
+    {
         for (var i = 0; i < this._counterUI.length; i++)
             this._counterUI[i].clearCurrentValueAndMarker(ctx);
     },
@@ -350,12 +384,17 @@
             return;
         var i = this._recordIndexAt(this._markerXPosition);
 
-        for (var j = 0; j < this._counterUI.length; j++)
-            this._counterUI[j].updateCurrentValue(this._counters[i]);
+        this._updateCurrentValue(this._counters[i]);
 
         this._highlightCurrentPositionOnGraphs(this._markerXPosition, i);
     },
 
+    _updateCurrentValue: function(counterEntry)
+    {
+        for (var j = 0; j < this._counterUI.length; j++)
+            this._counterUI[j].updateCurrentValue(counterEntry);
+    },
+
     _recordIndexAt: function(x)
     {
         var i;
@@ -371,13 +410,23 @@
     _highlightCurrentPositionOnGraphs: function(x, index)
     {
         var ctx = this._canvas.getContext("2d");
+        this._restoreImageUnderMarker(ctx);
+        this._saveImageUnderMarker(ctx, x, index);
+        this._drawMarker(ctx, x, index);
+    },
+
+    _restoreImageUnderMarker: function(ctx)
+    {
         for (var i = 0; i < this._counterUI.length; i++) {
             var counterUI = this._counterUI[i];
             if (!counterUI.visible)
                 continue;
             counterUI.restoreImageUnderMarker(ctx);
         }
+    },
 
+    _saveImageUnderMarker: function(ctx, x, index)
+    {
         const radius = 2;
         for (var i = 0; i < this._counterUI.length; i++) {
             var counterUI = this._counterUI[i];
@@ -386,7 +435,11 @@
             var y = counterUI.graphYValues[index];
             counterUI.saveImageUnderMarker(ctx, x, y, radius);
         }
+    },
 
+    _drawMarker: function(ctx, x, index)
+    {
+        const radius = 2;
         for (var i = 0; i < this._counterUI.length; i++) {
             var counterUI = this._counterUI[i];
             if (!counterUI.visible)
@@ -509,6 +562,11 @@
     _clear: function() {
         var ctx = this._canvas.getContext("2d");
         ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
+        this._discardImageUnderMarker();
+    },
+
+    _discardImageUnderMarker: function()
+    {
         for (var i = 0; i < this._counterUI.length; i++)
             this._counterUI[i].discardImageUnderMarker();
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to