Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Side by Side Diff: chrome/browser/resources/options2/chromeos/set_wallpaper_options.js

Issue 9580023: Enable user change background image in settings page in Aura build. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Address review Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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));
James Hawkins 2012/03/08 14:30:39 Indentation is off.
bshe 2012/03/08 16:36:40 Done.
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 chrome.send('onSetWallpaperPageShown');
59 },
60
61 /**
62 * Called right before the page is hidden.
63 */
64 willHidePage: function() {
65 var wallpaperGrid = $('wallpaper-grid');
66 wallpaperGrid.blur();
67 },
68
69 /**
70 * Closes current page, returning back to Personal Stuff page.
71 * @private
72 */
73 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
74 OptionsPage.closeOverlay();
75 },
76
77 /**
78 * Handles image selection change.
79 * @private
80 */
81 handleImageSelected_: function() {
82 var wallpaperGrid = $('wallpaper-grid');
83 var index = wallpaperGrid.selectionModel.selectedIndex;
84 // Ignore deselection, selection change caused by program itself and
85 // selection of one of the action buttons.
86 if (index != -1 &&
87 !wallpaperGrid.inProgramSelection) {
88 chrome.send('selectWallpaper', [index.toString()]);
89 }
90 },
91
92 /**
93 * Handles image activation (by pressing Enter).
94 * @private
95 */
96 handleImageActivated_: function() {
97 this.closePage_();
98 },
99
100 /**
101 * Handles double click on the image grid.
102 * @param {Event} e Double click Event.
103 */
104 handleImageDblClick_: function(e) {
105 // Close page unless the click target is the grid itself.
106 if (e.target instanceof HTMLImageElement)
107 this.closePage_();
108 },
109
110 /**
111 * Selects user image with the given index.
112 * @param {int} index index of the image to select.
113 * @private
114 */
115 setSelectedImage_: function(index) {
116 $('wallpaper-grid').selectionModel.selectedIndex = index;
117 },
118
119 /**
120 * Appends default images to the image grid. Should only be called once.
121 * @param {Array.<string>} images An array of URLs to default images.
122 * @private
123 */
124 setDefaultImages_: function(images) {
125 var wallpaperGrid = $('wallpaper-grid');
126 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.
127 wallpaperGrid.addItem(url);
128 }
129 },
130
131 };
132
133 // Forward public APIs to private implementations.
134 [
135 'setDefaultImages',
136 'setSelectedImage'
137 ].forEach(function(name) {
138 SetWallpaperOptions[name] = function() {
139 var instance = SetWallpaperOptions.getInstance();
140 return instance[name + '_'].apply(instance, arguments);
141 };
142 });
143
144 // Export
145 return {
146 SetWallpaperOptions: SetWallpaperOptions
147 };
148
149 });
150
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698