OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 /** | 5 /** |
6 * WallpaperManager constructor. | 6 * WallpaperManager constructor. |
7 * | 7 * |
8 * WallpaperManager objects encapsulate the functionality of the wallpaper | 8 * WallpaperManager objects encapsulate the functionality of the wallpaper |
9 * manager extension. | 9 * manager extension. |
10 * | 10 * |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 window.addEventListener('online', function() { | 267 window.addEventListener('online', function() { |
268 self.downloadedListMap_ = null; | 268 self.downloadedListMap_ = null; |
269 $('wallpaper-grid').classList.remove('image-picker-offline'); | 269 $('wallpaper-grid').classList.remove('image-picker-offline'); |
270 }); | 270 }); |
271 } | 271 } |
272 $('window-close-button').addEventListener('click', function() { | 272 $('window-close-button').addEventListener('click', function() { |
273 window.close(); | 273 window.close(); |
274 }); | 274 }); |
275 this.document_.defaultView.addEventListener( | 275 this.document_.defaultView.addEventListener( |
276 'resize', this.onResize_.bind(this)); | 276 'resize', this.onResize_.bind(this)); |
| 277 this.document_.defaultView.addEventListener( |
| 278 'keydown', this.onKeyDown_.bind(this)); |
277 $('learn-more').href = LearnMoreURL; | 279 $('learn-more').href = LearnMoreURL; |
278 $('close-error').addEventListener('click', function() { | 280 $('close-error').addEventListener('click', function() { |
279 $('error-container').hidden = true; | 281 $('error-container').hidden = true; |
280 }); | 282 }); |
281 $('close-wallpaper-selection').addEventListener('click', function() { | 283 $('close-wallpaper-selection').addEventListener('click', function() { |
282 $('wallpaper-selection-container').hidden = true; | 284 $('wallpaper-selection-container').hidden = true; |
283 $('set-wallpaper-layout').disabled = true; | 285 $('set-wallpaper-layout').disabled = true; |
284 }); | 286 }); |
285 | 287 |
286 this.onResize_(); | 288 this.onResize_(); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 | 648 |
647 /** | 649 /** |
648 * Resize thumbnails grid and categories list to fit the new window size. | 650 * Resize thumbnails grid and categories list to fit the new window size. |
649 */ | 651 */ |
650 WallpaperManager.prototype.onResize_ = function() { | 652 WallpaperManager.prototype.onResize_ = function() { |
651 this.wallpaperGrid_.redraw(); | 653 this.wallpaperGrid_.redraw(); |
652 this.categoriesList_.redraw(); | 654 this.categoriesList_.redraw(); |
653 }; | 655 }; |
654 | 656 |
655 /** | 657 /** |
| 658 * Close the last opened overlay on pressing the Escape key. |
| 659 * @param {Event} event A keydown event. |
| 660 */ |
| 661 WallpaperManager.prototype.onKeyDown_ = function(event) { |
| 662 if (event.keyCode == 27) { |
| 663 // The last opened overlay coincides with the first match of querySelector |
| 664 // because the Error Container is declared in the DOM before the Wallpaper |
| 665 // Selection Container. |
| 666 // TODO(bshe): Make the overlay selection not dependent on the DOM. |
| 667 var closeButtonSelector = '.overlay-container:not([hidden]) .close'; |
| 668 var closeButton = this.document_.querySelector(closeButtonSelector); |
| 669 if (closeButton) { |
| 670 closeButton.click(); |
| 671 event.preventDefault(); |
| 672 } |
| 673 } |
| 674 }; |
| 675 |
| 676 /** |
656 * Constructs the categories list. | 677 * Constructs the categories list. |
657 */ | 678 */ |
658 WallpaperManager.prototype.initCategoriesList_ = function() { | 679 WallpaperManager.prototype.initCategoriesList_ = function() { |
659 this.categoriesList_ = $('categories-list'); | 680 this.categoriesList_ = $('categories-list'); |
660 cr.ui.List.decorate(this.categoriesList_); | 681 cr.ui.List.decorate(this.categoriesList_); |
661 // cr.ui.list calculates items in view port based on client height and item | 682 // cr.ui.list calculates items in view port based on client height and item |
662 // height. However, categories list is displayed horizontally. So we should | 683 // height. However, categories list is displayed horizontally. So we should |
663 // not calculate visible items here. Sets autoExpands to true to show every | 684 // not calculate visible items here. Sets autoExpands to true to show every |
664 // item in the list. | 685 // item in the list. |
665 // TODO(bshe): Use ul to replace cr.ui.list for category list. | 686 // TODO(bshe): Use ul to replace cr.ui.list for category list. |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 } | 1006 } |
986 } | 1007 } |
987 } | 1008 } |
988 this.wallpaperGrid_.dataModel = wallpapersDataModel; | 1009 this.wallpaperGrid_.dataModel = wallpapersDataModel; |
989 this.wallpaperGrid_.selectedItem = selectedItem; | 1010 this.wallpaperGrid_.selectedItem = selectedItem; |
990 this.wallpaperGrid_.activeItem = selectedItem; | 1011 this.wallpaperGrid_.activeItem = selectedItem; |
991 } | 1012 } |
992 }; | 1013 }; |
993 | 1014 |
994 })(); | 1015 })(); |
OLD | NEW |