2011-01-28 Pavel Feldman <pfeldman@chromium.org>
[WebKit-https.git] / Source / WebCore / inspector / front-end / NetworkPanel.js
index 28cbd36..485856e 100644 (file)
@@ -78,6 +78,11 @@ WebInspector.NetworkPanel = function()
     this._filter(this._filterAllElement, false);
 
     this._toggleGridMode();
+
+    WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.ResourceStarted, this._onResourceStarted, this);
+    WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.ResourceUpdated, this._onResourceUpdated, this);
+    WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.ResourceFinished, this._onResourceUpdated, this);
+    WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.MainResourceCommitLoad, this._onMainResourceCommitLoad, this);
 }
 
 WebInspector.NetworkPanel.prototype = {
@@ -98,7 +103,7 @@ WebInspector.NetworkPanel.prototype = {
 
     elementsToRestoreScrollPositionsFor: function()
     {
-        return [this.containerElement];
+        return [this.containerElement, this._dataGrid.scrollContainer];
     },
 
     resize: function()
@@ -113,8 +118,6 @@ WebInspector.NetworkPanel.prototype = {
         if (!this._viewingResourceMode)
             return;
         WebInspector.Panel.prototype.updateSidebarWidth.call(this, width);
-        if (this._summaryBarElement.parentElement === this.element)
-            this._summaryBarElement.style.width = width + "px";
     },
 
     updateMainViewWidth: function(width)
@@ -142,7 +145,6 @@ WebInspector.NetworkPanel.prototype = {
                 delete this._summaryBarRowNode;
             }
             this._summaryBarElement.addStyleClass("network-summary-bar-bottom");
-            this._summaryBarElement.style.setProperty("width", this.sidebarElement.offsetWidth + "px");
             this.element.appendChild(this._summaryBarElement);
             this._dataGrid.element.style.bottom = "20px";
             return;
@@ -152,11 +154,11 @@ WebInspector.NetworkPanel.prototype = {
             // Glue status to table.
             this._summaryBarRowNode = new WebInspector.NetworkTotalGridNode(this._summaryBarElement);
             this._summaryBarElement.removeStyleClass("network-summary-bar-bottom");
-            this._summaryBarElement.style.removeProperty("width");
             this._dataGrid.appendChild(this._summaryBarRowNode);
             this._dataGrid.element.style.bottom = 0;
             this._sortItems();
         }
+        this._updateOffscreenRows();
     },
 
     _resetSummaryBar: function()
@@ -213,6 +215,7 @@ WebInspector.NetworkPanel.prototype = {
         this.containerElement.appendChild(this._dataGrid.element);
         this._dataGrid.addEventListener("sorting changed", this._sortItems, this);
         this._dataGrid.addEventListener("width changed", this._updateDividersIfNeeded, this);
+        this._dataGrid.scrollContainer.addEventListener("scroll", this._updateOffscreenRows.bind(this));
 
         this._patchTimelineHeader();
     },
@@ -772,7 +775,12 @@ WebInspector.NetworkPanel.prototype = {
         return this._resourcesById[id];
     },
 
-    appendResource: function(resource)
+    _onResourceStarted: function(event)
+    {
+        this._appendResource(event.data);
+    },
+
+    _appendResource: function(resource)
     {
         this._resources.push(resource);
         this._resourcesById[resource.identifier] = resource;
@@ -781,13 +789,18 @@ WebInspector.NetworkPanel.prototype = {
         // Pull all the redirects of the main resource upon commit load.
         if (resource.redirects) {
             for (var i = 0; i < resource.redirects.length; ++i)
-                this.refreshResource(resource.redirects[i]);
+                this._refreshResource(resource.redirects[i]);
         }
 
-        this.refreshResource(resource);
+        this._refreshResource(resource);
     },
 
-    refreshResource: function(resource)
+    _onResourceUpdated: function(event)
+    {
+        this._refreshResource(event.data);
+    },
+
+    _refreshResource: function(resource)
     {
         this._staleResources.push(resource);
         this._scheduleRefresh();
@@ -811,7 +824,7 @@ WebInspector.NetworkPanel.prototype = {
         this._reset();
     },
 
-    mainResourceChanged: function()
+    _onMainResourceCommitLoad: function()
     {
         if (this._preserveLogToggle.toggled)
             return;
@@ -819,7 +832,7 @@ WebInspector.NetworkPanel.prototype = {
         this._reset();
         // Now resurrect the main resource along with all redirects that lead to it.
         var resourcesToAppend = (WebInspector.mainResource.redirects || []).concat(WebInspector.mainResource);
-        resourcesToAppend.forEach(this.appendResource, this);
+        resourcesToAppend.forEach(this._appendResource, this);
     },
 
     canShowSourceLine: function(url, line)
@@ -918,7 +931,6 @@ WebInspector.NetworkPanel.prototype = {
             this._viewsContainerElement.addStyleClass("hidden");
             this.sidebarElement.style.right = 0;
             this.sidebarElement.style.removeProperty("width");
-            this._summaryBarElement.style.removeProperty("width");
             if (this._dataGrid.selectedNode)
                 this._dataGrid.selectedNode.selected = false;
         }
@@ -1008,13 +1020,43 @@ WebInspector.NetworkPanel.prototype = {
         var harArchive = {
             log: (new WebInspector.HARLog()).build()
         }
-        offerFileForDownload(JSON.stringify(harArchive));
+        InspectorFrontendHost.copyText(JSON.stringify(harArchive));
     },
 
     _exportResource: function(resource)
     {
         var har = (new WebInspector.HAREntry(resource)).build();
-        offerFileForDownload(JSON.stringify(har));
+        InspectorFrontendHost.copyText(JSON.stringify(har));
+    },
+
+    _updateOffscreenRows: function(e)
+    {
+        var dataTableBody = this._dataGrid.dataTableBody;
+        var rows = dataTableBody.children;
+        var recordsCount = rows.length;
+        if (recordsCount < 2)
+            return;  // Filler row only.
+
+        var visibleTop = this._dataGrid.scrollContainer.scrollTop;
+        var visibleBottom = visibleTop + this._dataGrid.scrollContainer.offsetHeight;
+
+        var rowHeight = rows[0].offsetHeight;
+
+        // Filler is at recordsCount - 1.
+        for (var i = 0; i < recordsCount - 1; ++i) {
+            var row = rows[i];
+            // Don't touch summaty - quit instead.
+            if (row === this._summaryBarRowNode)
+                break;
+            var rowIsVisible = i * rowHeight < visibleBottom && (i + 1) * rowHeight > visibleTop;
+            if (rowIsVisible !== row.rowIsVisible) {
+                if (rowIsVisible)
+                    row.removeStyleClass("offscreen");
+                else
+                    row.addStyleClass("offscreen");
+                row.rowIsVisible = rowIsVisible;
+            }
+        }
     }
 }