Commit aedac22a authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

[Files app] Convert to ES6 classes file file_table_list.js

Manual edit:
- change to reset onMergeItems_ inside FileTabledecorate because that
replaces the class constructor.
- remove closure markup @struct and @extends because they aren't needed
with ES6 class (they're implicit).

CL 3 of 4.

Bug: 778674
Change-Id: Iddbc2278b700f55588b85567aa9fbbe25a595b3f
Reviewed-on: https://chromium-review.googlesource.com/c/1460200
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630456}
parent 02171e5a
...@@ -9,120 +9,118 @@ const filelist = {}; ...@@ -9,120 +9,118 @@ const filelist = {};
/** /**
* File table list. * File table list.
* @constructor
* @struct
* @extends {cr.ui.table.TableList}
*/ */
function FileTableList() { class FileTableList extends cr.ui.table.TableList {
throw new Error('Designed to decorate elements'); constructor() {
} // To silence closure compiler.
super();
/** /*
* Decorates TableList as FileTableList. * @type {?function(number, number)}
* @param {!cr.ui.table.TableList} self A tabel list element. */
*/ this.onMergeItems_ = null;
FileTableList.decorate = self => {
self.__proto__ = FileTableList.prototype;
};
FileTableList.prototype.__proto__ = cr.ui.table.TableList.prototype;
/** throw new Error('Designed to decorate elements');
* @type {?function(number, number)} }
*/
FileTableList.prototype.onMergeItems_ = null;
/** /**
* @param {function(number, number)} onMergeItems callback called from * @param {function(number, number)} onMergeItems callback called from
* |mergeItems| with the parameters |beginIndex| and |endIndex|. * |mergeItems| with the parameters |beginIndex| and |endIndex|.
*/ */
FileTableList.prototype.setOnMergeItems = function(onMergeItems) { setOnMergeItems(onMergeItems) {
assert(!this.onMergeItems_); assert(!this.onMergeItems_);
this.onMergeItems_ = onMergeItems; this.onMergeItems_ = onMergeItems;
}; }
/** @override */ /** @override */
FileTableList.prototype.mergeItems = function(beginIndex, endIndex) { mergeItems(beginIndex, endIndex) {
cr.ui.table.TableList.prototype.mergeItems.call(this, beginIndex, endIndex); cr.ui.table.TableList.prototype.mergeItems.call(this, beginIndex, endIndex);
// Make sure that list item's selected attribute is updated just after the // Make sure that list item's selected attribute is updated just after the
// mergeItems operation is done. This prevents checkmarks on selected items // mergeItems operation is done. This prevents checkmarks on selected items
// from being animated unintentionally by redraw. // from being animated unintentionally by redraw.
for (let i = beginIndex; i < endIndex; i++) { for (let i = beginIndex; i < endIndex; i++) {
const item = this.getListItemByIndex(i); const item = this.getListItemByIndex(i);
if (!item) { if (!item) {
continue; continue;
}
const isSelected = this.selectionModel.getIndexSelected(i);
if (item.selected != isSelected) {
item.selected = isSelected;
}
} }
const isSelected = this.selectionModel.getIndexSelected(i);
if (item.selected != isSelected) { if (this.onMergeItems_) {
item.selected = isSelected; this.onMergeItems_(beginIndex, endIndex);
} }
} }
if (this.onMergeItems_) { /** @override */
this.onMergeItems_(beginIndex, endIndex); createSelectionController(sm) {
return new FileListSelectionController(assert(sm));
} }
}; }
/** @override */ /**
FileTableList.prototype.createSelectionController = function(sm) { * Decorates TableList as FileTableList.
return new FileListSelectionController(assert(sm)); * @param {!cr.ui.table.TableList} self A tabel list element.
*/
FileTableList.decorate = self => {
self.__proto__ = FileTableList.prototype;
self.onMergeItems_ = null;
}; };
/** /**
* Selection controller for the file table list. * Selection controller for the file table list.
* @param {!cr.ui.ListSelectionModel} selectionModel The selection model to
* interact with.
* @constructor
* @extends {cr.ui.ListSelectionController}
* @struct
*/ */
function FileListSelectionController(selectionModel) { class FileListSelectionController extends cr.ui.ListSelectionController {
cr.ui.ListSelectionController.call(this, selectionModel);
/** /**
* Whether to allow touch-specific interaction. * @param {!cr.ui.ListSelectionModel} selectionModel The selection model to
* @type {boolean} * interact with.
*/ */
this.enableTouchMode_ = false; constructor(selectionModel) {
util.isTouchModeEnabled().then(enabled => { super(selectionModel);
this.enableTouchMode_ = enabled; //cr.ui.ListSelectionController.call(this, selectionModel);
});
/** /**
* @type {!FileTapHandler} * Whether to allow touch-specific interaction.
* @const * @type {boolean}
*/ */
this.tapHandler_ = new FileTapHandler(); this.enableTouchMode_ = false;
} util.isTouchModeEnabled().then(enabled => {
this.enableTouchMode_ = enabled;
FileListSelectionController.prototype = /** @struct */ { });
__proto__: cr.ui.ListSelectionController.prototype
};
/** @override */ /**
FileListSelectionController.prototype.handlePointerDownUp = function(e, index) { * @type {!FileTapHandler}
filelist.handlePointerDownUp.call(this, e, index); * @const
}; */
this.tapHandler_ = new FileTapHandler();
}
/** @override */ /** @override */
FileListSelectionController.prototype.handleTouchEvents = function(e, index) { handlePointerDownUp(e, index) {
if (!this.enableTouchMode_) { filelist.handlePointerDownUp.call(this, e, index);
return;
} }
if (this.tapHandler_.handleTouchEvents(
e, index, filelist.handleTap.bind(this))) { /** @override */
// If a tap event is processed, FileTapHandler cancels the event to prevent handleTouchEvents(e, index) {
// triggering click events. Then it results not moving the focus to the if (!this.enableTouchMode_) {
// list. So we do that here explicitly. return;
filelist.focusParentList(e); }
if (this.tapHandler_.handleTouchEvents(
e, index, filelist.handleTap.bind(this))) {
// If a tap event is processed, FileTapHandler cancels the event to prevent
// triggering click events. Then it results not moving the focus to the
// list. So we do that here explicitly.
filelist.focusParentList(e);
}
} }
};
/** @override */ /** @override */
FileListSelectionController.prototype.handleKeyDown = function(e) { handleKeyDown(e) {
filelist.handleKeyDown.call(this, e); filelist.handleKeyDown.call(this, e);
}; }
}
/** /**
* Common item decoration for table's and grid's items. * Common item decoration for table's and grid's items.
......
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