summaryrefslogtreecommitdiffstats
path: root/ui/file_manager
diff options
context:
space:
mode:
authorhirono@chromium.org <hirono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-25 07:02:13 +0000
committerhirono@chromium.org <hirono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-25 07:02:13 +0000
commitec164eb42ebb0f14ecc586e27c0af647f23add08 (patch)
treefd79816d79ca261bd5c2af13691cff356dbd332a /ui/file_manager
parentb77635c3a8c9b7bcb086fa53b138d3c7c3d18099 (diff)
downloadchromium_src-ec164eb42ebb0f14ecc586e27c0af647f23add08.zip
chromium_src-ec164eb42ebb0f14ecc586e27c0af647f23add08.tar.gz
chromium_src-ec164eb42ebb0f14ecc586e27c0af647f23add08.tar.bz2
Gallery.app: Include metadata of entries into gallery items.
BUG=382804 TEST=manually Review URL: https://codereview.chromium.org/350443003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279648 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/file_manager')
-rw-r--r--ui/file_manager/gallery/js/gallery.js106
-rw-r--r--ui/file_manager/gallery/js/gallery_item.js28
2 files changed, 79 insertions, 55 deletions
diff --git a/ui/file_manager/gallery/js/gallery.js b/ui/file_manager/gallery/js/gallery.js
index db91273..1d0ff12 100644
--- a/ui/file_manager/gallery/js/gallery.js
+++ b/ui/file_manager/gallery/js/gallery.js
@@ -268,65 +268,69 @@ Gallery.prototype.createToolbarButton_ = function(className, title) {
* @param {!Array.<Entry>} selectedEntries Array of selected entries.
*/
Gallery.prototype.load = function(entries, selectedEntries) {
- var items = [];
- for (var index = 0; index < entries.length; ++index) {
- items.push(new Gallery.Item(entries[index]));
- }
- this.dataModel_.push.apply(this.dataModel_, items);
-
- this.selectionModel_.adjustLength(this.dataModel_.length);
+ // Obtain metadata.
+ var metadataPromise = new Promise(function(fulfill) {
+ this.metadataCache_.get(entries, Gallery.METADATA_TYPE, fulfill);
+ }.bind(this));
- // Comparing Entries by reference is not safe. Therefore we have to use URLs.
- var entryIndexesByURLs = {};
- for (var index = 0; index < entries.length; index++) {
- entryIndexesByURLs[entries[index].toURL()] = index;
- }
+ // Initialize the gallery by uisng the metadata.
+ metadataPromise.then(function(metadata) {
+ // Check the length of metadata.
+ if (entries.length !== metadata.length)
+ return Promise.reject('Failed to obtain metadata for the entries.');
- for (var i = 0; i !== selectedEntries.length; i++) {
- var selectedIndex = entryIndexesByURLs[selectedEntries[i].toURL()];
- if (selectedIndex !== undefined)
- this.selectionModel_.setIndexSelected(selectedIndex, true);
- else
- console.error('Cannot select ' + selectedEntries[i]);
- }
-
- if (this.selectionModel_.selectedIndexes.length === 0)
- this.onSelection_();
+ // Obtains items.
+ var items = entries.map(function(entry, i) {
+ return new Gallery.Item(entry, MetadataCache.cloneMetadata(metadata[i]));
+ });
- var mosaic = this.mosaicMode_ && this.mosaicMode_.getMosaic();
+ // Update the models.
+ this.dataModel_.push.apply(this.dataModel_, items);
+ this.selectionModel_.adjustLength(this.dataModel_.length);
- // Mosaic view should show up if most of the selected files are images.
- var imagesCount = 0;
- for (var i = 0; i !== selectedEntries.length; i++) {
- if (FileType.getMediaType(selectedEntries[i]) === 'image')
- imagesCount++;
- }
- var mostlyImages = imagesCount > (selectedEntries.length / 2.0);
+ // Apply selection.
+ var entryIndexesByURLs = {};
+ for (var index = 0; index < entries.length; index++) {
+ entryIndexesByURLs[entries[index].toURL()] = index;
+ }
+ for (var i = 0; i !== selectedEntries.length; i++) {
+ var selectedIndex = entryIndexesByURLs[selectedEntries[i].toURL()];
+ if (selectedIndex !== undefined)
+ this.selectionModel_.setIndexSelected(selectedIndex, true);
+ else
+ console.error('Cannot select ' + selectedEntries[i]);
+ }
+ if (this.selectionModel_.selectedIndexes.length === 0)
+ this.onSelection_();
- var forcedMosaic = (this.context_.pageState &&
- this.context_.pageState.gallery === 'mosaic');
+ // Determine the initial mode.
+ var shouldShowMosaic = selectedEntries.length > 1 ||
+ (this.context_.pageState &&
+ this.context_.pageState.gallery === 'mosaic');
+ this.setCurrentMode_(shouldShowMosaic ? this.mosaicMode_ : this.slideMode_);
- var showMosaic = (mostlyImages && selectedEntries.length > 1) || forcedMosaic;
- if (mosaic && showMosaic) {
- this.setCurrentMode_(this.mosaicMode_);
+ // Init mosaic mode.
+ var mosaic = this.mosaicMode_.getMosaic();
mosaic.init();
- mosaic.show();
- this.inactivityWatcher_.check(); // Show the toolbar.
- cr.dispatchSimpleEvent(this, 'loaded');
- } else {
- this.setCurrentMode_(this.slideMode_);
- var maybeLoadMosaic = function() {
- if (mosaic)
- mosaic.init();
+
+ // Do the initialization for each mode.
+ if (shouldShowMosaic) {
+ this.inactivityWatcher_.check(); // Show the toolbar.
cr.dispatchSimpleEvent(this, 'loaded');
- }.bind(this);
- /* TODO: consider nice blow-up animation for the first image */
- this.slideMode_.enter(null, function() {
- // Flash the toolbar briefly to show it is there.
- this.inactivityWatcher_.kick(Gallery.FIRST_FADE_TIMEOUT);
- }.bind(this),
- maybeLoadMosaic);
- }
+ } else {
+ this.slideMode_.enter(
+ null,
+ function() {
+ // Flash the toolbar briefly to show it is there.
+ this.inactivityWatcher_.kick(Gallery.FIRST_FADE_TIMEOUT);
+ }.bind(this),
+ function() {
+ cr.dispatchSimpleEvent(this, 'loaded');
+ }.bind(this));
+ }
+ }.bind(this)).catch(function(error) {
+ console.error(error.stack || error);
+ });
};
/**
diff --git a/ui/file_manager/gallery/js/gallery_item.js b/ui/file_manager/gallery/js/gallery_item.js
index 9b7899c..4d2e9fd 100644
--- a/ui/file_manager/gallery/js/gallery_item.js
+++ b/ui/file_manager/gallery/js/gallery_item.js
@@ -10,15 +10,35 @@
* @param {FileEntry} entry Image entry.
* @constructor
*/
-Gallery.Item = function(entry) {
+Gallery.Item = function(entry, metadata) {
+ /**
+ * @type {FileEntry}
+ * @private
+ */
this.entry_ = entry;
+
+ /**
+ * @type {Object}
+ * @private
+ */
+ this.metadata_ = Object.freeze(metadata);
+
+ /**
+ * @type {boolean}
+ * @private
+ */
this.original_ = true;
};
/**
* @return {FileEntry} Image entry.
*/
-Gallery.Item.prototype.getEntry = function() { return this.entry_ };
+Gallery.Item.prototype.getEntry = function() { return this.entry_; };
+
+/**
+ * @return {Object} Metadata.
+ */
+Gallery.Item.prototype.getMetadata = function() { return this.metadata_; };
/**
* @return {string} File name.
@@ -30,7 +50,7 @@ Gallery.Item.prototype.getFileName = function() {
/**
* @return {boolean} True if this image has not been created in this session.
*/
-Gallery.Item.prototype.isOriginal = function() { return this.original_ };
+Gallery.Item.prototype.isOriginal = function() { return this.original_; };
// TODO: Localize?
/**
@@ -55,7 +75,7 @@ Gallery.Item.REGEXP_COPY_N =
/**
* Creates a name for an edited copy of the file.
*
- * @param {Entry} dirEntry Entry.
+ * @param {DirectoryEntry} dirEntry Entry.
* @param {function} callback Callback.
* @private
*/