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
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.
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>} */
40 WebInspector
.UIList
._Key
= Symbol("ownerList");
42 WebInspector
.UIList
.prototype = {
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
);
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();
71 this.contentElement
.removeChildren();
75 __proto__
: WebInspector
.VBox
.prototype
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");
88 this.element
.classList
.add("label");
90 this.subtitleElement
= this.element
.createChild("div", "subtitle");
91 this.titleElement
= this.element
.createChild("div", "title");
94 this._isLabel
= !!isLabel
;
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;
123 setTitle: function(x
)
125 if (this._title
=== x
)
128 this.titleElement
.textContent
= x
;
136 return this._subtitle
;
142 setSubtitle: function(x
)
144 if (this._subtitle
=== x
)
147 this.subtitleElement
.textContent
= x
;
153 isSelected: function()
155 return this._selected
;
161 setSelected: function(x
)
173 this._selected
= true;
174 this.element
.classList
.add("selected");
181 this._selected
= false;
182 this.element
.classList
.remove("selected");
185 toggleSelected: function()
187 this.setSelected(!this.isSelected());
201 setHidden: function(x
)
203 if (this._hidden
=== x
)
206 this.element
.classList
.toggle("hidden", x
);
214 return this._isLabel
;
220 setDimmed: function(x
)
222 this.element
.classList
.toggle("dimmed", x
);