Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/UIList.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26
27 /** 26 /**
28 * @constructor 27 * @unrestricted
29 * @extends {WebInspector.VBox}
30 */ 28 */
31 WebInspector.UIList = function() 29 WebInspector.UIList = class extends WebInspector.VBox {
32 { 30 constructor() {
33 WebInspector.VBox.call(this, true); 31 super(true);
34 this.registerRequiredCSS("sources/uiList.css"); 32 this.registerRequiredCSS('sources/uiList.css');
35 33
36 /** @type {!Array.<!WebInspector.UIList.Item>} */ 34 /** @type {!Array.<!WebInspector.UIList.Item>} */
37 this._items = []; 35 this._items = [];
36 }
37
38 /**
39 * @param {!WebInspector.UIList.Item} item
40 * @param {?WebInspector.UIList.Item=} beforeItem
41 */
42 addItem(item, beforeItem) {
43 item[WebInspector.UIList._Key] = this;
44 var beforeElement = beforeItem ? beforeItem.element : null;
45 this.contentElement.insertBefore(item.element, beforeElement);
46
47 var index = beforeItem ? this._items.indexOf(beforeItem) : this._items.lengt h;
48 console.assert(index >= 0, 'Anchor item not found in UIList');
49 this._items.splice(index, 0, item);
50 }
51
52 /**
53 * @param {!WebInspector.UIList.Item} item
54 */
55 removeItem(item) {
56 var index = this._items.indexOf(item);
57 console.assert(index >= 0);
58 this._items.splice(index, 1);
59 item.element.remove();
60 }
61
62 clear() {
63 this.contentElement.removeChildren();
64 this._items = [];
65 }
38 }; 66 };
39 67
40 WebInspector.UIList._Key = Symbol("ownerList"); 68 WebInspector.UIList._Key = Symbol('ownerList');
41
42 WebInspector.UIList.prototype = {
43 /**
44 * @param {!WebInspector.UIList.Item} item
45 * @param {?WebInspector.UIList.Item=} beforeItem
46 */
47 addItem: function(item, beforeItem)
48 {
49 item[WebInspector.UIList._Key] = this;
50 var beforeElement = beforeItem ? beforeItem.element : null;
51 this.contentElement.insertBefore(item.element, beforeElement);
52
53 var index = beforeItem ? this._items.indexOf(beforeItem) : this._items.l ength;
54 console.assert(index >= 0, "Anchor item not found in UIList");
55 this._items.splice(index, 0, item);
56 },
57
58 /**
59 * @param {!WebInspector.UIList.Item} item
60 */
61 removeItem: function(item)
62 {
63 var index = this._items.indexOf(item);
64 console.assert(index >= 0);
65 this._items.splice(index, 1);
66 item.element.remove();
67 },
68
69 clear: function()
70 {
71 this.contentElement.removeChildren();
72 this._items = [];
73 },
74
75 __proto__: WebInspector.VBox.prototype
76 };
77 69
78 /** 70 /**
79 * @constructor 71 * @unrestricted
80 * @param {string} title
81 * @param {string} subtitle
82 * @param {boolean=} isLabel
83 */ 72 */
84 WebInspector.UIList.Item = function(title, subtitle, isLabel) 73 WebInspector.UIList.Item = class {
85 { 74 /**
86 this.element = createElementWithClass("div", "list-item"); 75 * @param {string} title
76 * @param {string} subtitle
77 * @param {boolean=} isLabel
78 */
79 constructor(title, subtitle, isLabel) {
80 this.element = createElementWithClass('div', 'list-item');
87 if (isLabel) 81 if (isLabel)
88 this.element.classList.add("label"); 82 this.element.classList.add('label');
89 83
90 this.titleElement = this.element.createChild("div", "title"); 84 this.titleElement = this.element.createChild('div', 'title');
91 this.subtitleElement = this.element.createChild("div", "subtitle"); 85 this.subtitleElement = this.element.createChild('div', 'subtitle');
92 86
93 this._hidden = false; 87 this._hidden = false;
94 this._isLabel = !!isLabel; 88 this._isLabel = !!isLabel;
95 this.setTitle(title); 89 this.setTitle(title);
96 this.setSubtitle(subtitle); 90 this.setSubtitle(subtitle);
97 this.setSelected(false); 91 this.setSelected(false);
92 }
93
94 /**
95 * @return {?WebInspector.UIList.Item}
96 */
97 nextSibling() {
98 var list = this[WebInspector.UIList._Key];
99 var index = list._items.indexOf(this);
100 console.assert(index >= 0);
101 return list._items[index + 1] || null;
102 }
103
104 /**
105 * @return {string}
106 */
107 title() {
108 return this._title;
109 }
110
111 /**
112 * @param {string} x
113 */
114 setTitle(x) {
115 if (this._title === x)
116 return;
117 this._title = x;
118 this.titleElement.textContent = x;
119 }
120
121 /**
122 * @return {string}
123 */
124 subtitle() {
125 return this._subtitle;
126 }
127
128 /**
129 * @param {string} x
130 */
131 setSubtitle(x) {
132 if (this._subtitle === x)
133 return;
134 this._subtitle = x;
135 this.subtitleElement.textContent = x;
136 }
137
138 /**
139 * @return {boolean}
140 */
141 isSelected() {
142 return this._selected;
143 }
144
145 /**
146 * @param {boolean} x
147 */
148 setSelected(x) {
149 if (x)
150 this.select();
151 else
152 this.deselect();
153 }
154
155 select() {
156 if (this._selected)
157 return;
158 this._selected = true;
159 this.element.classList.add('selected');
160 }
161
162 deselect() {
163 if (!this._selected)
164 return;
165 this._selected = false;
166 this.element.classList.remove('selected');
167 }
168
169 toggleSelected() {
170 this.setSelected(!this.isSelected());
171 }
172
173 /**
174 * @return {boolean}
175 */
176 isHidden() {
177 return this._hidden;
178 }
179
180 /**
181 * @param {boolean} x
182 */
183 setHidden(x) {
184 if (this._hidden === x)
185 return;
186 this._hidden = x;
187 this.element.classList.toggle('hidden', x);
188 }
189
190 /**
191 * @return {boolean}
192 */
193 isLabel() {
194 return this._isLabel;
195 }
196
197 /**
198 * @param {boolean} x
199 */
200 setDimmed(x) {
201 this.element.classList.toggle('dimmed', x);
202 }
203
204 discard() {
205 }
206
207 /**
208 * @param {boolean} hoverable
209 */
210 setHoverable(hoverable) {
211 this.element.classList.toggle('ignore-hover', !hoverable);
212 }
98 }; 213 };
99
100 WebInspector.UIList.Item.prototype = {
101 /**
102 * @return {?WebInspector.UIList.Item}
103 */
104 nextSibling: function()
105 {
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;
110 },
111
112 /**
113 * @return {string}
114 */
115 title: function()
116 {
117 return this._title;
118 },
119
120 /**
121 * @param {string} x
122 */
123 setTitle: function(x)
124 {
125 if (this._title === x)
126 return;
127 this._title = x;
128 this.titleElement.textContent = x;
129 },
130
131 /**
132 * @return {string}
133 */
134 subtitle: function()
135 {
136 return this._subtitle;
137 },
138
139 /**
140 * @param {string} x
141 */
142 setSubtitle: function(x)
143 {
144 if (this._subtitle === x)
145 return;
146 this._subtitle = x;
147 this.subtitleElement.textContent = x;
148 },
149
150 /**
151 * @return {boolean}
152 */
153 isSelected: function()
154 {
155 return this._selected;
156 },
157
158 /**
159 * @param {boolean} x
160 */
161 setSelected: function(x)
162 {
163 if (x)
164 this.select();
165 else
166 this.deselect();
167 },
168
169 select: function()
170 {
171 if (this._selected)
172 return;
173 this._selected = true;
174 this.element.classList.add("selected");
175 },
176
177 deselect: function()
178 {
179 if (!this._selected)
180 return;
181 this._selected = false;
182 this.element.classList.remove("selected");
183 },
184
185 toggleSelected: function()
186 {
187 this.setSelected(!this.isSelected());
188 },
189
190 /**
191 * @return {boolean}
192 */
193 isHidden: function()
194 {
195 return this._hidden;
196 },
197
198 /**
199 * @param {boolean} x
200 */
201 setHidden: function(x)
202 {
203 if (this._hidden === x)
204 return;
205 this._hidden = x;
206 this.element.classList.toggle("hidden", x);
207 },
208
209 /**
210 * @return {boolean}
211 */
212 isLabel: function()
213 {
214 return this._isLabel;
215 },
216
217 /**
218 * @param {boolean} x
219 */
220 setDimmed: function(x)
221 {
222 this.element.classList.toggle("dimmed", x);
223 },
224
225 discard: function()
226 {
227 },
228
229 /**
230 * @param {boolean} hoverable
231 */
232 setHoverable: function(hoverable)
233 {
234 this.element.classList.toggle("ignore-hover", !hoverable);
235 },
236 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698