Changeset 47822 in webkit


Ignore:
Timestamp:
Aug 27, 2009 9:09:54 AM (15 years ago)
Author:
pfeldman@chromium.org
Message:

2009-08-27 Mikhail Naganov <mnaganov@chromium.org>

Reviewed by Timothy Hatcher.

Factor out Factor out summary bar from Resources panel.

https://bugs.webkit.org/show_bug.cgi?id=28740

  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • inspector/front-end/ResourcesPanel.js: (WebInspector.ResourcesPanel.prototype.reset): (WebInspector.ResourcesPanel.prototype._updateSummaryGraph): (WebInspector.ResourcesPanel.prototype._updateDividersLabelBarPosition): (WebInspector.ResourcesPanel.prototype._changeSortingFunction):
  • inspector/front-end/SummaryBar.js: Added. (WebInspector.SummaryBar): (WebInspector.SummaryBar.prototype.get calculator): (WebInspector.SummaryBar.prototype.set calculator): (WebInspector.SummaryBar.prototype.reset): (WebInspector.SummaryBar.prototype.update): (WebInspector.SummaryBar.prototype._drawSwatch.drawSwatchSquare): (WebInspector.SummaryBar.prototype._drawSwatch): (WebInspector.SummaryBar.prototype._drawSummaryGraph.var): (WebInspector.SummaryBar.prototype._drawSummaryGraph): (WebInspector.SummaryBar.prototype._drawSummaryGraph.drawPill): (WebInspector.SummaryBar.prototype._fadeOutRect): (WebInspector.SummaryBar.prototype._makeLegendElement):
  • inspector/front-end/WebKit.qrc:
  • inspector/front-end/inspector.css:
  • inspector/front-end/inspector.html:
Location:
trunk/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r47821 r47822  
     12009-08-27  Mikhail Naganov  <mnaganov@chromium.org>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Factor out Factor out summary bar from Resources panel.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=28740
     8
     9        * WebCore.gypi:
     10        * WebCore.vcproj/WebCore.vcproj:
     11        * inspector/front-end/ResourcesPanel.js:
     12        (WebInspector.ResourcesPanel.prototype.reset):
     13        (WebInspector.ResourcesPanel.prototype._updateSummaryGraph):
     14        (WebInspector.ResourcesPanel.prototype._updateDividersLabelBarPosition):
     15        (WebInspector.ResourcesPanel.prototype._changeSortingFunction):
     16        * inspector/front-end/SummaryBar.js: Added.
     17        (WebInspector.SummaryBar):
     18        (WebInspector.SummaryBar.prototype.get calculator):
     19        (WebInspector.SummaryBar.prototype.set calculator):
     20        (WebInspector.SummaryBar.prototype.reset):
     21        (WebInspector.SummaryBar.prototype.update):
     22        (WebInspector.SummaryBar.prototype._drawSwatch.drawSwatchSquare):
     23        (WebInspector.SummaryBar.prototype._drawSwatch):
     24        (WebInspector.SummaryBar.prototype._drawSummaryGraph.var):
     25        (WebInspector.SummaryBar.prototype._drawSummaryGraph):
     26        (WebInspector.SummaryBar.prototype._drawSummaryGraph.drawPill):
     27        (WebInspector.SummaryBar.prototype._fadeOutRect):
     28        (WebInspector.SummaryBar.prototype._makeLegendElement):
     29        * inspector/front-end/WebKit.qrc:
     30        * inspector/front-end/inspector.css:
     31        * inspector/front-end/inspector.html:
     32
    1332009-08-26  Mikhail Naganov  <mnaganov@chromium.org>
    234
  • trunk/WebCore/WebCore.gypi

    r47763 r47822  
    34943494            'inspector/front-end/StoragePanel.js',
    34953495            'inspector/front-end/StylesSidebarPane.js',
     3496            'inspector/front-end/SummaryBar.js',
    34963497            'inspector/front-end/TextPrompt.js',
    34973498            'inspector/front-end/TopDownProfileDataGridTree.js',
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r47763 r47822  
    3135631356                                </File>
    3135731357                                <File
     31358                                        RelativePath="..\inspector\front-end\SummaryBar.js"
     31359                                        >
     31360                                </File>
     31361                                <File
    3135831362                                        RelativePath="..\inspector\front-end\TextPrompt.js"
    3135931363                                        >
  • trunk/WebCore/inspector/front-end/ResourcesPanel.js

    r47703 r47822  
    6161    this.containerElement.appendChild(this.containerContentElement);
    6262
    63     this.summaryElement = document.createElement("div");
    64     this.summaryElement.id = "resources-summary";
    65     this.containerContentElement.appendChild(this.summaryElement);
     63    this.summaryBar = new WebInspector.SummaryBar(this.categoryColors, this.categoryOrder);
     64    this.summaryBar.element.id = "resources-summary";
     65    this.containerContentElement.appendChild(this.summaryBar.element);
    6666
    6767    this.resourcesGraphsElement = document.createElement("div");
     
    7676    this.dividersLabelBarElement.id = "resources-dividers-label-bar";
    7777    this.containerContentElement.appendChild(this.dividersLabelBarElement);
    78 
    79     this.summaryGraphElement = document.createElement("canvas");
    80     this.summaryGraphElement.setAttribute("width", "450");
    81     this.summaryGraphElement.setAttribute("height", "38");
    82     this.summaryGraphElement.id = "resources-summary-graph";
    83     this.summaryElement.appendChild(this.summaryGraphElement);
    84 
    85     this.legendElement = document.createElement("div");
    86     this.legendElement.id = "resources-graph-legend";
    87     this.summaryElement.appendChild(this.legendElement);
    8878
    8979    this.sidebarTreeElement = document.createElement("ol");
     
    177167    toolbarItemClass: "resources",
    178168
     169    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}},
     170
    179171    categoryOrder: ["documents", "stylesheets", "images", "scripts", "xhr", "fonts", "other"],
    180172
     
    457449        this.viewsContainerElement.removeChildren();
    458450        this.resourcesGraphsElement.removeChildren();
    459         this.legendElement.removeChildren();
     451        this.summaryBar.reset();
    460452
    461453        this._updateGraphDividersIfNeeded(true);
    462 
    463         this._drawSummaryGraph(); // draws an empty graph
    464454
    465455        if (InspectorController.resourceTrackingEnabled()) {
     
    663653    },
    664654
    665     _makeLegendElement: function(label, value, color)
    666     {
    667         var legendElement = document.createElement("label");
    668         legendElement.className = "resources-graph-legend-item";
    669 
    670         if (color) {
    671             var swatch = document.createElement("canvas");
    672             swatch.className = "resources-graph-legend-swatch";
    673             swatch.setAttribute("width", "13");
    674             swatch.setAttribute("height", "24");
    675 
    676             legendElement.appendChild(swatch);
    677 
    678             this._drawSwatch(swatch, color);
    679         }
    680 
    681         var labelElement = document.createElement("div");
    682         labelElement.className = "resources-graph-legend-label";
    683         legendElement.appendChild(labelElement);
    684 
    685         var headerElement = document.createElement("div");
    686         var headerElement = document.createElement("div");
    687         headerElement.className = "resources-graph-legend-header";
    688         headerElement.textContent = label;
    689         labelElement.appendChild(headerElement);
    690 
    691         var valueElement = document.createElement("div");
    692         valueElement.className = "resources-graph-legend-value";
    693         valueElement.textContent = value;
    694         labelElement.appendChild(valueElement);
    695 
    696         return legendElement;
    697     },
    698 
    699655    _sortResourcesIfNeeded: function()
    700656    {
     
    761717    },
    762718
    763     _fadeOutRect: function(ctx, x, y, w, h, a1, a2)
    764     {
    765         ctx.save();
    766 
    767         var gradient = ctx.createLinearGradient(x, y, x, y + h);
    768         gradient.addColorStop(0.0, "rgba(0, 0, 0, " + (1.0 - a1) + ")");
    769         gradient.addColorStop(0.8, "rgba(0, 0, 0, " + (1.0 - a2) + ")");
    770         gradient.addColorStop(1.0, "rgba(0, 0, 0, 1.0)");
    771 
    772         ctx.globalCompositeOperation = "destination-out";
    773 
    774         ctx.fillStyle = gradient;
    775         ctx.fillRect(x, y, w, h);
    776 
    777         ctx.restore();
    778     },
    779 
    780     _drawSwatch: function(canvas, color)
    781     {
    782         var ctx = canvas.getContext("2d");
    783 
    784         function drawSwatchSquare() {
    785             ctx.fillStyle = color;
    786             ctx.fillRect(0, 0, 13, 13);
    787 
    788             var gradient = ctx.createLinearGradient(0, 0, 13, 13);
    789             gradient.addColorStop(0.0, "rgba(255, 255, 255, 0.2)");
    790             gradient.addColorStop(1.0, "rgba(255, 255, 255, 0.0)");
    791 
    792             ctx.fillStyle = gradient;
    793             ctx.fillRect(0, 0, 13, 13);
    794 
    795             gradient = ctx.createLinearGradient(13, 13, 0, 0);
    796             gradient.addColorStop(0.0, "rgba(0, 0, 0, 0.2)");
    797             gradient.addColorStop(1.0, "rgba(0, 0, 0, 0.0)");
    798 
    799             ctx.fillStyle = gradient;
    800             ctx.fillRect(0, 0, 13, 13);
    801 
    802             ctx.strokeStyle = "rgba(0, 0, 0, 0.6)";
    803             ctx.strokeRect(0.5, 0.5, 12, 12);
    804         }
    805 
    806         ctx.clearRect(0, 0, 13, 24);
    807 
    808         drawSwatchSquare();
    809 
    810         ctx.save();
    811 
    812         ctx.translate(0, 25);
    813         ctx.scale(1, -1);
    814 
    815         drawSwatchSquare();
    816 
    817         ctx.restore();
    818 
    819         this._fadeOutRect(ctx, 0, 13, 13, 13, 0.5, 0.0);
    820     },
    821 
    822     _drawSummaryGraph: function(segments)
    823     {
    824         if (!this.summaryGraphElement)
    825             return;
    826 
    827         if (!segments || !segments.length) {
    828             segments = [{color: "white", value: 1}];
    829             this._showingEmptySummaryGraph = true;
    830         } else
    831             delete this._showingEmptySummaryGraph;
    832 
    833         // Calculate the total of all segments.
    834         var total = 0;
    835         for (var i = 0; i < segments.length; ++i)
    836             total += segments[i].value;
    837 
    838         // Calculate the percentage of each segment, rounded to the nearest percent.
    839         var percents = segments.map(function(s) { return Math.max(Math.round(100 * s.value / total), 1) });
    840 
    841         // Calculate the total percentage.
    842         var percentTotal = 0;
    843         for (var i = 0; i < percents.length; ++i)
    844             percentTotal += percents[i];
    845 
    846         // Make sure our percentage total is not greater-than 100, it can be greater
    847         // if we rounded up for a few segments.
    848         while (percentTotal > 100) {
    849             for (var i = 0; i < percents.length && percentTotal > 100; ++i) {
    850                 if (percents[i] > 1) {
    851                     --percents[i];
    852                     --percentTotal;
    853                 }
    854             }
    855         }
    856 
    857         // Make sure our percentage total is not less-than 100, it can be less
    858         // if we rounded down for a few segments.
    859         while (percentTotal < 100) {
    860             for (var i = 0; i < percents.length && percentTotal < 100; ++i) {
    861                 ++percents[i];
    862                 ++percentTotal;
    863             }
    864         }
    865 
    866         var ctx = this.summaryGraphElement.getContext("2d");
    867 
    868         var x = 0;
    869         var y = 0;
    870         var w = 450;
    871         var h = 19;
    872         var r = (h / 2);
    873 
    874         function drawPillShadow()
    875         {
    876             // This draws a line with a shadow that is offset away from the line. The line is stroked
    877             // twice with different X shadow offsets to give more feathered edges. Later we erase the
    878             // line with destination-out 100% transparent black, leaving only the shadow. This only
    879             // works if nothing has been drawn into the canvas yet.
    880 
    881             ctx.beginPath();
    882             ctx.moveTo(x + 4, y + h - 3 - 0.5);
    883             ctx.lineTo(x + w - 4, y + h - 3 - 0.5);
    884             ctx.closePath();
    885 
    886             ctx.save();
    887 
    888             ctx.shadowBlur = 2;
    889             ctx.shadowColor = "rgba(0, 0, 0, 0.5)";
    890             ctx.shadowOffsetX = 3;
    891             ctx.shadowOffsetY = 5;
    892 
    893             ctx.strokeStyle = "white";
    894             ctx.lineWidth = 1;
    895 
    896             ctx.stroke();
    897 
    898             ctx.shadowOffsetX = -3;
    899 
    900             ctx.stroke();
    901 
    902             ctx.restore();
    903 
    904             ctx.save();
    905 
    906             ctx.globalCompositeOperation = "destination-out";
    907             ctx.strokeStyle = "rgba(0, 0, 0, 1)";
    908             ctx.lineWidth = 1;
    909 
    910             ctx.stroke();
    911 
    912             ctx.restore();
    913         }
    914 
    915         function drawPill()
    916         {
    917             // Make a rounded rect path.
    918             ctx.beginPath();
    919             ctx.moveTo(x, y + r);
    920             ctx.lineTo(x, y + h - r);
    921             ctx.quadraticCurveTo(x, y + h, x + r, y + h);
    922             ctx.lineTo(x + w - r, y + h);
    923             ctx.quadraticCurveTo(x + w, y + h, x + w, y + h - r);
    924             ctx.lineTo(x + w, y + r);
    925             ctx.quadraticCurveTo(x + w, y, x + w - r, y);
    926             ctx.lineTo(x + r, y);
    927             ctx.quadraticCurveTo(x, y, x, y + r);
    928             ctx.closePath();
    929 
    930             // Clip to the rounded rect path.
    931             ctx.save();
    932             ctx.clip();
    933 
    934             // Fill the segments with the associated color.
    935             var previousSegmentsWidth = 0;
    936             for (var i = 0; i < segments.length; ++i) {
    937                 var segmentWidth = Math.round(w * percents[i] / 100);
    938                 ctx.fillStyle = segments[i].color;
    939                 ctx.fillRect(x + previousSegmentsWidth, y, segmentWidth, h);
    940                 previousSegmentsWidth += segmentWidth;
    941             }
    942 
    943             // Draw the segment divider lines.
    944             ctx.lineWidth = 1;
    945             for (var i = 1; i < 20; ++i) {
    946                 ctx.beginPath();
    947                 ctx.moveTo(x + (i * Math.round(w / 20)) + 0.5, y);
    948                 ctx.lineTo(x + (i * Math.round(w / 20)) + 0.5, y + h);
    949                 ctx.closePath();
    950 
    951                 ctx.strokeStyle = "rgba(0, 0, 0, 0.2)";
    952                 ctx.stroke();
    953 
    954                 ctx.beginPath();
    955                 ctx.moveTo(x + (i * Math.round(w / 20)) + 1.5, y);
    956                 ctx.lineTo(x + (i * Math.round(w / 20)) + 1.5, y + h);
    957                 ctx.closePath();
    958 
    959                 ctx.strokeStyle = "rgba(255, 255, 255, 0.2)";
    960                 ctx.stroke();
    961             }
    962 
    963             // Draw the pill shading.
    964             var lightGradient = ctx.createLinearGradient(x, y, x, y + (h / 1.5));
    965             lightGradient.addColorStop(0.0, "rgba(220, 220, 220, 0.6)");
    966             lightGradient.addColorStop(0.4, "rgba(220, 220, 220, 0.2)");
    967             lightGradient.addColorStop(1.0, "rgba(255, 255, 255, 0.0)");
    968 
    969             var darkGradient = ctx.createLinearGradient(x, y + (h / 3), x, y + h);
    970             darkGradient.addColorStop(0.0, "rgba(0, 0, 0, 0.0)");
    971             darkGradient.addColorStop(0.8, "rgba(0, 0, 0, 0.2)");
    972             darkGradient.addColorStop(1.0, "rgba(0, 0, 0, 0.5)");
    973 
    974             ctx.fillStyle = darkGradient;
    975             ctx.fillRect(x, y, w, h);
    976 
    977             ctx.fillStyle = lightGradient;
    978             ctx.fillRect(x, y, w, h);
    979 
    980             ctx.restore();
    981         }
    982 
    983         ctx.clearRect(x, y, w, (h * 2));
    984 
    985         drawPillShadow();
    986         drawPill();
    987 
    988         ctx.save();
    989 
    990         ctx.translate(0, (h * 2) + 1);
    991         ctx.scale(1, -1);
    992 
    993         drawPill();
    994 
    995         ctx.restore();
    996 
    997         this._fadeOutRect(ctx, x, y + h + 1, w, h, 0.5, 0.0);
    998     },
    999 
    1000719    _updateSummaryGraph: function()
    1001720    {
    1002         var graphInfo = this.calculator.computeSummaryValues(this._resources);
    1003 
    1004         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}};
    1005         var fillSegments = [];
    1006 
    1007         this.legendElement.removeChildren();
    1008 
    1009         for (var i = 0; i < this.categoryOrder.length; ++i) {
    1010             var category = this.categoryOrder[i];
    1011             var size = graphInfo.categoryValues[category];
    1012             if (!size)
    1013                 continue;
    1014 
    1015             var color = categoryColors[category];
    1016             var colorString = "rgb(" + color.r + ", " + color.g + ", " + color.b + ")";
    1017 
    1018             var fillSegment = {color: colorString, value: size};
    1019             fillSegments.push(fillSegment);
    1020 
    1021             var legendLabel = this._makeLegendElement(WebInspector.resourceCategories[category].title, this.calculator.formatValue(size), colorString);
    1022             this.legendElement.appendChild(legendLabel);
    1023         }
    1024 
    1025         if (graphInfo.total) {
    1026             var totalLegendLabel = this._makeLegendElement(WebInspector.UIString("Total"), this.calculator.formatValue(graphInfo.total));
    1027             totalLegendLabel.addStyleClass("total");
    1028             this.legendElement.appendChild(totalLegendLabel);
    1029         }
    1030 
    1031         this._drawSummaryGraph(fillSegments);
     721        this.summaryBar.update(this._resources);
    1032722    },
    1033723
     
    1035725    {
    1036726        var scrollTop = this.containerElement.scrollTop;
    1037         var dividersTop = (scrollTop < this.summaryElement.offsetHeight ? this.summaryElement.offsetHeight : scrollTop);
     727        var dividersTop = (scrollTop < this.summaryBar.element.offsetHeight ? this.summaryBar.element.offsetHeight : scrollTop);
    1038728        this.dividersElement.style.top = scrollTop + "px";
    1039729        this.dividersLabelBarElement.style.top = dividersTop + "px";
     
    1094784        var selectedOption = this.sortingSelectElement[this.sortingSelectElement.selectedIndex];
    1095785        this.sortingFunction = selectedOption.sortingFunction;
    1096         this.calculator = selectedOption.calculator;
     786        this.calculator = this.summaryBar.calculator = selectedOption.calculator;
    1097787    },
    1098788
  • trunk/WebCore/inspector/front-end/WebKit.qrc

    r47639 r47822  
    5454    <file>StoragePanel.js</file>
    5555    <file>StylesSidebarPane.js</file>
     56    <file>SummaryBar.js</file>
    5657    <file>TextPrompt.js</file>
    5758    <file>TopDownProfileDataGridTree.js</file>
  • trunk/WebCore/inspector/front-end/inspector.css

    r47821 r47822  
    23332333}
    23342334
    2335 #resources-graph-legend {
     2335.summary-graph-legend {
    23362336    margin-top: -10px;
    23372337    padding-left: 15px;
    23382338}
    23392339
    2340 .resources-graph-legend-item {
     2340.summary-graph-legend-item {
    23412341    display: inline-block;
    23422342    font-weight: bold;
     
    23452345}
    23462346
    2347 .resources-graph-legend-item.total {
     2347.summary-graph-legend-item.total {
    23482348    margin-left: 10px;
    23492349}
    23502350
    2351 .resources-graph-legend-label {
     2351.summary-graph-legend-label {
    23522352    display: inline-block;
    23532353    text-align: left;
    23542354}
    23552355
    2356 .resources-graph-legend-header {
     2356.summary-graph-legend-header {
    23572357    font-size: 12px;
    23582358}
    23592359
    2360 .resources-graph-legend-value {
     2360.summary-graph-legend-value {
    23612361    font-size: 10px;
    23622362}
    23632363
    2364 .resources-graph-legend-swatch {
     2364.summary-graph-legend-swatch {
    23652365    vertical-align: top;
    23662366    margin-top: 1px;
  • trunk/WebCore/inspector/front-end/inspector.html

    r47639 r47822  
    6969    <script type="text/javascript" src="PanelEnablerView.js"></script>
    7070    <script type="text/javascript" src="StatusBarButton.js"></script>
     71    <script type="text/javascript" src="SummaryBar.js"></script>
    7172    <script type="text/javascript" src="ElementsPanel.js"></script>
    7273    <script type="text/javascript" src="ResourcesPanel.js"></script>
Note: See TracChangeset for help on using the changeset viewer.