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

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

Issue 288883004: Select the pointed item when drag operation starts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | « no previous file | no next file » | 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 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.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698