home *** CD-ROM | disk | FTP | other *** search
/ Computer Active Guide 2009 July / CAG7.ISO / Internetas / SafariSetup.exe / AppleApplicationSupport.msi / WebKit.resources_inspector_TimelineGrid.js < prev    next >
Encoding:
JavaScript  |  2010-06-03  |  6.6 KB  |  168 lines

  1. /*
  2.  * Copyright (C) 2007, 2008 Apple Inc.  All rights reserved.
  3.  * Copyright (C) 2008, 2009 Anthony Ricaud <rik@webkit.org>
  4.  * Copyright (C) 2009 Google Inc. All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  *
  10.  * 1.  Redistributions of source code must retain the above copyright
  11.  *     notice, this list of conditions and the following disclaimer.
  12.  * 2.  Redistributions in binary form must reproduce the above copyright
  13.  *     notice, this list of conditions and the following disclaimer in the
  14.  *     documentation and/or other materials provided with the distribution.
  15.  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  16.  *     its contributors may be used to endorse or promote products derived
  17.  *     from this software without specific prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  20.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22.  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  23.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  */
  30.  
  31. WebInspector.TimelineGrid = function()
  32. {
  33.     this.element = document.createElement("div");
  34.  
  35.     this._itemsGraphsElement = document.createElement("div");
  36.     this._itemsGraphsElement.id = "resources-graphs";
  37.     this.element.appendChild(this._itemsGraphsElement);
  38.  
  39.     this._dividersElement = document.createElement("div");
  40.     this._dividersElement.className = "resources-dividers";
  41.     this.element.appendChild(this._dividersElement);
  42.  
  43.     this._eventDividersElement = document.createElement("div");
  44.     this._eventDividersElement.className = "resources-event-dividers";
  45.     this.element.appendChild(this._eventDividersElement);
  46.  
  47.     this._dividersLabelBarElement = document.createElement("div");
  48.     this._dividersLabelBarElement.className = "resources-dividers-label-bar";
  49.     this.element.appendChild(this._dividersLabelBarElement);
  50. }
  51.  
  52. WebInspector.TimelineGrid.prototype = {
  53.     get itemsGraphsElement()
  54.     {
  55.         return this._itemsGraphsElement;
  56.     },
  57.  
  58.     updateDividers: function(force, calculator, paddingLeft)
  59.     {
  60.         var dividerCount = Math.round(this._dividersElement.offsetWidth / 64);
  61.         var slice = calculator.boundarySpan / dividerCount;
  62.         if (!force && this._currentDividerSlice === slice)
  63.             return false;
  64.  
  65.         if (typeof paddingLeft !== "number")
  66.             paddingLeft = 0;
  67.         this._currentDividerSlice = slice;
  68.  
  69.         // Reuse divider elements and labels.
  70.         var divider = this._dividersElement.firstChild;
  71.         var dividerLabelBar = this._dividersLabelBarElement.firstChild;
  72.  
  73.         var dividersLabelBarElementClientWidth = this._dividersLabelBarElement.clientWidth;
  74.         var clientWidth = dividersLabelBarElementClientWidth - paddingLeft;
  75.         for (var i = paddingLeft ? 0 : 1; i <= dividerCount; ++i) {
  76.             if (!divider) {
  77.                 divider = document.createElement("div");
  78.                 divider.className = "resources-divider";
  79.                 this._dividersElement.appendChild(divider);
  80.  
  81.                 dividerLabelBar = document.createElement("div");
  82.                 dividerLabelBar.className = "resources-divider";
  83.                 var label = document.createElement("div");
  84.                 label.className = "resources-divider-label";
  85.                 dividerLabelBar._labelElement = label;
  86.                 dividerLabelBar.appendChild(label);
  87.                 this._dividersLabelBarElement.appendChild(dividerLabelBar);
  88.                 dividersLabelBarElementClientWidth = this._dividersLabelBarElement.clientWidth;
  89.             }
  90.  
  91.             if (i === dividerCount)
  92.                 divider.addStyleClass("last");
  93.             else
  94.                 divider.removeStyleClass("last");
  95.  
  96.             var left = paddingLeft + clientWidth * (i / dividerCount);
  97.             var percentLeft = 100 * left / dividersLabelBarElementClientWidth;
  98.             this._setDividerAndBarLeft(divider, dividerLabelBar, percentLeft);
  99.  
  100.             if (!isNaN(slice))
  101.                 dividerLabelBar._labelElement.textContent = calculator.formatValue(slice * i);
  102.             else
  103.                 dividerLabelBar._labelElement.textContent = "";
  104.  
  105.             divider = divider.nextSibling;
  106.             dividerLabelBar = dividerLabelBar.nextSibling;
  107.         }
  108.  
  109.         // Remove extras.
  110.         while (divider) {
  111.             var nextDivider = divider.nextSibling;
  112.             this._dividersElement.removeChild(divider);
  113.             divider = nextDivider;
  114.         }
  115.         while (dividerLabelBar) {
  116.             var nextDivider = dividerLabelBar.nextSibling;
  117.             this._dividersLabelBarElement.removeChild(dividerLabelBar);
  118.             dividerLabelBar = nextDivider;
  119.         }
  120.         return true;
  121.     },
  122.  
  123.     _setDividerAndBarLeft: function(divider, dividerLabelBar, percentLeft)
  124.     {
  125.         var percentStyleLeft = parseFloat(divider.style.left);
  126.         if (!isNaN(percentStyleLeft) && Math.abs(percentStyleLeft - percentLeft) < 0.1)
  127.             return;
  128.         divider.style.left = percentLeft + "%";
  129.         dividerLabelBar.style.left = percentLeft + "%";
  130.     },
  131.  
  132.     addEventDivider: function(divider)
  133.     {
  134.         this._eventDividersElement.appendChild(divider);
  135.     },
  136.  
  137.     addEventDividers: function(dividers)
  138.     {
  139.         this.element.removeChild(this._eventDividersElement);
  140.         for (var i = 0; i < dividers.length; ++i)
  141.             if (dividers[i])
  142.                 this._eventDividersElement.appendChild(dividers[i]);
  143.         this.element.appendChild(this._eventDividersElement);
  144.     },
  145.  
  146.     removeEventDividers: function()
  147.     {
  148.         this._eventDividersElement.removeChildren();
  149.     },
  150.  
  151.     hideEventDividers: function()
  152.     {
  153.         this._eventDividersElement.addStyleClass("hidden");
  154.     },
  155.  
  156.     showEventDividers: function()
  157.     {
  158.         this._eventDividersElement.removeStyleClass("hidden");
  159.     },
  160.  
  161.     setScrollAndDividerTop: function(scrollTop, dividersTop)
  162.     {
  163.         this._dividersElement.style.top = scrollTop + "px";
  164.         this._eventDividersElement.style.top = scrollTop + "px";
  165.         this._dividersLabelBarElement.style.top = dividersTop + "px";
  166.     }
  167. }
  168.