Commit 9edba1f3 authored by François Degros's avatar François Degros Committed by Commit Bot

[Files app] ES6 class for quick_view_controller.js

Bug: 778674
Change-Id: Ib5903f1983d52418855ca50ec75b67c5b756426b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1614650Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Auto-Submit: François Degros <fdegros@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660336}
parent bc183a91
......@@ -4,6 +4,9 @@
/**
* Controller for QuickView.
*/
class QuickViewController {
/**
* This should be initialized with |init_| method.
*
* @param {!MetadataModel} metadataModel File system metadata.
......@@ -17,84 +20,47 @@
* @param {!MetadataBoxController} metadataBoxController
* @param {DialogType} dialogType
* @param {!VolumeManager} volumeManager
*
* @constructor
*/
function QuickViewController(
constructor(
metadataModel, selectionHandler, listContainer, selectionMenuButton,
quickViewModel, taskController, fileListSelectionModel, quickViewUma,
metadataBoxController, dialogType, volumeManager) {
/**
* @type {FilesQuickView}
* @private
*/
/** @private {?FilesQuickView} */
this.quickView_ = null;
/**
* @type {!FileSelectionHandler}
* @private
*/
/** @private @const {!FileSelectionHandler} */
this.selectionHandler_ = selectionHandler;
/**
* @type {!ListContainer}
* @private
*/
/** @private @const {!ListContainer} */
this.listContainer_ = listContainer;
/**
* @type{!QuickViewModel}
* @private
*/
/** @private @const{!QuickViewModel} */
this.quickViewModel_ = quickViewModel;
/**
* @type {!QuickViewUma}
* @private
*/
/** @private @const {!QuickViewUma} */
this.quickViewUma_ = quickViewUma;
/**
* @type {!MetadataModel}
* @private
*/
/** @private @const {!MetadataModel} */
this.metadataModel_ = metadataModel;
/**
* @type {!TaskController}
* @private
*/
/** @private @const {!TaskController} */
this.taskController_ = taskController;
/**
* @type {!cr.ui.ListSelectionModel}
* @private
*/
/** @private @const {!cr.ui.ListSelectionModel} */
this.fileListSelectionModel_ = fileListSelectionModel;
/**
* @type {!MetadataBoxController}
* @private
*/
/** @private @const {!MetadataBoxController} */
this.metadataBoxController_ = metadataBoxController;
/**
* @type {DialogType}
* @private
*/
/** @private @const {DialogType} */
this.dialogType_ = dialogType;
/**
* @type {!VolumeManager}
* @private
*/
/** @private @const {!VolumeManager} */
this.volumeManager_ = volumeManager;
/**
* Current selection of selectionHandler.
*
* @type {!Array<!FileEntry>}
* @private
* @private {!Array<!FileEntry>}
*/
this.entries_ = [];
......@@ -113,50 +79,14 @@ function QuickViewController(
this.display_(QuickViewUma.WayToOpen.SELECTION_MENU);
}
});
}
/**
* List of local volume types.
*
* In this context, "local" means that files in that volume are directly
* accessible from the Chrome browser process by Linux VFS paths. In this
* regard, media views are NOT local even though files in media views are
* actually stored in the local disk.
*
* Due to access control of WebView, non-local files can not be previewed
* with Quick View unless thumbnails are provided (which is the case with
* Drive).
*
* @type {!Array<!VolumeManagerCommon.VolumeType>}
* @const
* @private
*/
QuickViewController.LOCAL_VOLUME_TYPES_ = [
VolumeManagerCommon.VolumeType.ARCHIVE,
VolumeManagerCommon.VolumeType.DOWNLOADS,
VolumeManagerCommon.VolumeType.REMOVABLE,
VolumeManagerCommon.VolumeType.ANDROID_FILES,
VolumeManagerCommon.VolumeType.CROSTINI,
VolumeManagerCommon.VolumeType.MEDIA_VIEW,
VolumeManagerCommon.VolumeType.DOCUMENTS_PROVIDER,
];
/**
* List of unsupported image subtypes
* @type {!Array<string>}
* @const
* @private
*/
QuickViewController.UNSUPPORTED_IMAGE_SUBTYPES_ = [
'TIFF',
];
}
/**
/**
* Initialize the controller with quick view which will be lazily loaded.
* @param {!FilesQuickView} quickView
* @private
*/
QuickViewController.prototype.init_ = function(quickView) {
init_(quickView) {
this.quickView_ = quickView;
this.metadataBoxController_.init(quickView);
document.body.addEventListener(
......@@ -170,40 +100,40 @@ QuickViewController.prototype.init_ = function(quickView) {
const elems =
this.quickView_.$$('#toolbar').querySelectorAll('[has-tooltip]');
toolTip.addTargets(elems);
};
}
/**
* Craete quick view element.
/**
* Create quick view element.
* @return Promise<!FilesQuickView>
* @private
*/
QuickViewController.prototype.createQuickView_ = () => {
createQuickView_() {
return new Promise((resolve, reject) => {
Polymer.Base.importHref(constants.FILES_QUICK_VIEW_HTML, () => {
const quickView = document.querySelector('#quick-view');
resolve(quickView);
}, reject);
});
};
}
/**
/**
* Handles open-in-new button tap.
*
* @param {!Event} event A button click event.
* @private
*/
QuickViewController.prototype.onOpenInNewButtonTap_ = function(event) {
onOpenInNewButtonTap_(event) {
this.taskController_.executeDefaultTask();
this.quickView_.close();
};
}
/**
/**
* Handles key event on listContainer if it's relevant to quick view.
*
* @param {!Event} event A keyboard event.
* @private
*/
QuickViewController.prototype.onKeyDownToOpen_ = function(event) {
onKeyDownToOpen_(event) {
if (event.key === ' ') {
event.preventDefault();
if (this.entries_.length != 1) {
......@@ -212,15 +142,15 @@ QuickViewController.prototype.onKeyDownToOpen_ = function(event) {
event.stopImmediatePropagation();
this.display_(QuickViewUma.WayToOpen.SPACE_KEY);
}
};
}
/**
/**
* Handles key event on quick view.
*
* @param {!Event} event A keyboard event.
* @private
*/
QuickViewController.prototype.onQuickViewKeyDown_ = function(event) {
onQuickViewKeyDown_(event) {
if (this.quickView_.isOpened()) {
let index;
switch (event.key) {
......@@ -249,31 +179,31 @@ QuickViewController.prototype.onQuickViewKeyDown_ = function(event) {
break;
}
}
};
}
/**
/**
* Display quick view.
*
* @param {QuickViewUma.WayToOpen=} opt_wayToOpen in which way opening of
* quick view was triggered. Can be omitted if quick view is already open.
* @private
*/
QuickViewController.prototype.display_ = function(opt_wayToOpen) {
display_(opt_wayToOpen) {
this.updateQuickView_().then(() => {
if (!this.quickView_.isOpened()) {
this.quickView_.open();
this.quickViewUma_.onOpened(this.entries_[0], assert(opt_wayToOpen));
}
});
};
}
/**
/**
* Update quick view on file selection change.
*
* @param {!Event} event an Event whose target is FileSelectionHandler.
* @private
*/
QuickViewController.prototype.onFileSelectionChanged_ = function(event) {
onFileSelectionChanged_(event) {
this.entries_ = event.target.selection.entries;
if (this.quickView_ && this.quickView_.isOpened()) {
assert(this.entries_.length > 0);
......@@ -284,26 +214,26 @@ QuickViewController.prototype.onFileSelectionChanged_ = function(event) {
this.quickViewModel_.setSelectedEntry(entry);
this.display_();
}
};
}
/**
/**
* @param {!FileEntry} entry
* @return {!Promise<!Array<!chrome.fileManagerPrivate.FileTask>>}
* @private
*/
QuickViewController.prototype.getAvailableTasks_ = function(entry) {
getAvailableTasks_(entry) {
return this.taskController_.getFileTasks().then(tasks => {
return tasks.getTaskItems();
});
};
}
/**
/**
* Update quick view using current entries.
*
* @return {!Promise} Promise fulfilled after quick view is updated.
* @private
*/
QuickViewController.prototype.updateQuickView_ = function() {
updateQuickView_() {
if (!this.quickView_) {
return this.createQuickView_()
.then(this.init_.bind(this))
......@@ -325,14 +255,15 @@ QuickViewController.prototype.updateQuickView_ = function() {
])
.then(values => {
const items = (/**@type{Array<MetadataItem>}*/ (values[0]));
const tasks = (/**@type{!Array<!chrome.fileManagerPrivate.FileTask>}*/ (
const tasks =
(/**@type{!Array<!chrome.fileManagerPrivate.FileTask>}*/ (
values[1]));
return this.onMetadataLoaded_(entry, items, tasks);
})
.catch(console.error);
};
}
/**
/**
* Update quick view using file entry and loaded metadata and tasks.
*
* @param {!FileEntry} entry
......@@ -340,8 +271,7 @@ QuickViewController.prototype.updateQuickView_ = function() {
* @param {!Array<!chrome.fileManagerPrivate.FileTask>} tasks
* @private
*/
QuickViewController.prototype.onMetadataLoaded_ = function(
entry, items, tasks) {
onMetadataLoaded_(entry, items, tasks) {
return this.getQuickViewParameters_(entry, items, tasks).then(params => {
this.quickView_.type = params.type || '';
this.quickView_.subtype = params.subtype || '';
......@@ -353,23 +283,9 @@ QuickViewController.prototype.onMetadataLoaded_ = function(
this.quickView_.autoplay = params.autoplay || false;
this.quickView_.browsable = params.browsable || false;
});
};
/**
* @typedef {{
* type: string,
* subtype: string,
* filePath: string,
* contentUrl: (string|undefined),
* videoPoster: (string|undefined),
* audioArtwork: (string|undefined),
* autoplay: (boolean|undefined),
* browsable: (boolean|undefined),
* }}
*/
let QuickViewParams;
}
/**
/**
* @param {!FileEntry} entry
* @param {Array<MetadataItem>} items
* @param {!Array<!chrome.fileManagerPrivate.FileTask>} tasks
......@@ -377,8 +293,7 @@ let QuickViewParams;
*
* @private
*/
QuickViewController.prototype.getQuickViewParameters_ = function(
entry, items, tasks) {
getQuickViewParameters_(entry, items, tasks) {
const item = items[0];
const typeInfo = FileType.getType(entry, item.mediaMimeType);
const type = typeInfo.type;
......@@ -393,8 +308,8 @@ QuickViewController.prototype.getQuickViewParameters_ = function(
const volumeInfo = this.volumeManager_.getVolumeInfo(entry);
const localFile = volumeInfo &&
QuickViewController.LOCAL_VOLUME_TYPES_.indexOf(volumeInfo.volumeType) >=
0;
QuickViewController.LOCAL_VOLUME_TYPES_.indexOf(
volumeInfo.volumeType) >= 0;
if (!localFile) {
// For Drive files, display a thumbnail if there is one.
......@@ -485,18 +400,66 @@ QuickViewController.prototype.getQuickViewParameters_ = function(
console.error(e);
return params;
});
};
}
/**
/**
* Loads a thumbnail from Drive.
*
* @param {string} url Thumbnail url
* @return Promise<{{status: string, data:string, width:number, height:number}}>
* @return Promise<{{status: string, data:string, width:number,
* height:number}}>
* @private
*/
QuickViewController.prototype.loadThumbnailFromDrive_ = url => {
loadThumbnailFromDrive_(url) {
return new Promise(resolve => {
ImageLoaderClient.getInstance().load(
LoadImageRequest.createForUrl(url), resolve);
});
};
}
}
/**
* List of local volume types.
*
* In this context, "local" means that files in that volume are directly
* accessible from the Chrome browser process by Linux VFS paths. In this
* regard, media views are NOT local even though files in media views are
* actually stored in the local disk.
*
* Due to access control of WebView, non-local files can not be previewed
* with Quick View unless thumbnails are provided (which is the case with
* Drive).
*
* @private @const {!Array<!VolumeManagerCommon.VolumeType>}
*/
QuickViewController.LOCAL_VOLUME_TYPES_ = [
VolumeManagerCommon.VolumeType.ARCHIVE,
VolumeManagerCommon.VolumeType.DOWNLOADS,
VolumeManagerCommon.VolumeType.REMOVABLE,
VolumeManagerCommon.VolumeType.ANDROID_FILES,
VolumeManagerCommon.VolumeType.CROSTINI,
VolumeManagerCommon.VolumeType.MEDIA_VIEW,
VolumeManagerCommon.VolumeType.DOCUMENTS_PROVIDER,
];
/**
* List of unsupported image subtypes
* @private @const {!Array<string>}
*/
QuickViewController.UNSUPPORTED_IMAGE_SUBTYPES_ = [
'TIFF',
];
/**
* @typedef {{
* type: string,
* subtype: string,
* filePath: string,
* contentUrl: (string|undefined),
* videoPoster: (string|undefined),
* audioArtwork: (string|undefined),
* autoplay: (boolean|undefined),
* browsable: (boolean|undefined),
* }}
*/
let QuickViewParams;
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