Chromium Code Reviews| Index: ui/webui/resources/js/cr/ui/list.js |
| diff --git a/ui/webui/resources/js/cr/ui/list.js b/ui/webui/resources/js/cr/ui/list.js |
| index 91df98de53466534e19737e5a41693d7f65864bd..e69873851a89e1c4d94a9a9082678f7bc6f40893 100644 |
| --- a/ui/webui/resources/js/cr/ui/list.js |
| +++ b/ui/webui/resources/js/cr/ui/list.js |
| @@ -21,7 +21,7 @@ cr.define('cr.ui', function() { |
| * false if the mouseevent was generated over a border or a scrollbar. |
| * @param {!HTMLElement} el The element to test the event with. |
| * @param {!Event} e The mouse event. |
| - * @param {boolean} Whether the mouse event was inside the viewport. |
| + * @return {boolean} Whether the mouse event was inside the viewport. |
| */ |
| function inViewport(el, e) { |
| var rect = el.getBoundingClientRect(); |
| @@ -53,11 +53,11 @@ cr.define('cr.ui', function() { |
| * is needed. Note that lead item is allowed to have a different height, to |
| * accommodate lists where a single item at a time can be expanded to show |
| * more detail. |
| - * @type {{height: number, marginTop: number, marginBottom:number, |
| - * width: number, marginLeft: number, marginRight:number}} |
| + * @type {?{height: number, marginTop: number, marginBottom: number, |
| + * width: number, marginLeft: number, marginRight: number}} |
| * @private |
| */ |
| - measured_: undefined, |
| + measured_: null, |
| /** |
| * Whether or not the list is autoexpanding. If true, the list resizes |
| @@ -85,14 +85,14 @@ cr.define('cr.ui', function() { |
| /** |
| * Function used to create grid items. |
| - * @type {function(): !ListItem} |
| + * @type {function(new:cr.ui.ListItem, string)} |
| * @private |
| */ |
| itemConstructor_: cr.ui.ListItem, |
| /** |
| * Function used to create grid items. |
| - * @type {function(): !ListItem} |
| + * @return {function(new:cr.ui.ListItem, string)} |
| */ |
| get itemConstructor() { |
| return this.itemConstructor_; |
| @@ -242,7 +242,7 @@ cr.define('cr.ui', function() { |
| /** |
| * Convenience alias for selectionModel.selectedItems |
| - * @type {!Array<*>} |
| + * @type {!Array.<*>} |
| */ |
| get selectedItems() { |
| var indexes = this.selectionModel.selectedIndexes; |
| @@ -313,7 +313,8 @@ cr.define('cr.ui', function() { |
| this.selectionModel = new ListSelectionModel(length); |
| this.addEventListener('dblclick', this.handleDoubleClick_); |
| - this.addEventListener('mousedown', handleMouseDown); |
| + this.addEventListener('mousedown', /** @type {function(Event)} */( |
|
Dan Beam
2014/08/22 21:57:14
remove cast
Vitaly Pavlenko
2014/08/23 00:59:03
Done.
|
| + handleMouseDown)); |
| this.addEventListener('dragstart', handleDragStart, true); |
| this.addEventListener('mouseup', this.handlePointerDownUp_); |
| this.addEventListener('keydown', this.handleKeyDown); |
| @@ -380,7 +381,7 @@ cr.define('cr.ui', function() { |
| }, |
| /** |
| - * @return {{height: number, width: number}} The height and width |
| + * @return {?{height: number, width: number}} The height and width |
| * of default item, measuring it if necessary. |
| * @private |
| */ |
| @@ -397,8 +398,8 @@ cr.define('cr.ui', function() { |
| * @param {ListItem=} opt_item The list item to use to do the measuring. If |
| * this is not provided an item will be created based on the first value |
| * in the model. |
| - * @return {{height: number, marginTop: number, marginBottom:number, |
| - * width: number, marginLeft: number, marginRight:number}} |
| + * @return {?{height: number, marginTop: number, marginBottom: number, |
| + * width: number, marginLeft: number, marginRight: number}} |
| * The height and width of the item, taking |
| * margins into account, and the top, bottom, left and right margins |
| * themselves. |
| @@ -406,7 +407,7 @@ cr.define('cr.ui', function() { |
| measureItem: function(opt_item) { |
| var dataModel = this.dataModel; |
| if (!dataModel || !dataModel.length) |
| - return 0; |
| + return null; |
| var item = opt_item || this.cachedMeasuredItem_ || |
| this.createItem(dataModel.item(0)); |
| if (!opt_item) { |
| @@ -462,11 +463,11 @@ cr.define('cr.ui', function() { |
| if (this.disabled) |
| return; |
| - var target = e.target; |
| + var target = /** @type {HTMLElement} */(e.target); |
| - target = this.getListItemAncestor(target); |
| - if (target) |
| - this.activateItemAtIndex(this.getIndexOfListItem(target)); |
| + var ancestor = this.getListItemAncestor(target); |
| + if (ancestor) |
| + this.activateItemAtIndex(this.getIndexOfListItem(ancestor)); |
| }, |
| /** |
| @@ -478,7 +479,7 @@ cr.define('cr.ui', function() { |
| if (this.disabled) |
| return; |
| - var target = e.target; |
| + var target = /** @type {HTMLElement} */(e.target); |
| // If the target was this element we need to make sure that the user did |
| // not click on a border or a scrollbar. |
| @@ -513,7 +514,7 @@ cr.define('cr.ui', function() { |
| * @private |
| */ |
| handleElementBlur_: function(e) { |
| - if (!this.contains(e.relatedTarget)) |
| + if (!this.contains(assertInstanceof(e.relatedTarget, Element))) |
| this.hasElementFocus = false; |
| }, |
| @@ -521,26 +522,23 @@ cr.define('cr.ui', function() { |
| * Returns the list item element containing the given element, or null if |
| * it doesn't belong to any list item element. |
| * @param {HTMLElement} element The element. |
| - * @return {ListItem} The list item containing |element|, or null. |
| + * @return {cr.ui.ListItem} The list item containing |element|, or null. |
| */ |
| getListItemAncestor: function(element) { |
| var container = element; |
| while (container && container.parentNode != this) { |
| container = container.parentNode; |
| } |
| - return container; |
| + return assertInstanceof(container, cr.ui.ListItem); |
| }, |
| /** |
| * Handle a keydown event. |
| * @param {Event} e The keydown event. |
| - * @return {boolean} Whether the key event was handled. |
| */ |
| handleKeyDown: function(e) { |
| - if (this.disabled) |
| - return; |
| - |
| - return this.selectionController_.handleKeyDown(e); |
| + if (!this.disabled) |
| + this.selectionController_.handleKeyDown(e); |
| }, |
| /** |
| @@ -554,7 +552,7 @@ cr.define('cr.ui', function() { |
| /** |
| * Callback from the selection model. We dispatch {@code change} events |
| * when the selection changes. |
| - * @param {!Event} e Event with change info. |
| + * @param {!Event} ce Event with change info. |
| * @private |
| */ |
| handleOnChange_: function(ce) { |
| @@ -606,7 +604,7 @@ cr.define('cr.ui', function() { |
| var self = this; |
| window.setTimeout(function() { |
| self.scrollIndexIntoView(pe.newValue); |
| - }); |
| + }, 0); |
| } |
| } |
| }, |
| @@ -797,10 +795,11 @@ cr.define('cr.ui', function() { |
| /** |
| * Creates a new list item. |
| - * @param {*} value The value to use for the item. |
| + * @param {string} value The value to use for the item. |
| * @return {!ListItem} The newly created list item. |
| */ |
| createItem: function(value) { |
| + assert(typeof value === "string"); |
|
Dan Beam
2014/08/22 21:57:14
=== should be ==
Vitaly Pavlenko
2014/08/23 00:59:03
Done.
|
| var item = new this.itemConstructor_(value); |
| item.label = value; |
| item.id = this.uniqueIdPrefix_ + '-' + this.nextUniqueIdSuffix_++; |
| @@ -1062,7 +1061,7 @@ cr.define('cr.ui', function() { |
| this.firstIndex_ = 0; |
| this.lastIndex_ = 0; |
| this.remainingSpace_ = this.clientHeight != 0; |
| - this.mergeItems(0, 0, {}, {}); |
| + this.mergeItems(0, 0); |
| return; |
| } |
| @@ -1276,10 +1275,11 @@ cr.define('cr.ui', function() { |
| /** |
| * Mousedown event handler. |
| - * @this {List} |
| + * @this {cr.ui.List} |
| * @param {MouseEvent} e The mouse event object. |
| */ |
| function handleMouseDown(e) { |
| + e.target = /** @type {!HTMLElement} */(e.target); |
| var listItem = this.getListItemAncestor(e.target); |
| var wasSelected = listItem && listItem.selected; |
| this.handlePointerDownUp_(e); |
| @@ -1307,10 +1307,11 @@ cr.define('cr.ui', function() { |
| * Dragstart event handler. |
| * If there is an item at starting position of drag operation and the item |
| * is not selected, select it. |
| - * @this {List} |
| - * @param {MouseEvent} e The event object for 'dragstart'. |
| + * @this {cr.ui.List} |
| + * @param {Event} e The event object for 'dragstart'. |
| */ |
| function handleDragStart(e) { |
| + e = /** @type {MouseEvent} */(e); |
| var element = e.target.ownerDocument.elementFromPoint(e.clientX, e.clientY); |
| var listItem = this.getListItemAncestor(element); |
| if (!listItem) |