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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 this.beforeFiller_ = this.ownerDocument.createElement('div'); | 262 this.beforeFiller_ = this.ownerDocument.createElement('div'); |
263 this.afterFiller_ = this.ownerDocument.createElement('div'); | 263 this.afterFiller_ = this.ownerDocument.createElement('div'); |
264 this.beforeFiller_.className = 'spacer'; | 264 this.beforeFiller_.className = 'spacer'; |
265 this.afterFiller_.className = 'spacer'; | 265 this.afterFiller_.className = 'spacer'; |
266 this.appendChild(this.beforeFiller_); | 266 this.appendChild(this.beforeFiller_); |
267 this.appendChild(this.afterFiller_); | 267 this.appendChild(this.afterFiller_); |
268 | 268 |
269 var length = this.dataModel ? this.dataModel.length : 0; | 269 var length = this.dataModel ? this.dataModel.length : 0; |
270 this.selectionModel = new ListSelectionModel(length); | 270 this.selectionModel = new ListSelectionModel(length); |
271 | 271 |
272 this.addEventListener('dblclick', this.handleDoubleClick_); | |
272 this.addEventListener('mousedown', this.handleMouseDownUp_); | 273 this.addEventListener('mousedown', this.handleMouseDownUp_); |
273 this.addEventListener('mouseup', this.handleMouseDownUp_); | 274 this.addEventListener('mouseup', this.handleMouseDownUp_); |
274 this.addEventListener('keydown', this.handleKeyDown); | 275 this.addEventListener('keydown', this.handleKeyDown); |
275 this.addEventListener('scroll', this.redraw.bind(this)); | 276 this.addEventListener('scroll', this.redraw.bind(this)); |
276 | 277 |
277 // Make list focusable | 278 // Make list focusable |
278 if (!this.hasAttribute('tabindex')) | 279 if (!this.hasAttribute('tabindex')) |
279 this.tabIndex = 0; | 280 this.tabIndex = 0; |
280 }, | 281 }, |
281 | 282 |
282 /** | 283 /** |
283 * Returns the height of an item, measuring it if necessary. | 284 * Returns the height of an item, measuring it if necessary. |
284 * @private | 285 * @private |
285 */ | 286 */ |
286 getItemHeight_: function() { | 287 getItemHeight_: function() { |
287 if (!this.itemHeight_) | 288 if (!this.itemHeight_) |
288 this.itemHeight_ = measureItem(this); | 289 this.itemHeight_ = measureItem(this); |
289 return this.itemHeight_; | 290 return this.itemHeight_; |
290 }, | 291 }, |
291 | 292 |
292 /** | 293 /** |
294 * Callback for the double click event. | |
295 * @param {Event} e The mouse event object. | |
296 * @private | |
297 */ | |
298 handleDoubleClick_: function(e) { | |
299 if (this.disabled) | |
300 return; | |
301 | |
302 var target = e.target; | |
303 | |
304 // If the target was this element we need to make sure that the user did | |
305 // not click on a border or a scrollbar. | |
306 if (target == this && !inViewport(target, e)) | |
arv (Not doing code reviews)
2010/12/22 18:14:07
In this case I think you can skip this check since
James Hawkins
2010/12/22 21:22:31
Done.
| |
307 return; | |
308 | |
309 target = this.getListItemAncestor(target); | |
310 | |
311 var index = target ? this.getIndexOfListItem(target) : -1; | |
312 this.activateItemAtIndex(index); | |
arv (Not doing code reviews)
2010/12/22 18:14:07
Now the question arise if we should allow Enter (a
James Hawkins
2010/12/22 21:22:31
We should allow Enter to activate the item as well
| |
313 }, | |
314 | |
315 /** | |
293 * Callback for mousedown and mouseup events. | 316 * Callback for mousedown and mouseup events. |
294 * @param {Event} e The mouse event object. | 317 * @param {Event} e The mouse event object. |
295 * @private | 318 * @private |
296 */ | 319 */ |
297 handleMouseDownUp_: function(e) { | 320 handleMouseDownUp_: function(e) { |
298 if (this.disabled) | 321 if (this.disabled) |
299 return; | 322 return; |
300 | 323 |
301 var target = e.target; | 324 var target = e.target; |
302 | 325 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 } | 616 } |
594 }, | 617 }, |
595 }; | 618 }; |
596 | 619 |
597 cr.defineProperty(List, 'disabled', cr.PropertyKind.BOOL_ATTR); | 620 cr.defineProperty(List, 'disabled', cr.PropertyKind.BOOL_ATTR); |
598 | 621 |
599 return { | 622 return { |
600 List: List | 623 List: List |
601 } | 624 } |
602 }); | 625 }); |
OLD | NEW |