Skip to content

Commit

Permalink
Files app: ES6 class mock_thumbnail_loader.js and selection_menu_cont…
Browse files Browse the repository at this point in the history
…roller.js

Bug: 778674
Change-Id: Ia4ac22739529b81862f7d4c04fad196b631e9baf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1760642
Commit-Queue: Alex Danilo <adanilo@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: Alex Danilo <adanilo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688875}
  • Loading branch information
Luciano Pacheco authored and Commit Bot committed Aug 21, 2019
1 parent 280369c commit e62a7b6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 71 deletions.
62 changes: 32 additions & 30 deletions ui/file_manager/file_manager/foreground/js/mock_thumbnail_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,39 @@

/**
* Mock thumbnail loader.
*
* @param {Entry} entry An entry.
* @param {ThumbnailLoader.LoaderType=} opt_loaderType Loader type.
* @param {Object=} opt_metadata Metadata.
* @param {string=} opt_mediaType Media type.
* @param {Array<ThumbnailLoader.LoadTarget>=} opt_loadTargets Load targets.
* @param {number=} opt_priority Priority.
* @constructor
*/
function MockThumbnailLoader(
entry, opt_loaderType, opt_metadata, opt_mediaType, opt_loadTargets,
opt_priority) {
this.entry_ = entry;
class MockThumbnailLoader {
/**
* @param {Entry} entry An entry.
* @param {ThumbnailLoader.LoaderType=} opt_loaderType Loader type.
* @param {Object=} opt_metadata Metadata.
* @param {string=} opt_mediaType Media type.
* @param {Array<ThumbnailLoader.LoadTarget>=} opt_loadTargets Load targets.
* @param {number=} opt_priority Priority.
*/
constructor(
entry, opt_loaderType, opt_metadata, opt_mediaType, opt_loadTargets,
opt_priority) {
this.entry_ = entry;
}

/**
* Loads thumbnail as data url.
*
* @return {!Promise<{data:?string, width:number, height:number}>} A
* promise which is resolved with data url.
*/
loadAsDataUrl() {
if (MockThumbnailLoader.errorUrls.indexOf(this.entry_.toURL()) !== -1) {
throw new Error('Failed to load thumbnail.');
}

return Promise.resolve({
data: MockThumbnailLoader.testImageDataUrl,
width: MockThumbnailLoader.testImageWidth,
height: MockThumbnailLoader.testImageHeight
});
}
}

/**
Expand All @@ -42,21 +62,3 @@ MockThumbnailLoader.testImageHeight = 0;
* @private {Array<string>}
*/
MockThumbnailLoader.errorUrls = [];

/**
* Loads thumbnail as data url.
*
* @return {!Promise<{data:?string, width:number, height:number}>} A
* promise which is resolved with data url.
*/
MockThumbnailLoader.prototype.loadAsDataUrl = function() {
if (MockThumbnailLoader.errorUrls.indexOf(this.entry_.toURL()) !== -1) {
throw new Error('Failed to load thumbnail.');
}

return Promise.resolve({
data: MockThumbnailLoader.testImageDataUrl,
width: MockThumbnailLoader.testImageWidth,
height: MockThumbnailLoader.testImageHeight
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,53 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
* @param {!cr.ui.MenuButton} selectionMenuButton
* @param {!cr.ui.Menu} menu
* @constructor
* @struct
*/
function SelectionMenuController(selectionMenuButton, menu) {
class SelectionMenuController {
/**
* @type {!FilesToggleRipple}
* @const
* @private
* @param {!cr.ui.MenuButton} selectionMenuButton
* @param {!cr.ui.Menu} menu
*/
this.toggleRipple_ =
/** @type {!FilesToggleRipple} */ (
queryRequiredElement('files-toggle-ripple', selectionMenuButton));
constructor(selectionMenuButton, menu) {
/**
* @type {!FilesToggleRipple}
* @const
* @private
*/
this.toggleRipple_ =
/** @type {!FilesToggleRipple} */ (
queryRequiredElement('files-toggle-ripple', selectionMenuButton));

/**
* @type {!cr.ui.Menu}
* @const
*/
this.menu_ = menu;
/**
* @type {!cr.ui.Menu}
* @const
*/
this.menu_ = menu;

selectionMenuButton.addEventListener('menushow', this.onShowMenu_.bind(this));
selectionMenuButton.addEventListener('menuhide', this.onHideMenu_.bind(this));
}
selectionMenuButton.addEventListener(
'menushow', this.onShowMenu_.bind(this));
selectionMenuButton.addEventListener(
'menuhide', this.onHideMenu_.bind(this));
}

/**
* @private
*/
SelectionMenuController.prototype.onShowMenu_ = function() {
this.menu_.classList.toggle('toolbar-menu', true);
this.toggleRipple_.activated = true;
// crbug.com 752035 focus still on button, get rid of the tooltip
document.querySelector('files-tooltip').hideTooltip();
};
/**
* @private
*/
onShowMenu_() {
this.menu_.classList.toggle('toolbar-menu', true);
this.toggleRipple_.activated = true;
// crbug.com 752035 focus still on button, get rid of the tooltip
document.querySelector('files-tooltip').hideTooltip();
}

/**
* @private
*/
SelectionMenuController.prototype.onHideMenu_ = function() {
// If menu is animating to close, then do not remove 'toolbar-menu' yet, it
// will be removed at the end of FilesMenuItem.setMenuAsAnimating_ to avoid
// flicker. See crbug.com/862926.
if (!this.menu_.classList.contains('animating')) {
this.menu_.classList.toggle('toolbar-menu', false);
/**
* @private
*/
onHideMenu_() {
// If menu is animating to close, then do not remove 'toolbar-menu' yet, it
// will be removed at the end of FilesMenuItem.setMenuAsAnimating_ to avoid
// flicker. See crbug.com/862926.
if (!this.menu_.classList.contains('animating')) {
this.menu_.classList.toggle('toolbar-menu', false);
}
this.toggleRipple_.activated = false;
}
this.toggleRipple_.activated = false;
};
}

0 comments on commit e62a7b6

Please sign in to comment.