OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('options', function() { |
| 6 |
| 7 var OptionsPage = options.OptionsPage; |
| 8 var UserImagesGrid = options.UserImagesGrid; |
| 9 |
| 10 ///////////////////////////////////////////////////////////////////////////// |
| 11 // SetWallpaperOptions class: |
| 12 |
| 13 /** |
| 14 * Encapsulated handling of ChromeOS set wallpaper options page. |
| 15 * @constructor |
| 16 */ |
| 17 function SetWallpaperOptions() { |
| 18 OptionsPage.call( |
| 19 this, |
| 20 'setWallpaper', |
| 21 localStrings.getString('setWallpaper'), |
| 22 'set-wallpaper-page'); |
| 23 } |
| 24 |
| 25 cr.addSingletonGetter(SetWallpaperOptions); |
| 26 |
| 27 SetWallpaperOptions.prototype = { |
| 28 // Inherit SetWallpaperOptions from OptionsPage. |
| 29 __proto__: options.OptionsPage.prototype, |
| 30 |
| 31 /** |
| 32 * Initializes SetWallpaperOptions page. |
| 33 */ |
| 34 initializePage: function() { |
| 35 // Call base class implementation to start preferences initialization. |
| 36 OptionsPage.prototype.initializePage.call(this); |
| 37 |
| 38 var wallpaperGrid = $('wallpaper-grid'); |
| 39 UserImagesGrid.decorate(wallpaperGrid); |
| 40 |
| 41 wallpaperGrid.addEventListener('change', |
| 42 this.handleImageSelected_.bind(this)); |
| 43 wallpaperGrid.addEventListener('activate', |
| 44 this.handleImageActivated_.bind(this)); |
| 45 wallpaperGrid.addEventListener('dblclick', |
| 46 this.handleImageDblClick_.bind(this)); |
| 47 |
| 48 $('set-wallpaper-overlay-confirm').onclick = this.closePage_; |
| 49 |
| 50 chrome.send('onSetWallpaperPageInitialized'); |
| 51 }, |
| 52 |
| 53 /** |
| 54 * Called right after the page has been shown to user. |
| 55 */ |
| 56 didShowPage: function() { |
| 57 $('wallpaper-grid').updateAndFocus(); |
| 58 }, |
| 59 |
| 60 /** |
| 61 * Called right before the page is hidden. |
| 62 */ |
| 63 willHidePage: function() { |
| 64 var wallpaperGrid = $('wallpaper-grid'); |
| 65 wallpaperGrid.blur(); |
| 66 }, |
| 67 |
| 68 /** |
| 69 * Closes current page, returning back to Personal Stuff page. |
| 70 * @private |
| 71 */ |
| 72 closePage_: function() { |
| 73 OptionsPage.closeOverlay(); |
| 74 }, |
| 75 |
| 76 /** |
| 77 * Handles image selection change. |
| 78 * @private |
| 79 */ |
| 80 handleImageSelected_: function() { |
| 81 var wallpaperGrid = $('wallpaper-grid'); |
| 82 var index = wallpaperGrid.selectionModel.selectedIndex; |
| 83 // Ignore deselection, selection change caused by program itself and |
| 84 // selection of one of the action buttons. |
| 85 if (index != -1 && |
| 86 !wallpaperGrid.inProgramSelection) { |
| 87 chrome.send('selectWallpaper', [index.toString()]); |
| 88 } |
| 89 }, |
| 90 |
| 91 /** |
| 92 * Handles image activation (by pressing Enter). |
| 93 * @private |
| 94 */ |
| 95 handleImageActivated_: function() { |
| 96 this.closePage_(); |
| 97 }, |
| 98 |
| 99 /** |
| 100 * Handles double click on the image grid. |
| 101 * @param {Event} e Double click Event. |
| 102 */ |
| 103 handleImageDblClick_: function(e) { |
| 104 // Close page unless the click target is the grid itself. |
| 105 if (e.target instanceof HTMLImageElement) |
| 106 this.closePage_(); |
| 107 }, |
| 108 |
| 109 /** |
| 110 * Appends default images to the image grid. Should only be called once. |
| 111 * @param {Array.<string>} images An array of URLs to default images. |
| 112 * @private |
| 113 */ |
| 114 setDefaultImages_: function(images) { |
| 115 var wallpaperGrid = $('wallpaper-grid'); |
| 116 for (var i = 0, url; url = images[i]; i++) { |
| 117 wallpaperGrid.addItem(url); |
| 118 } |
| 119 }, |
| 120 |
| 121 }; |
| 122 |
| 123 // Forward public APIs to private implementations. |
| 124 [ |
| 125 'setDefaultImages', |
| 126 ].forEach(function(name) { |
| 127 SetWallpaperOptions[name] = function() { |
| 128 var instance = SetWallpaperOptions.getInstance(); |
| 129 return instance[name + '_'].apply(instance, arguments); |
| 130 }; |
| 131 }); |
| 132 |
| 133 // Export |
| 134 return { |
| 135 SetWallpaperOptions: SetWallpaperOptions |
| 136 }; |
| 137 |
| 138 }); |
| 139 |
OLD | NEW |