⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resourcespanel.js

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 JS
📖 第 1 页 / 共 4 页
字号:
            ctx.lineWidth = 1;            ctx.stroke();            ctx.restore();        }        function drawPill()        {            // Make a rounded rect path.            ctx.beginPath();            ctx.moveTo(x, y + r);            ctx.lineTo(x, y + h - r);            ctx.quadraticCurveTo(x, y + h, x + r, y + h);            ctx.lineTo(x + w - r, y + h);            ctx.quadraticCurveTo(x + w, y + h, x + w, y + h - r);            ctx.lineTo(x + w, y + r);            ctx.quadraticCurveTo(x + w, y, x + w - r, y);            ctx.lineTo(x + r, y);            ctx.quadraticCurveTo(x, y, x, y + r);            ctx.closePath();            // Clip to the rounded rect path.            ctx.save();            ctx.clip();            // Fill the segments with the associated color.            var previousSegmentsWidth = 0;            for (var i = 0; i < segments.length; ++i) {                var segmentWidth = Math.round(w * percents[i] / 100);                ctx.fillStyle = segments[i].color;                ctx.fillRect(x + previousSegmentsWidth, y, segmentWidth, h);                previousSegmentsWidth += segmentWidth;            }            // Draw the segment divider lines.            ctx.lineWidth = 1;            for (var i = 1; i < 20; ++i) {                ctx.beginPath();                ctx.moveTo(x + (i * Math.round(w / 20)) + 0.5, y);                ctx.lineTo(x + (i * Math.round(w / 20)) + 0.5, y + h);                ctx.closePath();                ctx.strokeStyle = "rgba(0, 0, 0, 0.2)";                ctx.stroke();                ctx.beginPath();                ctx.moveTo(x + (i * Math.round(w / 20)) + 1.5, y);                ctx.lineTo(x + (i * Math.round(w / 20)) + 1.5, y + h);                ctx.closePath();                ctx.strokeStyle = "rgba(255, 255, 255, 0.2)";                ctx.stroke();            }            // Draw the pill shading.            var lightGradient = ctx.createLinearGradient(x, y, x, y + (h / 1.5));            lightGradient.addColorStop(0.0, "rgba(220, 220, 220, 0.6)");            lightGradient.addColorStop(0.4, "rgba(220, 220, 220, 0.2)");            lightGradient.addColorStop(1.0, "rgba(255, 255, 255, 0.0)");            var darkGradient = ctx.createLinearGradient(x, y + (h / 3), x, y + h);            darkGradient.addColorStop(0.0, "rgba(0, 0, 0, 0.0)");            darkGradient.addColorStop(0.8, "rgba(0, 0, 0, 0.2)");            darkGradient.addColorStop(1.0, "rgba(0, 0, 0, 0.5)");            ctx.fillStyle = darkGradient;            ctx.fillRect(x, y, w, h);            ctx.fillStyle = lightGradient;            ctx.fillRect(x, y, w, h);            ctx.restore();        }        ctx.clearRect(x, y, w, (h * 2));        drawPillShadow();        drawPill();        ctx.save();        ctx.translate(0, (h * 2) + 1);        ctx.scale(1, -1);        drawPill();        ctx.restore();        this._fadeOutRect(ctx, x, y + h + 1, w, h, 0.5, 0.0);    },    _updateSummaryGraph: function()    {        var graphInfo = this.calculator.computeSummaryValues(this._resources);        var categoryOrder = ["documents", "stylesheets", "images", "scripts", "xhr", "fonts", "other"];        var categoryColors = {documents: {r: 47, g: 102, b: 236}, stylesheets: {r: 157, g: 231, b: 119}, images: {r: 164, g: 60, b: 255}, scripts: {r: 255, g: 121, b: 0}, xhr: {r: 231, g: 231, b: 10}, fonts: {r: 255, g: 82, b: 62}, other: {r: 186, g: 186, b: 186}};        var fillSegments = [];        this.legendElement.removeChildren();        for (var i = 0; i < categoryOrder.length; ++i) {            var category = categoryOrder[i];            var size = graphInfo.categoryValues[category];            if (!size)                continue;            var color = categoryColors[category];            var colorString = "rgb(" + color.r + ", " + color.g + ", " + color.b + ")";            var fillSegment = {color: colorString, value: size};            fillSegments.push(fillSegment);            var legendLabel = this._makeLegendElement(WebInspector.resourceCategories[category].title, this.calculator.formatValue(size), colorString);            this.legendElement.appendChild(legendLabel);        }        if (graphInfo.total) {            var totalLegendLabel = this._makeLegendElement(WebInspector.UIString("Total"), this.calculator.formatValue(graphInfo.total));            totalLegendLabel.addStyleClass("total");            this.legendElement.appendChild(totalLegendLabel);        }        this._drawSummaryGraph(fillSegments);    },    _updateDividersLabelBarPosition: function()    {        var scrollTop = this.containerElement.scrollTop;        var dividersTop = (scrollTop < this.summaryElement.offsetHeight ? this.summaryElement.offsetHeight : scrollTop);        this.dividersElement.style.top = scrollTop + "px";        this.dividersLabelBarElement.style.top = dividersTop + "px";    },    _graphSelected: function(treeElement)    {        if (this._lastSelectedGraphTreeElement)            this._lastSelectedGraphTreeElement.selectedSortingOptionIndex = this.sortingSelectElement.selectedIndex;        this._lastSelectedGraphTreeElement = treeElement;        this.sortingSelectElement.removeChildren();        for (var i = 0; i < treeElement.sortingOptions.length; ++i) {            var sortingOption = treeElement.sortingOptions[i];            var option = document.createElement("option");            option.label = sortingOption.name;            option.sortingFunction = sortingOption.sortingFunction;            option.calculator = sortingOption.calculator;            this.sortingSelectElement.appendChild(option);        }        this.sortingSelectElement.selectedIndex = treeElement.selectedSortingOptionIndex;        this._changeSortingFunction();        this.closeVisibleResource();        this.containerElement.scrollTop = 0;    },    _toggleLargerResources: function()    {        if (!this.resourcesTreeElement._childrenListNode)            return;        this.resourcesTreeElement.smallChildren = !this.resourcesTreeElement.smallChildren;        if (this.resourcesTreeElement.smallChildren) {            this.resourcesGraphsElement.addStyleClass("small");            this.largerResourcesButton.title = WebInspector.UIString("Use large resource rows.");            this.largerResourcesButton.removeStyleClass("toggled-on");            this._adjustScrollPosition();        } else {            this.resourcesGraphsElement.removeStyleClass("small");            this.largerResourcesButton.title = WebInspector.UIString("Use small resource rows.");            this.largerResourcesButton.addStyleClass("toggled-on");        }    },    _adjustScrollPosition: function()    {        // Prevent the container from being scrolled off the end.        if ((this.containerElement.scrollTop + this.containerElement.offsetHeight) > this.sidebarElement.offsetHeight)            this.containerElement.scrollTop = (this.sidebarElement.offsetHeight - this.containerElement.offsetHeight);    },    _changeSortingFunction: function()    {        var selectedOption = this.sortingSelectElement[this.sortingSelectElement.selectedIndex];        this.sortingFunction = selectedOption.sortingFunction;        this.calculator = selectedOption.calculator;    },    _createResourceView: function(resource)    {        switch (resource.category) {            case WebInspector.resourceCategories.documents:            case WebInspector.resourceCategories.stylesheets:            case WebInspector.resourceCategories.scripts:            case WebInspector.resourceCategories.xhr:                return new WebInspector.SourceView(resource);            case WebInspector.resourceCategories.images:                return new WebInspector.ImageView(resource);            case WebInspector.resourceCategories.fonts:                return new WebInspector.FontView(resource);            default:                return new WebInspector.ResourceView(resource);        }    },    _startSidebarDragging: function(event)    {        WebInspector.elementDragStart(this.sidebarResizeElement, this._sidebarDragging.bind(this), this._endSidebarDragging.bind(this), event, "col-resize");    },    _sidebarDragging: function(event)    {        this._updateSidebarWidth(event.pageX);        event.preventDefault();    },    _endSidebarDragging: function(event)    {        WebInspector.elementDragEnd(event);    },    _updateSidebarWidth: function(width)    {        if (this.sidebarElement.offsetWidth <= 0) {            // The stylesheet hasn't loaded yet or the window is closed,            // so we can't calculate what is need. Return early.            return;        }        if (!("_currentSidebarWidth" in this))            this._currentSidebarWidth = this.sidebarElement.offsetWidth;        if (typeof width === "undefined")            width = this._currentSidebarWidth;        width = Number.constrain(width, Preferences.minSidebarWidth, window.innerWidth / 2);        this._currentSidebarWidth = width;        if (this.visibleResource) {            this.containerElement.style.width = width + "px";            this.sidebarElement.style.removeProperty("width");        } else {            this.sidebarElement.style.width = width + "px";            this.containerElement.style.removeProperty("width");        }        this.containerContentElement.style.left = width + "px";        this.viewsContainerElement.style.left = width + "px";        this.sidebarResizeElement.style.left = (width - 3) + "px";        this._updateGraphDividersIfNeeded();        var visibleView = this.visibleView;        if (visibleView && "resize" in visibleView)            visibleView.resize();    }}WebInspector.ResourcesPanel.prototype.__proto__ = WebInspector.Panel.prototype;WebInspector.ResourceCalculator = function(){}WebInspector.ResourceCalculator.prototype = {    computeSummaryValues: function(resources)    {        var total = 0;        var categoryValues = {};        var resourcesLength = resources.length;        for (var i = 0; i < resourcesLength; ++i) {            var resource = resources[i];            var value = this._value(resource);            if (typeof value === "undefined")                continue;            if (!(resource.category.name in categoryValues))                categoryValues[resource.category.name] = 0;            categoryValues[resource.category.name] += value;            total += value;        }        return {categoryValues: categoryValues, total: total};    },    computeBarGraphPercentages: function(resource)    {        return {start: 0, middle: 0, end: (this._value(resource) / this.boundarySpan) * 100};    },    computeBarGraphLabels: function(resource)    {        const label = this.formatValue(this._value(resource));        var tooltip = label;        if (resource.cached)            tooltip = WebInspector.UIString("%s (from cache)", tooltip);        return {left: label, right: label, tooltip: tooltip};    },    get boundarySpan()    {        return this.maximumBoundary - this.minimumBoundary;    },    updateBoundaries: function(resource)    {        this.minimumBoundary = 0;        var value = this._value(resource);        if (typeof this.maximumBoundary === "undefined" || value > this.maximumBoundary) {            this.maximumBoundary = value;            return true;        }        return false;    },    reset: function()    {        delete this.minimumBoundary;        delete this.maximumBoundary;    },    _value: function(resource)    {        return 0;    },    formatValue: function(value)    {        return value.toString();    }}WebInspector.ResourceTimeCalculator = function(startAtZero){    WebInspector.ResourceCalculator.call(this);    this.startAtZero = startAtZero;}WebInspector.ResourceTimeCalculator.prototype = {    computeSummaryValues: function(resources)    {        var resourcesByCategory = {};        var resourcesLength = resources.length;        for (var i = 0; i < resourcesLength; ++i) {            var resource = resources[i];            if (!(resource.category.name in resourcesByCategory))                resourcesByCategory[resource.category.name] = [];            resourcesByCategory[resource.category.name].push(resource);        }        var earliestStart;        var latestEnd;        var categoryValues = {};        for (var category in resourcesByCategory) {            resourcesByCategory[category].sort(WebInspector.Resource.CompareByTime);            categoryValues[category] = 0;            var segment = {start: -1, end: -1};            var categoryResources = resourcesByCategory[category];            var resourcesLength = categoryResources.length;            for (var i = 0; i < resourcesLength; ++i) {                var resource = categoryResources[i];                if (resource.startTime === -1 || resource.endTime === -1)                    continue;                if (typeof earliestStart === "undefined")                    earliestStart = resource.startTime;                else                    earliestStart = Math.min(earliestStart, resource.startTime);                if (typeof latestEnd === "undefined")                    latestEnd = resource.endTime;                else                    latestEnd = Math.max(latestEnd, resource.endTime);                if (resource.startTime <= segment.end) {                    segment.end = Math.max(segment.end, resource.endTime);                    continue;                }                categoryValues[category] += segment.end - segment.start;                segment.start = resource.startTime;                segment.end = resource.endTime;            }            // Add the last segment            categoryValues[category] += segment.end - segment.start;        }        return {categoryValues: categoryValues, total: latestEnd - earliestStart};    },    computeBarGraphPercentages: function(resource)    {        if (resource.startTime !== -1)            var start = ((resource.startTime - this.minimumBoundary) / this.boundarySpan) * 100;        else            var start = 0;        if (resource.responseReceivedTime !== -1)            var middle = ((resource.responseReceivedTime - this.minimumBoundary) / this.boundarySpan) * 100;        else            var middle = (this.startAtZero ? start : 100);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -