Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / sources / UIList.js
blobcf4876b26a86f07d3ff4b4e3e83f02c93de82ae4
1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 /**
28 * @constructor
29 * @extends {WebInspector.VBox}
31 WebInspector.UIList = function()
33 WebInspector.VBox.call(this, true);
34 this.registerRequiredCSS("sources/uiList.css");
36 /** @type {!Array.<!WebInspector.UIList.Item>} */
37 this._items = [];
40 WebInspector.UIList._Key = Symbol("ownerList");
42 WebInspector.UIList.prototype = {
43 /**
44 * @param {!WebInspector.UIList.Item} item
45 * @param {?WebInspector.UIList.Item=} beforeItem
47 addItem: function(item, beforeItem)
49 item[WebInspector.UIList._Key] = this;
50 var beforeElement = beforeItem ? beforeItem.element : null;
51 this.contentElement.insertBefore(item.element, beforeElement);
53 var index = beforeItem ? this._items.indexOf(beforeItem) : this._items.length;
54 console.assert(index >= 0, "Anchor item not found in UIList");
55 this._items.splice(index, 0, item);
58 /**
59 * @param {!WebInspector.UIList.Item} item
61 removeItem: function(item)
63 var index = this._items.indexOf(item);
64 console.assert(index >= 0);
65 this._items.splice(index, 1);
66 item.element.remove();
69 clear: function()
71 this.contentElement.removeChildren();
72 this._items = [];
75 __proto__: WebInspector.VBox.prototype
78 /**
79 * @constructor
80 * @param {string} title
81 * @param {string} subtitle
82 * @param {boolean=} isLabel
84 WebInspector.UIList.Item = function(title, subtitle, isLabel)
86 this.element = createElementWithClass("div", "list-item");
87 if (isLabel)
88 this.element.classList.add("label");
90 this.subtitleElement = this.element.createChild("div", "subtitle");
91 this.titleElement = this.element.createChild("div", "title");
93 this._hidden = false;
94 this._isLabel = !!isLabel;
95 this.setTitle(title);
96 this.setSubtitle(subtitle);
97 this.setSelected(false);
100 WebInspector.UIList.Item.prototype = {
102 * @return {?WebInspector.UIList.Item}
104 nextSibling: function()
106 var list = this[WebInspector.UIList._Key];
107 var index = list._items.indexOf(this);
108 console.assert(index >= 0);
109 return list._items[index + 1] || null;
113 * @return {string}
115 title: function()
117 return this._title;
121 * @param {string} x
123 setTitle: function(x)
125 if (this._title === x)
126 return;
127 this._title = x;
128 this.titleElement.textContent = x;
132 * @return {string}
134 subtitle: function()
136 return this._subtitle;
140 * @param {string} x
142 setSubtitle: function(x)
144 if (this._subtitle === x)
145 return;
146 this._subtitle = x;
147 this.subtitleElement.textContent = x;
151 * @return {boolean}
153 isSelected: function()
155 return this._selected;
159 * @param {boolean} x
161 setSelected: function(x)
163 if (x)
164 this.select();
165 else
166 this.deselect();
169 select: function()
171 if (this._selected)
172 return;
173 this._selected = true;
174 this.element.classList.add("selected");
177 deselect: function()
179 if (!this._selected)
180 return;
181 this._selected = false;
182 this.element.classList.remove("selected");
185 toggleSelected: function()
187 this.setSelected(!this.isSelected());
191 * @return {boolean}
193 isHidden: function()
195 return this._hidden;
199 * @param {boolean} x
201 setHidden: function(x)
203 if (this._hidden === x)
204 return;
205 this._hidden = x;
206 this.element.classList.toggle("hidden", x);
210 * @return {boolean}
212 isLabel: function()
214 return this._isLabel;
218 * @param {boolean} x
220 setDimmed: function(x)
222 this.element.classList.toggle("dimmed", x);
225 discard: function()