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._listItemNode.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.createElement("button");
     88         this.disclosureButton.className = "disclosure-button";
     89     }
     90 
     91     this.iconElement = document.createElementWithClass("div", "icon");
     92     this.statusElement = document.createElementWithClass("div", "status");
     93     this.titlesElement = document.createElementWithClass("div", "titles");
     94 
     95     this.titleContainer = this.titlesElement.createChild("span", "title-container");
     96     this.titleElement = this.titleContainer.createChild("span", "title");
     97 
     98     this.subtitleElement = this.titlesElement.createChild("span", "subtitle");
     99 
    100     this.className = className;
    101     this.mainTitle = title;
    102     this.subtitle = subtitle;
    103 }
    104 
    105 WebInspector.SidebarTreeElement.prototype = {
    106     get small()
    107     {
    108         return this._small;
    109     },
    110 
    111     set small(x)
    112     {
    113         this._small = x;
    114         if (this._listItemNode)
    115             this._listItemNode.classList.toggle("small", this._small);
    116     },
    117 
    118     get mainTitle()
    119     {
    120         return this._mainTitle;
    121     },
    122 
    123     set mainTitle(x)
    124     {
    125         this._mainTitle = x;
    126         this.refreshTitles();
    127     },
    128 
    129     get subtitle()
    130     {
    131         return this._subtitle;
    132     },
    133 
    134     set subtitle(x)
    135     {
    136         this._subtitle = x;
    137         this.refreshTitles();
    138     },
    139 
    140     set wait(x)
    141     {
    142         this._listItemNode.classList.toggle("wait", x);
    143     },
    144 
    145     refreshTitles: function()
    146     {
    147         var mainTitle = this.mainTitle;
    148         if (this.titleElement.textContent !== mainTitle)
    149             this.titleElement.textContent = mainTitle;
    150 
    151         var subtitle = this.subtitle;
    152         if (subtitle) {
    153             if (this.subtitleElement.textContent !== subtitle)
    154                 this.subtitleElement.textContent = subtitle;
    155             this.titlesElement.classList.remove("no-subtitle");
    156         } else {
    157             this.subtitleElement.textContent = "";
    158             this.titlesElement.classList.add("no-subtitle");
    159         }
    160     },
    161 
    162     /**
    163      * @return {boolean}
    164      */
    165     isEventWithinDisclosureTriangle: function(event)
    166     {
    167         return event.target === this.disclosureButton;
    168     },
    169 
    170     onattach: function()
    171     {
    172         this._listItemNode.classList.add("sidebar-tree-item");
    173 
    174         if (this.className)
    175             this._listItemNode.classList.add(this.className);
    176 
    177         if (this.small)
    178             this._listItemNode.classList.add("small");
    179 
    180         if (this.hasChildren && this.disclosureButton)
    181             this._listItemNode.appendChild(this.disclosureButton);
    182 
    183         this._listItemNode.appendChild(this.iconElement);
    184         this._listItemNode.appendChild(this.statusElement);
    185         this._listItemNode.appendChild(this.titlesElement);
    186     },
    187 
    188     onreveal: function()
    189     {
    190         if (this._listItemNode)
    191             this._listItemNode.scrollIntoViewIfNeeded(false);
    192     },
    193 
    194     __proto__: TreeElement.prototype
    195 }
    196