Chromium Code Reviews| Index: chrome/browser/resources/options2/chromeos/set_wallpaper_options.js |
| diff --git a/chrome/browser/resources/options2/chromeos/set_wallpaper_options.js b/chrome/browser/resources/options2/chromeos/set_wallpaper_options.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ee0007bbc8804161896280728dfc397c9fcee964 |
| --- /dev/null |
| +++ b/chrome/browser/resources/options2/chromeos/set_wallpaper_options.js |
| @@ -0,0 +1,150 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +cr.define('options', function() { |
| + |
| + var OptionsPage = options.OptionsPage; |
| + var UserImagesGrid = options.UserImagesGrid; |
| + |
| + ///////////////////////////////////////////////////////////////////////////// |
| + // SetWallpaperOptions class: |
| + |
| + /** |
| + * Encapsulated handling of ChromeOS set wallpaper options page. |
| + * @constructor |
| + */ |
| + function SetWallpaperOptions() { |
| + OptionsPage.call( |
| + this, |
| + 'setWallpaper', |
| + localStrings.getString('setWallpaper'), |
| + 'set-wallpaper-page'); |
| + } |
| + |
| + cr.addSingletonGetter(SetWallpaperOptions); |
| + |
| + SetWallpaperOptions.prototype = { |
| + // Inherit SetWallpaperOptions from OptionsPage. |
| + __proto__: options.OptionsPage.prototype, |
| + |
| + /** |
| + * Initializes SetWallpaperOptions page. |
| + */ |
| + initializePage: function() { |
| + // Call base class implementation to start preferences initialization. |
| + OptionsPage.prototype.initializePage.call(this); |
| + |
| + var wallpaperGrid = $('wallpaper-grid'); |
| + UserImagesGrid.decorate(wallpaperGrid); |
| + |
| + wallpaperGrid.addEventListener('change', |
| + this.handleImageSelected_.bind(this)); |
|
James Hawkins
2012/03/08 14:30:39
Indentation is off.
bshe
2012/03/08 16:36:40
Done.
|
| + wallpaperGrid.addEventListener('activate', |
| + this.handleImageActivated_.bind(this)); |
| + wallpaperGrid.addEventListener('dblclick', |
| + this.handleImageDblClick_.bind(this)); |
| + |
| + $('set-wallpaper-overlay-confirm').onclick = this.closePage_; |
| + |
| + chrome.send('onSetWallpaperPageInitialized'); |
| + }, |
| + |
| + /** |
| + * Called right after the page has been shown to user. |
| + */ |
| + didShowPage: function() { |
| + $('wallpaper-grid').updateAndFocus(); |
| + chrome.send('onSetWallpaperPageShown'); |
| + }, |
| + |
| + /** |
| + * Called right before the page is hidden. |
| + */ |
| + willHidePage: function() { |
| + var wallpaperGrid = $('wallpaper-grid'); |
| + wallpaperGrid.blur(); |
| + }, |
| + |
| + /** |
| + * Closes current page, returning back to Personal Stuff page. |
| + * @private |
| + */ |
| + closePage_: function() { |
|
James Hawkins
2012/03/08 14:30:39
Why do you need this method? Just use OptionsPage
bshe
2012/03/08 16:36:40
There are three different places use this and one
|
| + OptionsPage.closeOverlay(); |
| + }, |
| + |
| + /** |
| + * Handles image selection change. |
| + * @private |
| + */ |
| + handleImageSelected_: function() { |
| + var wallpaperGrid = $('wallpaper-grid'); |
| + var index = wallpaperGrid.selectionModel.selectedIndex; |
| + // Ignore deselection, selection change caused by program itself and |
| + // selection of one of the action buttons. |
| + if (index != -1 && |
| + !wallpaperGrid.inProgramSelection) { |
| + chrome.send('selectWallpaper', [index.toString()]); |
| + } |
| + }, |
| + |
| + /** |
| + * Handles image activation (by pressing Enter). |
| + * @private |
| + */ |
| + handleImageActivated_: function() { |
| + this.closePage_(); |
| + }, |
| + |
| + /** |
| + * Handles double click on the image grid. |
| + * @param {Event} e Double click Event. |
| + */ |
| + handleImageDblClick_: function(e) { |
| + // Close page unless the click target is the grid itself. |
| + if (e.target instanceof HTMLImageElement) |
| + this.closePage_(); |
| + }, |
| + |
| + /** |
| + * Selects user image with the given index. |
| + * @param {int} index index of the image to select. |
| + * @private |
| + */ |
| + setSelectedImage_: function(index) { |
| + $('wallpaper-grid').selectionModel.selectedIndex = index; |
| + }, |
| + |
| + /** |
| + * Appends default images to the image grid. Should only be called once. |
| + * @param {Array.<string>} images An array of URLs to default images. |
| + * @private |
| + */ |
| + setDefaultImages_: function(images) { |
| + var wallpaperGrid = $('wallpaper-grid'); |
| + for (var i = 0, url; url = images[i]; i++) { |
|
James Hawkins
2012/03/08 14:30:39
nit: No braces.
bshe
2012/03/08 16:36:40
Done.
|
| + wallpaperGrid.addItem(url); |
| + } |
| + }, |
| + |
| + }; |
| + |
| + // Forward public APIs to private implementations. |
| + [ |
| + 'setDefaultImages', |
| + 'setSelectedImage' |
| + ].forEach(function(name) { |
| + SetWallpaperOptions[name] = function() { |
| + var instance = SetWallpaperOptions.getInstance(); |
| + return instance[name + '_'].apply(instance, arguments); |
| + }; |
| + }); |
| + |
| + // Export |
| + return { |
| + SetWallpaperOptions: SetWallpaperOptions |
| + }; |
| + |
| +}); |
| + |