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('dblclick', |
| 44 this.handleImageDblClick_.bind(this)); |
| 45 wallpaperGrid.addEventListener('activate', |
| 46 function() { OptionsPage.closeOverlay() }); |
| 47 |
| 48 $('set-wallpaper-overlay-confirm').onclick = function() { |
| 49 OptionsPage.closeOverlay(); |
| 50 }; |
| 51 |
| 52 chrome.send('onSetWallpaperPageInitialized'); |
| 53 }, |
| 54 |
| 55 /** |
| 56 * Called right after the page has been shown to user. |
| 57 */ |
| 58 didShowPage: function() { |
| 59 $('wallpaper-grid').updateAndFocus(); |
| 60 chrome.send('onSetWallpaperPageShown'); |
| 61 }, |
| 62 |
| 63 /** |
| 64 * Called right before the page is hidden. |
| 65 */ |
| 66 willHidePage: function() { |
| 67 var wallpaperGrid = $('wallpaper-grid'); |
| 68 wallpaperGrid.blur(); |
| 69 }, |
| 70 |
| 71 /** |
| 72 * Handles image selection change. |
| 73 * @private |
| 74 */ |
| 75 handleImageSelected_: function() { |
| 76 var wallpaperGrid = $('wallpaper-grid'); |
| 77 var index = wallpaperGrid.selectionModel.selectedIndex; |
| 78 // Ignore deselection, selection change caused by program itself and |
| 79 // selection of one of the action buttons. |
| 80 if (index != -1 && |
| 81 !wallpaperGrid.inProgramSelection) { |
| 82 chrome.send('selectWallpaper', [index.toString()]); |
| 83 } |
| 84 }, |
| 85 |
| 86 /** |
| 87 * Handles double click on the image grid. |
| 88 * @param {Event} e Double click Event. |
| 89 */ |
| 90 handleImageDblClick_: function(e) { |
| 91 // Close page unless the click target is the grid itself. |
| 92 if (e.target instanceof HTMLImageElement) |
| 93 OptionsPage.closeOverlay(); |
| 94 }, |
| 95 |
| 96 /** |
| 97 * Selects user image with the given index. |
| 98 * @param {int} index index of the image to select. |
| 99 * @private |
| 100 */ |
| 101 setSelectedImage_: function(index) { |
| 102 var wallpaperGrid = $('wallpaper-grid'); |
| 103 wallpaperGrid.selectionModel.selectedIndex = index; |
| 104 wallpaperGrid.selectionModel.leadIndex = index; |
| 105 }, |
| 106 |
| 107 /** |
| 108 * Appends default images to the image grid. Should only be called once. |
| 109 * @param {Array.<string>} images An array of URLs to default images. |
| 110 * @private |
| 111 */ |
| 112 setDefaultImages_: function(images) { |
| 113 var wallpaperGrid = $('wallpaper-grid'); |
| 114 for (var i = 0, url; url = images[i]; i++) |
| 115 wallpaperGrid.addItem(url); |
| 116 }, |
| 117 |
| 118 }; |
| 119 |
| 120 // Forward public APIs to private implementations. |
| 121 [ |
| 122 'setDefaultImages', |
| 123 'setSelectedImage' |
| 124 ].forEach(function(name) { |
| 125 SetWallpaperOptions[name] = function() { |
| 126 var instance = SetWallpaperOptions.getInstance(); |
| 127 return instance[name + '_'].apply(instance, arguments); |
| 128 }; |
| 129 }); |
| 130 |
| 131 // Export |
| 132 return { |
| 133 SetWallpaperOptions: SetWallpaperOptions |
| 134 }; |
| 135 |
| 136 }); |
| 137 |
OLD | NEW |