Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 | 6 |
| 7 var OptionsPage = options.OptionsPage; | 7 var OptionsPage = options.OptionsPage; |
| 8 var UserImagesGrid = options.UserImagesGrid; | 8 var UserImagesGrid = options.UserImagesGrid; |
| 9 | 9 |
| 10 /** @const */ var CustomWallpaperPrefix = 'chrome://wallpaper/custom_'; | |
|
James Hawkins
2012/05/06 15:49:50
nit: Variables start lowerCase.
However, this is
bshe
2012/05/08 22:22:18
Done.
| |
| 11 | |
| 10 ///////////////////////////////////////////////////////////////////////////// | 12 ///////////////////////////////////////////////////////////////////////////// |
| 11 // SetWallpaperOptions class: | 13 // SetWallpaperOptions class: |
| 12 | 14 |
| 13 /** | 15 /** |
| 14 * Encapsulated handling of ChromeOS set wallpaper options page. | 16 * Encapsulated handling of ChromeOS set wallpaper options page. |
| 15 * @constructor | 17 * @constructor |
| 16 */ | 18 */ |
| 17 function SetWallpaperOptions() { | 19 function SetWallpaperOptions() { |
| 18 OptionsPage.call( | 20 OptionsPage.call( |
| 19 this, | 21 this, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 40 | 42 |
| 41 wallpaperGrid.addEventListener('change', | 43 wallpaperGrid.addEventListener('change', |
| 42 this.handleImageSelected_.bind(this)); | 44 this.handleImageSelected_.bind(this)); |
| 43 wallpaperGrid.addEventListener('dblclick', | 45 wallpaperGrid.addEventListener('dblclick', |
| 44 this.handleImageDblClick_.bind(this)); | 46 this.handleImageDblClick_.bind(this)); |
| 45 wallpaperGrid.addEventListener('activate', | 47 wallpaperGrid.addEventListener('activate', |
| 46 function() { OptionsPage.closeOverlay() }); | 48 function() { OptionsPage.closeOverlay() }); |
| 47 | 49 |
| 48 $('random-wallpaper-checkbox').addEventListener('click', | 50 $('random-wallpaper-checkbox').addEventListener('click', |
| 49 this.handleCheckboxClick_.bind(this)); | 51 this.handleCheckboxClick_.bind(this)); |
| 52 $('set-custome-wallpaper').addEventListener('click', | |
| 53 this.handleChooseFile_); | |
| 54 $('set-wallpaper-layout').addEventListener('change', | |
| 55 this.handleLayoutChange_); | |
| 50 $('set-wallpaper-overlay-confirm').onclick = function() { | 56 $('set-wallpaper-overlay-confirm').onclick = function() { |
| 51 OptionsPage.closeOverlay(); | 57 OptionsPage.closeOverlay(); |
| 52 }; | 58 }; |
| 53 | 59 |
| 54 // @type {Array.<author: string, url: string, website: string>} | 60 // @type {Array.<author: string, url: string, website: string>} |
| 55 this.wallpapers_ = []; | 61 this.wallpapers_ = []; |
| 56 | 62 |
| 63 this.oldImage_ = null; | |
|
James Hawkins
2012/05/06 15:49:50
Document.
bshe
2012/05/08 22:22:18
Done.
| |
| 64 | |
| 57 chrome.send('onSetWallpaperPageInitialized'); | 65 chrome.send('onSetWallpaperPageInitialized'); |
| 58 }, | 66 }, |
| 59 | 67 |
| 60 /** | 68 /** |
| 61 * Called right after the page has been shown to user. | 69 * Called right after the page has been shown to user. |
| 62 */ | 70 */ |
| 63 didShowPage: function() { | 71 didShowPage: function() { |
| 64 $('wallpaper-grid').updateAndFocus(); | 72 $('wallpaper-grid').updateAndFocus(); |
| 65 // A quick hack to fix issue 118472. This is a general problem of list | 73 // A quick hack to fix issue 118472. This is a general problem of list |
| 66 // control and options overlay. | 74 // control and options overlay. |
| 67 // TODO(bshe): Remove this hack when we fixed the general problem which | 75 // TODO(bshe): Remove this hack when we fixed the general problem which |
| 68 // tracked in issue 118829. | 76 // tracked in issue 118829. |
| 69 $('wallpaper-grid').redraw(); | 77 $('wallpaper-grid').redraw(); |
| 70 chrome.send('onSetWallpaperPageShown'); | 78 chrome.send('onSetWallpaperPageShown'); |
| 71 }, | 79 }, |
| 72 | 80 |
| 73 /** | 81 /** |
| 74 * Called right before the page is hidden. | 82 * Called right before the page is hidden. |
| 75 */ | 83 */ |
| 76 willHidePage: function() { | 84 willHidePage: function() { |
| 77 var wallpaperGrid = $('wallpaper-grid'); | 85 var wallpaperGrid = $('wallpaper-grid'); |
| 78 wallpaperGrid.blur(); | 86 wallpaperGrid.blur(); |
| 87 if (this.oldImage_) { | |
| 88 wallpaperGrid.removeItem(this.oldImage_); | |
| 89 this.oldImage_ = null; | |
| 90 } | |
| 91 $('set-wallpaper-layout').innerText = ''; | |
| 79 }, | 92 }, |
| 80 | 93 |
| 81 /** | 94 /** |
| 82 * Set attributions of wallpaper with given URL. | 95 * Set attributions of wallpaper with given URL. |
| 83 * @param {string} url URL of the selected wallpaper. | 96 * @param {string} url URL of the selected wallpaper. |
| 84 * @private | 97 * @private |
| 85 */ | 98 */ |
| 86 setWallpaperAttribution_: function(url) { | 99 setWallpaperAttribution_: function(url) { |
| 87 for (var i = 0; i < this.wallpapers_.length; i++) { | 100 for (var i = 0; i < this.wallpapers_.length; i++) { |
| 88 if (this.wallpapers_[i].url == url) { | 101 if (this.wallpapers_[i].url == url) { |
| 89 $('author-name').textContent = this.wallpapers_[i].author; | 102 $('author-name').textContent = this.wallpapers_[i].author; |
| 90 $('author-website').textContent = this.wallpapers_[i].website; | 103 $('author-website').textContent = this.wallpapers_[i].website; |
| 91 return; | 104 return; |
| 92 } | 105 } |
| 93 } | 106 } |
| 94 $('author-name').textContent = ''; | 107 $('author-name').textContent = ''; |
| 95 $('author-website').textContent = ''; | 108 $('author-website').textContent = ''; |
| 96 }, | 109 }, |
| 97 | 110 |
| 98 /** | 111 /** |
| 112 * Populate the drop down box for custom wallpaper layout. | |
| 113 * param {string} layouts Available wallpaper layout. | |
|
flackr
2012/05/04 19:06:17
s/layout/layouts
bshe
2012/05/08 22:22:18
Done.
| |
| 114 * param {number} selectedLayout The value of selected/default layout. | |
| 115 * @private | |
| 116 */ | |
| 117 populateWallpaperLayout_: function(layouts, selectedLayout) { | |
|
flackr
2012/05/04 19:06:17
s/populateWallpaperLayout/populateWallpaperLayouts
bshe
2012/05/08 22:22:18
Done.
| |
| 118 var wallpaperLayout = $('set-wallpaper-layout'); | |
| 119 var selectedIndex = -1; | |
| 120 for (var i = 0; i < layouts.length; i++) { | |
| 121 var option = new Option(layouts[i]['name'], layouts[i]['index']); | |
| 122 if (selectedLayout == option.value) | |
| 123 selectedIndex = i; | |
| 124 wallpaperLayout.appendChild(option); | |
| 125 } | |
| 126 if (selectedIndex >= 0) | |
| 127 wallpaperLayout.selectedIndex = selectedIndex; | |
| 128 }, | |
| 129 | |
| 130 /** | |
| 131 * Handles "Custom..." button activation. | |
| 132 * @private | |
| 133 */ | |
| 134 handleChooseFile_: function() { | |
| 135 chrome.send('chooseWallpaper'); | |
| 136 }, | |
| 137 | |
| 138 /** | |
| 139 * Handle the wallpaper layout setting change. | |
| 140 * @private | |
| 141 */ | |
| 142 handleLayoutChange_: function() { | |
| 143 var setWallpaperLayout = $('set-wallpaper-layout'); | |
| 144 var layout = setWallpaperLayout.options[ | |
| 145 setWallpaperLayout.selectedIndex].value; | |
| 146 //var value = event.target.options[event.target.selectedIndex].value; | |
|
flackr
2012/05/04 19:06:17
Remove commented code.
bshe
2012/05/08 22:22:18
Done.
| |
| 147 chrome.send('changeWallpaperLayout', [layout]); | |
| 148 }, | |
| 149 | |
| 150 /** | |
| 99 * Handles image selection change. | 151 * Handles image selection change. |
| 100 * @private | 152 * @private |
| 101 */ | 153 */ |
| 102 handleImageSelected_: function() { | 154 handleImageSelected_: function() { |
| 103 var wallpaperGrid = $('wallpaper-grid'); | 155 var wallpaperGrid = $('wallpaper-grid'); |
| 104 var url = wallpaperGrid.selectedItemUrl; | 156 var url = wallpaperGrid.selectedItemUrl; |
| 105 if (url && | 157 if (url && |
| 106 !wallpaperGrid.inProgramSelection) { | 158 !wallpaperGrid.inProgramSelection) { |
| 159 if (url.indexOf(CustomWallpaperPrefix) != -1) { | |
|
flackr
2012/05/04 19:06:17
This is strictly a prefix right? Maybe if == 0?
bshe
2012/05/08 22:22:18
Done.
| |
| 160 // User custom wallpaper is selected | |
| 161 $('set-wallpaper-layout').hidden = false; | |
| 162 $('attribution-label').hidden = true; | |
| 163 // When users select the custom wallpaper thumbnail from picker UI, | |
| 164 // use the saved layout value and redraw the wallpaper. | |
| 165 this.handleLayoutChange_(); | |
| 166 } else { | |
| 167 $('set-wallpaper-layout').hidden = true; | |
| 168 $('attribution-label').hidden = false; | |
| 169 chrome.send('selectDefaultWallpaper', [url]); | |
| 170 } | |
| 107 this.setWallpaperAttribution_(url); | 171 this.setWallpaperAttribution_(url); |
| 108 chrome.send('selectDefaultWallpaper', [url]); | |
| 109 } | 172 } |
| 110 }, | 173 }, |
| 111 | 174 |
| 112 /** | 175 /** |
| 113 * Handles double click on the image grid. | 176 * Handles double click on the image grid. |
| 114 * @param {Event} e Double click Event. | 177 * @param {Event} e Double click Event. |
| 115 */ | 178 */ |
| 116 handleImageDblClick_: function(e) { | 179 handleImageDblClick_: function(e) { |
| 117 var wallpaperGrid = $('wallpaper-grid'); | 180 var wallpaperGrid = $('wallpaper-grid'); |
| 118 if (wallpaperGrid.disabled) | 181 if (wallpaperGrid.disabled) |
| 119 return; | 182 return; |
| 120 // Close page unless the click target is the grid itself. | 183 // Close page unless the click target is the grid itself. |
| 121 if (e.target instanceof HTMLImageElement) | 184 if (e.target instanceof HTMLImageElement) |
| 122 OptionsPage.closeOverlay(); | 185 OptionsPage.closeOverlay(); |
| 123 }, | 186 }, |
| 124 | 187 |
| 125 /** | 188 /** |
| 126 * Handles click on the "I'm feeling lucky" checkbox. | 189 * Handles click on the "I'm feeling lucky" checkbox. |
| 127 * @private | 190 * @private |
| 128 */ | 191 */ |
| 129 handleCheckboxClick_: function() { | 192 handleCheckboxClick_: function() { |
| 130 var wallpaperGrid = $('wallpaper-grid'); | 193 var wallpaperGrid = $('wallpaper-grid'); |
| 131 if ($('random-wallpaper-checkbox').checked) { | 194 if ($('random-wallpaper-checkbox').checked) { |
| 132 wallpaperGrid.disabled = true; | 195 wallpaperGrid.disabled = true; |
| 196 $('attribution-label').hidden = false; | |
| 133 chrome.send('selectRandomWallpaper'); | 197 chrome.send('selectRandomWallpaper'); |
| 134 wallpaperGrid.classList.add('grayout'); | 198 wallpaperGrid.classList.add('grayout'); |
| 199 $('set-wallpaper-layout').hidden = true; | |
| 135 } else { | 200 } else { |
| 136 wallpaperGrid.disabled = false; | 201 wallpaperGrid.disabled = false; |
| 137 wallpaperGrid.classList.remove('grayout'); | 202 wallpaperGrid.classList.remove('grayout'); |
| 138 // Set the wallpaper type to User::DEFAULT. | 203 // Set the wallpaper type to User::DEFAULT. |
| 139 this.handleImageSelected_(); | 204 this.handleImageSelected_(); |
| 140 } | 205 } |
| 141 }, | 206 }, |
| 142 | 207 |
| 143 /** | 208 /** |
| 144 * Selects corresponding wallpaper thumbnail with the given URL and toggle | 209 * Selects corresponding wallpaper thumbnail with the given URL and toggle |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 172 // TODO(bshe): Ideally we should save author and website with the actual | 237 // TODO(bshe): Ideally we should save author and website with the actual |
| 173 // image (URL) and not use index related storage. This way this data is | 238 // image (URL) and not use index related storage. This way this data is |
| 174 // stored in one place rather than depending on the index to be | 239 // stored in one place rather than depending on the index to be |
| 175 // consistent. | 240 // consistent. |
| 176 for (var i = 0, wallpaper; wallpaper = wallpapers[i]; i++) { | 241 for (var i = 0, wallpaper; wallpaper = wallpapers[i]; i++) { |
| 177 this.wallpapers_.push(wallpaper); | 242 this.wallpapers_.push(wallpaper); |
| 178 wallpaperGrid.addItem(wallpaper.url); | 243 wallpaperGrid.addItem(wallpaper.url); |
| 179 } | 244 } |
| 180 }, | 245 }, |
| 181 | 246 |
| 247 /** | |
| 248 * Called when user select a valid file from file system. Display layout | |
| 249 * drop down box and disable random mode if enabled. | |
| 250 */ | |
| 251 didSelectFile_: function() { | |
| 252 $('set-wallpaper-layout').hidden = false; | |
| 253 var wallpaperGrid = $('wallpaper-grid'); | |
| 254 if ($('random-wallpaper-checkbox').checked) { | |
| 255 $('random-wallpaper-checkbox').checked = false; | |
| 256 wallpaperGrid.disabled = false; | |
| 257 wallpaperGrid.classList.remove('grayout'); | |
| 258 } | |
| 259 }, | |
| 260 | |
| 261 /** | |
| 262 * Get url of current user's custom wallpaper thumbnail. | |
| 263 */ | |
| 264 get currentWallpaperImageUrl() { | |
| 265 return CustomWallpaperPrefix + BrowserOptions.getLoggedInUsername() + | |
| 266 '?id=' + (new Date()).getTime(); | |
|
flackr
2012/05/04 19:06:17
This is non-trivial and non-deterministic, I think
bshe
2012/05/08 22:22:18
Done.
| |
| 267 }, | |
| 268 | |
| 269 /** | |
| 270 * Adds or updates custom user wallpaper thumbnail from file. | |
| 271 * @private | |
| 272 */ | |
| 273 setCustomImage_: function() { | |
| 274 var wallpaperGrid = $('wallpaper-grid'); | |
| 275 var url = this.currentWallpaperImageUrl; | |
| 276 if (this.oldImage_) { | |
| 277 this.oldImage_ = wallpaperGrid.updateItem(this.oldImage_, url); | |
| 278 } else { | |
| 279 // Insert to the end of wallpaper list. | |
| 280 var pos = wallpaperGrid.length; | |
| 281 this.oldImage_ = wallpaperGrid.addItem(url, undefined, undefined, pos); | |
| 282 } | |
| 283 | |
| 284 // Clear attributions for custom wallpaper. | |
| 285 $('attribution-label').hidden = true; | |
| 286 this.setWallpaperAttribution_(''); | |
| 287 wallpaperGrid.selectedItem = this.oldImage_; | |
| 288 // Enable the layout drop down box when custom wallpaper is selected. | |
| 289 $('set-wallpaper-layout').hidden = false; | |
|
flackr
2012/05/04 19:06:17
We're updating the visibility of attribution-label
bshe
2012/05/08 22:22:18
Done.
| |
| 290 }, | |
| 182 }; | 291 }; |
| 183 | 292 |
| 184 // Forward public APIs to private implementations. | 293 // Forward public APIs to private implementations. |
| 185 [ | 294 [ |
| 186 'setDefaultImages', | 295 'setDefaultImages', |
| 187 'setSelectedImage' | 296 'setSelectedImage', |
| 297 'populateWallpaperLayout', | |
| 298 'didSelectFile', | |
| 299 'setCustomImage' | |
| 188 ].forEach(function(name) { | 300 ].forEach(function(name) { |
| 189 SetWallpaperOptions[name] = function() { | 301 SetWallpaperOptions[name] = function() { |
| 190 var instance = SetWallpaperOptions.getInstance(); | 302 var instance = SetWallpaperOptions.getInstance(); |
| 191 return instance[name + '_'].apply(instance, arguments); | 303 return instance[name + '_'].apply(instance, arguments); |
| 192 }; | 304 }; |
| 193 }); | 305 }); |
| 194 | 306 |
| 195 // Export | 307 // Export |
| 196 return { | 308 return { |
| 197 SetWallpaperOptions: SetWallpaperOptions | 309 SetWallpaperOptions: SetWallpaperOptions |
| 198 }; | 310 }; |
| 199 | 311 |
| 200 }); | 312 }); |
| 201 | 313 |
| OLD | NEW |