Commit 6635c886 authored by fukino@chromium.org's avatar fukino@chromium.org

Select the pointed item when drag operation starts.

What this CL do:
 If there is an item at the drag's starting position and
the item is not selected, select the item.

Why this handling is needed:
 If the drag operation is initiated by mouse, the
'mousedown' event eventually selects the pointed item,
but there is no such chance when the drag operation is 
initiated by touch.

BUG=373839
TEST=manually tested

Review URL: https://codereview.chromium.org/288883004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271535 0039d316-1c4b-4281-b951-d872f2087c98
parent 299d0676
...@@ -314,6 +314,7 @@ cr.define('cr.ui', function() { ...@@ -314,6 +314,7 @@ cr.define('cr.ui', function() {
this.addEventListener('dblclick', this.handleDoubleClick_); this.addEventListener('dblclick', this.handleDoubleClick_);
this.addEventListener('mousedown', handleMouseDown); this.addEventListener('mousedown', handleMouseDown);
this.addEventListener('dragstart', handleDragStart, true);
this.addEventListener('mouseup', this.handlePointerDownUp_); this.addEventListener('mouseup', this.handlePointerDownUp_);
this.addEventListener('keydown', this.handleKeyDown); this.addEventListener('keydown', this.handleKeyDown);
this.addEventListener('focus', this.handleElementFocus_, true); this.addEventListener('focus', this.handleElementFocus_, true);
...@@ -1302,6 +1303,24 @@ cr.define('cr.ui', function() { ...@@ -1302,6 +1303,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. * Check if |start| or its ancestor under |root| is focusable.
* This is a helper for handleMouseDown. * This is a helper for handleMouseDown.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment