Commit 15d768df authored by Sasha Morrissey's avatar Sasha Morrissey Committed by Commit Bot

Deselect elements and cancel drag if initiated in files list padding

Deselect elements and cancel a touchscreen drag if the drag is initiated
in the files list padding area, below the list.

Bug: 760552
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I163ebe6c16f7295af3feb25c56a9abfd99d483fc
Reviewed-on: https://chromium-review.googlesource.com/923619Reviewed-by: default avatarNaoki Fukino <fukino@chromium.org>
Commit-Queue: Sasha Morrissey <sashab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537743}
parent e8cd111a
...@@ -994,12 +994,19 @@ FileTransferController.prototype.onDragStart_ = function(list, event) { ...@@ -994,12 +994,19 @@ FileTransferController.prototype.onDragStart_ = function(list, event) {
return; return;
} }
// Check if a drag selection should be initiated or not. // If this drag operation is initiated by mouse, check if we should start
if (list.shouldStartDragSelection(event)) { // selecting area.
if (!this.touching_ && list.shouldStartDragSelection(event)) {
event.preventDefault(); event.preventDefault();
// If this drag operation is initiated by mouse, start selecting area. this.dragSelector_.startDragSelection(list, event);
if (!this.touching_) return;
this.dragSelector_.startDragSelection(list, event); }
// If the drag starts outside the files list on a touch device, cancel the
// drag.
if (this.touching_ && !list.hasDragHitElement(event)) {
event.preventDefault();
list.selectionModel_.unselectAll();
return; return;
} }
......
...@@ -555,12 +555,12 @@ FileGrid.prototype.decorateThumbnail_ = function(li, entry) { ...@@ -555,12 +555,12 @@ FileGrid.prototype.decorateThumbnail_ = function(li, entry) {
var isDirectory = entry && entry.isDirectory; var isDirectory = entry && entry.isDirectory;
if (!isDirectory) { if (!isDirectory) {
var active_checkmark = li.ownerDocument.createElement('div'); var activeCheckmark = li.ownerDocument.createElement('div');
active_checkmark.className = 'checkmark active'; activeCheckmark.className = 'checkmark active';
frame.appendChild(active_checkmark); frame.appendChild(activeCheckmark);
var inactive_checkmark = li.ownerDocument.createElement('div'); var inactiveCheckmark = li.ownerDocument.createElement('div');
inactive_checkmark.className = 'checkmark inactive'; inactiveCheckmark.className = 'checkmark inactive';
frame.appendChild(inactive_checkmark); frame.appendChild(inactiveCheckmark);
} }
var badge = li.ownerDocument.createElement('div'); var badge = li.ownerDocument.createElement('div');
...@@ -813,6 +813,18 @@ FileGrid.Item.prototype.decorate = function() { ...@@ -813,6 +813,18 @@ FileGrid.Item.prototype.decorate = function() {
this.setAttribute('role', 'option'); this.setAttribute('role', 'option');
}; };
/**
* Returns whether the drag event is inside a file entry in the list (and not
* the background padding area).
* @param {MouseEvent} event Drag start event.
* @return {boolean} True if the mouse is over an element in the list, False if
* it is in the background.
*/
FileGrid.prototype.hasDragHitElement = function(event) {
var pos = DragSelector.getScrolledPosition(this, event);
return this.getHitElements(pos.x, pos.y).length !== 0;
};
/** /**
* Obtains if the drag selection should be start or not by referring the mouse * Obtains if the drag selection should be start or not by referring the mouse
* event. * event.
...@@ -820,8 +832,8 @@ FileGrid.Item.prototype.decorate = function() { ...@@ -820,8 +832,8 @@ FileGrid.Item.prototype.decorate = function() {
* @return {boolean} True if the mouse is hit to the background of the list. * @return {boolean} True if the mouse is hit to the background of the list.
*/ */
FileGrid.prototype.shouldStartDragSelection = function(event) { FileGrid.prototype.shouldStartDragSelection = function(event) {
var pos = DragSelector.getScrolledPosition(this, event); // Start dragging area if the drag starts outside of the contents of the grid.
return this.getHitElements(pos.x, pos.y).length === 0; return !this.hasDragHitElement(event);
}; };
/** /**
......
...@@ -463,6 +463,7 @@ FileTable.decorate = function( ...@@ -463,6 +463,7 @@ FileTable.decorate = function(
}.bind(self), true); }.bind(self), true);
self.list.shouldStartDragSelection = self.list.shouldStartDragSelection =
self.shouldStartDragSelection_.bind(self); self.shouldStartDragSelection_.bind(self);
self.list.hasDragHitElement = self.hasDragHitElement_.bind(self);
/** /**
* Obtains the index list of elements that are hit by the point or the * Obtains the index list of elements that are hit by the point or the
...@@ -634,23 +635,37 @@ FileTable.prototype.setUseModificationByMeTime = function( ...@@ -634,23 +635,37 @@ FileTable.prototype.setUseModificationByMeTime = function(
this.useModificationByMeTime_ = useModificationByMeTime; this.useModificationByMeTime_ = useModificationByMeTime;
}; };
/**
* Returns whether the drag event is inside a file entry in the list (and not
* the background padding area).
* @param {MouseEvent} event Drag start event.
* @return {boolean} True if the mouse is over an element in the list, False if
* it is in the background.
*/
FileTable.prototype.hasDragHitElement_ = function(event) {
var pos = DragSelector.getScrolledPosition(this.list, event);
return this.list.getHitElements(pos.x, pos.y).length !== 0;
};
/** /**
* Obtains if the drag selection should be start or not by referring the mouse * Obtains if the drag selection should be start or not by referring the mouse
* event. * event.
* @param {MouseEvent} event Drag start event. * @param {MouseEvent} event Drag start event.
* @return {boolean} True if the mouse is hit to the background of the list. * @return {boolean} True if the mouse is hit to the background of the list, or
* certain areas of the inside of the list that would start a
* drag selection.
* @private * @private
*/ */
FileTable.prototype.shouldStartDragSelection_ = function(event) { FileTable.prototype.shouldStartDragSelection_ = function(event) {
// If the shift key is pressed, it should starts drag selection. // If the shift key is pressed, it should starts drag selection.
if (event.shiftKey) if (event.shiftKey)
return true; return true;
// We don't support drag selection by touch.
if (event.sourceCapabilities && event.sourceCapabilities.firesTouchEvents) // If we're outside of the element list, start the drag selection.
return false; if (!this.list.hasDragHitElement(event))
return true;
// If the position values are negative, it points the out of list. // If the position values are negative, it points the out of list.
// It should start the drag selection.
var pos = DragSelector.getScrolledPosition(this.list, event); var pos = DragSelector.getScrolledPosition(this.list, event);
if (!pos) if (!pos)
return false; return false;
......
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