Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / 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     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.classList.add("small");
58         else
59             this._childrenListNode.classList.remove("small");
60     },
61
62     onattach: function()
63     {
64         this._listItemNode.classList.add("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} className
80  * @param {string} title
81  * @param {string=} subtitle
82  * @param {?Object=} representedObject
83  * @param {boolean=} hasChildren
84  */
85 WebInspector.SidebarTreeElement = function(className, title, subtitle, representedObject, hasChildren)
86 {
87     TreeElement.call(this, "", representedObject, hasChildren);
88
89     if (hasChildren) {
90         this.disclosureButton = document.createElement("button");
91         this.disclosureButton.className = "disclosure-button";
92     }
93
94     this.iconElement = document.createElementWithClass("img", "icon");
95     this.statusElement = document.createElementWithClass("div", "status");
96     this.titlesElement = document.createElementWithClass("div", "titles");
97
98     this.titleContainer = this.titlesElement.createChild("span", "title-container");
99     this.titleElement = this.titleContainer.createChild("span", "title");
100
101     this.subtitleElement = this.titlesElement.createChild("span", "subtitle");
102
103     this.className = className;
104     this.mainTitle = title;
105     this.subtitle = subtitle;
106 }
107
108 WebInspector.SidebarTreeElement.prototype = {
109     get small()
110     {
111         return this._small;
112     },
113
114     set small(x)
115     {
116         this._small = x;
117
118         if (this._listItemNode) {
119             if (this._small)
120                 this._listItemNode.classList.add("small");
121             else
122                 this._listItemNode.classList.remove("small");
123         }
124     },
125
126     get mainTitle()
127     {
128         return this._mainTitle;
129     },
130
131     set mainTitle(x)
132     {
133         this._mainTitle = x;
134         this.refreshTitles();
135     },
136
137     get subtitle()
138     {
139         return this._subtitle;
140     },
141
142     set subtitle(x)
143     {
144         this._subtitle = x;
145         this.refreshTitles();
146     },
147
148     set wait(x)
149     {
150         if (x)
151             this._listItemNode.classList.add("wait");
152         else
153             this._listItemNode.classList.remove("wait");
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.classList.remove("no-subtitle");
167         } else {
168             this.subtitleElement.textContent = "";
169             this.titlesElement.classList.add("no-subtitle");
170         }
171     },
172
173     /**
174      * @return {boolean}
175      */
176     isEventWithinDisclosureTriangle: function(event)
177     {
178         return event.target === this.disclosureButton;
179     },
180
181     onattach: function()
182     {
183         this._listItemNode.classList.add("sidebar-tree-item");
184
185         if (this.className)
186             this._listItemNode.classList.add(this.className);
187
188         if (this.small)
189             this._listItemNode.classList.add("small");
190
191         if (this.hasChildren && this.disclosureButton)
192             this._listItemNode.appendChild(this.disclosureButton);
193
194         this._listItemNode.appendChild(this.iconElement);
195         this._listItemNode.appendChild(this.statusElement);
196         this._listItemNode.appendChild(this.titlesElement);
197     },
198
199     onreveal: function()
200     {
201         if (this._listItemNode)
202             this._listItemNode.scrollIntoViewIfNeeded(false);
203     },
204
205     __proto__: TreeElement.prototype
206 }