Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / ui / SidebarTreeElement.js
blob9259239ba10de3903413cba96569b2d5092589d6
1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
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.
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.
26 /**
27 * @constructor
28 * @extends {TreeElement}
29 * @param {string} title
31 WebInspector.SidebarSectionTreeElement = function(title)
33 TreeElement.call(this, title.escapeHTML(), true);
34 this.expand();
37 WebInspector.SidebarSectionTreeElement.prototype = {
38 selectable: false,
40 collapse: function()
42 // Should not collapse as it is not selectable.
45 get smallChildren()
47 return this._smallChildren;
50 set smallChildren(x)
52 if (this._smallChildren === x)
53 return;
55 this._smallChildren = x;
57 this._childrenListNode.classList.toggle("small", this._smallChildren);
60 onattach: function()
62 this.listItemElement.classList.add("sidebar-tree-section");
65 onreveal: function()
67 if (this.listItemElement)
68 this.listItemElement.scrollIntoViewIfNeeded(false);
71 __proto__: TreeElement.prototype
74 /**
75 * @constructor
76 * @extends {TreeElement}
77 * @param {string} className
78 * @param {string} title
79 * @param {string=} subtitle
80 * @param {boolean=} expandable
82 WebInspector.SidebarTreeElement = function(className, title, subtitle, expandable)
84 TreeElement.call(this, "", expandable);
86 if (expandable)
87 this.disclosureButton = createElementWithClass("button", "disclosure-button");
89 this.iconElement = createElementWithClass("div", "icon");
90 this.statusElement = createElementWithClass("div", "status");
91 this.titlesElement = createElementWithClass("div", "titles");
93 this.titleContainer = this.titlesElement.createChild("span", "title-container");
94 this.titleElement = this.titleContainer.createChild("span", "title");
96 this.subtitleElement = this.titlesElement.createChild("span", "subtitle");
98 this.className = className;
99 this.mainTitle = title;
100 this.subtitle = subtitle;
103 WebInspector.SidebarTreeElement.prototype = {
104 get small()
106 return this._small;
109 set small(x)
111 this._small = x;
112 if (this.listItemElement)
113 this.listItemElement.classList.toggle("small", this._small);
116 get mainTitle()
118 return this._mainTitle;
121 set mainTitle(x)
123 this._mainTitle = x;
124 this.refreshTitles();
127 get subtitle()
129 return this._subtitle;
132 set subtitle(x)
134 this._subtitle = x;
135 this.refreshTitles();
138 set wait(x)
140 this.listItemElement.classList.toggle("wait", x);
143 refreshTitles: function()
145 var mainTitle = this.mainTitle;
146 if (this.titleElement.textContent !== mainTitle)
147 this.titleElement.textContent = mainTitle;
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");
161 * @override
162 * @return {boolean}
164 isEventWithinDisclosureTriangle: function(event)
166 return event.target === this.disclosureButton;
169 onattach: function()
171 this.listItemElement.classList.add("sidebar-tree-item");
173 if (this.className)
174 this.listItemElement.classList.add(this.className);
176 if (this.small)
177 this.listItemElement.classList.add("small");
179 if (this.isExpandable() && this.disclosureButton)
180 this.listItemElement.appendChild(this.disclosureButton);
182 this.listItemElement.appendChildren(this.iconElement, this.statusElement, this.titlesElement);
185 onreveal: function()
187 if (this.listItemElement)
188 this.listItemElement.scrollIntoViewIfNeeded(false);
191 __proto__: TreeElement.prototype