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 240bd6e901033fe5a4739519fbf9e56efcd87a68..be30dff539fc62ce25537260711de15bcd239d51 100644 |
--- a/ui/webui/resources/js/cr/ui/list.js |
+++ b/ui/webui/resources/js/cr/ui/list.js |
@@ -314,6 +314,7 @@ cr.define('cr.ui', function() { |
this.addEventListener('dblclick', this.handleDoubleClick_); |
this.addEventListener('mousedown', handleMouseDown); |
+ this.addEventListener('dragstart', handleDragStart, true); |
this.addEventListener('mouseup', this.handlePointerDownUp_); |
this.addEventListener('keydown', this.handleKeyDown); |
this.addEventListener('focus', this.handleElementFocus_, true); |
@@ -1303,6 +1304,24 @@ 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'. |
+ */ |
+ function handleDragStart(e) { |
+ var element = e.target.ownerDocument.elementFromPoint(e.clientX, e.clientY); |
+ var target = this.getListItemAncestor(element); |
+ var index = this.getIndexOfListItem(target); |
+ if (index != -1) { |
+ var isAlreadySelected = this.selectionModel_.getIndexSelected(index); |
+ if (!isAlreadySelected) |
+ this.selectionModel_.selectedIndex = index; |
+ } |
+ } |
+ |
+ /** |
* Check if |start| or its ancestor under |root| is focusable. |
* This is a helper for handleMouseDown. |
* @param {!Element} start An element which we start to check. |