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 /** | 5 /** |
6 * @fileoverview Display manager for WebUI OOBE and login. | 6 * @fileoverview Display manager for WebUI OOBE and login. |
7 */ | 7 */ |
8 | 8 |
9 // TODO(xiyuan): Find a better to share those constants. | 9 // TODO(xiyuan): Find a better to share those constants. |
10 /** @const */ var SCREEN_OOBE_NETWORK = 'connect'; | 10 /** @const */ var SCREEN_OOBE_NETWORK = 'connect'; |
11 /** @const */ var SCREEN_OOBE_EULA = 'eula'; | 11 /** @const */ var SCREEN_OOBE_EULA = 'eula'; |
| 12 /** @const */ var SCREEN_OOBE_UPDATE = 'update'; |
12 /** @const */ var SCREEN_OOBE_ENROLLMENT = 'oauth-enrollment'; | 13 /** @const */ var SCREEN_OOBE_ENROLLMENT = 'oauth-enrollment'; |
13 /** @const */ var SCREEN_GAIA_SIGNIN = 'gaia-signin'; | 14 /** @const */ var SCREEN_GAIA_SIGNIN = 'gaia-signin'; |
14 /** @const */ var SCREEN_ACCOUNT_PICKER = 'account-picker'; | 15 /** @const */ var SCREEN_ACCOUNT_PICKER = 'account-picker'; |
15 | 16 |
16 /* Accelerator identifiers. Must be kept in sync with webui_login_view.cc. */ | 17 /* Accelerator identifiers. Must be kept in sync with webui_login_view.cc. */ |
17 /** @const */ var ACCELERATOR_CANCEL = 'cancel'; | 18 /** @const */ var ACCELERATOR_CANCEL = 'cancel'; |
18 /** @const */ var ACCELERATOR_ENROLLMENT = 'enrollment'; | 19 /** @const */ var ACCELERATOR_ENROLLMENT = 'enrollment'; |
19 /** @const */ var ACCELERATOR_VERSION = 'version'; | 20 /** @const */ var ACCELERATOR_VERSION = 'version'; |
20 | 21 |
21 /* Help topic identifiers. */ | 22 /* Help topic identifiers. */ |
22 /** @const */ var HELP_TOPIC_ENTERPRISE_REPORTING = 2535613; | 23 /** @const */ var HELP_TOPIC_ENTERPRISE_REPORTING = 2535613; |
23 | 24 |
24 cr.define('cr.ui.login', function() { | 25 cr.define('cr.ui.login', function() { |
25 var Bubble = cr.ui.Bubble; | 26 var Bubble = cr.ui.Bubble; |
26 | 27 |
27 /** | 28 /** |
| 29 * Groups of screens (screen IDs) that should have the same dimensions. |
| 30 * @type Array.<Array.<string>> |
| 31 * @const |
| 32 */ |
| 33 var SCREEN_GROUPS = [[SCREEN_OOBE_NETWORK, |
| 34 SCREEN_OOBE_EULA, |
| 35 SCREEN_OOBE_UPDATE] |
| 36 ]; |
| 37 |
| 38 /** |
28 * Constructor a display manager that manages initialization of screens, | 39 * Constructor a display manager that manages initialization of screens, |
29 * transitions, error messages display. | 40 * transitions, error messages display. |
30 * | 41 * |
31 * @constructor | 42 * @constructor |
32 */ | 43 */ |
33 function DisplayManager() { | 44 function DisplayManager() { |
34 } | 45 } |
35 | 46 |
36 DisplayManager.prototype = { | 47 DisplayManager.prototype = { |
37 /** | 48 /** |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 this.currentScreen.cancelAutoEnrollment(); | 113 this.currentScreen.cancelAutoEnrollment(); |
103 } | 114 } |
104 } else if (name == ACCELERATOR_VERSION) { | 115 } else if (name == ACCELERATOR_VERSION) { |
105 if (this.allowToggleVersion_) | 116 if (this.allowToggleVersion_) |
106 $('version-labels').hidden = !$('version-labels').hidden; | 117 $('version-labels').hidden = !$('version-labels').hidden; |
107 } | 118 } |
108 }, | 119 }, |
109 | 120 |
110 /** | 121 /** |
111 * Appends buttons to the button strip. | 122 * Appends buttons to the button strip. |
112 * @param {Array} buttons Array with the buttons to append. | 123 * @param {Array.<HTMLElement>} buttons Array with the buttons to append. |
113 * @param {string} screenId Id of the screen that buttons belong to. | 124 * @param {string} screenId Id of the screen that buttons belong to. |
114 */ | 125 */ |
115 appendButtons_: function(buttons, screenId) { | 126 appendButtons_: function(buttons, screenId) { |
116 if (buttons) { | 127 if (buttons) { |
117 var buttonStrip = null; | 128 var buttonStrip = null; |
118 if (this.isNewOobe()) | 129 if (this.isNewOobe()) |
119 buttonStrip = $(screenId + '-controls'); | 130 buttonStrip = $(screenId + '-controls'); |
120 else | 131 else |
121 buttonStrip = $('button-strip'); | 132 buttonStrip = $('button-strip'); |
122 if (buttonStrip) { | 133 if (buttonStrip) { |
123 for (var i = 0; i < buttons.length; ++i) | 134 for (var i = 0; i < buttons.length; ++i) |
124 buttonStrip.appendChild(buttons[i]); | 135 buttonStrip.appendChild(buttons[i]); |
125 } | 136 } |
126 } | 137 } |
127 }, | 138 }, |
128 | 139 |
129 /** | 140 /** |
| 141 * Disables or enables control buttons on the specified screen. |
| 142 * @param {HTMLElement} screen Screen which controls should be affected. |
| 143 * @param {boolean} disabled Whether to disable controls. |
| 144 */ |
| 145 disableButtons_: function(screen, disabled) { |
| 146 var buttons = document.querySelectorAll( |
| 147 '#' + screen.id + '-controls button'); |
| 148 for (var i = 0; i < buttons.length; ++i) { |
| 149 buttons[i].disabled = disabled; |
| 150 } |
| 151 }, |
| 152 |
| 153 /** |
130 * Updates a step's css classes to reflect left, current, or right position. | 154 * Updates a step's css classes to reflect left, current, or right position. |
131 * @param {number} stepIndex step index. | 155 * @param {number} stepIndex step index. |
132 * @param {string} state one of 'left', 'current', 'right'. | 156 * @param {string} state one of 'left', 'current', 'right'. |
133 */ | 157 */ |
134 updateStep_: function(stepIndex, state) { | 158 updateStep_: function(stepIndex, state) { |
135 var stepId = this.screens_[stepIndex]; | 159 var stepId = this.screens_[stepIndex]; |
136 var step = $(stepId); | 160 var step = $(stepId); |
137 var header = $('header-' + stepId); | 161 var header = $('header-' + stepId); |
138 var states = ['left', 'right', 'current']; | 162 var states = ['left', 'right', 'current']; |
139 for (var i = 0; i < states.length; ++i) { | 163 for (var i = 0; i < states.length; ++i) { |
(...skipping 10 matching lines...) Expand all Loading... |
150 * Switches to the next OOBE step. | 174 * Switches to the next OOBE step. |
151 * @param {number} nextStepIndex Index of the next step. | 175 * @param {number} nextStepIndex Index of the next step. |
152 */ | 176 */ |
153 toggleStep_: function(nextStepIndex, screenData) { | 177 toggleStep_: function(nextStepIndex, screenData) { |
154 var currentStepId = this.screens_[this.currentStep_]; | 178 var currentStepId = this.screens_[this.currentStep_]; |
155 var nextStepId = this.screens_[nextStepIndex]; | 179 var nextStepId = this.screens_[nextStepIndex]; |
156 var oldStep = $(currentStepId); | 180 var oldStep = $(currentStepId); |
157 var newStep = $(nextStepId); | 181 var newStep = $(nextStepId); |
158 var newHeader = $('header-' + nextStepId); | 182 var newHeader = $('header-' + nextStepId); |
159 | 183 |
| 184 // Disable controls before starting animation. |
| 185 this.disableButtons_(oldStep, true); |
| 186 |
160 if (oldStep.onBeforeHide) | 187 if (oldStep.onBeforeHide) |
161 oldStep.onBeforeHide(); | 188 oldStep.onBeforeHide(); |
162 | 189 |
163 if (newStep.onBeforeShow) | 190 if (newStep.onBeforeShow) |
164 newStep.onBeforeShow(screenData); | 191 newStep.onBeforeShow(screenData); |
165 | 192 |
166 newStep.classList.remove('hidden'); | 193 newStep.classList.remove('hidden'); |
167 | 194 |
168 if (newStep.onAfterShow) | 195 if (newStep.onAfterShow) |
169 newStep.onAfterShow(screenData); | 196 newStep.onAfterShow(screenData); |
170 | 197 |
| 198 this.disableButtons_(newStep, false); |
| 199 |
171 if (this.isOobeUI()) { | 200 if (this.isOobeUI()) { |
172 // Start gliding animation for OOBE steps. | 201 // Start gliding animation for OOBE steps. |
173 if (nextStepIndex > this.currentStep_) { | 202 if (nextStepIndex > this.currentStep_) { |
174 for (var i = this.currentStep_; i < nextStepIndex; ++i) | 203 for (var i = this.currentStep_; i < nextStepIndex; ++i) |
175 this.updateStep_(i, 'left'); | 204 this.updateStep_(i, 'left'); |
176 this.updateStep_(nextStepIndex, 'current'); | 205 this.updateStep_(nextStepIndex, 'current'); |
177 } else if (nextStepIndex < this.currentStep_) { | 206 } else if (nextStepIndex < this.currentStep_) { |
178 for (var i = this.currentStep_; i > nextStepIndex; --i) | 207 for (var i = this.currentStep_; i > nextStepIndex; --i) |
179 this.updateStep_(i, 'right'); | 208 this.updateStep_(i, 'right'); |
180 this.updateStep_(nextStepIndex, 'current'); | 209 this.updateStep_(nextStepIndex, 'current'); |
181 } | 210 } |
182 } else { | 211 } else { |
183 // Start fading animation for login display. | 212 // Start fading animation for login display. |
184 oldStep.classList.add('faded'); | 213 oldStep.classList.add('faded'); |
185 newStep.classList.remove('faded'); | 214 newStep.classList.remove('faded'); |
186 } | 215 } |
187 | 216 |
188 // Adjust inner container height based on new step's height. | 217 // Adjust inner container height based on new step's height. |
189 this.updateInnerContainerSize_(newStep); | 218 this.updateInnerContainerSize_(newStep); |
190 | 219 |
191 if (this.currentStep_ != nextStepIndex && | 220 if (this.currentStep_ != nextStepIndex && |
192 !oldStep.classList.contains('hidden')) { | 221 !oldStep.classList.contains('hidden')) { |
193 // TODO(nkostylev): Remove when new transitions are added back. | 222 if (oldStep.classList.contains('animated') || !this.isNewOobe()) { |
194 if (this.isNewOobe()) { | 223 oldStep.classList.add('animation'); |
195 if (oldStep.classList.contains('faded') || | |
196 oldStep.classList.contains('left') || | |
197 oldStep.classList.contains('right')) { | |
198 oldStep.classList.add('hidden'); | |
199 } | |
200 } else { | |
201 oldStep.addEventListener('webkitTransitionEnd', function f(e) { | 224 oldStep.addEventListener('webkitTransitionEnd', function f(e) { |
202 oldStep.removeEventListener('webkitTransitionEnd', f); | 225 oldStep.removeEventListener('webkitTransitionEnd', f); |
203 if (oldStep.classList.contains('faded') || | 226 if (oldStep.classList.contains('faded') || |
204 oldStep.classList.contains('left') || | 227 oldStep.classList.contains('left') || |
205 oldStep.classList.contains('right')) { | 228 oldStep.classList.contains('right')) { |
| 229 oldStep.classList.remove('animation'); |
206 oldStep.classList.add('hidden'); | 230 oldStep.classList.add('hidden'); |
207 } | 231 } |
208 }); | 232 }); |
| 233 } else { |
| 234 oldStep.classList.add('hidden'); |
209 } | 235 } |
210 } else { | 236 } else { |
211 // First screen on OOBE launch. | 237 // First screen on OOBE launch. |
| 238 $('inner-container').classList.remove('down'); |
212 newHeader.classList.remove('right'); | 239 newHeader.classList.remove('right'); |
213 // Report back first OOBE screen being painted. | 240 // Report back first OOBE screen being painted. |
214 window.webkitRequestAnimationFrame(function() { | 241 window.webkitRequestAnimationFrame(function() { |
215 chrome.send('loginVisible'); | 242 chrome.send('loginVisible'); |
216 }); | 243 }); |
217 } | 244 } |
218 this.currentStep_ = nextStepIndex; | 245 this.currentStep_ = nextStepIndex; |
219 $('oobe').className = nextStepId; | 246 $('oobe').className = nextStepId; |
| 247 |
| 248 $('step-logo').hidden = newStep.classList.contains('no-logo'); |
220 }, | 249 }, |
221 | 250 |
222 /** | 251 /** |
223 * Show screen of given screen id. | 252 * Show screen of given screen id. |
224 * @param {Object} screen Screen params dict, | 253 * @param {Object} screen Screen params dict, |
225 * e.g. {id: screenId, data: data}. | 254 * e.g. {id: screenId, data: data}. |
226 */ | 255 */ |
227 showScreen: function(screen) { | 256 showScreen: function(screen) { |
228 var screenId = screen.id; | 257 var screenId = screen.id; |
229 | 258 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 305 |
277 if (this.isNewOobe()) | 306 if (this.isNewOobe()) |
278 $('progress-dots').appendChild(dot); | 307 $('progress-dots').appendChild(dot); |
279 else | 308 else |
280 $('progress').appendChild(dot); | 309 $('progress').appendChild(dot); |
281 | 310 |
282 this.appendButtons_(el.buttons, screenId); | 311 this.appendButtons_(el.buttons, screenId); |
283 }, | 312 }, |
284 | 313 |
285 /** | 314 /** |
286 * Updates inner container size based on the size of the current screen. | 315 * Updates inner container size based on the size of the current screen and |
| 316 * other screens in the same group. |
287 * Should be executed on screen change / screen size change. | 317 * Should be executed on screen change / screen size change. |
288 * @param {!HTMLElement} screen Screen that is being shown. | 318 * @param {!HTMLElement} screen Screen that is being shown. |
289 */ | 319 */ |
290 updateInnerContainerSize_: function(screen) { | 320 updateInnerContainerSize_: function(screen) { |
291 $('inner-container').style.height = screen.offsetHeight + 'px'; | 321 var height = screen.offsetHeight; |
292 if (this.isNewOobe()) | 322 var width = screen.offsetWidth; |
293 $('inner-container').style.width = screen.offsetWidth + 'px'; | 323 for (var i = 0, screenGroup; screenGroup = SCREEN_GROUPS[i]; i++) { |
| 324 if (screenGroup.indexOf(screen.id) != -1) { |
| 325 // Set screen dimensions to maximum dimensions within this group. |
| 326 for (var j = 0, screen2; screen2 = $(screenGroup[j]); j++) { |
| 327 height = Math.max(height, screen2.offsetHeight); |
| 328 width = Math.max(width, screen2.offsetWidth); |
| 329 } |
| 330 break; |
| 331 } |
| 332 } |
| 333 $('inner-container').style.height = height + 'px'; |
| 334 if (this.isNewOobe()) { |
| 335 $('inner-container').style.width = width + 'px'; |
| 336 // This requires |screen| to have |box-sizing: border-box|. |
| 337 screen.style.width = width + 'px'; |
| 338 screen.style.height = height + 'px'; |
| 339 } |
294 }, | 340 }, |
295 | 341 |
296 /** | 342 /** |
297 * Updates localized content of the screens like headers, buttons and links. | 343 * Updates localized content of the screens like headers, buttons and links. |
298 * Should be executed on language change. | 344 * Should be executed on language change. |
299 */ | 345 */ |
300 updateLocalizedContent_: function() { | 346 updateLocalizedContent_: function() { |
301 if (!this.isNewOobe()) | 347 if (!this.isNewOobe()) |
302 $('button-strip').innerHTML = ''; | 348 $('button-strip').innerHTML = ''; |
303 for (var i = 0, screenId; screenId = this.screens_[i]; ++i) { | 349 for (var i = 0, screenId; screenId = this.screens_[i]; ++i) { |
304 var screen = $(screenId); | 350 var screen = $(screenId); |
305 if (this.isNewOobe()) { | 351 if (this.isNewOobe()) { |
306 buttonStrip = $(screenId + '-controls'); | 352 var buttonStrip = $(screenId + '-controls'); |
307 if (buttonStrip) | 353 if (buttonStrip) |
308 buttonStrip.innerHTML = ''; | 354 buttonStrip.innerHTML = ''; |
309 // TODO(nkostylev): Update screen headers for new OOBE design. | 355 // TODO(nkostylev): Update screen headers for new OOBE design. |
310 } else { | 356 } else { |
311 $('header-' + screenId).textContent = screen.header; | 357 $('header-' + screenId).textContent = screen.header; |
312 } | 358 } |
313 this.appendButtons_(screen.buttons, screenId); | 359 this.appendButtons_(screen.buttons, screenId); |
314 if (screen.updateLocalizedContent) | 360 if (screen.updateLocalizedContent) |
315 screen.updateLocalizedContent(); | 361 screen.updateLocalizedContent(); |
316 } | 362 } |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 }); | 544 }); |
499 } | 545 } |
500 } | 546 } |
501 }; | 547 }; |
502 | 548 |
503 // Export | 549 // Export |
504 return { | 550 return { |
505 DisplayManager: DisplayManager | 551 DisplayManager: DisplayManager |
506 }; | 552 }; |
507 }); | 553 }); |
OLD | NEW |