📄 resourcespanel.js
字号:
/* * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. * Copyright (C) 2008 Anthony Ricaud (rik24d@gmail.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */WebInspector.ResourcesPanel = function(){ WebInspector.Panel.call(this); this.element.addStyleClass("resources"); this.viewsContainerElement = document.createElement("div"); this.viewsContainerElement.id = "resource-views"; this.element.appendChild(this.viewsContainerElement); this.containerElement = document.createElement("div"); this.containerElement.id = "resources-container"; this.containerElement.addEventListener("scroll", this._updateDividersLabelBarPosition.bind(this), false); this.element.appendChild(this.containerElement); this.sidebarElement = document.createElement("div"); this.sidebarElement.id = "resources-sidebar"; this.sidebarElement.className = "sidebar"; this.containerElement.appendChild(this.sidebarElement); this.sidebarResizeElement = document.createElement("div"); this.sidebarResizeElement.className = "sidebar-resizer-vertical"; this.sidebarResizeElement.addEventListener("mousedown", this._startSidebarDragging.bind(this), false); this.element.appendChild(this.sidebarResizeElement); this.containerContentElement = document.createElement("div"); this.containerContentElement.id = "resources-container-content"; this.containerElement.appendChild(this.containerContentElement); this.summaryElement = document.createElement("div"); this.summaryElement.id = "resources-summary"; this.containerContentElement.appendChild(this.summaryElement); this.resourcesGraphsElement = document.createElement("div"); this.resourcesGraphsElement.id = "resources-graphs"; this.containerContentElement.appendChild(this.resourcesGraphsElement); this.dividersElement = document.createElement("div"); this.dividersElement.id = "resources-dividers"; this.containerContentElement.appendChild(this.dividersElement); this.dividersLabelBarElement = document.createElement("div"); this.dividersLabelBarElement.id = "resources-dividers-label-bar"; this.containerContentElement.appendChild(this.dividersLabelBarElement); this.summaryGraphElement = document.createElement("canvas"); this.summaryGraphElement.setAttribute("width", "450"); this.summaryGraphElement.setAttribute("height", "38"); this.summaryGraphElement.id = "resources-summary-graph"; this.summaryElement.appendChild(this.summaryGraphElement); this.legendElement = document.createElement("div"); this.legendElement.id = "resources-graph-legend"; this.summaryElement.appendChild(this.legendElement); this.sidebarTreeElement = document.createElement("ol"); this.sidebarTreeElement.className = "sidebar-tree"; this.sidebarElement.appendChild(this.sidebarTreeElement); this.sidebarTree = new TreeOutline(this.sidebarTreeElement); var timeGraphItem = new WebInspector.SidebarTreeElement("resources-time-graph-sidebar-item", WebInspector.UIString("Time")); timeGraphItem.onselect = this._graphSelected.bind(this); var transferTimeCalculator = new WebInspector.ResourceTransferTimeCalculator(); var transferDurationCalculator = new WebInspector.ResourceTransferDurationCalculator(); timeGraphItem.sortingOptions = [ { name: WebInspector.UIString("Sort by Start Time"), sortingFunction: WebInspector.ResourceSidebarTreeElement.CompareByAscendingStartTime, calculator: transferTimeCalculator }, { name: WebInspector.UIString("Sort by Response Time"), sortingFunction: WebInspector.ResourceSidebarTreeElement.CompareByAscendingResponseReceivedTime, calculator: transferTimeCalculator }, { name: WebInspector.UIString("Sort by End Time"), sortingFunction: WebInspector.ResourceSidebarTreeElement.CompareByAscendingEndTime, calculator: transferTimeCalculator }, { name: WebInspector.UIString("Sort by Duration"), sortingFunction: WebInspector.ResourceSidebarTreeElement.CompareByDescendingDuration, calculator: transferDurationCalculator }, { name: WebInspector.UIString("Sort by Latency"), sortingFunction: WebInspector.ResourceSidebarTreeElement.CompareByDescendingLatency, calculator: transferDurationCalculator }, ]; timeGraphItem.selectedSortingOptionIndex = 1; var sizeGraphItem = new WebInspector.SidebarTreeElement("resources-size-graph-sidebar-item", WebInspector.UIString("Size")); sizeGraphItem.onselect = this._graphSelected.bind(this); var transferSizeCalculator = new WebInspector.ResourceTransferSizeCalculator(); sizeGraphItem.sortingOptions = [ { name: WebInspector.UIString("Sort by Size"), sortingFunction: WebInspector.ResourceSidebarTreeElement.CompareByDescendingSize, calculator: transferSizeCalculator }, ]; sizeGraphItem.selectedSortingOptionIndex = 0; this.graphsTreeElement = new WebInspector.SidebarSectionTreeElement(WebInspector.UIString("GRAPHS"), {}, true); this.sidebarTree.appendChild(this.graphsTreeElement); this.graphsTreeElement.appendChild(timeGraphItem); this.graphsTreeElement.appendChild(sizeGraphItem); this.graphsTreeElement.expand(); this.resourcesTreeElement = new WebInspector.SidebarSectionTreeElement(WebInspector.UIString("RESOURCES"), {}, true); this.sidebarTree.appendChild(this.resourcesTreeElement); this.resourcesTreeElement.expand(); this.largerResourcesButton = document.createElement("button"); this.largerResourcesButton.id = "resources-larger-resources-status-bar-item"; this.largerResourcesButton.className = "status-bar-item toggled-on"; this.largerResourcesButton.title = WebInspector.UIString("Use small resource rows."); this.largerResourcesButton.addEventListener("click", this._toggleLargerResources.bind(this), false); this.sortingSelectElement = document.createElement("select"); this.sortingSelectElement.className = "status-bar-item"; this.sortingSelectElement.addEventListener("change", this._changeSortingFunction.bind(this), false); this.reset(); timeGraphItem.select();}WebInspector.ResourcesPanel.prototype = { toolbarItemClass: "resources", get toolbarItemLabel() { return WebInspector.UIString("Resources"); }, get statusBarItems() { return [this.largerResourcesButton, this.sortingSelectElement]; }, show: function() { WebInspector.Panel.prototype.show.call(this); this._updateDividersLabelBarPosition(); this._updateSidebarWidth(); this.refreshIfNeeded(); var visibleView = this.visibleView; if (visibleView) { visibleView.headersVisible = true; visibleView.show(this.viewsContainerElement); } // Hide any views that are visible that are not this panel's current visible view. // This can happen when a ResourceView is visible in the Scripts panel then switched // to the this panel. var resourcesLength = this._resources.length; for (var i = 0; i < resourcesLength; ++i) { var resource = this._resources[i]; var view = resource._resourcesView; if (!view || view === visibleView) continue; view.visible = false; } }, resize: function() { this._updateGraphDividersIfNeeded(); var visibleView = this.visibleView; if (visibleView && "resize" in visibleView) visibleView.resize(); }, get searchableViews() { var views = []; const visibleView = this.visibleView; if (visibleView && visibleView.performSearch) views.push(visibleView); var resourcesLength = this._resources.length; for (var i = 0; i < resourcesLength; ++i) { var resource = this._resources[i]; if (!resource._resourcesTreeElement) continue; var resourceView = this.resourceViewForResource(resource); if (!resourceView.performSearch || resourceView === visibleView) continue; views.push(resourceView); } return views; }, get searchResultsSortFunction() { const resourceTreeElementSortFunction = this.sortingFunction; function sortFuction(a, b) { return resourceTreeElementSortFunction(a.resource._resourcesTreeElement, b.resource._resourcesTreeElement); } return sortFuction; }, searchMatchFound: function(view, matches) { view.resource._resourcesTreeElement.searchMatches = matches; }, searchCanceled: function(startingNewSearch) { WebInspector.Panel.prototype.searchCanceled.call(this, startingNewSearch); if (startingNewSearch || !this._resources) return; for (var i = 0; i < this._resources.length; ++i) { var resource = this._resources[i]; if (resource._resourcesTreeElement) resource._resourcesTreeElement.updateErrorsAndWarnings(); } }, performSearch: function(query) { for (var i = 0; i < this._resources.length; ++i) { var resource = this._resources[i]; if (resource._resourcesTreeElement) resource._resourcesTreeElement.resetBubble(); } WebInspector.Panel.prototype.performSearch.call(this, query); }, get visibleView() { if (this.visibleResource) return this.visibleResource._resourcesView; return null; }, get calculator() { return this._calculator; }, set calculator(x) { if (!x || this._calculator === x) return; this._calculator = x; this._calculator.reset(); this._staleResources = this._resources; this.refresh(); }, get sortingFunction() { return this._sortingFunction; }, set sortingFunction(x) { this._sortingFunction = x; this._sortResourcesIfNeeded(); }, get needsRefresh() { return this._needsRefresh; }, set needsRefresh(x) { if (this._needsRefresh === x) return; this._needsRefresh = x; if (x) { if (this.visible && !("_refreshTimeout" in this)) this._refreshTimeout = setTimeout(this.refresh.bind(this), 500); } else { if ("_refreshTimeout" in this) { clearTimeout(this._refreshTimeout); delete this._refreshTimeout; } } }, refreshIfNeeded: function() { if (this.needsRefresh) this.refresh(); }, refresh: function() { this.needsRefresh = false; var staleResourcesLength = this._staleResources.length; var boundariesChanged = false; for (var i = 0; i < staleResourcesLength; ++i) { var resource = this._staleResources[i]; if (!resource._resourcesTreeElement) { // Create the resource tree element and graph. resource._resourcesTreeElement = new WebInspector.ResourceSidebarTreeElement(resource); resource._resourcesTreeElement._resourceGraph = new WebInspector.ResourceGraph(resource); this.resourcesTreeElement.appendChild(resource._resourcesTreeElement); this.resourcesGraphsElement.appendChild(resource._resourcesTreeElement._resourceGraph.graphElement); } resource._resourcesTreeElement.refresh(); if (this.calculator.updateBoundaries(resource)) boundariesChanged = true; } if (boundariesChanged) { // The boundaries changed, so all resource graphs are stale. this._staleResources = this._resources; staleResourcesLength = this._staleResources.length; } for (var i = 0; i < staleResourcesLength; ++i) this._staleResources[i]._resourcesTreeElement._resourceGraph.refresh(this.calculator); this._staleResources = []; this._updateGraphDividersIfNeeded(); this._sortResourcesIfNeeded(); this._updateSummaryGraph(); }, reset: function() { this.closeVisibleResource(); this.containerElement.scrollTop = 0; delete this.currentQuery; this.searchCanceled(); if (this._calculator) this._calculator.reset(); if (this._resources) { var resourcesLength = this._resources.length; for (var i = 0; i < resourcesLength; ++i) { var resource = this._resources[i]; resource.warnings = 0; resource.errors = 0; delete resource._resourcesTreeElement; delete resource._resourcesView; } } this._resources = []; this._staleResources = []; this.resourcesTreeElement.removeChildren(); this.viewsContainerElement.removeChildren(); this.resourcesGraphsElement.removeChildren(); this.legendElement.removeChildren(); this._updateGraphDividersIfNeeded(true); this._drawSummaryGraph(); // draws an empty graph }, addResource: function(resource) { this._resources.push(resource); this.refreshResource(resource); }, removeResource: function(resource) { if (this.visibleView === resource._resourcesView) this.closeVisibleResource(); this._resources.remove(resource, true); if (resource._resourcesTreeElement) { this.resourcesTreeElement.removeChild(resource._resourcesTreeElement);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -