| 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 if (!this.hasAttribute('tabindex')) | 276 if (!this.hasAttribute('tabindex')) |
| 277 this.tabIndex = 0; | 277 this.tabIndex = 0; |
| 278 }, | 278 }, |
| 279 | 279 |
| 280 /** | 280 /** |
| 281 * Callback for mousedown and mouseup events. | 281 * Callback for mousedown and mouseup events. |
| 282 * @param {Event} e The mouse event object. | 282 * @param {Event} e The mouse event object. |
| 283 * @private | 283 * @private |
| 284 */ | 284 */ |
| 285 handleMouseDownUp_: function(e) { | 285 handleMouseDownUp_: function(e) { |
| 286 if (this.disabled) |
| 287 return; |
| 288 |
| 286 var target = e.target; | 289 var target = e.target; |
| 287 | 290 |
| 288 // If the target was this element we need to make sure that the user did | 291 // If the target was this element we need to make sure that the user did |
| 289 // not click on a border or a scrollbar. | 292 // not click on a border or a scrollbar. |
| 290 if (target == this && !inViewport(target, e)) | 293 if (target == this && !inViewport(target, e)) |
| 291 return; | 294 return; |
| 292 | 295 |
| 293 while (target && target.parentNode != this) { | 296 while (target && target.parentNode != this) { |
| 294 target = target.parentNode; | 297 target = target.parentNode; |
| 295 } | 298 } |
| 296 | 299 |
| 297 if (!target) { | 300 if (!target) { |
| 298 this.selectionController_.handleMouseDownUp(e, -1); | 301 this.selectionController_.handleMouseDownUp(e, -1); |
| 299 } else { | 302 } else { |
| 300 var cs = getComputedStyle(target); | 303 var cs = getComputedStyle(target); |
| 301 var top = target.offsetTop - | 304 var top = target.offsetTop - |
| 302 parseFloat(cs.marginTop); | 305 parseFloat(cs.marginTop); |
| 303 var index = Math.floor(top / this.itemHeight_); | 306 var index = Math.floor(top / this.itemHeight_); |
| 304 this.selectionController_.handleMouseDownUp(e, index); | 307 this.selectionController_.handleMouseDownUp(e, index); |
| 305 } | 308 } |
| 306 }, | 309 }, |
| 307 | 310 |
| 308 /** | 311 /** |
| 309 * Handle a keydown event. | 312 * Handle a keydown event. |
| 310 * @param {Event} e The keydown event. | 313 * @param {Event} e The keydown event. |
| 311 * @return {boolean} Whether the key event was handled. | 314 * @return {boolean} Whether the key event was handled. |
| 312 */ | 315 */ |
| 313 handleKeyDown: function(e) { | 316 handleKeyDown: function(e) { |
| 317 if (this.disabled) |
| 318 return; |
| 319 |
| 314 return this.selectionController_.handleKeyDown(e); | 320 return this.selectionController_.handleKeyDown(e); |
| 315 }, | 321 }, |
| 316 | 322 |
| 317 /** | 323 /** |
| 318 * Callback from the selection model. We dispatch {@code change} events | 324 * Callback from the selection model. We dispatch {@code change} events |
| 319 * when the selection changes. | 325 * when the selection changes. |
| 320 * @param {!cr.Event} e Event with change info. | 326 * @param {!cr.Event} e Event with change info. |
| 321 * @private | 327 * @private |
| 322 */ | 328 */ |
| 323 handleOnChange_: function(ce) { | 329 handleOnChange_: function(ce) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 * @param {number} index The row index to redraw. | 557 * @param {number} index The row index to redraw. |
| 552 */ | 558 */ |
| 553 redrawItem: function(index) { | 559 redrawItem: function(index) { |
| 554 if (index >= this.firstIndex_ && index < this.lastIndex_) { | 560 if (index >= this.firstIndex_ && index < this.lastIndex_) { |
| 555 delete this.cachedItems_[index]; | 561 delete this.cachedItems_[index]; |
| 556 this.redraw(); | 562 this.redraw(); |
| 557 } | 563 } |
| 558 } | 564 } |
| 559 }; | 565 }; |
| 560 | 566 |
| 567 cr.defineProperty(List, 'disabled', cr.PropertyKind.BOOL_ATTR); |
| 568 |
| 561 return { | 569 return { |
| 562 List: List | 570 List: List |
| 563 } | 571 } |
| 564 }); | 572 }); |
| OLD | NEW |