• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
26WebInspector.SidebarSectionTreeElement = function(title, representedObject, hasChildren)
27{
28    TreeElement.call(this, title.escapeHTML(), representedObject || {}, hasChildren);
29}
30
31WebInspector.SidebarSectionTreeElement.prototype = {
32    selectable: false,
33
34    get smallChildren()
35    {
36        return this._smallChildren;
37    },
38
39    set smallChildren(x)
40    {
41        if (this._smallChildren === x)
42            return;
43
44        this._smallChildren = x;
45
46        if (this._smallChildren)
47            this._childrenListNode.addStyleClass("small");
48        else
49            this._childrenListNode.removeStyleClass("small");
50    },
51
52    onattach: function()
53    {
54        this._listItemNode.addStyleClass("sidebar-tree-section");
55    },
56
57    onreveal: function()
58    {
59        if (this.listItemElement)
60            this.listItemElement.scrollIntoViewIfNeeded(false);
61    }
62}
63
64WebInspector.SidebarSectionTreeElement.prototype.__proto__ = TreeElement.prototype;
65
66WebInspector.SidebarTreeElement = function(className, title, subtitle, representedObject, hasChildren)
67{
68    TreeElement.call(this, "", representedObject || {}, hasChildren);
69
70    if (hasChildren) {
71        this.disclosureButton = document.createElement("button");
72        this.disclosureButton.className = "disclosure-button";
73    }
74
75    if (!this.iconElement) {
76        this.iconElement = document.createElement("img");
77        this.iconElement.className = "icon";
78    }
79
80    this.statusElement = document.createElement("div");
81    this.statusElement.className = "status";
82
83    this.titlesElement = document.createElement("div");
84    this.titlesElement.className = "titles";
85
86    this.titleElement = document.createElement("span");
87    this.titleElement.className = "title";
88    this.titlesElement.appendChild(this.titleElement);
89
90    this.subtitleElement = document.createElement("span");
91    this.subtitleElement.className = "subtitle";
92    this.titlesElement.appendChild(this.subtitleElement);
93
94    this.className = className;
95    this.mainTitle = title;
96    this.subtitle = subtitle;
97}
98
99WebInspector.SidebarTreeElement.prototype = {
100    get small()
101    {
102        return this._small;
103    },
104
105    set small(x)
106    {
107        this._small = x;
108
109        if (this._listItemNode) {
110            if (this._small)
111                this._listItemNode.addStyleClass("small");
112            else
113                this._listItemNode.removeStyleClass("small");
114        }
115    },
116
117    get mainTitle()
118    {
119        return this._mainTitle;
120    },
121
122    set mainTitle(x)
123    {
124        this._mainTitle = x;
125        this.refreshTitles();
126    },
127
128    get subtitle()
129    {
130        return this._subtitle;
131    },
132
133    set subtitle(x)
134    {
135        this._subtitle = x;
136        this.refreshTitles();
137    },
138
139    get bubbleText()
140    {
141        return this._bubbleText;
142    },
143
144    set bubbleText(x)
145    {
146        if (!this.bubbleElement) {
147            this.bubbleElement = document.createElement("div");
148            this.bubbleElement.className = "bubble";
149            this.statusElement.appendChild(this.bubbleElement);
150        }
151
152        this._bubbleText = x;
153        this.bubbleElement.textContent = x;
154    },
155
156    refreshTitles: function()
157    {
158        var mainTitle = this.mainTitle;
159        if (this.titleElement.textContent !== mainTitle)
160            this.titleElement.textContent = mainTitle;
161
162        var subtitle = this.subtitle;
163        if (subtitle) {
164            if (this.subtitleElement.textContent !== subtitle)
165                this.subtitleElement.textContent = subtitle;
166            this.titlesElement.removeStyleClass("no-subtitle");
167        } else
168            this.titlesElement.addStyleClass("no-subtitle");
169    },
170
171    isEventWithinDisclosureTriangle: function(event)
172    {
173        return event.target === this.disclosureButton;
174    },
175
176    onattach: function()
177    {
178        this._listItemNode.addStyleClass("sidebar-tree-item");
179
180        if (this.className)
181            this._listItemNode.addStyleClass(this.className);
182
183        if (this.small)
184            this._listItemNode.addStyleClass("small");
185
186        if (this.hasChildren && this.disclosureButton)
187            this._listItemNode.appendChild(this.disclosureButton);
188
189        this._listItemNode.appendChild(this.iconElement);
190        this._listItemNode.appendChild(this.statusElement);
191        this._listItemNode.appendChild(this.titlesElement);
192    },
193
194    onreveal: function()
195    {
196        if (this._listItemNode)
197            this._listItemNode.scrollIntoViewIfNeeded(false);
198    }
199}
200
201WebInspector.SidebarTreeElement.prototype.__proto__ = TreeElement.prototype;
202