tizen beta release
[profile/ivi/webkit-efl.git] / debian / tmp / usr / share / ewebkit-0 / webinspector / SidebarTreeElement.js
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 }
34
35 WebInspector.SidebarSectionTreeElement.prototype = {
36     selectable: false,
37
38     get smallChildren()
39     {
40         return this._smallChildren;
41     },
42
43     set smallChildren(x)
44     {
45         if (this._smallChildren === x)
46             return;
47
48         this._smallChildren = x;
49
50         if (this._smallChildren)
51             this._childrenListNode.addStyleClass("small");
52         else
53             this._childrenListNode.removeStyleClass("small");
54     },
55
56     onattach: function()
57     {
58         this._listItemNode.addStyleClass("sidebar-tree-section");
59     },
60
61     onreveal: function()
62     {
63         if (this.listItemElement)
64             this.listItemElement.scrollIntoViewIfNeeded(false);
65     }
66 }
67
68 WebInspector.SidebarSectionTreeElement.prototype.__proto__ = TreeElement.prototype;
69
70 /**
71  * @constructor
72  * @extends {TreeElement}
73  * @param {string=} subtitle
74  * @param {Object=} representedObject
75  * @param {boolean=} hasChildren
76  */
77 WebInspector.SidebarTreeElement = function(className, title, subtitle, representedObject, hasChildren)
78 {
79     TreeElement.call(this, "", representedObject, hasChildren);
80
81     if (hasChildren) {
82         this.disclosureButton = document.createElement("button");
83         this.disclosureButton.className = "disclosure-button";
84     }
85
86     if (!this.iconElement) {
87         this.iconElement = document.createElement("img");
88         this.iconElement.className = "icon";
89     }
90
91     this.statusElement = document.createElement("div");
92     this.statusElement.className = "status";
93
94     this.titlesElement = document.createElement("div");
95     this.titlesElement.className = "titles";
96
97     this.titleElement = document.createElement("span");
98     this.titleElement.className = "title";
99     this.titlesElement.appendChild(this.titleElement);
100
101     this.subtitleElement = document.createElement("span");
102     this.subtitleElement.className = "subtitle";
103     this.titlesElement.appendChild(this.subtitleElement);
104
105     this.className = className;
106     this.mainTitle = title;
107     this.subtitle = subtitle;
108 }
109
110 WebInspector.SidebarTreeElement.prototype = {
111     get small()
112     {
113         return this._small;
114     },
115
116     set small(x)
117     {
118         this._small = x;
119
120         if (this._listItemNode) {
121             if (this._small)
122                 this._listItemNode.addStyleClass("small");
123             else
124                 this._listItemNode.removeStyleClass("small");
125         }
126     },
127
128     get mainTitle()
129     {
130         return this._mainTitle;
131     },
132
133     set mainTitle(x)
134     {
135         this._mainTitle = x;
136         this.refreshTitles();
137     },
138
139     get subtitle()
140     {
141         return this._subtitle;
142     },
143
144     set subtitle(x)
145     {
146         this._subtitle = x;
147         this.refreshTitles();
148     },
149
150     get bubbleText()
151     {
152         return this._bubbleText;
153     },
154
155     set bubbleText(x)
156     {
157         if (!this.bubbleElement) {
158             this.bubbleElement = document.createElement("div");
159             this.bubbleElement.className = "bubble";
160             this.statusElement.appendChild(this.bubbleElement);
161         }
162
163         this._bubbleText = x;
164         this.bubbleElement.textContent = x;
165     },
166
167     set wait(x)
168     {
169         if (x)
170             this._listItemNode.addStyleClass("wait");
171         else
172             this._listItemNode.removeStyleClass("wait");
173     },
174
175     refreshTitles: function()
176     {
177         var mainTitle = this.mainTitle;
178         if (this.titleElement.textContent !== mainTitle)
179             this.titleElement.textContent = mainTitle;
180
181         var subtitle = this.subtitle;
182         if (subtitle) {
183             if (this.subtitleElement.textContent !== subtitle)
184                 this.subtitleElement.textContent = subtitle;
185             this.titlesElement.removeStyleClass("no-subtitle");
186         } else {
187             this.subtitleElement.textContent = "";
188             this.titlesElement.addStyleClass("no-subtitle");
189         }
190     },
191
192     isEventWithinDisclosureTriangle: function(event)
193     {
194         return event.target === this.disclosureButton;
195     },
196
197     onattach: function()
198     {
199         this._listItemNode.addStyleClass("sidebar-tree-item");
200
201         if (this.className)
202             this._listItemNode.addStyleClass(this.className);
203
204         if (this.small)
205             this._listItemNode.addStyleClass("small");
206
207         if (this.hasChildren && this.disclosureButton)
208             this._listItemNode.appendChild(this.disclosureButton);
209
210         this._listItemNode.appendChild(this.iconElement);
211         this._listItemNode.appendChild(this.statusElement);
212         this._listItemNode.appendChild(this.titlesElement);
213     },
214
215     onreveal: function()
216     {
217         if (this._listItemNode)
218             this._listItemNode.scrollIntoViewIfNeeded(false);
219     }
220 }
221
222 WebInspector.SidebarTreeElement.prototype.__proto__ = TreeElement.prototype;