Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Unified Diff: ui/webui/resources/js/cr/ui/list.js

Issue 512003002: Revert of Revert "Typecheck JS files for chrome://extensions" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/webui/resources/js/cr/ui/grid.js ('k') | ui/webui/resources/js/cr/ui/list_item.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..4fc97ba510614ef5b39a9b931a7a5a0a7b74ed16 100644
--- a/ui/webui/resources/js/cr/ui/list.js
+++ b/ui/webui/resources/js/cr/ui/list.js
@@ -21,7 +21,7 @@
* 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 @@
* 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}}
- * @private
- */
- measured_: undefined,
+ * @type {?{height: number, marginTop: number, marginBottom: number,
+ * width: number, marginLeft: number, marginRight: number}}
+ * @private
+ */
+ measured_: null,
/**
* Whether or not the list is autoexpanding. If true, the list resizes
@@ -85,14 +85,14 @@
/**
* Function used to create grid items.
- * @type {function(): !ListItem}
+ * @type {function(new:cr.ui.ListItem, Object)}
* @private
*/
itemConstructor_: cr.ui.ListItem,
/**
* Function used to create grid items.
- * @type {function(): !ListItem}
+ * @return {function(new:cr.ui.ListItem, Object)}
*/
get itemConstructor() {
return this.itemConstructor_;
@@ -242,7 +242,7 @@
/**
* Convenience alias for selectionModel.selectedItems
- * @type {!Array<*>}
+ * @type {!Array.<*>}
*/
get selectedItems() {
var indexes = this.selectionModel.selectedIndexes;
@@ -397,16 +397,18 @@
* @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.
*/
measureItem: function(opt_item) {
var dataModel = this.dataModel;
- if (!dataModel || !dataModel.length)
- return 0;
+ if (!dataModel || !dataModel.length) {
+ return {height: 0, marginTop: 0, marginBottom: 0,
+ width: 0, marginLeft: 0, marginRight: 0};
+ }
var item = opt_item || this.cachedMeasuredItem_ ||
this.createItem(dataModel.item(0));
if (!opt_item) {
@@ -462,11 +464,11 @@
if (this.disabled)
return;
- var target = e.target;
-
- target = this.getListItemAncestor(target);
- if (target)
- this.activateItemAtIndex(this.getIndexOfListItem(target));
+ var target = /** @type {HTMLElement} */(e.target);
+
+ var ancestor = this.getListItemAncestor(target);
+ if (ancestor)
+ this.activateItemAtIndex(this.getIndexOfListItem(ancestor));
},
/**
@@ -478,7 +480,7 @@
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.
@@ -521,26 +523,23 @@
* 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 {HTMLLIElement} The list item containing |element|, or null.
*/
getListItemAncestor: function(element) {
var container = element;
while (container && container.parentNode != this) {
container = container.parentNode;
}
- return container;
+ return container && assertInstanceof(container, HTMLLIElement);
},
/**
* 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 +553,7 @@
/**
* 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 +605,7 @@
var self = this;
window.setTimeout(function() {
self.scrollIndexIntoView(pe.newValue);
- });
+ }, 0);
}
}
},
@@ -797,7 +796,7 @@
/**
* Creates a new list item.
- * @param {*} value The value to use for the item.
+ * @param {Object} value The value to use for the item.
* @return {!ListItem} The newly created list item.
*/
createItem: function(value) {
@@ -1062,7 +1061,7 @@
this.firstIndex_ = 0;
this.lastIndex_ = 0;
this.remainingSpace_ = this.clientHeight != 0;
- this.mergeItems(0, 0, {}, {});
+ this.mergeItems(0, 0);
return;
}
@@ -1276,10 +1275,11 @@
/**
* Mousedown event handler.
- * @this {List}
- * @param {MouseEvent} e The mouse event object.
+ * @this {cr.ui.List}
+ * @param {Event} 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 @@
* 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)
« no previous file with comments | « ui/webui/resources/js/cr/ui/grid.js ('k') | ui/webui/resources/js/cr/ui/list_item.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698