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 /** | 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')) { |
| 194 if (this.isNewOobe()) { | |
|
Nikita (slow)
2012/08/10 08:43:21
Please leave support for this flag for now.
Ivan Korotkov
2012/08/10 10:12:41
Done.
| |
| 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) { | 223 oldStep.addEventListener('webkitTransitionEnd', function f(e) { |
| 202 oldStep.removeEventListener('webkitTransitionEnd', f); | 224 oldStep.removeEventListener('webkitTransitionEnd', f); |
| 203 if (oldStep.classList.contains('faded') || | 225 if (oldStep.classList.contains('faded') || |
| 204 oldStep.classList.contains('left') || | 226 oldStep.classList.contains('left') || |
| 205 oldStep.classList.contains('right')) { | 227 oldStep.classList.contains('right')) { |
| 206 oldStep.classList.add('hidden'); | 228 oldStep.classList.add('hidden'); |
| 207 } | 229 } |
| 208 }); | 230 }); |
| 231 } else { | |
| 232 oldStep.classList.add('hidden'); | |
| 209 } | 233 } |
| 210 } else { | 234 } else { |
| 235 // TODO(ivankr): initial animation. | |
|
Nikita (slow)
2012/08/10 08:43:21
Could you please add it as a part of this CL if po
Ivan Korotkov
2012/08/10 10:12:41
Done.
| |
| 211 // First screen on OOBE launch. | 236 // First screen on OOBE launch. |
| 212 newHeader.classList.remove('right'); | 237 newHeader.classList.remove('right'); |
| 213 // Report back first OOBE screen being painted. | 238 // Report back first OOBE screen being painted. |
| 214 window.webkitRequestAnimationFrame(function() { | 239 window.webkitRequestAnimationFrame(function() { |
| 215 chrome.send('loginVisible'); | 240 chrome.send('loginVisible'); |
| 216 }); | 241 }); |
| 217 } | 242 } |
| 218 this.currentStep_ = nextStepIndex; | 243 this.currentStep_ = nextStepIndex; |
| 219 $('oobe').className = nextStepId; | 244 $('oobe').className = nextStepId; |
| 245 | |
| 246 $('step-logo').hidden = newStep.classList.contains('no-logo'); | |
| 220 }, | 247 }, |
| 221 | 248 |
| 222 /** | 249 /** |
| 223 * Show screen of given screen id. | 250 * Show screen of given screen id. |
| 224 * @param {Object} screen Screen params dict, | 251 * @param {Object} screen Screen params dict, |
| 225 * e.g. {id: screenId, data: data}. | 252 * e.g. {id: screenId, data: data}. |
| 226 */ | 253 */ |
| 227 showScreen: function(screen) { | 254 showScreen: function(screen) { |
| 228 var screenId = screen.id; | 255 var screenId = screen.id; |
| 229 | 256 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 | 303 |
| 277 if (this.isNewOobe()) | 304 if (this.isNewOobe()) |
| 278 $('progress-dots').appendChild(dot); | 305 $('progress-dots').appendChild(dot); |
| 279 else | 306 else |
| 280 $('progress').appendChild(dot); | 307 $('progress').appendChild(dot); |
| 281 | 308 |
| 282 this.appendButtons_(el.buttons, screenId); | 309 this.appendButtons_(el.buttons, screenId); |
| 283 }, | 310 }, |
| 284 | 311 |
| 285 /** | 312 /** |
| 286 * Updates inner container size based on the size of the current screen. | 313 * Updates inner container size based on the size of the current screen and |
| 314 * other screens in the same group. | |
| 287 * Should be executed on screen change / screen size change. | 315 * Should be executed on screen change / screen size change. |
| 288 * @param {!HTMLElement} screen Screen that is being shown. | 316 * @param {!HTMLElement} screen Screen that is being shown. |
| 289 */ | 317 */ |
| 290 updateInnerContainerSize_: function(screen) { | 318 updateInnerContainerSize_: function(screen) { |
| 291 $('inner-container').style.height = screen.offsetHeight + 'px'; | 319 var height = screen.offsetHeight; |
| 292 if (this.isNewOobe()) | 320 var width = screen.offsetWidth; |
| 293 $('inner-container').style.width = screen.offsetWidth + 'px'; | 321 for (var i = 0, screenGroup; screenGroup = SCREEN_GROUPS[i]; i++) { |
| 322 if (screenGroup.indexOf(screen.id) != -1) { | |
| 323 // Set screen dimensions to maximum dimensions within this group. | |
| 324 for (var j = 0, screen2; screen2 = $(screenGroup[j]); j++) { | |
|
Nikita (slow)
2012/08/10 08:43:21
We might as well cache these max values.
| |
| 325 height = Math.max(height, screen2.offsetHeight); | |
| 326 width = Math.max(width, screen2.offsetWidth); | |
| 327 } | |
| 328 break; | |
| 329 } | |
| 330 } | |
| 331 $('inner-container').style.height = height + 'px'; | |
| 332 if (this.isNewOobe()) { | |
| 333 $('inner-container').style.width = width + 'px'; | |
| 334 // This requires |screen| to have |box-sizing: border-box|. | |
| 335 screen.style.width = width + 'px'; | |
| 336 screen.style.height = height + 'px'; | |
| 337 } | |
| 294 }, | 338 }, |
| 295 | 339 |
| 296 /** | 340 /** |
| 297 * Updates localized content of the screens like headers, buttons and links. | 341 * Updates localized content of the screens like headers, buttons and links. |
| 298 * Should be executed on language change. | 342 * Should be executed on language change. |
| 299 */ | 343 */ |
| 300 updateLocalizedContent_: function() { | 344 updateLocalizedContent_: function() { |
| 301 if (!this.isNewOobe()) | 345 if (!this.isNewOobe()) |
| 302 $('button-strip').innerHTML = ''; | 346 $('button-strip').innerHTML = ''; |
| 303 for (var i = 0, screenId; screenId = this.screens_[i]; ++i) { | 347 for (var i = 0, screenId; screenId = this.screens_[i]; ++i) { |
| 304 var screen = $(screenId); | 348 var screen = $(screenId); |
| 305 if (this.isNewOobe()) { | 349 if (this.isNewOobe()) { |
| 306 buttonStrip = $(screenId + '-controls'); | 350 var buttonStrip = $(screenId + '-controls'); |
| 307 if (buttonStrip) | 351 if (buttonStrip) |
| 308 buttonStrip.innerHTML = ''; | 352 buttonStrip.innerHTML = ''; |
| 309 // TODO(nkostylev): Update screen headers for new OOBE design. | 353 // TODO(nkostylev): Update screen headers for new OOBE design. |
| 310 } else { | 354 } else { |
| 311 $('header-' + screenId).textContent = screen.header; | 355 $('header-' + screenId).textContent = screen.header; |
| 312 } | 356 } |
| 313 this.appendButtons_(screen.buttons, screenId); | 357 this.appendButtons_(screen.buttons, screenId); |
| 314 if (screen.updateLocalizedContent) | 358 if (screen.updateLocalizedContent) |
| 315 screen.updateLocalizedContent(); | 359 screen.updateLocalizedContent(); |
| 316 } | 360 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 }); | 542 }); |
| 499 } | 543 } |
| 500 } | 544 } |
| 501 }; | 545 }; |
| 502 | 546 |
| 503 // Export | 547 // Export |
| 504 return { | 548 return { |
| 505 DisplayManager: DisplayManager | 549 DisplayManager: DisplayManager |
| 506 }; | 550 }; |
| 507 }); | 551 }); |
| OLD | NEW |