OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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: array_data_model.js | 5 // require: array_data_model.js |
6 // require: list_selection_model.js | 6 // require: list_selection_model.js |
7 // require: list_selection_controller.js | 7 // require: list_selection_controller.js |
8 // require: list_item.js | 8 // require: list_item.js |
9 | 9 |
10 /** | 10 /** |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 this.beforeFiller_ = this.ownerDocument.createElement('div'); | 341 this.beforeFiller_ = this.ownerDocument.createElement('div'); |
342 this.afterFiller_ = this.ownerDocument.createElement('div'); | 342 this.afterFiller_ = this.ownerDocument.createElement('div'); |
343 this.beforeFiller_.className = 'spacer'; | 343 this.beforeFiller_.className = 'spacer'; |
344 this.afterFiller_.className = 'spacer'; | 344 this.afterFiller_.className = 'spacer'; |
345 this.appendChild(this.beforeFiller_); | 345 this.appendChild(this.beforeFiller_); |
346 this.appendChild(this.afterFiller_); | 346 this.appendChild(this.afterFiller_); |
347 | 347 |
348 var length = this.dataModel ? this.dataModel.length : 0; | 348 var length = this.dataModel ? this.dataModel.length : 0; |
349 this.selectionModel = new ListSelectionModel(length); | 349 this.selectionModel = new ListSelectionModel(length); |
350 | 350 |
| 351 this.addEventListener('dblclick', this.handleDoubleClick_); |
351 this.addEventListener('mousedown', this.handleMouseDownUp_); | 352 this.addEventListener('mousedown', this.handleMouseDownUp_); |
352 this.addEventListener('mouseup', this.handleMouseDownUp_); | 353 this.addEventListener('mouseup', this.handleMouseDownUp_); |
353 this.addEventListener('keydown', this.handleKeyDown); | 354 this.addEventListener('keydown', this.handleKeyDown); |
354 this.addEventListener('focus', this.handleElementFocus_, true); | 355 this.addEventListener('focus', this.handleElementFocus_, true); |
355 this.addEventListener('blur', this.handleElementBlur_, true); | 356 this.addEventListener('blur', this.handleElementBlur_, true); |
356 this.addEventListener('scroll', this.redraw.bind(this)); | 357 this.addEventListener('scroll', this.redraw.bind(this)); |
357 this.setAttribute('role', 'listbox'); | 358 this.setAttribute('role', 'listbox'); |
358 | 359 |
359 // Make list focusable | 360 // Make list focusable |
360 if (!this.hasAttribute('tabindex')) | 361 if (!this.hasAttribute('tabindex')) |
(...skipping 22 matching lines...) Expand all Loading... |
383 * @private | 384 * @private |
384 */ | 385 */ |
385 getItemSize_: function() { | 386 getItemSize_: function() { |
386 if (!this.measured_ || !this.measured_.height) { | 387 if (!this.measured_ || !this.measured_.height) { |
387 this.measured_ = measureItem(this); | 388 this.measured_ = measureItem(this); |
388 } | 389 } |
389 return this.measured_; | 390 return this.measured_; |
390 }, | 391 }, |
391 | 392 |
392 /** | 393 /** |
| 394 * Callback for the double click event. |
| 395 * @param {Event} e The mouse event object. |
| 396 * @private |
| 397 */ |
| 398 handleDoubleClick_: function(e) { |
| 399 if (this.disabled) |
| 400 return; |
| 401 |
| 402 var target = this.getListItemAncestor(e.target); |
| 403 if (target) |
| 404 this.activateItemAtIndex(this.getIndexOfListItem(target)); |
| 405 }, |
| 406 |
| 407 /** |
393 * Callback for mousedown and mouseup events. | 408 * Callback for mousedown and mouseup events. |
394 * @param {Event} e The mouse event object. | 409 * @param {Event} e The mouse event object. |
395 * @private | 410 * @private |
396 */ | 411 */ |
397 handleMouseDownUp_: function(e) { | 412 handleMouseDownUp_: function(e) { |
398 if (this.disabled) | 413 if (this.disabled) |
399 return; | 414 return; |
400 | 415 |
401 var target = e.target; | 416 var target = e.target; |
402 | 417 |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 /** | 938 /** |
924 * Redraws a single item. | 939 * Redraws a single item. |
925 * @param {number} index The row index to redraw. | 940 * @param {number} index The row index to redraw. |
926 */ | 941 */ |
927 redrawItem: function(index) { | 942 redrawItem: function(index) { |
928 if (index >= this.firstIndex_ && index < this.lastIndex_) { | 943 if (index >= this.firstIndex_ && index < this.lastIndex_) { |
929 delete this.cachedItems_[index]; | 944 delete this.cachedItems_[index]; |
930 this.redraw(); | 945 this.redraw(); |
931 } | 946 } |
932 }, | 947 }, |
| 948 |
| 949 /** |
| 950 * Called when a list item is activated, currently only by a double click |
| 951 * event. |
| 952 * @param {number} index The index of the activated item. |
| 953 */ |
| 954 activateItemAtIndex: function(index) { |
| 955 }, |
933 }; | 956 }; |
934 | 957 |
935 cr.defineProperty(List, 'disabled', cr.PropertyKind.BOOL_ATTR); | 958 cr.defineProperty(List, 'disabled', cr.PropertyKind.BOOL_ATTR); |
936 | 959 |
937 /** | 960 /** |
938 * Whether the list or one of its descendents has focus. This is necessary | 961 * Whether the list or one of its descendents has focus. This is necessary |
939 * because list items can contain controls that can be focused, and for some | 962 * because list items can contain controls that can be focused, and for some |
940 * purposes (e.g., styling), the list can still be conceptually focused at | 963 * purposes (e.g., styling), the list can still be conceptually focused at |
941 * that point even though it doesn't actually have the page focus. | 964 * that point even though it doesn't actually have the page focus. |
942 */ | 965 */ |
943 cr.defineProperty(List, 'hasElementFocus', cr.PropertyKind.BOOL_ATTR); | 966 cr.defineProperty(List, 'hasElementFocus', cr.PropertyKind.BOOL_ATTR); |
944 | 967 |
945 return { | 968 return { |
946 List: List | 969 List: List |
947 } | 970 } |
948 }); | 971 }); |
OLD | NEW |