Home | History | Annotate | Download | only in ui
      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         this._childrenListNode.classList.toggle("small", this._smallChildren);
     57     },
     58 
     59     onattach: function()
     60     {
     61         this.listItemElement.classList.add("sidebar-tree-section");
     62     },
     63 
     64     onreveal: function()
     65     {
     66         if (this.listItemElement)
     67             this.listItemElement.scrollIntoViewIfNeeded(false);
     68     },
     69 
     70     __proto__: TreeElement.prototype
     71 }
     72 
     73 /**
     74  * @constructor
     75  * @extends {TreeElement}
     76  * @param {string} className
     77  * @param {string} title
     78  * @param {string=} subtitle
     79  * @param {?Object=} representedObject
     80  * @param {boolean=} hasChildren
     81  */
     82 WebInspector.SidebarTreeElement = function(className, title, subtitle, representedObject, hasChildren)
     83 {
     84     TreeElement.call(this, "", representedObject, hasChildren);
     85 
     86     if (hasChildren)
     87         this.disclosureButton = document.createElementWithClass("button", "disclosure-button");
     88 
     89     this.iconElement = document.createElementWithClass("div", "icon");
     90     this.statusElement = document.createElementWithClass("div", "status");
     91     this.titlesElement = document.createElementWithClass("div", "titles");
     92 
     93     this.titleContainer = this.titlesElement.createChild("span", "title-container");
     94     this.titleElement = this.titleContainer.createChild("span", "title");
     95 
     96     this.subtitleElement = this.titlesElement.createChild("span", "subtitle");
     97 
     98     this.className = className;
     99     this.mainTitle = title;
    100     this.subtitle = subtitle;
    101 }
    102 
    103 WebInspector.SidebarTreeElement.prototype = {
    104     get small()
    105     {
    106         return this._small;
    107     },
    108 
    109     set small(x)
    110     {
    111         this._small = x;
    112         if (this.listItemElement)
    113             this.listItemElement.classList.toggle("small", this._small);
    114     },
    115 
    116     get mainTitle()
    117     {
    118         return this._mainTitle;
    119     },
    120 
    121     set mainTitle(x)
    122     {
    123         this._mainTitle = x;
    124         this.refreshTitles();
    125     },
    126 
    127     get subtitle()
    128     {
    129         return this._subtitle;
    130     },
    131 
    132     set subtitle(x)
    133     {
    134         this._subtitle = x;
    135         this.refreshTitles();
    136     },
    137 
    138     set wait(x)
    139     {
    140         this.listItemElement.classList.toggle("wait", x);
    141     },
    142 
    143     refreshTitles: function()
    144     {
    145         var mainTitle = this.mainTitle;
    146         if (this.titleElement.textContent !== mainTitle)
    147             this.titleElement.textContent = mainTitle;
    148 
    149         var subtitle = this.subtitle;
    150         if (subtitle) {
    151             if (this.subtitleElement.textContent !== subtitle)
    152                 this.subtitleElement.textContent = subtitle;
    153             this.titlesElement.classList.remove("no-subtitle");
    154         } else {
    155             this.subtitleElement.textContent = "";
    156             this.titlesElement.classList.add("no-subtitle");
    157         }
    158     },
    159 
    160     /**
    161      * @return {boolean}
    162      */
    163     isEventWithinDisclosureTriangle: function(event)
    164     {
    165         return event.target === this.disclosureButton;
    166     },
    167 
    168     onattach: function()
    169     {
    170         this.listItemElement.classList.add("sidebar-tree-item");
    171 
    172         if (this.className)
    173             this.listItemElement.classList.add(this.className);
    174 
    175         if (this.small)
    176             this.listItemElement.classList.add("small");
    177 
    178         if (this.hasChildren && this.disclosureButton)
    179             this.listItemElement.appendChild(this.disclosureButton);
    180 
    181         this.listItemElement.appendChildren(this.iconElement, this.statusElement, this.titlesElement);
    182     },
    183 
    184     onreveal: function()
    185     {
    186         if (this.listItemElement)
    187             this.listItemElement.scrollIntoViewIfNeeded(false);
    188     },
    189 
    190     __proto__: TreeElement.prototype
    191 }
    192