Home | History | Annotate | Download | only in front_end
      1 /*
      2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 /**
     27  * @constructor
     28  * @extends {TreeElement}
     29  */
     30 WebInspector.SidebarSectionTreeElement = function(title, representedObject, hasChildren)
     31 {
     32     TreeElement.call(this, title.escapeHTML(), representedObject || {}, hasChildren);
     33     this.expand();
     34 }
     35 
     36 WebInspector.SidebarSectionTreeElement.prototype = {
     37     selectable: false,
     38 
     39     collapse: function()
     40     {
     41         // Should not collapse as it is not selectable.
     42     },
     43 
     44     get smallChildren()
     45     {
     46         return this._smallChildren;
     47     },
     48 
     49     set smallChildren(x)
     50     {
     51         if (this._smallChildren === x)
     52             return;
     53 
     54         this._smallChildren = x;
     55 
     56         if (this._smallChildren)
     57             this._childrenListNode.addStyleClass("small");
     58         else
     59             this._childrenListNode.removeStyleClass("small");
     60     },
     61 
     62     onattach: function()
     63     {
     64         this._listItemNode.addStyleClass("sidebar-tree-section");
     65     },
     66 
     67     onreveal: function()
     68     {
     69         if (this.listItemElement)
     70             this.listItemElement.scrollIntoViewIfNeeded(false);
     71     },
     72 
     73     __proto__: TreeElement.prototype
     74 }
     75 
     76 /**
     77  * @constructor
     78  * @extends {TreeElement}
     79  * @param {string=} subtitle
     80  * @param {Object=} representedObject
     81  * @param {boolean=} hasChildren
     82  */
     83 WebInspector.SidebarTreeElement = function(className, title, subtitle, representedObject, hasChildren)
     84 {
     85     TreeElement.call(this, "", representedObject, hasChildren);
     86 
     87     if (hasChildren) {
     88         this.disclosureButton = document.createElement("button");
     89         this.disclosureButton.className = "disclosure-button";
     90     }
     91 
     92     if (!this.iconElement) {
     93         this.iconElement = document.createElement("img");
     94         this.iconElement.className = "icon";
     95     }
     96 
     97     this.statusElement = document.createElement("div");
     98     this.statusElement.className = "status";
     99 
    100     this.titlesElement = document.createElement("div");
    101     this.titlesElement.className = "titles";
    102 
    103     this.titleElement = document.createElement("span");
    104     this.titleElement.className = "title";
    105     this.titlesElement.appendChild(this.titleElement);
    106 
    107     this.subtitleElement = document.createElement("span");
    108     this.subtitleElement.className = "subtitle";
    109     this.titlesElement.appendChild(this.subtitleElement);
    110 
    111     this.className = className;
    112     this.mainTitle = title;
    113     this.subtitle = subtitle;
    114 }
    115 
    116 WebInspector.SidebarTreeElement.prototype = {
    117     get small()
    118     {
    119         return this._small;
    120     },
    121 
    122     set small(x)
    123     {
    124         this._small = x;
    125 
    126         if (this._listItemNode) {
    127             if (this._small)
    128                 this._listItemNode.addStyleClass("small");
    129             else
    130                 this._listItemNode.removeStyleClass("small");
    131         }
    132     },
    133 
    134     get mainTitle()
    135     {
    136         return this._mainTitle;
    137     },
    138 
    139     set mainTitle(x)
    140     {
    141         this._mainTitle = x;
    142         this.refreshTitles();
    143     },
    144 
    145     get subtitle()
    146     {
    147         return this._subtitle;
    148     },
    149 
    150     set subtitle(x)
    151     {
    152         this._subtitle = x;
    153         this.refreshTitles();
    154     },
    155 
    156     get bubbleText()
    157     {
    158         return this._bubbleText;
    159     },
    160 
    161     set bubbleText(x)
    162     {
    163         if (!this.bubbleElement) {
    164             this.bubbleElement = document.createElement("div");
    165             this.bubbleElement.className = "bubble";
    166             this.statusElement.appendChild(this.bubbleElement);
    167         }
    168 
    169         this._bubbleText = x;
    170         this.bubbleElement.textContent = x;
    171     },
    172 
    173     set wait(x)
    174     {
    175         if (x)
    176             this._listItemNode.addStyleClass("wait");
    177         else
    178             this._listItemNode.removeStyleClass("wait");
    179     },
    180 
    181     refreshTitles: function()
    182     {
    183         var mainTitle = this.mainTitle;
    184         if (this.titleElement.textContent !== mainTitle)
    185             this.titleElement.textContent = mainTitle;
    186 
    187         var subtitle = this.subtitle;
    188         if (subtitle) {
    189             if (this.subtitleElement.textContent !== subtitle)
    190                 this.subtitleElement.textContent = subtitle;
    191             this.titlesElement.removeStyleClass("no-subtitle");
    192         } else {
    193             this.subtitleElement.textContent = "";
    194             this.titlesElement.addStyleClass("no-subtitle");
    195         }
    196     },
    197 
    198     isEventWithinDisclosureTriangle: function(event)
    199     {
    200         return event.target === this.disclosureButton;
    201     },
    202 
    203     onattach: function()
    204     {
    205         this._listItemNode.addStyleClass("sidebar-tree-item");
    206 
    207         if (this.className)
    208             this._listItemNode.addStyleClass(this.className);
    209 
    210         if (this.small)
    211             this._listItemNode.addStyleClass("small");
    212 
    213         if (this.hasChildren && this.disclosureButton)
    214             this._listItemNode.appendChild(this.disclosureButton);
    215 
    216         this._listItemNode.appendChild(this.iconElement);
    217         this._listItemNode.appendChild(this.statusElement);
    218         this._listItemNode.appendChild(this.titlesElement);
    219     },
    220 
    221     onreveal: function()
    222     {
    223         if (this._listItemNode)
    224             this._listItemNode.scrollIntoViewIfNeeded(false);
    225     },
    226 
    227     __proto__: TreeElement.prototype
    228 }
    229