📄 resourcespanel.js
字号:
this.resourcesGraphsElement.removeChild(resource._resourcesTreeElement._resourceGraph.graphElement); } resource.warnings = 0; resource.errors = 0; delete resource._resourcesTreeElement; delete resource._resourcesView; this._adjustScrollPosition(); }, addMessageToResource: function(resource, msg) { if (!resource) return; switch (msg.level) { case WebInspector.ConsoleMessage.MessageLevel.Warning: resource.warnings += msg.repeatDelta; break; case WebInspector.ConsoleMessage.MessageLevel.Error: resource.errors += msg.repeatDelta; break; } if (!this.currentQuery && resource._resourcesTreeElement) resource._resourcesTreeElement.updateErrorsAndWarnings(); var view = this.resourceViewForResource(resource); if (view.addMessage) view.addMessage(msg); }, clearMessages: function() { var resourcesLength = this._resources.length; for (var i = 0; i < resourcesLength; ++i) { var resource = this._resources[i]; resource.warnings = 0; resource.errors = 0; if (!this.currentQuery && resource._resourcesTreeElement) resource._resourcesTreeElement.updateErrorsAndWarnings(); var view = resource._resourcesView; if (!view || !view.clearMessages) continue; view.clearMessages(); } }, refreshResource: function(resource) { this._staleResources.push(resource); this.needsRefresh = true; }, recreateViewForResourceIfNeeded: function(resource) { if (!resource || !resource._resourcesView) return; var newView = this._createResourceView(resource); if (newView.prototype === resource._resourcesView.prototype) return; resource.warnings = 0; resource.errors = 0; if (!this.currentQuery && resource._resourcesTreeElement) resource._resourcesTreeElement.updateErrorsAndWarnings(); var oldView = resource._resourcesView; resource._resourcesView.detach(); delete resource._resourcesView; resource._resourcesView = newView; newView.headersVisible = oldView.headersVisible; if (oldView.visible && oldView.element.parentNode) newView.show(oldView.element.parentNode); }, showResource: function(resource, line) { if (!resource) return; this.containerElement.addStyleClass("viewing-resource"); if (this.visibleResource && this.visibleResource._resourcesView) this.visibleResource._resourcesView.hide(); var view = this.resourceViewForResource(resource); view.headersVisible = true; view.show(this.viewsContainerElement); if (line) { if (view.revealLine) view.revealLine(line); if (view.highlightLine) view.highlightLine(line); } if (resource._resourcesTreeElement) { resource._resourcesTreeElement.reveal(); resource._resourcesTreeElement.select(true); } this.visibleResource = resource; this._updateSidebarWidth(); }, showView: function(view) { if (!view) return; this.showResource(view.resource); }, closeVisibleResource: function() { this.containerElement.removeStyleClass("viewing-resource"); this._updateDividersLabelBarPosition(); if (this.visibleResource && this.visibleResource._resourcesView) this.visibleResource._resourcesView.hide(); delete this.visibleResource; if (this._lastSelectedGraphTreeElement) this._lastSelectedGraphTreeElement.select(true); this._updateSidebarWidth(); }, resourceViewForResource: function(resource) { if (!resource) return null; if (!resource._resourcesView) resource._resourcesView = this._createResourceView(resource); return resource._resourcesView; }, sourceFrameForResource: function(resource) { var view = this.resourceViewForResource(resource); if (!view) return null; if (!view.setupSourceFrameIfNeeded) return null; // Setting up the source frame requires that we be attached. if (!this.element.parentNode) this.attach(); view.setupSourceFrameIfNeeded(); return view.sourceFrame; }, handleKeyEvent: function(event) { this.sidebarTree.handleKeyEvent(event); }, _makeLegendElement: function(label, value, color) { var legendElement = document.createElement("label"); legendElement.className = "resources-graph-legend-item"; if (color) { var swatch = document.createElement("canvas"); swatch.className = "resources-graph-legend-swatch"; swatch.setAttribute("width", "13"); swatch.setAttribute("height", "24"); legendElement.appendChild(swatch); this._drawSwatch(swatch, color); } var labelElement = document.createElement("div"); labelElement.className = "resources-graph-legend-label"; legendElement.appendChild(labelElement); var headerElement = document.createElement("div"); var headerElement = document.createElement("div"); headerElement.className = "resources-graph-legend-header"; headerElement.textContent = label; labelElement.appendChild(headerElement); var valueElement = document.createElement("div"); valueElement.className = "resources-graph-legend-value"; valueElement.textContent = value; labelElement.appendChild(valueElement); return legendElement; }, _sortResourcesIfNeeded: function() { var sortedElements = [].concat(this.resourcesTreeElement.children); sortedElements.sort(this.sortingFunction); var sortedElementsLength = sortedElements.length; for (var i = 0; i < sortedElementsLength; ++i) { var treeElement = sortedElements[i]; if (treeElement === this.resourcesTreeElement.children[i]) continue; var wasSelected = treeElement.selected; this.resourcesTreeElement.removeChild(treeElement); this.resourcesTreeElement.insertChild(treeElement, i); if (wasSelected) treeElement.select(true); var graphElement = treeElement._resourceGraph.graphElement; this.resourcesGraphsElement.insertBefore(graphElement, this.resourcesGraphsElement.children[i]); } }, _updateGraphDividersIfNeeded: function(force) { if (!this.visible) { this.needsRefresh = true; return; } if (document.body.offsetWidth <= 0) { // The stylesheet hasn't loaded yet or the window is closed, // so we can't calculate what is need. Return early. return; } var dividerCount = Math.round(this.dividersElement.offsetWidth / 64); var slice = this.calculator.boundarySpan / dividerCount; if (!force && this._currentDividerSlice === slice) return; this._currentDividerSlice = slice; this.dividersElement.removeChildren(); this.dividersLabelBarElement.removeChildren(); for (var i = 1; i <= dividerCount; ++i) { var divider = document.createElement("div"); divider.className = "resources-divider"; if (i === dividerCount) divider.addStyleClass("last"); divider.style.left = ((i / dividerCount) * 100) + "%"; this.dividersElement.appendChild(divider.cloneNode()); var label = document.createElement("div"); label.className = "resources-divider-label"; if (!isNaN(slice)) label.textContent = this.calculator.formatValue(slice * i); divider.appendChild(label); this.dividersLabelBarElement.appendChild(divider); } }, _fadeOutRect: function(ctx, x, y, w, h, a1, a2) { ctx.save(); var gradient = ctx.createLinearGradient(x, y, x, y + h); gradient.addColorStop(0.0, "rgba(0, 0, 0, " + (1.0 - a1) + ")"); gradient.addColorStop(0.8, "rgba(0, 0, 0, " + (1.0 - a2) + ")"); gradient.addColorStop(1.0, "rgba(0, 0, 0, 1.0)"); ctx.globalCompositeOperation = "destination-out"; ctx.fillStyle = gradient; ctx.fillRect(x, y, w, h); ctx.restore(); }, _drawSwatch: function(canvas, color) { var ctx = canvas.getContext("2d"); function drawSwatchSquare() { ctx.fillStyle = color; ctx.fillRect(0, 0, 13, 13); var gradient = ctx.createLinearGradient(0, 0, 13, 13); gradient.addColorStop(0.0, "rgba(255, 255, 255, 0.2)"); gradient.addColorStop(1.0, "rgba(255, 255, 255, 0.0)"); ctx.fillStyle = gradient; ctx.fillRect(0, 0, 13, 13); gradient = ctx.createLinearGradient(13, 13, 0, 0); gradient.addColorStop(0.0, "rgba(0, 0, 0, 0.2)"); gradient.addColorStop(1.0, "rgba(0, 0, 0, 0.0)"); ctx.fillStyle = gradient; ctx.fillRect(0, 0, 13, 13); ctx.strokeStyle = "rgba(0, 0, 0, 0.6)"; ctx.strokeRect(0.5, 0.5, 12, 12); } ctx.clearRect(0, 0, 13, 24); drawSwatchSquare(); ctx.save(); ctx.translate(0, 25); ctx.scale(1, -1); drawSwatchSquare(); ctx.restore(); this._fadeOutRect(ctx, 0, 13, 13, 13, 0.5, 0.0); }, _drawSummaryGraph: function(segments) { if (!this.summaryGraphElement) return; if (!segments || !segments.length) { segments = [{color: "white", value: 1}]; this._showingEmptySummaryGraph = true; } else delete this._showingEmptySummaryGraph; // Calculate the total of all segments. var total = 0; for (var i = 0; i < segments.length; ++i) total += segments[i].value; // Calculate the percentage of each segment, rounded to the nearest percent. var percents = segments.map(function(s) { return Math.max(Math.round(100 * s.value / total), 1) }); // Calculate the total percentage. var percentTotal = 0; for (var i = 0; i < percents.length; ++i) percentTotal += percents[i]; // Make sure our percentage total is not greater-than 100, it can be greater // if we rounded up for a few segments. while (percentTotal > 100) { for (var i = 0; i < percents.length && percentTotal > 100; ++i) { if (percents[i] > 1) { --percents[i]; --percentTotal; } } } // Make sure our percentage total is not less-than 100, it can be less // if we rounded down for a few segments. while (percentTotal < 100) { for (var i = 0; i < percents.length && percentTotal < 100; ++i) { ++percents[i]; ++percentTotal; } } var ctx = this.summaryGraphElement.getContext("2d"); var x = 0; var y = 0; var w = 450; var h = 19; var r = (h / 2); function drawPillShadow() { // This draws a line with a shadow that is offset away from the line. The line is stroked // twice with different X shadow offsets to give more feathered edges. Later we erase the // line with destination-out 100% transparent black, leaving only the shadow. This only // works if nothing has been drawn into the canvas yet. ctx.beginPath(); ctx.moveTo(x + 4, y + h - 3 - 0.5); ctx.lineTo(x + w - 4, y + h - 3 - 0.5); ctx.closePath(); ctx.save(); ctx.shadowBlur = 2; ctx.shadowColor = "rgba(0, 0, 0, 0.5)"; ctx.shadowOffsetX = 3; ctx.shadowOffsetY = 5; ctx.strokeStyle = "white"; ctx.lineWidth = 1; ctx.stroke(); ctx.shadowOffsetX = -3; ctx.stroke(); ctx.restore(); ctx.save(); ctx.globalCompositeOperation = "destination-out"; ctx.strokeStyle = "rgba(0, 0, 0, 1)";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -