Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7841)

Unified Diff: chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js

Issue 12334030: New custom wallpaper picker UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js
diff --git a/chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js b/chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js
index c7b44d8a4187b59320960cc5df5917b3232c7d43..5682acc1e529b1cd3747ffc640914cf4778d96f4 100644
--- a/chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js
+++ b/chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js
@@ -236,6 +236,10 @@ function WallpaperManager(dialogDom) {
$('close-error').addEventListener('click', function() {
$('error-container').hidden = true;
});
+ $('close-wallpaper-selection').addEventListener('click', function() {
+ $('wallpaper-selection-container').hidden = true;
+ $('set-wallpaper-layout').disabled = true;
+ });
this.onResize_();
};
@@ -245,7 +249,8 @@ function WallpaperManager(dialogDom) {
*/
WallpaperManager.prototype.presetCategory_ = function() {
this.currentWallpaper_ = str('currentWallpaper');
- if (this.currentWallpaper_ && this.currentWallpaper_ == 'CUSTOM') {
+ if (this.currentWallpaper_ &&
bshe 2013/02/26 19:07:26 the currentWallpaper is either a url contains High
flackr 2013/02/26 21:37:35 Great, I was going to comment on this. Can you add
bshe 2013/02/27 03:16:38 Done.
+ this.currentWallpaper_.indexOf(HighResolutionSuffix) == -1) {
// Custom is the last one in the categories list.
this.categoriesList_.selectionModel.selectedIndex =
this.categoriesList_.dataModel.length - 1;
@@ -257,12 +262,14 @@ function WallpaperManager(dialogDom) {
// wallpaper as the default selected category when showing wallpaper
// picker UI.
var presetCategory = AllCategoryIndex;
- for (var key in self.manifest_.wallpaper_list) {
- var url = self.manifest_.wallpaper_list[key].base_url +
- HighResolutionSuffix;
- if (url.indexOf(self.currentWallpaper_) != -1)
- presetCategory = self.manifest_.wallpaper_list[key].categories[0] +
- OnlineCategoriesOffset;
+ if (self.currentWallpaper_) {
+ for (var key in self.manifest_.wallpaper_list) {
+ var url = self.manifest_.wallpaper_list[key].base_url +
+ HighResolutionSuffix;
+ if (url.indexOf(self.currentWallpaper_) != -1)
flackr 2013/02/26 21:37:35 nit: I believe you need braces for a multi-line lo
bshe 2013/02/27 03:16:38 Done.
+ presetCategory = self.manifest_.wallpaper_list[key].categories[0] +
+ OnlineCategoriesOffset;
flackr 2013/02/26 21:37:35 You should break when you've found the category.
bshe 2013/02/27 03:16:38 Done.
+ }
}
self.categoriesList_.selectionModel.selectedIndex = presetCategory;
};
@@ -291,7 +298,7 @@ function WallpaperManager(dialogDom) {
wallpapers.WallpaperThumbnailsGrid.decorate(this.wallpaperGrid_);
this.wallpaperGrid_.addEventListener('change',
- this.onThumbnailClicked_.bind(this));
+ this.onThumbnailSelectionChanged_.bind(this));
this.wallpaperGrid_.addEventListener('dblclick', this.onClose_.bind(this));
};
@@ -310,54 +317,84 @@ function WallpaperManager(dialogDom) {
};
/**
- * Sets wallpaper to the corresponding wallpaper of selected thumbnail.
- */
- WallpaperManager.prototype.onThumbnailClicked_ = function() {
- var selectedItem = this.wallpaperGrid_.selectedItem;
- if (selectedItem && selectedItem.dynamicURL &&
- !this.wallpaperGrid_.inProgramSelection) {
- var wallpaperURL = selectedItem.baseURL + HighResolutionSuffix;
- var selectedGridItem = this.wallpaperGrid_.getListItem(selectedItem);
- var self = this;
+ * Sets wallpaper to the corresponding wallpaper of selected thumbnail.
+ * @param {{baseURL: string, layout: string, source: string,
+ * availableOffline: boolean, opt_dynamicURL: string,
+ * opt_author: string, opt_authorWebsite: string}}
+ * selectedItem the selected item in WallpaperThumbnailsGrid's data
+ * model.
+ */
bshe 2013/02/26 19:07:26 Most of the code in this function is moved from on
+ WallpaperManager.prototype.setSelectedWallpaper_ = function(selectedItem) {
+ var self = this;
+ var wallpaperURL = selectedItem.baseURL;
+ if (selectedItem.source == 'ONLINE')
flackr 2013/02/26 21:37:35 nit: constants for source values.
bshe 2013/02/27 03:16:38 Done.
+ wallpaperURL += HighResolutionSuffix;
flackr 2013/02/26 21:37:35 TODO: Use non high resolution wallpaper when appro
bshe 2013/02/27 03:16:38 There are changes in the design on how to fetch wa
flackr 2013/02/27 14:39:52 In light of that, I'm surprised we have a high res
bshe 2013/03/01 17:43:56 Discussed offline. We should investigate removing
+ var selectedGridItem = this.wallpaperGrid_.getListItem(selectedItem);
+
+ chrome.wallpaperPrivate.setWallpaperIfExist(wallpaperURL,
+ selectedItem.layout,
+ selectedItem.source,
+ function() {
+ if (chrome.runtime.lastError == undefined) {
+ self.currentWallpaper_ = wallpaperURL;
+ self.wallpaperGrid_.activeItem = selectedItem;
+ return;
+ }
- chrome.wallpaperPrivate.setWallpaperIfExist(wallpaperURL,
- selectedItem.layout,
- 'ONLINE',
- function() {
- if (chrome.runtime.lastError == undefined) {
+ if (selectedItem.source == 'CUSTOM')
+ return;
+
+ // Falls back to request wallpaper from server.
+ if (self.wallpaperRequest_)
+ self.wallpaperRequest_.abort();
+
+ self.wallpaperRequest_ = new XMLHttpRequest();
+ self.wallpaperRequest_.open('GET', wallpaperURL, true);
+ self.wallpaperRequest_.responseType = 'arraybuffer';
+ self.progressManager_.reset(self.wallpaperRequest_, selectedGridItem);
+ self.wallpaperRequest_.send(null);
+ self.wallpaperRequest_.addEventListener('load', function(e) {
+ if (self.wallpaperRequest_.status === 200) {
+ var image = self.wallpaperRequest_.response;
+ chrome.wallpaperPrivate.setWallpaper(
+ image,
+ selectedItem.layout,
+ wallpaperURL,
+ self.onFinished_.bind(self, selectedGridItem, selectedItem));
self.currentWallpaper_ = wallpaperURL;
- self.wallpaperGrid_.activeItem = selectedItem;
- return;
+ } else {
+ self.progressManager_.hideProgressBar(selectedGridItem);
+ self.showError_(str('downloadFailed'));
}
+ self.wallpaperRequest_ = null;
+ });
+ self.wallpaperRequest_.addEventListener('error', function() {
+ self.showError_(str('downloadFailed'));
+ });
+ });
+ };
- // Falls back to request wallpaper from server.
- if (self.wallpaperRequest_)
- self.wallpaperRequest_.abort();
-
- self.wallpaperRequest_ = new XMLHttpRequest();
- self.wallpaperRequest_.open('GET', wallpaperURL, true);
- self.wallpaperRequest_.responseType = 'arraybuffer';
- self.progressManager_.reset(self.wallpaperRequest_, selectedGridItem);
- self.wallpaperRequest_.send(null);
- self.wallpaperRequest_.addEventListener('load', function(e) {
- if (self.wallpaperRequest_.status === 200) {
- var image = self.wallpaperRequest_.response;
- chrome.wallpaperPrivate.setWallpaper(
- image,
- selectedItem.layout,
- wallpaperURL,
- self.onFinished_.bind(self, selectedGridItem, selectedItem));
- self.currentWallpaper_ = wallpaperURL;
- } else {
- self.progressManager_.hideProgressBar(selectedGridItem);
- self.showError_(str('downloadFailed'));
- }
- self.wallpaperRequest_ = null;
- });
- self.wallpaperRequest_.addEventListener('error', function() {
- self.showError_(str('downloadFailed'));
+ /**
+ * Handles click on a different thumbnail in wallpaper grid.
+ */
+ WallpaperManager.prototype.onThumbnailSelectionChanged_ = function() {
+ var selectedItem = this.wallpaperGrid_.selectedItem;
+ if (selectedItem && selectedItem.source == 'ADDNEW')
+ return;
+
+ if (selectedItem && selectedItem.baseURL &&
+ !this.wallpaperGrid_.inProgramSelection) {
flackr 2013/02/26 21:37:35 pardon my ignorance, but what does inProgramSelect
bshe 2013/02/27 03:16:38 Sorry for confusion. When the current thumbnail se
+ if (selectedItem.source == 'CUSTOM') {
+ var items = {};
+ var key = selectedItem.baseURL;
+ var self = this;
+ this.storage_.get(key, function(items) {
+ selectedItem.layout = items[key] ? items[key] : 'CENTER_CROPPED';
+ self.setSelectedWallpaper_(selectedItem);
});
- });
+ } else {
+ this.setSelectedWallpaper_(selectedItem);
+ }
}
this.setWallpaperAttribution_(selectedItem);
};
@@ -376,6 +413,7 @@ function WallpaperManager(dialogDom) {
$('author-website').textContent = $('author-website').href =
selectedItem.authorWebsite;
chrome.wallpaperPrivate.getThumbnail(selectedItem.baseURL,
+ selectedItem.source,
function(data) {
var img = $('attribute-image');
if (data) {
@@ -477,32 +515,59 @@ function WallpaperManager(dialogDom) {
});
reader.addEventListener('load', function(e) {
self.customWallpaperData_ = e.target.result;
- self.refreshWallpaper_(self.customWallpaperData_);
+ var layout = self.getSelectedLayout_();
+ chrome.wallpaperPrivate.setCustomWallpaper(self.customWallpaperData_,
+ layout, self.onSetCustomWallpaperFinished_.bind(self));
});
- this.generateThumbnail_(files[0]);
};
/**
- * Refreshes the custom wallpaper with the current selected layout.
- * @param {ArrayBuffer} customWallpaper The raw wallpaper file data.
+ * Retruns the current selected layout.
+ * @return {string} The selected layout.
*/
- WallpaperManager.prototype.refreshWallpaper_ = function(customWallpaper) {
+ WallpaperManager.prototype.getSelectedLayout_ = function() {
var setWallpaperLayout = $('set-wallpaper-layout');
- var layout =
- setWallpaperLayout.options[setWallpaperLayout.selectedIndex].value;
- chrome.wallpaperPrivate.setCustomWallpaper(customWallpaper,
- layout,
- this.onFinished_.bind(this));
- this.currentWallpaper_ = 'CUSTOM';
+ return setWallpaperLayout.options[setWallpaperLayout.selectedIndex].value;
};
/**
- * Sets wallpaper finished. Displays error message in butter bar if any.
+ * Add new thumbnail to custom wallpaper grid and set it as active thumbnail.
+ * @param {string=} opt_fileName The file name used to save the new selected
flackr 2013/02/26 21:37:35 When is the filename optional / not passed?
bshe 2013/02/27 03:16:38 When custom wallpaper layout change finished, this
flackr 2013/02/27 14:39:52 Comment this please. On 2013/02/27 03:16:38, bshe
bshe 2013/03/01 17:43:56 Done.
+ * custom wallpaper.
+ */
+ WallpaperManager.prototype.onSetCustomWallpaperFinished_ =
+ function(opt_fileName) {
+ if (chrome.runtime.lastError != undefined) {
+ this.showError_(chrome.runtime.lastError.message);
+ $('set-wallpaper-layout').disabled = true;
+ } else {
+ var layout = this.getSelectedLayout_();
+ $('set-wallpaper-layout').disabled = false;
+ if (opt_fileName) {
+ var wallpaperInfo = {
+ baseURL: opt_fileName,
+ layout: layout,
+ source: 'CUSTOM',
+ availableOffline: true
+ };
+ this.currentWallpaper_ = opt_fileName;
+ var items = {};
+ items[this.currentWallpaper_] = layout;
+ this.storage_.set(items, function() {});
+ this.wallpaperGrid_.dataModel.splice(0, 0, wallpaperInfo);
+ this.wallpaperGrid_.selectedItem = wallpaperInfo;
+ this.wallpaperGrid_.activeItem = wallpaperInfo;
+ }
+ }
+ };
+
+ /**
+ * Sets wallpaper finished. Displays error message if any.
* @param {WallpaperThumbnailsGridItem=} opt_selectedGridItem The wallpaper
* thumbnail grid item. It extends from cr.ui.ListItem.
- * @param {{baseURL: string, dynamicURL: string, layout: string,
- * author: string, authorWebsite: string,
- * availableOffline: boolean}=}
+ * @param {{baseURL: string, layout: string, source: string,
+ * availableOffline: boolean, opt_dynamicURL: string,
+ * opt_author: string, opt_authorWebsite: string}=}
* opt_selectedItem the selected item in WallpaperThumbnailsGrid's data
* model.
*/
@@ -522,35 +587,12 @@ function WallpaperManager(dialogDom) {
* Handles the layout setting change of custom wallpaper.
*/
WallpaperManager.prototype.onWallpaperLayoutChanged_ = function() {
- var setWallpaperLayout = $('set-wallpaper-layout');
- var layout =
- setWallpaperLayout.options[setWallpaperLayout.selectedIndex].value;
- chrome.wallpaperPrivate.setCustomWallpaperLayout(layout,
- this.onFinished_.bind(this));
- };
-
- /**
- * Generates a thumbnail of user selected image file.
- * @param {Object} file The file user selected from file manager.
- */
- WallpaperManager.prototype.generateThumbnail_ = function(file) {
- var img = $('preview');
- img.file = file;
- var reader = new FileReader();
- reader.addEventListener('load', function(e) {
- img.src = e.target.result;
- });
- reader.readAsDataURL(file);
- };
-
- /**
- * Toggle visibility of custom container and category container.
- * @param {boolean} showCustom True if display custom container and hide
- * category container.
- */
- WallpaperManager.prototype.showCustomContainer_ = function(showCustom) {
- $('category-container').hidden = showCustom;
- $('custom-container').hidden = !showCustom;
+ var layout = this.getSelectedLayout_();
+ var items = {};
+ items[this.currentWallpaper_] = layout;
+ this.storage_.set(items, function() {});
+ chrome.wallpaperPrivate.setCustomWallpaperLayout(layout,
+ this.onSetCustomWallpaperFinished_.bind(this));
};
/**
@@ -566,23 +608,49 @@ function WallpaperManager(dialogDom) {
bar.style.left = selectedListItem.offsetLeft + 'px';
bar.style.width = selectedListItem.offsetWidth + 'px';
+ var wallpapersDataModel = new cr.ui.ArrayDataModel([]);
+ var selectedItem;
if (selectedListItem.custom) {
- this.showCustomContainer_(true);
+ $('online-wallpaper-attribute').hidden = true;
+ var self = this;
+ chrome.wallpaperPrivate.getOfflineWallpaperList('CUSTOM',
+ function(lists) {
+ for (var i = 0; i < lists.length; i++) {
+ var wallpaperInfo = {
+ baseURL: lists[i],
+ layout: 'CENTER_CROPPED',
flackr 2013/02/26 21:37:35 So this is later replaced with the last used layou
bshe 2013/02/27 03:16:38 Right. It will be replaced by the value in local s
flackr 2013/02/27 14:39:52 Please add comment to this effect. On 2013/02/27
bshe 2013/03/01 17:43:56 Done.
+ source: 'CUSTOM',
+ availableOffline: true
+ };
+ if (self.currentWallpaper_ == lists[i])
+ selectedItem = wallpaperInfo;
+ wallpapersDataModel.push(wallpaperInfo);
+ }
+ var lastElement = {
+ baseURL: '',
+ layout: '',
+ source: 'ADDNEW',
+ availableOffline: true
+ };
+ wallpapersDataModel.push(lastElement);
+ self.wallpaperGrid_.dataModel = wallpapersDataModel;
+ self.wallpaperGrid_.selectedItem = selectedItem;
+ self.wallpaperGrid_.activeItem = selectedItem;
+ });
} else {
- this.showCustomContainer_(false);
- var selectedItem;
- var wallpapersDataModel = new cr.ui.ArrayDataModel([]);
+ $('online-wallpaper-attribute').hidden = false;
for (var key in this.manifest_.wallpaper_list) {
if (selectedIndex == AllCategoryIndex ||
this.manifest_.wallpaper_list[key].categories.indexOf(
selectedIndex - OnlineCategoriesOffset) != -1) {
var wallpaperInfo = {
baseURL: this.manifest_.wallpaper_list[key].base_url,
- dynamicURL: this.manifest_.wallpaper_list[key].dynamic_url,
layout: this.manifest_.wallpaper_list[key].default_layout,
+ source: 'ONLINE',
+ availableOffline: false,
author: this.manifest_.wallpaper_list[key].author,
authorWebsite: this.manifest_.wallpaper_list[key].author_website,
- availableOffline: false
+ dynamicURL: this.manifest_.wallpaper_list[key].dynamic_url
};
var startIndex = wallpaperInfo.baseURL.lastIndexOf('/') + 1;
var fileName = wallpaperInfo.baseURL.substring(startIndex) +

Powered by Google App Engine
This is Rietveld 408576698