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 = {};
/**
* File table list.
* @constructor
* @struct
* @extends {cr.ui.table.TableList}
*/
function FileTableList() {
throw new Error('Designed to decorate elements');
}
/**
* Decorates TableList as FileTableList.
* @param {!cr.ui.table.TableList} self A tabel list element.
*/
FileTableList.decorate = self => {
self.__proto__ = FileTableList.prototype;
};
FileTableList.prototype.__proto__ = cr.ui.table.TableList.prototype;
class FileTableList extends cr.ui.table.TableList {
constructor() {
// To silence closure compiler.
super();
/*
* @type {?function(number, number)}
*/
this.onMergeItems_ = null;
/**
* @type {?function(number, number)}
*/
FileTableList.prototype.onMergeItems_ = null;
throw new Error('Designed to decorate elements');
}
/**
* @param {function(number, number)} onMergeItems callback called from
* |mergeItems| with the parameters |beginIndex| and |endIndex|.
*/
FileTableList.prototype.setOnMergeItems = function(onMergeItems) {
assert(!this.onMergeItems_);
this.onMergeItems_ = onMergeItems;
};
/**
* @param {function(number, number)} onMergeItems callback called from
* |mergeItems| with the parameters |beginIndex| and |endIndex|.
*/
setOnMergeItems(onMergeItems) {
assert(!this.onMergeItems_);
this.onMergeItems_ = onMergeItems;
}
/** @override */
FileTableList.prototype.mergeItems = function(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
// mergeItems operation is done. This prevents checkmarks on selected items
// from being animated unintentionally by redraw.
for (let i = beginIndex; i < endIndex; i++) {
const item = this.getListItemByIndex(i);
if (!item) {
continue;
/** @override */
mergeItems(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
// mergeItems operation is done. This prevents checkmarks on selected items
// from being animated unintentionally by redraw.
for (let i = beginIndex; i < endIndex; i++) {
const item = this.getListItemByIndex(i);
if (!item) {
continue;
}
const isSelected = this.selectionModel.getIndexSelected(i);
if (item.selected != isSelected) {
item.selected = isSelected;
}
}
const isSelected = this.selectionModel.getIndexSelected(i);
if (item.selected != isSelected) {
item.selected = isSelected;
if (this.onMergeItems_) {
this.onMergeItems_(beginIndex, endIndex);
}
}
if (this.onMergeItems_) {
this.onMergeItems_(beginIndex, endIndex);
/** @override */
createSelectionController(sm) {
return new FileListSelectionController(assert(sm));
}
};
}
/** @override */
FileTableList.prototype.createSelectionController = function(sm) {
return new FileListSelectionController(assert(sm));
/**
* Decorates TableList as FileTableList.
* @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.
* @param {!cr.ui.ListSelectionModel} selectionModel The selection model to
* interact with.
* @constructor
* @extends {cr.ui.ListSelectionController}
* @struct
*/
function FileListSelectionController(selectionModel) {
cr.ui.ListSelectionController.call(this, selectionModel);
class FileListSelectionController extends cr.ui.ListSelectionController {
/**
* Whether to allow touch-specific interaction.
* @type {boolean}
* @param {!cr.ui.ListSelectionModel} selectionModel The selection model to
* interact with.
*/
this.enableTouchMode_ = false;
util.isTouchModeEnabled().then(enabled => {
this.enableTouchMode_ = enabled;
});
constructor(selectionModel) {
super(selectionModel);
//cr.ui.ListSelectionController.call(this, selectionModel);
/**
* @type {!FileTapHandler}
* @const
*/
this.tapHandler_ = new FileTapHandler();
}
FileListSelectionController.prototype = /** @struct */ {
__proto__: cr.ui.ListSelectionController.prototype
};
/**
* Whether to allow touch-specific interaction.
* @type {boolean}
*/
this.enableTouchMode_ = false;
util.isTouchModeEnabled().then(enabled => {
this.enableTouchMode_ = enabled;
});
/** @override */
FileListSelectionController.prototype.handlePointerDownUp = function(e, index) {
filelist.handlePointerDownUp.call(this, e, index);
};
/**
* @type {!FileTapHandler}
* @const
*/
this.tapHandler_ = new FileTapHandler();
}
/** @override */
FileListSelectionController.prototype.handleTouchEvents = function(e, index) {
if (!this.enableTouchMode_) {
return;
/** @override */
handlePointerDownUp(e, index) {
filelist.handlePointerDownUp.call(this, e, index);
}
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 */
handleTouchEvents(e, index) {
if (!this.enableTouchMode_) {
return;
}
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 */
FileListSelectionController.prototype.handleKeyDown = function(e) {
filelist.handleKeyDown.call(this, e);
};
/** @override */
handleKeyDown(e) {
filelist.handleKeyDown.call(this, e);
}
}
/**
* 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