summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/resources/file_manager/js/file_grid.js59
-rw-r--r--chrome/browser/resources/file_manager/js/file_manager.js1
2 files changed, 59 insertions, 1 deletions
diff --git a/chrome/browser/resources/file_manager/js/file_grid.js b/chrome/browser/resources/file_manager/js/file_grid.js
index dd5409f..5d31df0 100644
--- a/chrome/browser/resources/file_manager/js/file_grid.js
+++ b/chrome/browser/resources/file_manager/js/file_grid.js
@@ -239,5 +239,62 @@ FileGrid.prototype.setBottomMarginForPanel = function(margin) {
* @return {boolean} True if the mouse is hit to the background of the list.
*/
FileGrid.prototype.shouldStartDragSelection = function(event) {
- return false;
+ var pos = DragSelector.getScrolledPosition(this, event);
+ return this.getHitElements(pos.x, pos.y).length == 0;
+};
+
+/**
+ * Obtains the column/row index that the coordinate points.
+ * @param {number} coordinate Vertical/horizontal coodinate value that points
+ * column/row.
+ * @param {number} step Length from a column/row to the next one.
+ * @param {number} threshold Threshold that determinds whether 1 offset is added
+ * to the return value or not. This is used in order to handle the margin of
+ * column/row.
+ * @return {number} Index of hit column/row.
+ * @private
+ */
+FileGrid.prototype.getHitIndex_ = function(coordinate, step, threshold) {
+ var index = ~~(coordinate / step);
+ return (coordinate % step >= threshold) ? index + 1 : index;
+};
+
+/**
+ * Obtains the index list of elements that are hit by the point or the
+ * rectangle.
+ *
+ * We should match its argument interface with FileList.getHitElements.
+ *
+ * @param {number} x X coordinate value.
+ * @param {number} y Y coordinate value.
+ * @param {=number} opt_width Width of the coordinate.
+ * @param {=number} opt_height Height of the coordinate.
+ * @return {Array.<number>} Index list of hit elements.
+ */
+FileGrid.prototype.getHitElements = function(x, y, opt_width, opt_height) {
+ var currentSelection = [];
+ var right = x + (opt_width || 0);
+ var bottom = y + (opt_height || 0);
+ var itemMetrics = this.measureItem();
+ var horizontalStartIndex = this.getHitIndex_(
+ x, itemMetrics.width, itemMetrics.width - itemMetrics.marginRight);
+ var horizontalEndIndex = Math.min(this.columns, this.getHitIndex_(
+ right, itemMetrics.width, itemMetrics.marginLeft));
+ var verticalStartIndex = this.getHitIndex_(
+ y, itemMetrics.height, itemMetrics.height - itemMetrics.bottom);
+ var verticalEndIndex = this.getHitIndex_(
+ bottom, itemMetrics.height, itemMetrics.marginTop);
+ for (var verticalIndex = verticalStartIndex;
+ verticalIndex < verticalEndIndex;
+ verticalIndex++) {
+ var indexBase = this.getFirstItemInRow(verticalIndex);
+ for (var horizontalIndex = horizontalStartIndex;
+ horizontalIndex < horizontalEndIndex;
+ horizontalIndex++) {
+ var index = indexBase + horizontalIndex;
+ if (0 <= index && index < this.dataModel.length)
+ currentSelection.push(index);
+ }
+ }
+ return currentSelection;
};
diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js
index 64a6c7c..0007d82 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -1010,6 +1010,7 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
// This event is published by DragSelector because drag end event is not
// published at the end of drag selection.
this.table_.list.addEventListener('dragselectionend', dragEndBound);
+ this.grid_.addEventListener('dragselectionend', dragEndBound);
// TODO(mtomasz, yoshiki): Create navigation list earlier, and here just
// attach the directory model.