OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // require: listselectionmodel.js | 5 // require: listselectionmodel.js |
6 | 6 |
7 /** | 7 /** |
8 * @fileoverview This implements a list control. | 8 * @fileoverview This implements a list control. |
9 */ | 9 */ |
10 | 10 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 itemHeight_: 0, | 89 itemHeight_: 0, |
90 | 90 |
91 /** | 91 /** |
92 * Whether or not the list is autoexpanding. If true, the list resizes | 92 * Whether or not the list is autoexpanding. If true, the list resizes |
93 * its height to accomadate all children. | 93 * its height to accomadate all children. |
94 * @type {boolean} | 94 * @type {boolean} |
95 * @private | 95 * @private |
96 */ | 96 */ |
97 autoExpands_: false, | 97 autoExpands_: false, |
98 | 98 |
99 /** | |
100 * Whether or not the list is disabled. | |
101 * @type {boolean} | |
102 * @private | |
103 */ | |
104 disabled_: false, | |
arv (Not doing code reviews)
2010/12/04 01:03:27
cr.defineProperty(List, 'disabled', cr.PropertyKin
stuartmorgan
2010/12/04 01:36:51
Ah-ha, this is the magic I was missing; I original
| |
105 | |
99 dataModel_: null, | 106 dataModel_: null, |
100 | 107 |
101 /** | 108 /** |
102 * The data model driving the list. | 109 * The data model driving the list. |
103 * @type {ListDataModel} | 110 * @type {ListDataModel} |
104 */ | 111 */ |
105 set dataModel(dataModel) { | 112 set dataModel(dataModel) { |
106 if (this.dataModel_ != dataModel) { | 113 if (this.dataModel_ != dataModel) { |
107 if (!this.boundHandleDataModelSplice_) { | 114 if (!this.boundHandleDataModelSplice_) { |
108 this.boundHandleDataModelSplice_ = | 115 this.boundHandleDataModelSplice_ = |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 return this.autoExpands_; | 187 return this.autoExpands_; |
181 }, | 188 }, |
182 set autoExpands(autoExpands) { | 189 set autoExpands(autoExpands) { |
183 if (this.autoExpands_ == autoExpands) | 190 if (this.autoExpands_ == autoExpands) |
184 return; | 191 return; |
185 this.autoExpands_ = autoExpands; | 192 this.autoExpands_ = autoExpands; |
186 this.redraw(); | 193 this.redraw(); |
187 }, | 194 }, |
188 | 195 |
189 /** | 196 /** |
197 * Whether or not the list is disabled. | |
198 * @type {boolean} | |
199 */ | |
200 get disabled() { | |
201 return this.disabled_; | |
202 }, | |
203 set disabled(disabled) { | |
204 this.disabled_ = disabled; | |
205 if (disabled) | |
206 this.classList.add('disabled'); | |
207 else | |
208 this.classList.remove('disabled'); | |
209 }, | |
210 | |
211 /** | |
190 * Convenience alias for selectionModel.selectedItem | 212 * Convenience alias for selectionModel.selectedItem |
191 * @type {cr.ui.ListItem} | 213 * @type {cr.ui.ListItem} |
192 */ | 214 */ |
193 get selectedItem() { | 215 get selectedItem() { |
194 var dataModel = this.dataModel; | 216 var dataModel = this.dataModel; |
195 if (dataModel) { | 217 if (dataModel) { |
196 var index = this.selectionModel.selectedIndex; | 218 var index = this.selectionModel.selectedIndex; |
197 if (index != -1) | 219 if (index != -1) |
198 return dataModel.item(index); | 220 return dataModel.item(index); |
199 } | 221 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 }, | 300 }, |
279 | 301 |
280 /** | 302 /** |
281 * Callback for mousedown and mouseup events. | 303 * Callback for mousedown and mouseup events. |
282 * @param {Event} e The mouse event object. | 304 * @param {Event} e The mouse event object. |
283 * @private | 305 * @private |
284 */ | 306 */ |
285 handleMouseDownUp_: function(e) { | 307 handleMouseDownUp_: function(e) { |
286 var target = e.target; | 308 var target = e.target; |
287 | 309 |
310 if (this.disabled) | |
arv (Not doing code reviews)
2010/12/04 01:03:27
Do this before "var target"
stuartmorgan
2010/12/04 01:36:51
Done.
| |
311 return; | |
312 | |
288 // If the target was this element we need to make sure that the user did | 313 // If the target was this element we need to make sure that the user did |
289 // not click on a border or a scrollbar. | 314 // not click on a border or a scrollbar. |
290 if (target == this && !inViewport(target, e)) | 315 if (target == this && !inViewport(target, e)) |
291 return; | 316 return; |
292 | 317 |
293 while (target && target.parentNode != this) { | 318 while (target && target.parentNode != this) { |
294 target = target.parentNode; | 319 target = target.parentNode; |
295 } | 320 } |
296 | 321 |
297 if (!target) { | 322 if (!target) { |
298 this.selectionController_.handleMouseDownUp(e, -1); | 323 this.selectionController_.handleMouseDownUp(e, -1); |
299 } else { | 324 } else { |
300 var cs = getComputedStyle(target); | 325 var cs = getComputedStyle(target); |
301 var top = target.offsetTop - | 326 var top = target.offsetTop - |
302 parseFloat(cs.marginTop); | 327 parseFloat(cs.marginTop); |
303 var index = Math.floor(top / this.itemHeight_); | 328 var index = Math.floor(top / this.itemHeight_); |
304 this.selectionController_.handleMouseDownUp(e, index); | 329 this.selectionController_.handleMouseDownUp(e, index); |
305 } | 330 } |
306 }, | 331 }, |
307 | 332 |
308 /** | 333 /** |
309 * Handle a keydown event. | 334 * Handle a keydown event. |
310 * @param {Event} e The keydown event. | 335 * @param {Event} e The keydown event. |
311 * @return {boolean} Whether the key event was handled. | 336 * @return {boolean} Whether the key event was handled. |
312 */ | 337 */ |
313 handleKeyDown: function(e) { | 338 handleKeyDown: function(e) { |
339 if (this.disabled) | |
340 return; | |
341 | |
314 return this.selectionController_.handleKeyDown(e); | 342 return this.selectionController_.handleKeyDown(e); |
315 }, | 343 }, |
316 | 344 |
317 /** | 345 /** |
318 * Callback from the selection model. We dispatch {@code change} events | 346 * Callback from the selection model. We dispatch {@code change} events |
319 * when the selection changes. | 347 * when the selection changes. |
320 * @param {!cr.Event} e Event with change info. | 348 * @param {!cr.Event} e Event with change info. |
321 * @private | 349 * @private |
322 */ | 350 */ |
323 handleOnChange_: function(ce) { | 351 handleOnChange_: function(ce) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 delete this.cachedItems_[index]; | 583 delete this.cachedItems_[index]; |
556 this.redraw(); | 584 this.redraw(); |
557 } | 585 } |
558 } | 586 } |
559 }; | 587 }; |
560 | 588 |
561 return { | 589 return { |
562 List: List | 590 List: List |
563 } | 591 } |
564 }); | 592 }); |
OLD | NEW |